add hide on start option (#1919)
* add hide on start option (#1918) * text update * clean up * removed `hideOnStart` from ConfigV1 & ConfigV2 * tests update
This commit is contained in:
@@ -31,6 +31,7 @@ const defaultPreferences: ConfigV3 = {
|
||||
useSpellChecker: true,
|
||||
enableHardwareAcceleration: true,
|
||||
autostart: true,
|
||||
hideOnStart: false,
|
||||
spellCheckerLocales: [],
|
||||
darkMode: false,
|
||||
lastActiveTeam: 0,
|
||||
|
@@ -236,6 +236,9 @@ export class Config extends EventEmitter {
|
||||
get autostart() {
|
||||
return this.combinedData?.autostart ?? defaultPreferences.autostart;
|
||||
}
|
||||
get hideOnStart() {
|
||||
return this.combinedData?.hideOnStart ?? defaultPreferences.hideOnStart;
|
||||
}
|
||||
get notifications() {
|
||||
return this.combinedData?.notifications ?? defaultPreferences.notifications;
|
||||
}
|
||||
|
@@ -100,6 +100,7 @@ describe('common/config/upgradePreferences', () => {
|
||||
useSpellChecker: false,
|
||||
enableHardwareAcceleration: false,
|
||||
autostart: false,
|
||||
hideOnStart: false,
|
||||
spellCheckerLocale: 'en-CA',
|
||||
darkMode: true,
|
||||
downloadLocation: '/some/folder/name',
|
||||
|
@@ -126,6 +126,7 @@ describe('main/Validator', () => {
|
||||
describe('validateV3ConfigData', () => {
|
||||
const config = {
|
||||
autostart: true,
|
||||
hideOnStart: false,
|
||||
darkMode: false,
|
||||
enableHardwareAcceleration: true,
|
||||
lastActiveTeam: 0,
|
||||
|
@@ -119,6 +119,7 @@ const configDataSchemaV3 = Joi.object<ConfigV3>({
|
||||
useSpellChecker: Joi.boolean().default(true),
|
||||
enableHardwareAcceleration: Joi.boolean().default(true),
|
||||
autostart: Joi.boolean().default(true),
|
||||
hideOnStart: Joi.boolean().default(false),
|
||||
spellCheckerLocales: Joi.array().items(Joi.string()).default([]),
|
||||
spellCheckerURL: Joi.string().allow(null),
|
||||
darkMode: Joi.boolean().default(false),
|
||||
|
@@ -162,11 +162,28 @@ describe('main/windows/mainWindow', () => {
|
||||
};
|
||||
BrowserWindow.mockImplementation(() => window);
|
||||
fs.readFileSync.mockImplementation(() => '{"x":400,"y":300,"width":1280,"height":700,"maximized":true,"fullscreen":false}');
|
||||
Config.hideOnStart = false;
|
||||
createMainWindow({});
|
||||
expect(window.webContents.zoomLevel).toStrictEqual(0);
|
||||
expect(window.maximize).toBeCalled();
|
||||
});
|
||||
|
||||
it('should not show window on ready-to-show', () => {
|
||||
const window = {
|
||||
...baseWindow,
|
||||
once: jest.fn().mockImplementation((event, cb) => {
|
||||
if (event === 'ready-to-show') {
|
||||
cb();
|
||||
}
|
||||
}),
|
||||
};
|
||||
BrowserWindow.mockImplementation(() => window);
|
||||
fs.readFileSync.mockImplementation(() => '{"x":400,"y":300,"width":1280,"height":700,"maximized":true,"fullscreen":false}');
|
||||
Config.hideOnStart = true;
|
||||
createMainWindow({});
|
||||
expect(window.show).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should save window state on close if the app will quit', () => {
|
||||
global.willAppQuit = true;
|
||||
const window = {
|
||||
|
@@ -107,10 +107,12 @@ function createMainWindow(options: {linuxAppIcon: string}) {
|
||||
mainWindow.once('ready-to-show', () => {
|
||||
mainWindow.webContents.zoomLevel = 0;
|
||||
|
||||
if (Config.hideOnStart === false) {
|
||||
mainWindow.show();
|
||||
if (windowIsMaximized) {
|
||||
mainWindow.maximize();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
mainWindow.once('show', () => {
|
||||
|
@@ -58,6 +58,7 @@ export default class SettingsPage extends React.PureComponent<Record<string, nev
|
||||
downloadLocationRef: React.RefObject<HTMLInputElement>;
|
||||
showTrayIconRef: React.RefObject<HTMLInputElement>;
|
||||
autostartRef: React.RefObject<HTMLInputElement>;
|
||||
hideOnStartRef: React.RefObject<HTMLInputElement>;
|
||||
minimizeToTrayRef: React.RefObject<HTMLInputElement>;
|
||||
flashWindowRef: React.RefObject<HTMLInputElement>;
|
||||
bounceIconRef: React.RefObject<HTMLInputElement>;
|
||||
@@ -88,6 +89,7 @@ export default class SettingsPage extends React.PureComponent<Record<string, nev
|
||||
this.downloadLocationRef = React.createRef();
|
||||
this.showTrayIconRef = React.createRef();
|
||||
this.autostartRef = React.createRef();
|
||||
this.hideOnStartRef = React.createRef();
|
||||
this.minimizeToTrayRef = React.createRef();
|
||||
this.flashWindowRef = React.createRef();
|
||||
this.bounceIconRef = React.createRef();
|
||||
@@ -204,6 +206,13 @@ export default class SettingsPage extends React.PureComponent<Record<string, nev
|
||||
});
|
||||
}
|
||||
|
||||
handleChangeHideOnStart = () => {
|
||||
window.timers.setImmediate(this.saveSetting, CONFIG_TYPE_APP_OPTIONS, {key: 'hideOnStart', data: this.hideOnStartRef.current?.checked});
|
||||
this.setState({
|
||||
hideOnStart: this.hideOnStartRef.current?.checked,
|
||||
});
|
||||
}
|
||||
|
||||
handleChangeMinimizeToTray = () => {
|
||||
const shouldMinimizeToTray = this.state.showTrayIcon && this.minimizeToTrayRef.current?.checked;
|
||||
|
||||
@@ -419,6 +428,22 @@ export default class SettingsPage extends React.PureComponent<Record<string, nev
|
||||
{'If enabled, the app starts automatically when you log in to your machine.'}
|
||||
</FormText>
|
||||
</FormCheck>);
|
||||
|
||||
options.push(
|
||||
<FormCheck>
|
||||
<FormCheck.Input
|
||||
type='checkbox'
|
||||
key='inputHideOnStart'
|
||||
id='inputHideOnStart'
|
||||
ref={this.hideOnStartRef}
|
||||
checked={this.state.hideOnStart}
|
||||
onChange={this.handleChangeHideOnStart}
|
||||
/>
|
||||
{'Launch app minimized'}
|
||||
<FormText>
|
||||
{'If enabled, the app will start in system tray, and will not show the window on launch.'}
|
||||
</FormText>
|
||||
</FormCheck>);
|
||||
}
|
||||
|
||||
options.push(
|
||||
|
@@ -34,6 +34,7 @@ export type ConfigV3 = {
|
||||
useSpellChecker: boolean;
|
||||
enableHardwareAcceleration: boolean;
|
||||
autostart: boolean;
|
||||
hideOnStart: boolean;
|
||||
spellCheckerLocales: string[];
|
||||
darkMode: boolean;
|
||||
downloadLocation: string;
|
||||
|
Reference in New Issue
Block a user