Skip to content

Commit

Permalink
chore: toggle instead of just display
Browse files Browse the repository at this point in the history
  • Loading branch information
Leksat committed Mar 13, 2021
1 parent ebbe735 commit 3272600
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 17 deletions.
12 changes: 8 additions & 4 deletions src/main/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,14 @@ export const app = {
window: {} as BrowserWindow,
store,

showWindow: (): void => {
app.window.show();
app.window.focus();
app.focusToTextarea();
toggleWindow: (): void => {
if (app.window.isVisible()) {
app.electronApp.hide();
} else {
app.window.show();
app.window.focus();
app.focusToTextarea();
}
},

getTicketWithError: (): string => {
Expand Down
2 changes: 1 addition & 1 deletion src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ electronApp.on('ready', () => {
app.window.on('close', (event) => {
if (!shouldQuit) {
event.preventDefault();
app.window.hide();
app.electronApp.hide();
}
});

Expand Down
6 changes: 3 additions & 3 deletions src/main/shortcuts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const registerShortcuts = (app: App): void => {
const ticket = app.getTicketWithError();
app.addNewEntry(ticket);
} else {
app.showWindow();
app.toggleWindow();
}
lastHitNewEntry = now;
})
Expand All @@ -21,8 +21,8 @@ export const registerShortcuts = (app: App): void => {
}

if (
!globalShortcut.register(app.store.get('shortcuts').displayWindow, () => {
app.showWindow();
!globalShortcut.register(app.store.get('shortcuts').toggleWindow, () => {
app.toggleWindow();
})
) {
app.electronApp.exit(1);
Expand Down
6 changes: 3 additions & 3 deletions src/main/tray.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ export const createTray = (app: App): void => {
const contextMenu = Menu.buildFromTemplate([
{
label: 'Show window',
click: () => app.showWindow(),
click: () => app.toggleWindow(),
},
{
label: 'New...',
click: () => {
app.addNewEntry('');
app.showWindow();
app.toggleWindow();
},
},
{
Expand All @@ -34,7 +34,7 @@ export const createTray = (app: App): void => {
click: () => {
const ticket = app.getTicketWithError();
app.addNewEntry(ticket);
app.showWindow();
app.toggleWindow();
},
},
{
Expand Down
8 changes: 4 additions & 4 deletions src/renderer/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const Settings: React.FC<Props> = ({ close }) => {
});
store.set('shortcuts', {
newEntry: data.get('shortcuts.newEntry') as string,
displayWindow: data.get('shortcuts.displayWindow') as string,
toggleWindow: data.get('shortcuts.toggleWindow') as string,
});
close();
}}
Expand Down Expand Up @@ -47,10 +47,10 @@ export const Settings: React.FC<Props> = ({ close }) => {
/>
</label>
<label>
Shortcut display window
Shortcut toggle window
<input
name="shortcuts.displayWindow"
defaultValue={store.get('shortcuts').displayWindow}
name="shortcuts.toggleWindow"
defaultValue={store.get('shortcuts').toggleWindow}
/>
</label>
<button onClick={close}>Close</button>
Expand Down
4 changes: 2 additions & 2 deletions src/shared/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export interface State {
};
shortcuts: {
newEntry: string;
displayWindow: string;
toggleWindow: string;
};
}

Expand All @@ -28,6 +28,6 @@ export const defaults: State = {
},
shortcuts: {
newEntry: 'CommandOrControl+Alt+V',
displayWindow: 'CommandOrControl+Alt+X',
toggleWindow: 'CommandOrControl+Alt+X',
},
};

0 comments on commit 3272600

Please sign in to comment.