Created
September 29, 2017 16:01
-
-
Save pluma/22bd93821d77c64432bf56191562a7a1 to your computer and use it in GitHub Desktop.
Prevent window from closing when last tab is closed (works great with autohide and visor)
This file contains hidden or 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
'use strict'; | |
const seen = new Set(); | |
const $KNOWS_TO_HIDE = Symbol('knowsToHide'); | |
exports.onWindow = window => { | |
if (window[$KNOWS_TO_HIDE]) return; | |
window[$KNOWS_TO_HIDE] = true; | |
window.rpc.on('hide', () => setTimeout(() => window.hide(), 0)); | |
}; | |
exports.middleware = store => next => action => { | |
switch (action.type) { | |
case 'SESSION_USER_EXIT': | |
case 'SESSION_PTY_EXIT': | |
if (Object.keys(store.getState().sessions.sessions).length === 1) { | |
const {ui} = store.getState(); | |
const {cols, rows, cwd} = ui; | |
store.dispatch({ | |
type: 'TERM_GROUP_REQUEST', | |
effect: () => { | |
if (seen.has(action.uid)) return; | |
seen.add(action.uid); | |
global.rpc.emit('new', { | |
isNewGroup: true, | |
cols, | |
rows, | |
cwd, | |
}); | |
global.rpc.emit('hide', {}); | |
setTimeout(() => next(action), 100); | |
setTimeout(() => seen.delete(action.uid), 5000); | |
}, | |
}); | |
return; | |
} | |
break; | |
} | |
next(action); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is pretty hacky but works fine as long as you don't spam "close tab" commands. Sometimes it opens two tabs instead of one. No idea why that is.
There's a bug when using multiple windows so don't do that.