Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 096d410

Browse files
authored
Merge pull request #5793 from matrix-org/gsouquet-warn-before-exit
Add user settings for warn before exit
2 parents 33e8edb + 25a47b4 commit 096d410

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

src/BasePlatform.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,18 @@ export default abstract class BasePlatform {
212212
throw new Error("Unimplemented");
213213
}
214214

215+
supportsWarnBeforeExit(): boolean {
216+
return false;
217+
}
218+
219+
async shouldWarnBeforeExit(): Promise<boolean> {
220+
return false;
221+
}
222+
223+
async setWarnBeforeExit(enabled: boolean): Promise<void> {
224+
throw new Error("Unimplemented");
225+
}
226+
215227
supportsAutoHideMenuBar(): boolean {
216228
return false;
217229
}

src/components/views/settings/tabs/user/PreferencesUserSettingsTab.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ export default class PreferencesUserSettingsTab extends React.Component {
7474
this.state = {
7575
autoLaunch: false,
7676
autoLaunchSupported: false,
77+
warnBeforeExit: true,
78+
warnBeforeExitSupported: false,
7779
alwaysShowMenuBar: true,
7880
alwaysShowMenuBarSupported: false,
7981
minimizeToTray: true,
@@ -96,6 +98,12 @@ export default class PreferencesUserSettingsTab extends React.Component {
9698
autoLaunch = await platform.getAutoLaunchEnabled();
9799
}
98100

101+
const warnBeforeExitSupported = await platform.supportsWarnBeforeExit();
102+
let warnBeforeExit = false;
103+
if (warnBeforeExitSupported) {
104+
warnBeforeExit = await platform.shouldWarnBeforeExit();
105+
}
106+
99107
const alwaysShowMenuBarSupported = await platform.supportsAutoHideMenuBar();
100108
let alwaysShowMenuBar = true;
101109
if (alwaysShowMenuBarSupported) {
@@ -111,6 +119,8 @@ export default class PreferencesUserSettingsTab extends React.Component {
111119
this.setState({
112120
autoLaunch,
113121
autoLaunchSupported,
122+
warnBeforeExit,
123+
warnBeforeExitSupported,
114124
alwaysShowMenuBarSupported,
115125
alwaysShowMenuBar,
116126
minimizeToTraySupported,
@@ -122,6 +132,10 @@ export default class PreferencesUserSettingsTab extends React.Component {
122132
PlatformPeg.get().setAutoLaunchEnabled(checked).then(() => this.setState({autoLaunch: checked}));
123133
};
124134

135+
_onWarnBeforeExitChange = (checked) => {
136+
PlatformPeg.get().setWarnBeforeExit(checked).then(() => this.setState({warnBeforeExit: checked}));
137+
}
138+
125139
_onAlwaysShowMenuBarChange = (checked) => {
126140
PlatformPeg.get().setAutoHideMenuBarEnabled(!checked).then(() => this.setState({alwaysShowMenuBar: checked}));
127141
};
@@ -161,6 +175,14 @@ export default class PreferencesUserSettingsTab extends React.Component {
161175
label={_t('Start automatically after system login')} />;
162176
}
163177

178+
let warnBeforeExitOption = null;
179+
if (this.state.warnBeforeExitSupported) {
180+
warnBeforeExitOption = <LabelledToggleSwitch
181+
value={this.state.warnBeforeExit}
182+
onChange={this._onWarnBeforeExitChange}
183+
label={_t('Warn before quitting')} />;
184+
}
185+
164186
let autoHideMenuOption = null;
165187
if (this.state.alwaysShowMenuBarSupported) {
166188
autoHideMenuOption = <LabelledToggleSwitch
@@ -202,6 +224,7 @@ export default class PreferencesUserSettingsTab extends React.Component {
202224
{minimizeToTrayOption}
203225
{autoHideMenuOption}
204226
{autoLaunchOption}
227+
{warnBeforeExitOption}
205228
<Field
206229
label={_t('Autocomplete delay (ms)')}
207230
type='number'

src/i18n/strings/en_EN.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1287,6 +1287,7 @@
12871287
"Room ID or address of ban list": "Room ID or address of ban list",
12881288
"Subscribe": "Subscribe",
12891289
"Start automatically after system login": "Start automatically after system login",
1290+
"Warn before quitting": "Warn before quitting",
12901291
"Always show the window menu bar": "Always show the window menu bar",
12911292
"Show tray icon and minimize window to it on close": "Show tray icon and minimize window to it on close",
12921293
"Preferences": "Preferences",

0 commit comments

Comments
 (0)