Skip to content

Commit

Permalink
Add hideOnBlur config option (#20)
Browse files Browse the repository at this point in the history
* Add hideOnBlur config option

* Remove unused import

* Add electron as peerDependency
  • Loading branch information
dcalhoun authored Jun 13, 2017
1 parent 6772ab8 commit c49ef0a
Show file tree
Hide file tree
Showing 3 changed files with 388 additions and 28 deletions.
22 changes: 17 additions & 5 deletions modules/setup.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const registerShortcut = require('hyperterm-register-shortcut');
const toggleWindowVisibility = require('./windows').toggleWindowVisibility;
const showWindows = require('./windows').showWindows;
const windows = require('./windows');

const DEFAULTS = {
hideDock: false
hideDock: false,
hideOnBlur: true
}

module.exports = function setup (app, windowSet) {
Expand All @@ -13,9 +13,21 @@ module.exports = function setup (app, windowSet) {
app.dock.hide();
}

registerShortcut('summon', toggleWindowVisibility)(app, windowSet);
registerShortcut('summon', windows.toggleWindowVisibility)(app, windowSet);

app.on('activate', () => {
showWindows([...windowSet], app);
windows.showWindows([...windowSet], app);
});

if (config.hideOnBlur) {
app.on('browser-window-blur', () => {
const focusedWindows = [...windowSet].filter(window => window.isFocused());

if (focusedWindows.length > 0) {
return false;
}

windows.hideWindows([...windowSet], app);
});
}
}
51 changes: 40 additions & 11 deletions modules/setup.test.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
const setup = require('./setup');

jest.mock('./windows')
jest.mock('hyperterm-register-shortcut');

let app = {
config: {
getConfig: jest.fn(() => ({}))
},
dock: {
hide: jest.fn()
},
on: jest.fn()
};
let app;

describe('setup', () => {
beforeAll(() => {
app = {
config: {
getConfig: jest.fn(() => ({}))
},
dock: {
hide: jest.fn()
},
on: jest.fn()
}
});

afterEach(() => {
app.dock.hide.mockClear()
app.on.mockClear()
})

describe('with default config', () => {
beforeEach(() => {
setup(app);
Expand All @@ -21,6 +31,10 @@ describe('setup', () => {
it('does not hide the dock', () => {
expect(app.dock.hide).not.toHaveBeenCalled();
});

it('handles blur events', () => {
expect(app.on).toHaveBeenCalledWith('browser-window-blur', expect.any(Function));
});
});

describe('with hideDock config enabled', () => {
Expand All @@ -29,12 +43,27 @@ describe('setup', () => {
summon: {
hideDock: true
}
})
});
setup(app);
});

it('hides the dock', () => {
expect(app.dock.hide).toHaveBeenCalled();
});
});
})

describe('with hideOnBlur config disabled', () => {
beforeEach(() => {
app.config.getConfig.mockReturnValueOnce({
summon: {
hideOnBlur: false
}
});
setup(app);
});

it('does not handle blur events', () => {
expect(app.on).not.toHaveBeenCalledWith('browser-window-blur', expect.any(Function));
});
});
});
Loading

0 comments on commit c49ef0a

Please sign in to comment.