Skip to content
This repository was archived by the owner on Jun 23, 2021. It is now read-only.

Commit

Permalink
fix: registering shortcuts
Browse files Browse the repository at this point in the history
Closes #75
  • Loading branch information
sentialx committed Dec 10, 2019
1 parent 382cde1 commit 8da0a03
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 21 deletions.
6 changes: 3 additions & 3 deletions src/main/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ export class Container {
public constructor(appWindow: AppWindow, window: ProcessWindow) {
this.appWindow = appWindow;

let colId = spaceId++;
let rowId = spaceId++;
const colId = spaceId++;
const rowId = spaceId++;

this.columns.push({
id: colId,
Expand Down Expand Up @@ -190,7 +190,7 @@ export class Container {
x < col.x ||
y < area.y ||
y > area.y + area.height ||
((row && y > row.y + row.height) || y < row.y)
(row && y > row.y + row.height) || y < row.y
) {
this.removeWindow(win.id);
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ipcMain, app, Menu, BrowserWindow, webContents } from 'electron';
import { ipcMain, app, Menu, webContents } from 'electron';
import { resolve } from 'path';
import { platform, homedir } from 'os';
import { AppWindow } from './windows/app';
Expand All @@ -9,7 +9,7 @@ ipcMain.setMaxListeners(0);

app.setPath('userData', resolve(homedir(), '.multrin'));

export let appWindows: AppWindow[] = [];
export const appWindows: AppWindow[] = [];

const gotTheLock = app.requestSingleInstanceLock();

Expand Down
31 changes: 19 additions & 12 deletions src/main/windows/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,19 +151,9 @@ export class AppWindow extends BrowserWindow {
this.setIcon(nativeImage.createFromPath(dialogRes.filePaths[0]));
});

if (platform() !== 'darwin') {
globalShortcut.register('Ctrl+Tab', () => {
const { id } = windowManager.getActiveWindow();
if (
this.isFocused() ||
this.containers.find(x => x.windows.find(y => y.id === id))
) {
this.webContents.send('next-tab');
}
});
}

windowManager.on('window-activated', (window: Window) => {
this.registerShortcut(window.id);

if (!this.isFocused()) return;

for (const container of this.containers) {
Expand Down Expand Up @@ -331,6 +321,8 @@ export class AppWindow extends BrowserWindow {
setTimeout(() => {
this.selectContainer(container);
}, 50);

this.registerShortcut(win.id);
} else if (this.willSplitWindow) {
this.willSplitWindow = false;

Expand All @@ -345,6 +337,21 @@ export class AppWindow extends BrowserWindow {
});
}

private registerShortcut(id: number) {
if (
this.containers.find(x => x.windows.find(y => y.id === id)) ||
this.isFocused()
) {
if (!globalShortcut.isRegistered('CmdOrCtrl+Tab')) {
globalShortcut.register('CmdOrCtrl+Tab', () => {
this.webContents.send('next-tab');
});
}
} else if (globalShortcut.isRegistered('CmdOrCtrl+Tab')) {
globalShortcut.unregister('CmdOrCtrl+Tab');
}
}

private intervalCallback = () => {
if (!this.isMinimized()) {
for (const container of this.containers) {
Expand Down
5 changes: 1 addition & 4 deletions webpack.config.base.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,7 @@ const config = {
},
},

externals: getExternals([
'iohook',
'node-vibrant',
]),
externals: getExternals(['iohook', 'node-vibrant']),
};

if (dev) {
Expand Down

0 comments on commit 8da0a03

Please sign in to comment.