Fullscreen mode (#1968)
* Add preference to open app in full screen * CLI flag for fullscreen and function to return fullscreen state Parsing the config or the args to define how to open the app. Args take priority over the config, and fallback is the window state. * Optional TS config value Co-authored-by: Devin Binnie <52460000+devinbinnie@users.noreply.github.com> * Remove undefined check for `Config.startInFullscreen` * Fixed optional arg for test * Fixed jest test * fullscreen optional window value * Update src/main/windows/mainWindow.ts Co-authored-by: Guillermo Vayá <guivaya@gmail.com> * Update src/main/windows/mainWindow.ts Co-authored-by: Guillermo Vayá <guivaya@gmail.com> * Type fixes Co-authored-by: Mattermod <mattermod@users.noreply.github.com> Co-authored-by: Devin Binnie <52460000+devinbinnie@users.noreply.github.com> Co-authored-by: Guillermo Vayá <guivaya@gmail.com> Co-authored-by: Devin Binnie <devin.binnie@mattermost.com>
This commit is contained in:
parent
b7d9e771a2
commit
81cb2b6bed
|
@ -36,6 +36,7 @@ const defaultPreferences: ConfigV3 = {
|
||||||
darkMode: false,
|
darkMode: false,
|
||||||
lastActiveTeam: 0,
|
lastActiveTeam: 0,
|
||||||
downloadLocation: getDefaultDownloadLocation(),
|
downloadLocation: getDefaultDownloadLocation(),
|
||||||
|
startInFullscreen: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default defaultPreferences;
|
export default defaultPreferences;
|
||||||
|
|
|
@ -252,6 +252,10 @@ export class Config extends EventEmitter {
|
||||||
get enableHardwareAcceleration() {
|
get enableHardwareAcceleration() {
|
||||||
return this.combinedData?.enableHardwareAcceleration ?? defaultPreferences.enableHardwareAcceleration;
|
return this.combinedData?.enableHardwareAcceleration ?? defaultPreferences.enableHardwareAcceleration;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get startInFullscreen() {
|
||||||
|
return this.combinedData?.startInFullscreen ?? defaultPreferences.startInFullscreen;
|
||||||
|
}
|
||||||
get enableServerManagement() {
|
get enableServerManagement() {
|
||||||
return this.combinedData?.enableServerManagement ?? buildConfig.enableServerManagement;
|
return this.combinedData?.enableServerManagement ?? buildConfig.enableServerManagement;
|
||||||
}
|
}
|
||||||
|
|
|
@ -99,6 +99,7 @@ describe('common/config/upgradePreferences', () => {
|
||||||
showUnreadBadge: false,
|
showUnreadBadge: false,
|
||||||
useSpellChecker: false,
|
useSpellChecker: false,
|
||||||
enableHardwareAcceleration: false,
|
enableHardwareAcceleration: false,
|
||||||
|
startInFullscreen: false,
|
||||||
autostart: false,
|
autostart: false,
|
||||||
hideOnStart: false,
|
hideOnStart: false,
|
||||||
spellCheckerLocale: 'en-CA',
|
spellCheckerLocale: 'en-CA',
|
||||||
|
|
|
@ -44,6 +44,7 @@ export function upgradeV2toV3(configV2: ConfigV2) {
|
||||||
});
|
});
|
||||||
config.lastActiveTeam = 0;
|
config.lastActiveTeam = 0;
|
||||||
config.spellCheckerLocales = [];
|
config.spellCheckerLocales = [];
|
||||||
|
config.startInFullscreen = false;
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,7 @@ function parseArgs(args: string[]) {
|
||||||
alias('dataDir', 'd').string('dataDir').describe('dataDir', 'Set the path to where user data is stored.').
|
alias('dataDir', 'd').string('dataDir').describe('dataDir', 'Set the path to where user data is stored.').
|
||||||
alias('disableDevMode', 'p').boolean('disableDevMode').describe('disableDevMode', 'Disable development mode. Allows for testing as if it was Production.').
|
alias('disableDevMode', 'p').boolean('disableDevMode').describe('disableDevMode', 'Disable development mode. Allows for testing as if it was Production.').
|
||||||
alias('version', 'v').boolean('version').describe('version', 'Prints the application version.').
|
alias('version', 'v').boolean('version').describe('version', 'Prints the application version.').
|
||||||
|
alias('fullscreen', 'f').boolean('fullscreen').describe('fullscreen', 'Opens the application in fullscreen mode.').
|
||||||
help('help').
|
help('help').
|
||||||
parse(args);
|
parse(args);
|
||||||
}
|
}
|
||||||
|
|
|
@ -130,6 +130,7 @@ describe('main/Validator', () => {
|
||||||
hideOnStart: false,
|
hideOnStart: false,
|
||||||
darkMode: false,
|
darkMode: false,
|
||||||
enableHardwareAcceleration: true,
|
enableHardwareAcceleration: true,
|
||||||
|
startInFullscreen: false,
|
||||||
lastActiveTeam: 0,
|
lastActiveTeam: 0,
|
||||||
minimizeToTray: false,
|
minimizeToTray: false,
|
||||||
showTrayIcon: false,
|
showTrayIcon: false,
|
||||||
|
|
|
@ -27,6 +27,7 @@ const argsSchema = Joi.object<Args>({
|
||||||
disableDevMode: Joi.boolean(),
|
disableDevMode: Joi.boolean(),
|
||||||
dataDir: Joi.string(),
|
dataDir: Joi.string(),
|
||||||
version: Joi.boolean(),
|
version: Joi.boolean(),
|
||||||
|
fullscreen: Joi.boolean(),
|
||||||
});
|
});
|
||||||
|
|
||||||
const boundsInfoSchema = Joi.object<SavedWindowState>({
|
const boundsInfoSchema = Joi.object<SavedWindowState>({
|
||||||
|
@ -118,6 +119,7 @@ const configDataSchemaV3 = Joi.object<ConfigV3>({
|
||||||
showUnreadBadge: Joi.boolean().default(true),
|
showUnreadBadge: Joi.boolean().default(true),
|
||||||
useSpellChecker: Joi.boolean().default(true),
|
useSpellChecker: Joi.boolean().default(true),
|
||||||
enableHardwareAcceleration: Joi.boolean().default(true),
|
enableHardwareAcceleration: Joi.boolean().default(true),
|
||||||
|
startInFullscreen: Joi.boolean().default(false),
|
||||||
autostart: Joi.boolean().default(true),
|
autostart: Joi.boolean().default(true),
|
||||||
hideOnStart: Joi.boolean().default(false),
|
hideOnStart: Joi.boolean().default(false),
|
||||||
spellCheckerLocales: Joi.array().items(Joi.string()).default([]),
|
spellCheckerLocales: Joi.array().items(Joi.string()).default([]),
|
||||||
|
|
|
@ -124,6 +124,13 @@ describe('main/windows/mainWindow', () => {
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should open in fullscreen if fullscreen set to true', () => {
|
||||||
|
createMainWindow({fullscreen: true});
|
||||||
|
expect(BrowserWindow).toHaveBeenCalledWith(expect.objectContaining({
|
||||||
|
fullscreen: true,
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
it('should set default window size when failing to read bounds from file', () => {
|
it('should set default window size when failing to read bounds from file', () => {
|
||||||
fs.readFileSync.mockImplementation(() => 'just a bunch of garbage');
|
fs.readFileSync.mockImplementation(() => 'just a bunch of garbage');
|
||||||
createMainWindow({});
|
createMainWindow({});
|
||||||
|
|
|
@ -43,10 +43,10 @@ function isFramelessWindow() {
|
||||||
return os.platform() === 'darwin' || (os.platform() === 'win32' && Utils.isVersionGreaterThanOrEqualTo(os.release(), '6.2'));
|
return os.platform() === 'darwin' || (os.platform() === 'win32' && Utils.isVersionGreaterThanOrEqualTo(os.release(), '6.2'));
|
||||||
}
|
}
|
||||||
|
|
||||||
function createMainWindow(options: {linuxAppIcon: string}) {
|
function createMainWindow(options: {linuxAppIcon: string; fullscreen?: boolean}) {
|
||||||
// Create the browser window.
|
// Create the browser window.
|
||||||
const preload = getLocalPreload('mainWindow.js');
|
const preload = getLocalPreload('mainWindow.js');
|
||||||
let savedWindowState;
|
let savedWindowState: any;
|
||||||
try {
|
try {
|
||||||
savedWindowState = JSON.parse(fs.readFileSync(boundsInfoPath, 'utf-8'));
|
savedWindowState = JSON.parse(fs.readFileSync(boundsInfoPath, 'utf-8'));
|
||||||
savedWindowState = Validator.validateBoundsInfo(savedWindowState);
|
savedWindowState = Validator.validateBoundsInfo(savedWindowState);
|
||||||
|
@ -65,6 +65,16 @@ function createMainWindow(options: {linuxAppIcon: string}) {
|
||||||
const {maximized: windowIsMaximized} = savedWindowState;
|
const {maximized: windowIsMaximized} = savedWindowState;
|
||||||
|
|
||||||
const spellcheck = (typeof Config.useSpellChecker === 'undefined' ? true : Config.useSpellChecker);
|
const spellcheck = (typeof Config.useSpellChecker === 'undefined' ? true : Config.useSpellChecker);
|
||||||
|
const isFullScreen = () => {
|
||||||
|
if (global?.args?.fullscreen !== undefined) {
|
||||||
|
return global.args.fullscreen;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Config.startInFullscreen) {
|
||||||
|
return Config.startInFullscreen;
|
||||||
|
}
|
||||||
|
return options.fullscreen || savedWindowState.fullscreen || false;
|
||||||
|
};
|
||||||
|
|
||||||
const windowOptions: BrowserWindowConstructorOptions = Object.assign({}, savedWindowState, {
|
const windowOptions: BrowserWindowConstructorOptions = Object.assign({}, savedWindowState, {
|
||||||
title: app.name,
|
title: app.name,
|
||||||
|
@ -74,7 +84,7 @@ function createMainWindow(options: {linuxAppIcon: string}) {
|
||||||
minWidth: MINIMUM_WINDOW_WIDTH,
|
minWidth: MINIMUM_WINDOW_WIDTH,
|
||||||
minHeight: MINIMUM_WINDOW_HEIGHT,
|
minHeight: MINIMUM_WINDOW_HEIGHT,
|
||||||
frame: !isFramelessWindow(),
|
frame: !isFramelessWindow(),
|
||||||
fullscreen: savedWindowState.fullscreen,
|
fullscreen: isFullScreen(),
|
||||||
titleBarStyle: 'hidden' as const,
|
titleBarStyle: 'hidden' as const,
|
||||||
trafficLightPosition: {x: 12, y: 12},
|
trafficLightPosition: {x: 12, y: 12},
|
||||||
backgroundColor: '#fff', // prevents blurry text: https://electronjs.org/docs/faq#the-font-looks-blurry-what-is-this-and-what-can-i-do
|
backgroundColor: '#fff', // prevents blurry text: https://electronjs.org/docs/faq#the-font-looks-blurry-what-is-this-and-what-can-i-do
|
||||||
|
|
|
@ -68,8 +68,10 @@ export default class SettingsPage extends React.PureComponent<Record<string, nev
|
||||||
useSpellCheckerRef: React.RefObject<HTMLInputElement>;
|
useSpellCheckerRef: React.RefObject<HTMLInputElement>;
|
||||||
spellCheckerURLRef: React.RefObject<HTMLInputElement>;
|
spellCheckerURLRef: React.RefObject<HTMLInputElement>;
|
||||||
enableHardwareAccelerationRef: React.RefObject<HTMLInputElement>;
|
enableHardwareAccelerationRef: React.RefObject<HTMLInputElement>;
|
||||||
|
startInFullscreenRef: React.RefObject<HTMLInputElement>;
|
||||||
autoCheckForUpdatesRef: React.RefObject<HTMLInputElement>;
|
autoCheckForUpdatesRef: React.RefObject<HTMLInputElement>;
|
||||||
|
|
||||||
|
|
||||||
saveQueue: SaveQueueItem[];
|
saveQueue: SaveQueueItem[];
|
||||||
|
|
||||||
selectedSpellCheckerLocales: Array<{label: string; value: string}>;
|
selectedSpellCheckerLocales: Array<{label: string; value: string}>;
|
||||||
|
@ -99,6 +101,7 @@ export default class SettingsPage extends React.PureComponent<Record<string, nev
|
||||||
this.showUnreadBadgeRef = React.createRef();
|
this.showUnreadBadgeRef = React.createRef();
|
||||||
this.useSpellCheckerRef = React.createRef();
|
this.useSpellCheckerRef = React.createRef();
|
||||||
this.enableHardwareAccelerationRef = React.createRef();
|
this.enableHardwareAccelerationRef = React.createRef();
|
||||||
|
this.startInFullscreenRef = React.createRef();
|
||||||
this.spellCheckerURLRef = React.createRef();
|
this.spellCheckerURLRef = React.createRef();
|
||||||
this.autoCheckForUpdatesRef = React.createRef();
|
this.autoCheckForUpdatesRef = React.createRef();
|
||||||
|
|
||||||
|
@ -326,6 +329,13 @@ export default class SettingsPage extends React.PureComponent<Record<string, nev
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handleChangeStartInFullscreen = () => {
|
||||||
|
window.timers.setImmediate(this.saveSetting, CONFIG_TYPE_APP_OPTIONS, {key: 'startInFullscreen', data: this.startInFullscreenRef.current?.checked});
|
||||||
|
this.setState({
|
||||||
|
startInFullscreen: this.startInFullscreenRef.current?.checked,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
saveDownloadLocation = (location: string) => {
|
saveDownloadLocation = (location: string) => {
|
||||||
if (!location) {
|
if (!location) {
|
||||||
return;
|
return;
|
||||||
|
@ -747,6 +757,24 @@ export default class SettingsPage extends React.PureComponent<Record<string, nev
|
||||||
</FormCheck>,
|
</FormCheck>,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
options.push(
|
||||||
|
<FormCheck
|
||||||
|
key='inputStartInFullScreen'
|
||||||
|
>
|
||||||
|
<FormCheck.Input
|
||||||
|
type='checkbox'
|
||||||
|
id='inputStartInFullScreen'
|
||||||
|
ref={this.startInFullscreenRef}
|
||||||
|
checked={this.state.startInFullscreen}
|
||||||
|
onChange={this.handleChangeStartInFullscreen}
|
||||||
|
/>
|
||||||
|
{'Open app in fullscreen'}
|
||||||
|
<FormText>
|
||||||
|
{'If enabled, the Mattermost application will always open in full screen'}
|
||||||
|
</FormText>
|
||||||
|
</FormCheck>,
|
||||||
|
);
|
||||||
|
|
||||||
options.push(
|
options.push(
|
||||||
<div
|
<div
|
||||||
style={settingsPage.container}
|
style={settingsPage.container}
|
||||||
|
|
|
@ -40,7 +40,7 @@ export type ConfigV3 = {
|
||||||
downloadLocation: string;
|
downloadLocation: string;
|
||||||
spellCheckerURL?: string;
|
spellCheckerURL?: string;
|
||||||
lastActiveTeam?: number;
|
lastActiveTeam?: number;
|
||||||
|
startInFullscreen?: boolean;
|
||||||
autoCheckForUpdates?: boolean;
|
autoCheckForUpdates?: boolean;
|
||||||
alwaysMinimize?: boolean;
|
alwaysMinimize?: boolean;
|
||||||
alwaysClose?: boolean;
|
alwaysClose?: boolean;
|
||||||
|
|
1
src/types/global.d.ts
vendored
1
src/types/global.d.ts
vendored
|
@ -10,6 +10,7 @@ declare namespace NodeJS {
|
||||||
disableDevMode?: boolean;
|
disableDevMode?: boolean;
|
||||||
dataDir?: string;
|
dataDir?: string;
|
||||||
version?: boolean;
|
version?: boolean;
|
||||||
|
fullscreen?: boolean;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue