diff options
Diffstat (limited to 'gui')
| -rw-r--r-- | gui/packages/desktop/src/main/gui-settings.js | 50 | ||||
| -rw-r--r-- | gui/packages/desktop/src/main/index.js | 23 |
2 files changed, 53 insertions, 20 deletions
diff --git a/gui/packages/desktop/src/main/gui-settings.js b/gui/packages/desktop/src/main/gui-settings.js new file mode 100644 index 0000000000..c724ee8c47 --- /dev/null +++ b/gui/packages/desktop/src/main/gui-settings.js @@ -0,0 +1,50 @@ +// @flow + +import fs from 'fs'; +import log from 'electron-log'; +import path from 'path'; +import { app } from 'electron'; + +export type GuiSettingsState = { + startMinimized: boolean, +}; + +export default class GuiSettings { + _state: GuiSettingsState = { + startMinimized: false, + }; + + load() { + try { + const settingsFile = this._filePath(); + const contents = fs.readFileSync(settingsFile, 'utf8'); + const settings = JSON.parse(contents); + + this._state.startMinimized = settings.startMinimized || false; + } catch (error) { + log.error(`Failed to read GUI settings file: ${error}`); + } + } + + store() { + try { + const settingsFile = this._filePath(); + + fs.writeFileSync(settingsFile, JSON.stringify(this._state)); + } catch (error) { + log.error(`Failed to write GUI settings file: ${error}`); + } + } + + get state(): GuiSettingsState { + return this._state; + } + + get startMinimized(): boolean { + return this._state.startMinimized; + } + + _filePath() { + return path.join(app.getPath('userData'), 'gui_settings.json'); + } +} diff --git a/gui/packages/desktop/src/main/index.js b/gui/packages/desktop/src/main/index.js index bbcfdac0ea..1c25a5c382 100644 --- a/gui/packages/desktop/src/main/index.js +++ b/gui/packages/desktop/src/main/index.js @@ -25,6 +25,7 @@ import type { TunnelStateTransition, } from './daemon-rpc'; +import GuiSettings from './gui-settings'; import ReconnectionBackoff from './reconnection-backoff'; import { resolveBin } from './proc'; @@ -36,10 +37,6 @@ const DAEMON_RPC_PATH = type AppQuitStage = 'unready' | 'initiated' | 'ready'; -type GuiSettings = { - startMinimized: boolean, -}; - export type CurrentAppVersionInfo = { gui: string, daemon: string, @@ -85,9 +82,7 @@ const ApplicationMain = { proxy: null, }, }: Settings), - _guiSettings: ({ - startMinimized: false, - }: GuiSettings), + _guiSettings: new GuiSettings(), _location: (null: ?Location), _lastDisconnectedLocation: (null: ?Location), @@ -132,7 +127,7 @@ const ApplicationMain = { } if (process.platform === 'linux') { - this._loadGuiSettings(); + this._guiSettings.load(); } app.on('activate', () => this._onActivate()); @@ -216,18 +211,6 @@ const ApplicationMain = { } }, - _loadGuiSettings() { - try { - const settingsFile = path.join(app.getPath('userData'), 'gui_settings.json'); - const contents = fs.readFileSync(settingsFile, 'utf8'); - const settings = JSON.parse(contents); - - this._guiSettings.startMinimized = settings.startMinimized || false; - } catch (error) { - log.error(`Failed to read GUI settings file: ${error}`); - } - }, - // Returns platform specific logs folder for application // See open issue and PR on Github: // 1. https://github.com/electron/electron/issues/10118 |
