Skip to content

Commit

Permalink
fix multiple instances of hyper in linux
Browse files Browse the repository at this point in the history
  • Loading branch information
pomdtr committed Nov 29, 2023
1 parent eddae12 commit 07ccf55
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 14 deletions.
Binary file added hyper/assets/trayicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions hyper/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion hyper/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hyper-sunbeam",
"version": "0.0.20",
"version": "0.0.25",
"os": [
"darwin",
"linux"
Expand Down
30 changes: 19 additions & 11 deletions hyper/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,30 @@ const os = require("os");
let unload = () => { }

function onApp(app) {
if (!app.requestSingleInstanceLock()) {
app.quit()
return
}

app.on('second-instance', () => {
// Someone tried to run a second instance, we should focus our window.
showWindows(app)
})

// Prevent the app from quitting when all windows are closed
app.removeAllListeners('window-all-closed')
app.on('window-all-closed', (event) => {
// empty callback to prevent the default behavior
})

// Hide the dock icon
if (process.platform == "darwin") {
app.dock.hide();
}

app.on('window-all-closed', (event) => {
})

// Create tray icon
const tray = new Tray(path.join(__dirname, "../assets/trayiconTemplate.png"));
const iconPath = process.platform == "darwin" ? "../assets/trayiconTemplate.png" : "../assets/trayicon.png";
const tray = new Tray(path.join(__dirname, iconPath));
const contextMenu = Menu.buildFromTemplate([
{
label: 'Show Sunbeam',
Expand Down Expand Up @@ -72,7 +85,7 @@ function onApp(app) {
app.on("browser-window-blur", onBlur);

unload = () => {
tray.destroy();
if (tray) tray.destroy();
globalShortcut.unregisterAll();
app.removeListener("browser-window-blur", onBlur);
};
Expand Down Expand Up @@ -115,12 +128,7 @@ function decorateConfig(config) {

if (config.sunbeam && config.sunbeam.hotkey) {
const hotkey = config.sunbeam.hotkey;
if (!globalShortcut.register(hotkey, () => toggleWindows(app))) {
dialog.showMessageBox({
message: `Could not register hotkey (${hotkey})`,
buttons: ["Ok"]
});
}
globalShortcut.register(hotkey, () => toggleWindows(app));
}

const css = `
Expand Down

0 comments on commit 07ccf55

Please sign in to comment.