From 7a56ca59c63ecfe41c0bc2c89e94952d9f5becb2 Mon Sep 17 00:00:00 2001 From: Abhinav Date: Sat, 3 Sep 2022 16:25:04 +0530 Subject: [PATCH] hide dock icon on autoLaunch --- src/main.ts | 2 ++ src/utils/main.ts | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/src/main.ts b/src/main.ts index f85df41a6..1184c2402 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,3 +1,4 @@ +import { handleDockIconHideOnAutoLaunch } from './utils/main'; import { app, BrowserWindow } from 'electron'; import { createWindow } from './utils/createWindow'; import setupIpcComs from './utils/ipcComms'; @@ -42,6 +43,7 @@ const gotTheLock = app.requestSingleInstanceLock(); if (!gotTheLock) { app.quit(); } else { + handleDockIconHideOnAutoLaunch(); app.commandLine.appendSwitch('enable-features', 'SharedArrayBuffer'); app.on('second-instance', () => { // Someone tried to run a second instance, we should focus our window. diff --git a/src/utils/main.ts b/src/utils/main.ts index 58a3da499..f6803d284 100644 --- a/src/utils/main.ts +++ b/src/utils/main.ts @@ -7,6 +7,8 @@ import { existsSync } from 'promise-fs'; import appUpdater from './appUpdater'; import { isDev } from './common'; import { buildContextMenu, buildMenuBar } from './menu'; +import autoLauncher from '../services/autoLauncher'; +import { getHideDockIconPreference } from '../services/userPreference'; export function handleUpdates(mainWindow: BrowserWindow, tray: Tray) { if (!isDev) { @@ -84,3 +86,12 @@ export function isPlatformMac() { export function isPlatformWindows() { return process.platform === 'win32'; } + +export async function handleDockIconHideOnAutoLaunch() { + const shouldHideDockIcon = getHideDockIconPreference(); + const wasAutoLaunched = await autoLauncher.wasAutoLaunched(); + + if (isPlatformMac() && shouldHideDockIcon && wasAutoLaunched) { + app.dock.hide(); + } +}