From b71a7b22c0b61144f2bfaf9c50dfe370a44f60cb Mon Sep 17 00:00:00 2001 From: Core <64542347+coredev-uk@users.noreply.github.com> Date: Thu, 10 Mar 2022 14:56:07 +0000 Subject: [PATCH] macOS Changes onStartup implemented --- src/main/base/app.ts | 25 ++++++++- src/main/base/browserwindow.ts | 13 ++++- src/main/base/store.ts | 5 +- src/main/plugins/menubar.ts | 9 ++- src/renderer/style.less | 30 ++-------- src/renderer/views/pages/settings.ejs | 79 ++++++++++++++++----------- 6 files changed, 99 insertions(+), 62 deletions(-) diff --git a/src/main/base/app.ts b/src/main/base/app.ts index 4ce18bd9..4a268330 100644 --- a/src/main/base/app.ts +++ b/src/main/base/app.ts @@ -120,6 +120,8 @@ export class AppEvents { public ready(plug: any) { this.plugin = plug console.log('[AppEvents] App ready'); + + AppEvents.setLoginSettings() } public bwCreated() { @@ -139,7 +141,9 @@ export class AppEvents { } this.InstanceHandler() - this.InitTray() + if (process.platform !== "darwin") { + this.InitTray() + } } /*********************************************************************************************************************** @@ -329,4 +333,23 @@ export class AppEvents { clipboard.writeText(data) }) } + + /** + * Set login settings + * @private + */ + private static setLoginSettings() { + if (utils.getStoreValue('general.onStartup.enabled')) { + app.setLoginItemSettings({ + openAtLogin: true, + path: app.getPath('exe'), + args: [`${utils.getStoreValue('general.onStartup.hidden') ? '--hidden' : ''}`] + }) + } else { + app.setLoginItemSettings({ + openAtLogin: false, + path: app.getPath('exe') + }) + } + } } diff --git a/src/main/base/browserwindow.ts b/src/main/base/browserwindow.ts index 979d6b2d..0a04a416 100644 --- a/src/main/base/browserwindow.ts +++ b/src/main/base/browserwindow.ts @@ -10,7 +10,6 @@ import {networkInterfaces} from "os"; import * as mm from 'music-metadata'; import fetch from 'electron-fetch' import {wsapi} from "./wsapi"; -import {AppImageUpdater, NsisUpdater} from "electron-updater"; import {utils} from './utils'; import {Plugins} from "./plugins"; @@ -1130,8 +1129,18 @@ export class BrowserWindow { isQuiting = true }); + app.on('activate', function(){ + BrowserWindow.win.show() + BrowserWindow.win.focus() + }); + + // Quit when all windows are closed. app.on('window-all-closed', () => { - app.quit() + // On macOS it is common for applications and their menu bar + // to stay active until the user quits explicitly with Cmd + Q + if (process.platform !== 'darwin') { + app.quit() + } }) BrowserWindow.win.on("closed", () => { diff --git a/src/main/base/store.ts b/src/main/base/store.ts index f1ea8dc2..6aae7b8f 100644 --- a/src/main/base/store.ts +++ b/src/main/base/store.ts @@ -7,7 +7,6 @@ export class Store { private defaults: any = { "general": { "close_button_hide": false, - "open_on_startup": false, "discord_rpc": 1, // 0 = disabled, 1 = enabled as Cider, 2 = enabled as Apple Music "discord_rpc_clear_on_pause": true, "language": "en_US", // electron.app.getLocale().replace('-', '_') this can be used in future @@ -23,6 +22,10 @@ export class Store { "artists": true, "videos": true, "podcasts": true + }, + "onStartup": { + "enabled": false, + "hidden": false, } }, "home": { diff --git a/src/main/plugins/menubar.ts b/src/main/plugins/menubar.ts index ea070645..53f2059e 100644 --- a/src/main/plugins/menubar.ts +++ b/src/main/plugins/menubar.ts @@ -1,4 +1,5 @@ import {app, Menu, shell} from "electron"; +import {utils} from "../base/utils"; export default class Thumbar { /** @@ -76,13 +77,19 @@ export default class Thumbar { label: 'Window', submenu: [ {role: 'minimize'}, + { + label: 'Show', + click: () => utils.getWindow().show() + }, {role: 'zoom'}, ...(this.isMac ? [ {type: 'separator'}, {role: 'front'}, ] : [ - {role: 'close'} + {} ]), + {role: 'close'}, + {type: 'separator'}, { label: 'Edit', submenu: [ diff --git a/src/renderer/style.less b/src/renderer/style.less index f0505165..9772d62d 100644 --- a/src/renderer/style.less +++ b/src/renderer/style.less @@ -1060,41 +1060,19 @@ input[type=range].web-slider::-webkit-slider-runnable-track { } body[platform="darwin"] .app-chrome .app-chrome-item > .window-controls > div.minimize { - height: 12px; - width: 12px; - background-color: rgb(255, 92, 92); - border-radius: 50%; - display: inline-block; - margin: auto 4px; - color: rgb(130, 0, 5); - -webkit-app-region: no-drag; - background-image: unset; + display: none; } body[platform="darwin"] .app-chrome .app-chrome-item > .window-controls { - width: 67px; + display: none; } body[platform="darwin"] .app-chrome .app-chrome-item > .window-controls > div.minmax { - height: 12px; - width: 12px; - background-color: rgb(255, 189, 76); - border-radius: 50%; - display: inline-block; - margin: auto 4px; - -webkit-app-region: no-drag; - background-image: unset; + display: none; } body[platform="darwin"] .app-chrome .app-chrome-item > .window-controls > div.close { - height: 12px; - width: 12px; - background-color: rgb(0, 202, 86); - border-radius: 50%; - display: inline-block; - margin: auto 4px auto 4px; - -webkit-app-region: no-drag; - background-image: unset; + display: none; } .app-chrome .app-chrome-item.playback-controls { diff --git a/src/renderer/views/pages/settings.ejs b/src/renderer/views/pages/settings.ejs index a14ba8b5..cc68565d 100644 --- a/src/renderer/views/pages/settings.ejs +++ b/src/renderer/views/pages/settings.ejs @@ -1,6 +1,7 @@