Skip to content

Commit

Permalink
Added shortcut for toggling the window
Browse files Browse the repository at this point in the history
  • Loading branch information
dcrousso committed Sep 22, 2016
1 parent 41d2066 commit 12e3112
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 12 deletions.
7 changes: 7 additions & 0 deletions app/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"use strict";

const electron = require("electron");

let apiResult = null;
let previews = null;
let columns = null;
Expand Down Expand Up @@ -94,6 +96,11 @@ window.addEventListener("blur", event => {
resetPreviews(keepAPIResult);
});

document.addEventListener("keydown", event => {
if (event.keyCode === 27) // Escape
electron.ipcRenderer.send("hide-browser", true);
});

input.addEventListener("input", (event => {
if (event.metaKey || event.altKey)
return;
Expand Down
43 changes: 32 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@ require("electron-dl")();

electron.app.dock.hide();

const size = {
arrow: 12,
width: 301,
height: 400,
const Size = {
Arrow: 12,
Width: 301,
Height: 400,
};

const Shortcut = {
Toggle: "CommandOrControl+Shift+Space",
};

let tray = null;
Expand All @@ -23,10 +27,7 @@ function createTray() {
if (!browser)
createBrowser();

if (browser.isVisible())
hideBrowser();
else
showBrowser(bounds);
toggleBrowser(bounds);
});
}

Expand All @@ -39,8 +40,8 @@ function createBrowser() {
frame: false,
resizable: false,
transparent: true,
width: size.width,
height: size.height + size.arrow,
width: Size.Width,
height: Size.Height + Size.Arrow,
}

browser = new electron.BrowserWindow(options);
Expand All @@ -53,7 +54,7 @@ function createBrowser() {
}

function showBrowser(bounds) {
browser.setPosition(parseInt(bounds.x - (size.width / 2) + (bounds.width / 2)), bounds.y + size.arrow + 14);
browser.setPosition(parseInt(bounds.x - (Size.Width / 2) + (bounds.width / 2)), bounds.y + Size.Arrow + 14);
browser.show();

tray.setHighlightMode("always");
Expand All @@ -65,7 +66,27 @@ function hideBrowser() {
tray.setHighlightMode("never");
}

function toggleBrowser(bounds) {
if (browser.isVisible())
hideBrowser();
else
showBrowser(bounds || tray.getBounds());
}

electron.ipcMain.on("hide-browser", (event, data) => {
if (data)
hideBrowser();
});

electron.app.on("ready", event => {
createTray();
createBrowser();

electron.globalShortcut.register(Shortcut.Toggle, () => {
toggleBrowser();
});
});

electron.app.on("will-quit", event => {
electron.globalShortcut.unregister(Shortcut.Toggle);
});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "GIFBar",
"productName": "GIFBar",
"version": "1.0.1",
"version": "1.1.0",
"description": "A system tray icon that helps you find the perfect GIF",
"scripts": {
"start": "electron .",
Expand Down

0 comments on commit 12e3112

Please sign in to comment.