mirror of
https://github.com/quine-global/hyper.git
synced 2026-01-12 20:18:41 -09:00
Memorize window position and size (#617)
* Memorize window position * Memorize window size * Add forced settings and window config * use destructuring and shorthand method * Set default config * Use options defaults in createWindow * Use options object only * Update return function * xo comply
This commit is contained in:
parent
6959667589
commit
7aa20a8d45
2 changed files with 32 additions and 6 deletions
|
|
@ -5,8 +5,17 @@ const vm = require('vm');
|
|||
|
||||
const {dialog} = require('electron');
|
||||
const gaze = require('gaze');
|
||||
const Config = require('electron-config');
|
||||
const notify = require('./notify');
|
||||
|
||||
// local storage
|
||||
const winCfg = new Config({
|
||||
defaults: {
|
||||
windowPosition: [50, 50],
|
||||
windowSize: [540, 380]
|
||||
}
|
||||
});
|
||||
|
||||
const path = resolve(homedir(), '.hyperterm.js');
|
||||
const watchers = [];
|
||||
|
||||
|
|
@ -89,3 +98,15 @@ exports.getPlugins = function () {
|
|||
localPlugins: cfg.localPlugins
|
||||
};
|
||||
};
|
||||
|
||||
exports.window = {
|
||||
get() {
|
||||
const position = winCfg.get('windowPosition');
|
||||
const size = winCfg.get('windowSize');
|
||||
return {position, size};
|
||||
},
|
||||
recordState(win) {
|
||||
winCfg.set('windowPosition', win.getPosition());
|
||||
winCfg.set('windowSize', win.getSize());
|
||||
}
|
||||
};
|
||||
|
|
|
|||
17
app/index.js
17
app/index.js
|
|
@ -65,20 +65,25 @@ const url = 'file://' + resolve(
|
|||
console.log('electron will open', url);
|
||||
|
||||
app.on('ready', () => installDevExtensions(isDev).then(() => {
|
||||
function createWindow(fn) {
|
||||
function createWindow(fn, options = {}) {
|
||||
let cfg = plugins.getDecoratedConfig();
|
||||
|
||||
const [width, height] = cfg.windowSize || [540, 380];
|
||||
const winSet = app.config.window.get();
|
||||
let [startX, startY] = winSet.position;
|
||||
|
||||
const [width, height] = options.size ? options.size : (cfg.windowSize || winSet.size);
|
||||
const {screen} = require('electron');
|
||||
|
||||
let startX = 50;
|
||||
let startY = 50;
|
||||
const winPos = options.position;
|
||||
|
||||
// Open the new window roughly the height of the header away from the
|
||||
// previous window. This also ensures in multi monitor setups that the
|
||||
// new terminal is on the correct screen.
|
||||
const focusedWindow = BrowserWindow.getFocusedWindow() || app.getLastFocusedWindow();
|
||||
if (focusedWindow) {
|
||||
// In case of options defaults position and size, we should ignore the focusedWindow.
|
||||
if (winPos !== undefined) {
|
||||
[startX, startY] = winPos;
|
||||
} else if (focusedWindow) {
|
||||
const points = focusedWindow.getPosition();
|
||||
const currentScreen = screen.getDisplayNearestPoint({x: points[0], y: points[1]});
|
||||
|
||||
|
|
@ -222,7 +227,6 @@ app.on('ready', () => installDevExtensions(isDev).then(() => {
|
|||
|
||||
rpc.on('exit', ({uid}) => {
|
||||
const session = sessions.get(uid);
|
||||
|
||||
if (session) {
|
||||
session.exit();
|
||||
} else {
|
||||
|
|
@ -317,6 +321,7 @@ app.on('ready', () => installDevExtensions(isDev).then(() => {
|
|||
|
||||
// the window can be closed by the browser process itself
|
||||
win.on('close', () => {
|
||||
app.config.window.recordState(win);
|
||||
windowSet.delete(win);
|
||||
rpc.destroy();
|
||||
deleteSessions();
|
||||
|
|
|
|||
Loading…
Reference in a new issue