feat(desktop): add start minimized option for launch at login (#3094)

This commit is contained in:
Hampus
2026-10-01 19:51:43 +02:00
committed by GitHub
parent c2e7fde5bc
commit d691047884
46 changed files with 1198 additions and 526 deletions
@@ -34,6 +34,7 @@ interface PersistedDesktopWindowBehaviorSettings {
useNativeTitleBar?: boolean;
minimizeToTrayV2?: boolean;
closeToTrayV2?: boolean;
startMinimized?: boolean;
rememberWindowState?: boolean;
allowTransparency?: boolean;
smoothScrolling?: boolean;
@@ -59,6 +60,7 @@ function getDefaultDesktopWindowBehaviorSettings(): DesktopWindowBehaviorSetting
showTrayIcon: true,
minimizeToTray: false,
closeToTray: true,
startMinimized: false,
useNativeTitleBar: false,
activeUseNativeTitleBar: false,
rememberWindowState: true,
@@ -100,6 +102,9 @@ function sanitizePersistedDesktopWindowBehaviorSettings(
if (typeof value.middleClickAutoscroll === 'boolean') {
settings.middleClickAutoscroll = value.middleClickAutoscroll;
}
if (typeof value.startMinimized === 'boolean') {
settings.startMinimized = value.startMinimized;
}
const minimizeToTrayV2 = value[MINIMIZE_TO_TRAY_STORAGE_KEY_V2];
if (typeof minimizeToTrayV2 === 'boolean') {
settings.minimizeToTrayV2 = minimizeToTrayV2;
@@ -218,6 +223,10 @@ function normalizeDesktopWindowBehaviorSettings(
: typeof normalizedSettings?.closeToTrayV2 === 'boolean'
? normalizedSettings.closeToTrayV2
: defaults.closeToTray,
startMinimized:
typeof normalizedSettings?.startMinimized === 'boolean'
? normalizedSettings.startMinimized
: defaults.startMinimized,
useNativeTitleBar:
typeof normalizedSettings?.useNativeTitleBar === 'boolean'
? normalizedSettings.useNativeTitleBar
@@ -266,6 +275,7 @@ function normalizeDesktopWindowBehaviorSettings(
if (!normalized.showTrayIcon) {
normalized.minimizeToTray = false;
normalized.closeToTray = false;
normalized.startMinimized = false;
}
return normalized;
}
@@ -280,6 +290,7 @@ function serializeDesktopWindowBehaviorSettings(
allowTransparency: settings.allowTransparency,
smoothScrolling: settings.smoothScrolling,
middleClickAutoscroll: settings.middleClickAutoscroll,
startMinimized: settings.startMinimized,
[MINIMIZE_TO_TRAY_STORAGE_KEY_V2]: settings.minimizeToTray,
[CLOSE_TO_TRAY_STORAGE_KEY_V2]: settings.closeToTray,
};
+1
View File
@@ -103,6 +103,7 @@ export interface DesktopWindowBehaviorSettings {
showTrayIcon: boolean;
minimizeToTray: boolean;
closeToTray: boolean;
startMinimized: boolean;
useNativeTitleBar: boolean;
activeUseNativeTitleBar: boolean;
rememberWindowState: boolean;
@@ -338,6 +338,7 @@ function formatWindowBehavior(settings: DesktopWindowBehaviorSettings): string {
`showTrayIcon=${settings.showTrayIcon}`,
`minimizeToTray=${settings.minimizeToTray}`,
`closeToTray=${settings.closeToTray}`,
`startMinimized=${settings.startMinimized}`,
`useNativeTitleBar=${settings.useNativeTitleBar}`,
`rememberWindowState=${settings.rememberWindowState}`,
`allowTransparency=${settings.allowTransparency}`,
+3
View File
@@ -108,6 +108,9 @@ function normalizeDesktopWindowBehaviorUpdate(value: unknown): Partial<DesktopWi
if (typeof value.closeToTray === 'boolean') {
update.closeToTray = value.closeToTray;
}
if (typeof value.startMinimized === 'boolean') {
update.startMinimized = value.startMinimized;
}
if (typeof value.useNativeTitleBar === 'boolean') {
update.useNativeTitleBar = value.useNativeTitleBar;
}
@@ -1,40 +0,0 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
import assert from 'node:assert/strict';
import {readFileSync} from 'node:fs';
import {createRequire} from 'node:module';
import {describe, test} from 'node:test';
import {fileURLToPath} from 'node:url';
import vm from 'node:vm';
const require = createRequire(import.meta.url);
const esbuild = require('esbuild');
const sourcePath = fileURLToPath(new URL('./LaunchOptions.ts', import.meta.url));
const source = readFileSync(sourcePath, 'utf8');
const transformedSource = esbuild.transformSync(source, {
loader: 'ts',
format: 'cjs',
platform: 'node',
target: 'node20',
}).code;
function loadLaunchOptions() {
const module = {exports: {}};
const context = vm.createContext({
module,
exports: module.exports,
process: {env: {}, platform: 'linux'},
console,
});
vm.runInContext(transformedSource, context, {filename: sourcePath});
return module.exports;
}
describe('LaunchOptions start hidden at login', () => {
test('never starts hidden at login', () => {
const {shouldStartHiddenAtLogin} = loadLaunchOptions();
assert.equal(shouldStartHiddenAtLogin(), false);
});
});
-4
View File
@@ -135,10 +135,6 @@ export function shouldDisableV8CodeCache(argv: ReadonlyArray<string> = process.a
);
}
export function shouldStartHiddenAtLogin(): boolean {
return false;
}
export function isPortableLaunchFlag(argv: ReadonlyArray<string> = process.argv): boolean {
return hasFlag(argv, PORTABLE_MODE_ARGS);
}
+3 -3
View File
@@ -16,7 +16,7 @@ import {
WINDOWS_TOAST_ACTIVATOR_CLSID,
} from '@electron/common/DesktopIdentity';
import {configureUserDataPath} from '@electron/common/UserDataPath';
import {registerAutostartHandlers} from '@electron/main/Autostart';
import {isAutostartLaunch, registerAutostartHandlers} from '@electron/main/Autostart';
import {
addLinuxHardwareVideoEncodeFeatures,
addWindowsHardwareVideoEncodeFeatures,
@@ -53,7 +53,7 @@ import {initializeDockMenu} from '@electron/main/DockMenu';
import {cleanupGlobalKeyHook, registerGlobalKeyHookHandlers} from '@electron/main/GlobalKeyHook';
import {cleanupIpcHandlers, registerIpcHandlers} from '@electron/main/IpcHandlers';
import {initializeJumpList} from '@electron/main/JumpList';
import {describeLaunchDiagnosticOptions, shouldStartHiddenAtLogin} from '@electron/main/LaunchOptions';
import {describeLaunchDiagnosticOptions} from '@electron/main/LaunchOptions';
import {cleanupVirtmic, registerVirtmicHandlers} from '@electron/main/LinuxAudioCapture';
import {initializeMainI18n, t} from '@electron/main/MainI18n';
import {createApplicationMenu} from '@electron/main/Menu';
@@ -386,7 +386,7 @@ if (launchConfigurationError) {
log.error('[Init] Failed to create application menu:', error);
}
runStartupPhase('create-window', () => {
createWindow({startHidden: shouldStartHiddenAtLogin()});
createWindow({startHidden: isAutostartLaunch() && getDesktopWindowBehaviorSettings().startMinimized});
});
const initialTask = consumeInitialJumpListTask();
if (initialTask) {