Skip to content

Commit

Permalink
Remove config for login settings and add ts definition
Browse files Browse the repository at this point in the history
  • Loading branch information
whitecrownclown committed Feb 13, 2019
1 parent ae20cc2 commit 40db8b8
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 23 deletions.
4 changes: 4 additions & 0 deletions source/app-login-settings.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
interface AppLoginSettings {
openAtLogin: bool;
openAsHidden: bool;
}
10 changes: 0 additions & 10 deletions source/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,6 @@ 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
29 changes: 16 additions & 13 deletions source/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,23 @@ 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');
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 getLoginSettings(): AppLoginSettings {
return app.getLoginItemSettings({
path: updateExe
});
}

export default function updateMenu(): Menu {
const newConversationItem: MenuItemConstructorOptions = {
label: 'New Conversation',
Expand Down Expand Up @@ -142,6 +145,8 @@ Press Command/Ctrl+R in Caprine to see your changes.
}
];

const {openAtLogin, openAsHidden} = getLoginSettings();

const preferencesSubmenu: MenuItemConstructorOptions[] = [
{
label: 'Bounce Dock on Message',
Expand Down Expand Up @@ -207,21 +212,19 @@ Press Command/Ctrl+R in Caprine to see your changes.
{
type: 'checkbox',
label: 'Launch at login',
checked: config.get('openAtLogin'),
checked: openAtLogin,
click(item) {
config.set('openAtLogin', item.checked);
setLoginSettings();
setLoginSettings({openAtLogin: item.checked, openAsHidden});
updateMenu();
}
},
{
type: 'checkbox',
label: 'Launch as hidden',
checked: config.get('openAsHidden'),
enabled: config.get('openAtLogin'),
checked: openAsHidden,
enabled: openAtLogin,
click(item) {
config.set('openAsHidden', item.checked);
setLoginSettings();
setLoginSettings({openAtLogin, openAsHidden: item.checked});
}
},
{
Expand Down

0 comments on commit 40db8b8

Please sign in to comment.