Skip to content

Commit

Permalink
Use ts definition from electron; Remove launch as hidden option, de…
Browse files Browse the repository at this point in the history
…faults to true
  • Loading branch information
whitecrownclown committed Feb 13, 2019
1 parent 40db8b8 commit 97912c8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 32 deletions.
4 changes: 0 additions & 4 deletions source/app-login-settings.d.ts

This file was deleted.

37 changes: 9 additions & 28 deletions source/menu.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as path from 'path';
import {existsSync, writeFileSync} from 'fs';
import {app, shell, Menu, MenuItemConstructorOptions} from 'electron';
import {app, shell, Menu, MenuItemConstructorOptions, LoginItemSettings} from 'electron';
import {
is,
appMenu,
Expand All @@ -13,21 +13,12 @@ import config from './config';
import {sendAction, showRestartDialog} from './util';
import {generateSubmenu as generateEmojiSubmenu} from './emoji';

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

function setLoginSettings({openAtLogin, openAsHidden}: AppLoginSettings): void {
app.setLoginItemSettings({
openAtLogin,
openAsHidden,
path: updateExe
});
function setLoginSettings(settings: LoginItemSettings): void {
app.setLoginItemSettings(settings);
}

function getLoginSettings(): AppLoginSettings {
return app.getLoginItemSettings({
path: updateExe
});
function getLoginSettings(): LoginItemSettings {
return app.getLoginItemSettings();
}

export default function updateMenu(): Menu {
Expand Down Expand Up @@ -145,7 +136,7 @@ Press Command/Ctrl+R in Caprine to see your changes.
}
];

const {openAtLogin, openAsHidden} = getLoginSettings();
const settings: LoginItemSettings = getLoginSettings();

const preferencesSubmenu: MenuItemConstructorOptions[] = [
{
Expand Down Expand Up @@ -210,21 +201,11 @@ Press Command/Ctrl+R in Caprine to see your changes.
}
},
{
label: 'Launch at Login',
type: 'checkbox',
label: 'Launch at login',
checked: openAtLogin,
click(item) {
setLoginSettings({openAtLogin: item.checked, openAsHidden});
updateMenu();
}
},
{
type: 'checkbox',
label: 'Launch as hidden',
checked: openAsHidden,
enabled: openAtLogin,
checked: settings.openAtLogin,
click(item) {
setLoginSettings({openAtLogin, openAsHidden: item.checked});
setLoginSettings({...settings, openAtLogin: item.checked, openAsHidden: item.checked});
}
},
{
Expand Down

0 comments on commit 97912c8

Please sign in to comment.