diff options
| author | Andrej Mihajlov <and@mullvad.net> | 2019-06-27 19:43:17 +0200 |
|---|---|---|
| committer | Andrej Mihajlov <and@mullvad.net> | 2019-06-27 20:30:47 +0200 |
| commit | a18523cc1e5a07075403370c93e11564a8d2d94b (patch) | |
| tree | 78f093b22097b53c005eb16bfee5a21db739b60b /gui | |
| parent | bdf2b46118845c959b06e861a7a3ecec8f54788e (diff) | |
| download | mullvadvpn-a18523cc1e5a07075403370c93e11564a8d2d94b.tar.xz mullvadvpn-a18523cc1e5a07075403370c93e11564a8d2d94b.zip | |
Add notification settings
Diffstat (limited to 'gui')
| -rw-r--r-- | gui/locales/messages.pot | 8 | ||||
| -rw-r--r-- | gui/src/main/gui-settings.ts | 13 | ||||
| -rw-r--r-- | gui/src/main/index.ts | 20 | ||||
| -rw-r--r-- | gui/src/renderer/app.tsx | 10 | ||||
| -rw-r--r-- | gui/src/renderer/components/Preferences.tsx | 18 | ||||
| -rw-r--r-- | gui/src/renderer/containers/PreferencesPage.tsx | 14 | ||||
| -rw-r--r-- | gui/src/renderer/redux/settings/reducers.ts | 1 | ||||
| -rw-r--r-- | gui/src/shared/gui-settings-state.ts | 1 | ||||
| -rw-r--r-- | gui/src/shared/ipc-event-channel.ts | 5 |
9 files changed, 75 insertions, 15 deletions
diff --git a/gui/locales/messages.pot b/gui/locales/messages.pot index f150a42d5f..8e253a2670 100644 --- a/gui/locales/messages.pot +++ b/gui/locales/messages.pot @@ -408,6 +408,10 @@ msgid "Automatically connect to a server when the app launches." msgstr "" msgctxt "preferences-view" +msgid "Enable or disable system notifications. The critical notifications will always be displayed." +msgstr "" + +msgctxt "preferences-view" msgid "Launch app on start-up" msgstr "" @@ -420,6 +424,10 @@ msgid "Monochromatic tray icon" msgstr "" msgctxt "preferences-view" +msgid "Notifications" +msgstr "" + +msgctxt "preferences-view" msgid "Preferences" msgstr "" diff --git a/gui/src/main/gui-settings.ts b/gui/src/main/gui-settings.ts index 57c034b162..7e75d80e13 100644 --- a/gui/src/main/gui-settings.ts +++ b/gui/src/main/gui-settings.ts @@ -10,6 +10,14 @@ export default class GuiSettings { return this.stateValue; } + set enableSystemNotifications(newValue: boolean) { + this.changeStateAndNotify({ ...this.stateValue, enableSystemNotifications: newValue }); + } + + get enableSystemNotifications(): boolean { + return this.stateValue.enableSystemNotifications; + } + set autoConnect(newValue: boolean) { this.changeStateAndNotify({ ...this.stateValue, autoConnect: newValue }); } @@ -38,6 +46,7 @@ export default class GuiSettings { private stateValue: IGuiSettingsState = { autoConnect: true, + enableSystemNotifications: true, monochromaticIcon: false, startMinimized: false, }; @@ -50,6 +59,10 @@ export default class GuiSettings { this.stateValue.autoConnect = typeof settings.autoConnect === 'boolean' ? settings.autoConnect : true; + this.stateValue.enableSystemNotifications = + settings.enableSystemNotifications === 'boolean' + ? settings.enableSystemNotifications + : true; this.stateValue.monochromaticIcon = settings.monochromaticIcon || false; this.stateValue.startMinimized = settings.startMinimized || false; } catch (error) { diff --git a/gui/src/main/index.ts b/gui/src/main/index.ts index b086b97d08..b34cc87fbc 100644 --- a/gui/src/main/index.ts +++ b/gui/src/main/index.ts @@ -407,7 +407,7 @@ class ApplicationMain { // notify user about inconsistent version if ( process.env.NODE_ENV !== 'development' && - !this.shouldSuppressNotifications() && + !this.shouldSuppressNotifications(true) && !this.currentVersion.isConsistent ) { this.notificationController.notifyInconsistentVersion(); @@ -517,7 +517,7 @@ class ApplicationMain { this.updateTrayIcon(newState, this.settings.blockWhenDisconnected); this.updateLocation(); - if (!this.shouldSuppressNotifications()) { + if (!this.shouldSuppressNotifications(false)) { this.notificationController.notifyTunnelState(newState); } @@ -677,7 +677,7 @@ class ApplicationMain { // notify user to update the app if it became unsupported if ( process.env.NODE_ENV !== 'development' && - !this.shouldSuppressNotifications() && + !this.shouldSuppressNotifications(true) && currentVersionInfo.isConsistent && !latestVersionInfo.currentIsSupported && upgradeVersion @@ -713,8 +713,14 @@ class ApplicationMain { } } - private shouldSuppressNotifications(): boolean { - return this.windowController ? this.windowController.isVisible() : false; + private shouldSuppressNotifications(isCriticalNotification: boolean): boolean { + const isVisible = this.windowController ? this.windowController.isVisible() : false; + + if (isCriticalNotification) { + return isVisible; + } else { + return isVisible || !this.guiSettings.enableSystemNotifications; + } } private async updateLocation() { @@ -848,6 +854,10 @@ class ApplicationMain { IpcMainEventChannel.tunnel.handleConnect(() => this.daemonRpc.connectTunnel()); IpcMainEventChannel.tunnel.handleDisconnect(() => this.daemonRpc.disconnectTunnel()); + IpcMainEventChannel.guiSettings.handleEnableSystemNotifications((flag: boolean) => { + this.guiSettings.enableSystemNotifications = flag; + }); + IpcMainEventChannel.guiSettings.handleAutoConnect((autoConnect: boolean) => { this.guiSettings.autoConnect = autoConnect; }); diff --git a/gui/src/renderer/app.tsx b/gui/src/renderer/app.tsx index b530121672..ec7ba833e8 100644 --- a/gui/src/renderer/app.tsx +++ b/gui/src/renderer/app.tsx @@ -324,11 +324,15 @@ export default class AppRenderer { await IpcRendererEventChannel.settings.setOpenVpnMssfix(mssfix); } - public async setAutoConnect(autoConnect: boolean) { - return IpcRendererEventChannel.guiSettings.setAutoConnect(autoConnect); + public setAutoConnect(autoConnect: boolean) { + IpcRendererEventChannel.guiSettings.setAutoConnect(autoConnect); } - public async setAutoStart(autoStart: boolean): Promise<void> { + public setEnableSystemNotifications(flag: boolean) { + IpcRendererEventChannel.guiSettings.setEnableSystemNotifications(flag); + } + + public setAutoStart(autoStart: boolean): Promise<void> { this.storeAutoStart(autoStart); return IpcRendererEventChannel.autoStart.set(autoStart); diff --git a/gui/src/renderer/components/Preferences.tsx b/gui/src/renderer/components/Preferences.tsx index d8c8887c0d..b690a506b3 100644 --- a/gui/src/renderer/components/Preferences.tsx +++ b/gui/src/renderer/components/Preferences.tsx @@ -17,11 +17,13 @@ export interface IPreferencesProps { autoStart: boolean; autoConnect: boolean; allowLan: boolean; + enableSystemNotifications: boolean; monochromaticIcon: boolean; startMinimized: boolean; enableMonochromaticIconToggle: boolean; enableStartMinimizedToggle: boolean; setAutoStart: (autoStart: boolean) => void; + setEnableSystemNotifications: (flag: boolean) => void; setAutoConnect: (autoConnect: boolean) => void; setAllowLan: (allowLan: boolean) => void; setStartMinimized: (startMinimized: boolean) => void; @@ -93,6 +95,22 @@ export default class Preferences extends Component<IPreferencesProps> { )} </Cell.Footer> + <Cell.Container> + <Cell.Label> + {messages.pgettext('preferences-view', 'Notifications')} + </Cell.Label> + <Cell.Switch + isOn={this.props.enableSystemNotifications} + onChange={this.props.setEnableSystemNotifications} + /> + </Cell.Container> + <Cell.Footer> + {messages.pgettext( + 'preferences-view', + 'Enable or disable system notifications. The critical notifications will always be displayed.', + )} + </Cell.Footer> + <MonochromaticIconToggle enable={this.props.enableMonochromaticIconToggle} monochromaticIcon={this.props.monochromaticIcon} diff --git a/gui/src/renderer/containers/PreferencesPage.tsx b/gui/src/renderer/containers/PreferencesPage.tsx index 4147b42cfc..c78daccf29 100644 --- a/gui/src/renderer/containers/PreferencesPage.tsx +++ b/gui/src/renderer/containers/PreferencesPage.tsx @@ -9,8 +9,9 @@ import { ISharedRouteProps } from '../routes'; const mapStateToProps = (state: IReduxState) => ({ autoStart: state.settings.autoStart, - autoConnect: state.settings.guiSettings.autoConnect, allowLan: state.settings.allowLan, + autoConnect: state.settings.guiSettings.autoConnect, + enableSystemNotifications: state.settings.guiSettings.enableSystemNotifications, monochromaticIcon: state.settings.guiSettings.monochromaticIcon, startMinimized: state.settings.guiSettings.startMinimized, }); @@ -21,6 +22,9 @@ const mapDispatchToProps = (dispatch: ReduxDispatch, props: ISharedRouteProps) = onClose: () => { history.goBack(); }, + setEnableSystemNotifications: (flag: boolean) => { + props.app.setEnableSystemNotifications(flag); + }, setAutoStart: async (autoStart: boolean) => { try { await props.app.setAutoStart(autoStart); @@ -28,12 +32,8 @@ const mapDispatchToProps = (dispatch: ReduxDispatch, props: ISharedRouteProps) = log.error(`Cannot set auto-start: ${error.message}`); } }, - setAutoConnect: async (autoConnect: boolean) => { - try { - props.app.setAutoConnect(autoConnect); - } catch (error) { - log.error(`Cannot set auto-connect: ${error.message}`); - } + setAutoConnect: (autoConnect: boolean) => { + props.app.setAutoConnect(autoConnect); }, setAllowLan: (allowLan: boolean) => { props.app.setAllowLan(allowLan); diff --git a/gui/src/renderer/redux/settings/reducers.ts b/gui/src/renderer/redux/settings/reducers.ts index 7933fd3384..6c652f887d 100644 --- a/gui/src/renderer/redux/settings/reducers.ts +++ b/gui/src/renderer/redux/settings/reducers.ts @@ -58,6 +58,7 @@ export interface ISettingsReduxState { const initialState: ISettingsReduxState = { autoStart: false, guiSettings: { + enableSystemNotifications: true, autoConnect: true, monochromaticIcon: false, startMinimized: false, diff --git a/gui/src/shared/gui-settings-state.ts b/gui/src/shared/gui-settings-state.ts index 5bfb6e79c8..fdda92d830 100644 --- a/gui/src/shared/gui-settings-state.ts +++ b/gui/src/shared/gui-settings-state.ts @@ -1,4 +1,5 @@ export interface IGuiSettingsState { + enableSystemNotifications: boolean; autoConnect: boolean; monochromaticIcon: boolean; startMinimized: boolean; diff --git a/gui/src/shared/ipc-event-channel.ts b/gui/src/shared/ipc-event-channel.ts index 11ca42597c..b6292b554a 100644 --- a/gui/src/shared/ipc-event-channel.ts +++ b/gui/src/shared/ipc-event-channel.ts @@ -71,12 +71,14 @@ interface ISettingsHandlers extends ISender<ISettings> { } interface IGuiSettingsMethods extends IReceiver<IGuiSettingsState> { + setEnableSystemNotifications(flag: boolean): void; setAutoConnect(autoConnect: boolean): void; setStartMinimized(startMinimized: boolean): void; setMonochromaticIcon(monochromaticIcon: boolean): void; } interface IGuiSettingsHandlers extends ISender<IGuiSettingsState> { + handleEnableSystemNotifications(fn: (flag: boolean) => void): void; handleAutoConnect(fn: (autoConnect: boolean) => void): void; handleStartMinimized(fn: (startMinimized: boolean) => void): void; handleMonochromaticIcon(fn: (monochromaticIcon: boolean) => void): void; @@ -133,6 +135,7 @@ const CURRENT_VERSION_CHANGED = 'current-version-changed'; const UPGRADE_VERSION_CHANGED = 'upgrade-version-changed'; const GUI_SETTINGS_CHANGED = 'gui-settings-changed'; +const SET_ENABLE_SYSTEM_NOTIFICATIONS = 'set-enable-system-notifications'; const SET_AUTO_CONNECT = 'set-auto-connect'; const SET_MONOCHROMATIC_ICON = 'set-monochromatic-icon'; const SET_START_MINIMIZED = 'set-start-minimized'; @@ -204,6 +207,7 @@ export class IpcRendererEventChannel { public static guiSettings: IGuiSettingsMethods = { listen: listen(GUI_SETTINGS_CHANGED), + setEnableSystemNotifications: set(SET_ENABLE_SYSTEM_NOTIFICATIONS), setAutoConnect: set(SET_AUTO_CONNECT), setMonochromaticIcon: set(SET_MONOCHROMATIC_ICON), setStartMinimized: set(SET_START_MINIMIZED), @@ -277,6 +281,7 @@ export class IpcMainEventChannel { public static guiSettings: IGuiSettingsHandlers = { notify: sender(GUI_SETTINGS_CHANGED), + handleEnableSystemNotifications: handler(SET_ENABLE_SYSTEM_NOTIFICATIONS), handleAutoConnect: handler(SET_AUTO_CONNECT), handleMonochromaticIcon: handler(SET_MONOCHROMATIC_ICON), handleStartMinimized: handler(SET_START_MINIMIZED), |
