-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add Yarn, upgrade dependencies * Add option to hide dock icon - Add hide dock icon option - Split up entry file into testable modules * Modularize source - Separate source into testable modules - Remove seemingly unnecessary listeners - Clean up syntax * Revert removal of focus listener Re-instate focus listener that managed window stack order. * Add Travis CI config * Upgrade hyperterm-register-shortcut Pull in latest version that supports additional passed arguments. * Fix test titles
- Loading branch information
Showing
8 changed files
with
2,123 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
language: node_js | ||
node_js: | ||
- "stable" | ||
script: yarn test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
registerShortcut = () => jest.fn() | ||
|
||
module.exports = registerShortcut |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,9 @@ | ||
const registerShortcut = require('hyperterm-register-shortcut'); | ||
const windowSet = new Set([]); | ||
|
||
function showWindows (windows, app) { | ||
windows.forEach((win, index) => { | ||
if (index === windowSet.length-1) { | ||
win.focus(); | ||
} else { | ||
win.show(); | ||
} | ||
}); | ||
if (process.platform !== 'win32') app.show(); | ||
} | ||
const addWindow = require('./modules/windows').addWindow; | ||
const setup = require('./modules/setup'); | ||
|
||
function hideWindows (windows, app) { | ||
windows.forEach(win => { | ||
if (win.isFullScreen()) return; | ||
if (process.platform === 'win32') { | ||
win.minimize(); | ||
} else { | ||
win.hide(); | ||
} | ||
}); | ||
if (process.platform !== 'win32') app.hide(); // Mac OS only (re-focuses the last active app) | ||
} | ||
|
||
function toggleWindowVisibility (app) { | ||
const windows = [...windowSet]; | ||
const focusedWindows = windows.filter(window => window.isFocused()); | ||
if (focusedWindows.length > 0) { | ||
hideWindows(windows, app); | ||
} else { | ||
showWindows(windows, app); | ||
} | ||
} | ||
|
||
function addWindow (window) { | ||
windowSet.add(window); | ||
window.on('focus', () => { | ||
windowSet.delete(window); | ||
windowSet.add(window); | ||
}); | ||
window.on('close', () => { | ||
windowSet.delete(window); | ||
}); | ||
} | ||
|
||
function setup (app) { | ||
registerShortcut('summon', toggleWindowVisibility)(app); | ||
app.on('activate', () => { | ||
showWindows([...windowSet], app); | ||
}); | ||
} | ||
const windowSet = new Set([]); | ||
|
||
module.exports = { | ||
onApp: setup, | ||
onWindow: addWindow | ||
onApp: app => setup(app, windowSet), | ||
onWindow: window => addWindow(window, windowSet) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
const registerShortcut = require('hyperterm-register-shortcut'); | ||
const toggleWindowVisibility = require('./windows').toggleWindowVisibility; | ||
|
||
const DEFAULTS = { | ||
hideDock: false | ||
} | ||
|
||
module.exports = function setup (app, windowSet) { | ||
const config = Object.assign({}, DEFAULTS, app.config.getConfig().summon); | ||
|
||
if (config.hideDock) { | ||
app.dock.hide(); | ||
} | ||
|
||
registerShortcut('summon', toggleWindowVisibility)(app, windowSet); | ||
|
||
app.on('activate', () => { | ||
showWindows([...windowSet], app); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
const setup = require('./setup'); | ||
|
||
jest.mock('hyperterm-register-shortcut'); | ||
|
||
let app = { | ||
config: { | ||
getConfig: jest.fn(() => ({})) | ||
}, | ||
dock: { | ||
hide: jest.fn() | ||
}, | ||
on: jest.fn() | ||
}; | ||
|
||
describe('setup', () => { | ||
describe('with default config', () => { | ||
beforeEach(() => { | ||
setup(app); | ||
}); | ||
|
||
it('does not hide the dock', () => { | ||
expect(app.dock.hide).not.toHaveBeenCalled(); | ||
}); | ||
}); | ||
|
||
describe('with hideDock config enabled', () => { | ||
beforeEach(() => { | ||
app.config.getConfig.mockReturnValueOnce({ | ||
summon: { | ||
hideDock: true | ||
} | ||
}) | ||
setup(app); | ||
}); | ||
|
||
it('hides the dock', () => { | ||
expect(app.dock.hide).toHaveBeenCalled(); | ||
}); | ||
}); | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
function showWindows (windows, app) { | ||
windows.forEach((win, index) => { | ||
if (index === windows.length - 1) { | ||
win.show(); | ||
win.focus(); | ||
} else { | ||
win.show(); | ||
} | ||
}); | ||
|
||
if (process.platform !== 'win32') { | ||
app.show(); | ||
} | ||
} | ||
|
||
function hideWindows (windows, app) { | ||
windows.forEach(win => { | ||
if (win.isFullScreen()) { | ||
return; | ||
} | ||
|
||
process.platform === 'win32' | ||
? win.minimize() | ||
: win.hide(); | ||
}); | ||
|
||
// Re-focuses the last active app for macOS only | ||
if (process.platform !== 'win32') { | ||
app.hide(); | ||
} | ||
} | ||
|
||
function toggleWindowVisibility (app, windowSet) { | ||
const windows = [...windowSet]; | ||
const focusedWindows = windows.filter(window => window.isFocused()); | ||
|
||
focusedWindows.length > 0 | ||
? hideWindows(windows, app) | ||
: showWindows(windows, app); | ||
} | ||
|
||
function addWindow (window, windowSet) { | ||
windowSet.add(window); | ||
|
||
window.on('focus', () => { | ||
windowSet.delete(window); | ||
windowSet.add(window); | ||
}); | ||
|
||
window.on('close', () => { | ||
windowSet.delete(window); | ||
}); | ||
} | ||
|
||
module.exports = { | ||
addWindow, | ||
hideWindows, | ||
showWindows, | ||
toggleWindowVisibility | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ | |
"url": "https://github.com/Soutar/hyperterm-summon.git" | ||
}, | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"test": "jest" | ||
}, | ||
"keywords": [ | ||
"hyperterm", | ||
|
@@ -23,6 +23,12 @@ | |
"author": "John Soutar <[email protected]>", | ||
"license": "ISC", | ||
"dependencies": { | ||
"hyperterm-register-shortcut": "^1.0.1" | ||
"hyperterm-register-shortcut": "^1.2.0" | ||
}, | ||
"devDependencies": { | ||
"jest": "^19.0.2" | ||
}, | ||
"peerDependencies": { | ||
"electron": "^1.6.2" | ||
} | ||
} |
Oops, something went wrong.