Skip to content

Commit

Permalink
Handle mac auto launch / hidden
Browse files Browse the repository at this point in the history
  • Loading branch information
perry-mitchell committed Dec 16, 2023
1 parent 13764b3 commit 74a98ee
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
9 changes: 8 additions & 1 deletion source/main/services/arguments.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { app } from "electron";
import { isOSX } from "../../shared/library/platform";

let __autostarted = false,
__showMainWindow = true;

export function processCLFlags() {
export function processLaunchConfiguration() {
const cl = app.commandLine;
// Deprecated switch
if (cl.hasSwitch("no-window")) {
Expand All @@ -12,6 +13,12 @@ export function processCLFlags() {
if (cl.hasSwitch("hidden")) {
__showMainWindow = false;
}
if (isOSX() && app.getLoginItemSettings().wasOpenedAtLogin) {
__autostarted = true;
}
if (isOSX() && app.getLoginItemSettings().wasOpenedAsHidden) {
__showMainWindow = false;
}
if (cl.hasSwitch("autostart")) {
__autostarted = true;
}
Expand Down
4 changes: 2 additions & 2 deletions source/main/services/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { isPortable } from "../library/portability";
import { getLogPath } from "./log";
import { startUpdateWatcher } from "./update";
import { registerGoogleDriveAuthHandlers } from "./googleDrive";
import { processCLFlags } from "./arguments";
import { processLaunchConfiguration } from "./arguments";
import { supportsBiometricUnlock } from "./biometrics";
import { startAutoVaultLockTimer } from "./autoLock";
import { start as startBrowserAPI } from "./browser/index";
Expand All @@ -23,7 +23,7 @@ import { getLanguage } from "../../shared/library/i18n";
import { closeAndReopenMainWindow } from "./windows";

export async function initialise() {
processCLFlags();
processLaunchConfiguration();
await initialiseLogging();
logInfo("Application session started:", new Date());
logInfo(`Logs location: ${getLogPath()}`);
Expand Down
2 changes: 2 additions & 0 deletions source/main/services/launch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,13 @@ async function setStartWithSessionNative(enable: boolean): Promise<void> {
const isEnabled = app.getLoginItemSettings().openAtLogin;
if (enable && !isEnabled) {
app.setLoginItemSettings({
openAsHidden: true,
openAtLogin: true,
args: ["--autostart"]
});
} else if (!enable && isEnabled) {
app.setLoginItemSettings({
openAsHidden: false,
openAtLogin: false,
args: []
});
Expand Down

0 comments on commit 74a98ee

Please sign in to comment.