Skip to content

Commit e18e967

Browse files
committed
Added store settings
1 parent 0fd16ea commit e18e967

File tree

1 file changed

+31
-1
lines changed
  • apps/servicebus-browser-app/src/app

1 file changed

+31
-1
lines changed

apps/servicebus-browser-app/src/app/app.ts

+31-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { BrowserWindow, shell, screen, Menu, nativeTheme } from 'electron';
22
import { rendererAppName, rendererAppPort } from './constants';
33
import { environment } from '../environments/environment';
4-
import { join } from 'path';
4+
import path, { join } from 'path';
55
import { format } from 'url';
66
import { getMenu } from './menu';
7+
import * as fs from 'fs';
78

89
export default class App {
910
// Keep a global reference of the window object, if you don't, the window will
@@ -100,6 +101,7 @@ export default class App {
100101
}
101102

102103
static setTheme(source: 'system' | 'dark' | 'light') {
104+
this.saveSetting('theme', source);
103105
nativeTheme.themeSource = source;
104106
}
105107

@@ -122,6 +124,32 @@ export default class App {
122124
}
123125
}
124126

127+
private static saveSetting<T>(key: string, value: T) {
128+
const userData = App.application.getPath('userData');
129+
const settingsPath = path.join(userData, 'settings.json');
130+
131+
let settings = {};
132+
if (fs.existsSync(settingsPath)) {
133+
settings = JSON.parse(fs.readFileSync(settingsPath, 'utf8'));
134+
}
135+
136+
settings[key] = value;
137+
138+
fs.writeFileSync(settingsPath, JSON.stringify(settings), 'utf8');
139+
}
140+
141+
private static getSetting<T>(key: string): T | undefined {
142+
const userData = App.application.getPath('userData');
143+
const settingsPath = path.join(userData, 'settings.json');
144+
145+
let settings = {};
146+
if (fs.existsSync(settingsPath)) {
147+
settings = JSON.parse(fs.readFileSync(settingsPath, 'utf8'));
148+
}
149+
150+
return settings[key];
151+
}
152+
125153
static main(app: Electron.App, browserWindow: typeof BrowserWindow) {
126154
// we pass the Electron.App object and the
127155
// Electron.BrowserWindow into this function
@@ -131,6 +159,8 @@ export default class App {
131159
App.BrowserWindow = browserWindow;
132160
App.application = app;
133161

162+
nativeTheme.themeSource = App.getSetting('theme') ?? 'system';
163+
134164
App.application.on('window-all-closed', App.onWindowAllClosed); // Quit when all windows are closed.
135165
App.application.on('ready', App.onReady); // App is ready to load data
136166
App.application.on('activate', App.onActivate); // App is activated

0 commit comments

Comments
 (0)