Skip to content

Commit f9b3ccf

Browse files
committed
feat: load custom styles from userData folder #210
1 parent 719cb0f commit f9b3ccf

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

Diff for: electron/main-window.ts

+14-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { join, normalize } from 'path';
1414
import { format } from 'url';
1515
import { IPC } from './ipc-events.const';
1616
import { getSettings } from './get-settings';
17+
import { readFileSync, stat } from 'fs';
1718

1819
let mainWin: BrowserWindow;
1920

@@ -96,7 +97,19 @@ export const createWindow = ({
9697
slashes: true,
9798
});
9899

99-
mainWin.loadURL(url);
100+
mainWin.loadURL(url).then(() => {
101+
// load custom stylesheet if any
102+
const CSS_FILE_PATH = app.getPath('userData') + '/styles.css';
103+
stat(app.getPath('userData') + '/styles.css', (err) => {
104+
if (err) {
105+
console.log('No custom styles detected at ' + CSS_FILE_PATH);
106+
} else {
107+
console.log('Loading custom styles from ' + CSS_FILE_PATH);
108+
const styles = readFileSync(CSS_FILE_PATH, {encoding: 'utf8'});
109+
mainWin.webContents.insertCSS(styles).then(console.log).catch(console.error);
110+
}
111+
});
112+
});
100113

101114
// show gracefully
102115
mainWin.once('ready-to-show', () => {

0 commit comments

Comments
 (0)