Skip to content

Commit

Permalink
Add launchAtLogin and launchAsHidden menu options
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Andrei committed Feb 12, 2019
1 parent ffbba06 commit ae20cc2
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
10 changes: 10 additions & 0 deletions source/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@ app.setAppUserModelId('com.sindresorhus.caprine');
// https://github.com/electron/electron/issues/9671
app.commandLine.appendSwitch('disable-color-correct-rendering');

const appFolder = path.dirname(process.execPath);
const updateExe = path.resolve(appFolder, '..', 'Update.exe');

const {openAtLogin, openAsHidden, wasOpenedAsHidden} = app.getLoginItemSettings({
path: updateExe
});

config.set('openAtLogin', openAtLogin);
config.set('openAsHidden', openAsHidden || wasOpenedAsHidden);

if (!config.get('hardwareAcceleration')) {
app.disableHardwareAcceleration();
}
Expand Down
34 changes: 34 additions & 0 deletions source/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,20 @@ import config from './config';
import {sendAction, showRestartDialog} from './util';
import {generateSubmenu as generateEmojiSubmenu} from './emoji';

function setLoginSettings(): void {
const appFolder = path.dirname(process.execPath);
const updateExe = path.resolve(appFolder, '..', 'Update.exe');

const openAtLogin = config.get('openAtLogin');
const openAsHidden = config.get('openAsHidden');

app.setLoginItemSettings({
openAtLogin,
openAsHidden,
path: updateExe
});
}

export default function updateMenu(): Menu {
const newConversationItem: MenuItemConstructorOptions = {
label: 'New Conversation',
Expand Down Expand Up @@ -190,6 +204,26 @@ Press Command/Ctrl+R in Caprine to see your changes.
focusedWindow.setAlwaysOnTop(item.checked);
}
},
{
type: 'checkbox',
label: 'Launch at login',
checked: config.get('openAtLogin'),
click(item) {
config.set('openAtLogin', item.checked);
setLoginSettings();
updateMenu();
}
},
{
type: 'checkbox',
label: 'Launch as hidden',
checked: config.get('openAsHidden'),
enabled: config.get('openAtLogin'),
click(item) {
config.set('openAsHidden', item.checked);
setLoginSettings();
}
},
{
label: 'Auto Hide Menu Bar',
visible: !is.macos,
Expand Down

0 comments on commit ae20cc2

Please sign in to comment.