mirror of
https://github.com/quine-global/hyper.git
synced 2026-01-13 04:28:41 -09:00
parent
2a6d271816
commit
c01b4112ea
2 changed files with 24 additions and 23 deletions
|
|
@ -137,7 +137,7 @@ app.on('ready', () => installDevExtensions(isDev).then(() => {
|
||||||
// the window can be closed by the browser process itself
|
// the window can be closed by the browser process itself
|
||||||
hwin.on('close', () => {
|
hwin.on('close', () => {
|
||||||
hwin.clean();
|
hwin.clean();
|
||||||
windowSet.delete(this);
|
windowSet.delete(hwin);
|
||||||
});
|
});
|
||||||
|
|
||||||
hwin.on('closed', () => {
|
hwin.on('closed', () => {
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ const notify = require('../notify');
|
||||||
const fetchNotifications = require('../notifications');
|
const fetchNotifications = require('../notifications');
|
||||||
const Session = require('../session');
|
const Session = require('../session');
|
||||||
|
|
||||||
module.exports = class Window extends BrowserWindow {
|
module.exports = class Window {
|
||||||
constructor(options, cfg, fn) {
|
constructor(options, cfg, fn) {
|
||||||
const opts = Object.assign({
|
const opts = Object.assign({
|
||||||
minWidth: 370,
|
minWidth: 370,
|
||||||
|
|
@ -27,9 +27,8 @@ module.exports = class Window extends BrowserWindow {
|
||||||
show: process.env.HYPER_DEBUG || process.env.HYPERTERM_DEBUG || isDev,
|
show: process.env.HYPER_DEBUG || process.env.HYPERTERM_DEBUG || isDev,
|
||||||
acceptFirstMouse: true
|
acceptFirstMouse: true
|
||||||
}, options);
|
}, options);
|
||||||
const modOpts = app.plugins.getDecoratedBrowserOptions(opts);
|
const window = new BrowserWindow(app.plugins.getDecoratedBrowserOptions(opts));
|
||||||
super(modOpts);
|
const rpc = createRPC(window);
|
||||||
const rpc = createRPC(this);
|
|
||||||
const sessions = new Map();
|
const sessions = new Map();
|
||||||
|
|
||||||
// config changes
|
// config changes
|
||||||
|
|
@ -53,8 +52,8 @@ module.exports = class Window extends BrowserWindow {
|
||||||
});
|
});
|
||||||
|
|
||||||
rpc.on('init', () => {
|
rpc.on('init', () => {
|
||||||
this.setBackgroundColor(toElectronBackgroundColor(cfg.backgroundColor || '#000'));
|
window.setBackgroundColor(toElectronBackgroundColor(cfg.backgroundColor || '#000'));
|
||||||
this.show();
|
window.show();
|
||||||
|
|
||||||
// If no callback is passed to createWindow,
|
// If no callback is passed to createWindow,
|
||||||
// a new session will be created by default.
|
// a new session will be created by default.
|
||||||
|
|
@ -66,12 +65,12 @@ module.exports = class Window extends BrowserWindow {
|
||||||
// that can be set before the 'ready' app event
|
// that can be set before the 'ready' app event
|
||||||
// and createWindow deifinition. It's executed in place of
|
// and createWindow deifinition. It's executed in place of
|
||||||
// the callback passed as parameter, and deleted right after.
|
// the callback passed as parameter, and deleted right after.
|
||||||
(app.windowCallback || fn)(this);
|
(app.windowCallback || fn)(window);
|
||||||
delete (app.windowCallback);
|
delete (app.windowCallback);
|
||||||
fetchNotifications(this);
|
fetchNotifications(window);
|
||||||
// auto updates
|
// auto updates
|
||||||
if (!isDev && process.platform !== 'linux') {
|
if (!isDev && process.platform !== 'linux') {
|
||||||
AutoUpdater(this);
|
AutoUpdater(window);
|
||||||
} else {
|
} else {
|
||||||
console.log('ignoring auto updates during dev');
|
console.log('ignoring auto updates during dev');
|
||||||
}
|
}
|
||||||
|
|
@ -120,13 +119,13 @@ module.exports = class Window extends BrowserWindow {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
rpc.on('unmaximize', () => {
|
rpc.on('unmaximize', () => {
|
||||||
this.unmaximize();
|
window.unmaximize();
|
||||||
});
|
});
|
||||||
rpc.on('maximize', () => {
|
rpc.on('maximize', () => {
|
||||||
this.maximize();
|
window.maximize();
|
||||||
});
|
});
|
||||||
rpc.on('minimize', () => {
|
rpc.on('minimize', () => {
|
||||||
this.minimize();
|
window.minimize();
|
||||||
});
|
});
|
||||||
rpc.on('resize', ({uid, cols, rows}) => {
|
rpc.on('resize', ({uid, cols, rows}) => {
|
||||||
const session = sessions.get(uid);
|
const session = sessions.get(uid);
|
||||||
|
|
@ -155,7 +154,7 @@ module.exports = class Window extends BrowserWindow {
|
||||||
// is maximized on Windows results in unmaximize, without hitting any
|
// is maximized on Windows results in unmaximize, without hitting any
|
||||||
// app buttons
|
// app buttons
|
||||||
for (const ev of ['maximize', 'unmaximize', 'minimize', 'restore']) {
|
for (const ev of ['maximize', 'unmaximize', 'minimize', 'restore']) {
|
||||||
this.on(ev, () => rpc.emit('windowGeometry change'));
|
window.on(ev, () => rpc.emit('windowGeometry change'));
|
||||||
}
|
}
|
||||||
rpc.win.on('move', () => {
|
rpc.win.on('move', () => {
|
||||||
rpc.emit('move');
|
rpc.emit('move');
|
||||||
|
|
@ -173,7 +172,7 @@ module.exports = class Window extends BrowserWindow {
|
||||||
// we reset the rpc channel only upon
|
// we reset the rpc channel only upon
|
||||||
// subsequent refreshes (ie: F5)
|
// subsequent refreshes (ie: F5)
|
||||||
let i = 0;
|
let i = 0;
|
||||||
this.webContents.on('did-navigate', () => {
|
window.webContents.on('did-navigate', () => {
|
||||||
if (i++) {
|
if (i++) {
|
||||||
deleteSessions();
|
deleteSessions();
|
||||||
}
|
}
|
||||||
|
|
@ -181,7 +180,7 @@ module.exports = class Window extends BrowserWindow {
|
||||||
|
|
||||||
// If file is dropped onto the terminal window, navigate event is prevented
|
// If file is dropped onto the terminal window, navigate event is prevented
|
||||||
// and his path is added to active session.
|
// and his path is added to active session.
|
||||||
this.webContents.on('will-navigate', (event, url) => {
|
window.webContents.on('will-navigate', (event, url) => {
|
||||||
const protocol = typeof url === 'string' && parseUrl(url).protocol;
|
const protocol = typeof url === 'string' && parseUrl(url).protocol;
|
||||||
if (protocol === 'file:') {
|
if (protocol === 'file:') {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
@ -196,11 +195,11 @@ module.exports = class Window extends BrowserWindow {
|
||||||
});
|
});
|
||||||
|
|
||||||
// expose internals to extension authors
|
// expose internals to extension authors
|
||||||
this.rpc = rpc;
|
window.rpc = rpc;
|
||||||
this.sessions = sessions;
|
window.sessions = sessions;
|
||||||
|
|
||||||
const load = () => {
|
const load = () => {
|
||||||
app.plugins.onWindow(this);
|
app.plugins.onWindow(window);
|
||||||
};
|
};
|
||||||
|
|
||||||
// load plugins
|
// load plugins
|
||||||
|
|
@ -217,16 +216,16 @@ module.exports = class Window extends BrowserWindow {
|
||||||
// which one of the existing window is the last focused.
|
// which one of the existing window is the last focused.
|
||||||
// Works nicely even if a window is closed and removed.
|
// Works nicely even if a window is closed and removed.
|
||||||
const updateFocusTime = () => {
|
const updateFocusTime = () => {
|
||||||
this.focusTime = process.uptime();
|
window.focusTime = process.uptime();
|
||||||
};
|
};
|
||||||
|
|
||||||
this.on('focus', () => {
|
window.on('focus', () => {
|
||||||
updateFocusTime();
|
updateFocusTime();
|
||||||
});
|
});
|
||||||
|
|
||||||
// the window can be closed by the browser process itself
|
// the window can be closed by the browser process itself
|
||||||
this.clean = () => {
|
window.clean = () => {
|
||||||
app.config.winRecord(this);
|
app.config.winRecord(window);
|
||||||
rpc.destroy();
|
rpc.destroy();
|
||||||
deleteSessions();
|
deleteSessions();
|
||||||
cfgUnsubscribe();
|
cfgUnsubscribe();
|
||||||
|
|
@ -235,5 +234,7 @@ module.exports = class Window extends BrowserWindow {
|
||||||
// Ensure focusTime is set on window open. The focus event doesn't
|
// Ensure focusTime is set on window open. The focus event doesn't
|
||||||
// fire from the dock (see bug #583)
|
// fire from the dock (see bug #583)
|
||||||
updateFocusTime();
|
updateFocusTime();
|
||||||
|
|
||||||
|
return window;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue