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,
|
useSpellChecker: true,
|
||||||
enableHardwareAcceleration: true,
|
enableHardwareAcceleration: true,
|
||||||
autostart: true,
|
autostart: true,
|
||||||
|
hideOnStart: false,
|
||||||
spellCheckerLocales: [],
|
spellCheckerLocales: [],
|
||||||
darkMode: false,
|
darkMode: false,
|
||||||
lastActiveTeam: 0,
|
lastActiveTeam: 0,
|
||||||
|
@@ -236,6 +236,9 @@ export class Config extends EventEmitter {
|
|||||||
get autostart() {
|
get autostart() {
|
||||||
return this.combinedData?.autostart ?? defaultPreferences.autostart;
|
return this.combinedData?.autostart ?? defaultPreferences.autostart;
|
||||||
}
|
}
|
||||||
|
get hideOnStart() {
|
||||||
|
return this.combinedData?.hideOnStart ?? defaultPreferences.hideOnStart;
|
||||||
|
}
|
||||||
get notifications() {
|
get notifications() {
|
||||||
return this.combinedData?.notifications ?? defaultPreferences.notifications;
|
return this.combinedData?.notifications ?? defaultPreferences.notifications;
|
||||||
}
|
}
|
||||||
|
@@ -100,6 +100,7 @@ describe('common/config/upgradePreferences', () => {
|
|||||||
useSpellChecker: false,
|
useSpellChecker: false,
|
||||||
enableHardwareAcceleration: false,
|
enableHardwareAcceleration: false,
|
||||||
autostart: false,
|
autostart: false,
|
||||||
|
hideOnStart: false,
|
||||||
spellCheckerLocale: 'en-CA',
|
spellCheckerLocale: 'en-CA',
|
||||||
darkMode: true,
|
darkMode: true,
|
||||||
downloadLocation: '/some/folder/name',
|
downloadLocation: '/some/folder/name',
|
||||||
|
@@ -126,6 +126,7 @@ describe('main/Validator', () => {
|
|||||||
describe('validateV3ConfigData', () => {
|
describe('validateV3ConfigData', () => {
|
||||||
const config = {
|
const config = {
|
||||||
autostart: true,
|
autostart: true,
|
||||||
|
hideOnStart: false,
|
||||||
darkMode: false,
|
darkMode: false,
|
||||||
enableHardwareAcceleration: true,
|
enableHardwareAcceleration: true,
|
||||||
lastActiveTeam: 0,
|
lastActiveTeam: 0,
|
||||||
|
@@ -119,6 +119,7 @@ const configDataSchemaV3 = Joi.object<ConfigV3>({
|
|||||||
useSpellChecker: Joi.boolean().default(true),
|
useSpellChecker: Joi.boolean().default(true),
|
||||||
enableHardwareAcceleration: Joi.boolean().default(true),
|
enableHardwareAcceleration: Joi.boolean().default(true),
|
||||||
autostart: Joi.boolean().default(true),
|
autostart: Joi.boolean().default(true),
|
||||||
|
hideOnStart: Joi.boolean().default(false),
|
||||||
spellCheckerLocales: Joi.array().items(Joi.string()).default([]),
|
spellCheckerLocales: Joi.array().items(Joi.string()).default([]),
|
||||||
spellCheckerURL: Joi.string().allow(null),
|
spellCheckerURL: Joi.string().allow(null),
|
||||||
darkMode: Joi.boolean().default(false),
|
darkMode: Joi.boolean().default(false),
|
||||||
|
@@ -162,11 +162,28 @@ describe('main/windows/mainWindow', () => {
|
|||||||
};
|
};
|
||||||
BrowserWindow.mockImplementation(() => window);
|
BrowserWindow.mockImplementation(() => window);
|
||||||
fs.readFileSync.mockImplementation(() => '{"x":400,"y":300,"width":1280,"height":700,"maximized":true,"fullscreen":false}');
|
fs.readFileSync.mockImplementation(() => '{"x":400,"y":300,"width":1280,"height":700,"maximized":true,"fullscreen":false}');
|
||||||
|
Config.hideOnStart = false;
|
||||||
createMainWindow({});
|
createMainWindow({});
|
||||||
expect(window.webContents.zoomLevel).toStrictEqual(0);
|
expect(window.webContents.zoomLevel).toStrictEqual(0);
|
||||||
expect(window.maximize).toBeCalled();
|
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', () => {
|
it('should save window state on close if the app will quit', () => {
|
||||||
global.willAppQuit = true;
|
global.willAppQuit = true;
|
||||||
const window = {
|
const window = {
|
||||||
|
@@ -107,9 +107,11 @@ function createMainWindow(options: {linuxAppIcon: string}) {
|
|||||||
mainWindow.once('ready-to-show', () => {
|
mainWindow.once('ready-to-show', () => {
|
||||||
mainWindow.webContents.zoomLevel = 0;
|
mainWindow.webContents.zoomLevel = 0;
|
||||||
|
|
||||||
mainWindow.show();
|
if (Config.hideOnStart === false) {
|
||||||
if (windowIsMaximized) {
|
mainWindow.show();
|
||||||
mainWindow.maximize();
|
if (windowIsMaximized) {
|
||||||
|
mainWindow.maximize();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@@ -58,6 +58,7 @@ export default class SettingsPage extends React.PureComponent<Record<string, nev
|
|||||||
downloadLocationRef: React.RefObject<HTMLInputElement>;
|
downloadLocationRef: React.RefObject<HTMLInputElement>;
|
||||||
showTrayIconRef: React.RefObject<HTMLInputElement>;
|
showTrayIconRef: React.RefObject<HTMLInputElement>;
|
||||||
autostartRef: React.RefObject<HTMLInputElement>;
|
autostartRef: React.RefObject<HTMLInputElement>;
|
||||||
|
hideOnStartRef: React.RefObject<HTMLInputElement>;
|
||||||
minimizeToTrayRef: React.RefObject<HTMLInputElement>;
|
minimizeToTrayRef: React.RefObject<HTMLInputElement>;
|
||||||
flashWindowRef: React.RefObject<HTMLInputElement>;
|
flashWindowRef: React.RefObject<HTMLInputElement>;
|
||||||
bounceIconRef: 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.downloadLocationRef = React.createRef();
|
||||||
this.showTrayIconRef = React.createRef();
|
this.showTrayIconRef = React.createRef();
|
||||||
this.autostartRef = React.createRef();
|
this.autostartRef = React.createRef();
|
||||||
|
this.hideOnStartRef = React.createRef();
|
||||||
this.minimizeToTrayRef = React.createRef();
|
this.minimizeToTrayRef = React.createRef();
|
||||||
this.flashWindowRef = React.createRef();
|
this.flashWindowRef = React.createRef();
|
||||||
this.bounceIconRef = 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 = () => {
|
handleChangeMinimizeToTray = () => {
|
||||||
const shouldMinimizeToTray = this.state.showTrayIcon && this.minimizeToTrayRef.current?.checked;
|
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.'}
|
{'If enabled, the app starts automatically when you log in to your machine.'}
|
||||||
</FormText>
|
</FormText>
|
||||||
</FormCheck>);
|
</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(
|
options.push(
|
||||||
|
@@ -34,6 +34,7 @@ export type ConfigV3 = {
|
|||||||
useSpellChecker: boolean;
|
useSpellChecker: boolean;
|
||||||
enableHardwareAcceleration: boolean;
|
enableHardwareAcceleration: boolean;
|
||||||
autostart: boolean;
|
autostart: boolean;
|
||||||
|
hideOnStart: boolean;
|
||||||
spellCheckerLocales: string[];
|
spellCheckerLocales: string[];
|
||||||
darkMode: boolean;
|
darkMode: boolean;
|
||||||
downloadLocation: string;
|
downloadLocation: string;
|
||||||
|
Reference in New Issue
Block a user