mirror of
https://github.com/quine-global/hyper.git
synced 2026-01-13 04:28: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 {dialog} = require('electron');
|
||||||
const gaze = require('gaze');
|
const gaze = require('gaze');
|
||||||
|
const Config = require('electron-config');
|
||||||
const notify = require('./notify');
|
const notify = require('./notify');
|
||||||
|
|
||||||
|
// local storage
|
||||||
|
const winCfg = new Config({
|
||||||
|
defaults: {
|
||||||
|
windowPosition: [50, 50],
|
||||||
|
windowSize: [540, 380]
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
const path = resolve(homedir(), '.hyperterm.js');
|
const path = resolve(homedir(), '.hyperterm.js');
|
||||||
const watchers = [];
|
const watchers = [];
|
||||||
|
|
||||||
|
|
@ -89,3 +98,15 @@ exports.getPlugins = function () {
|
||||||
localPlugins: cfg.localPlugins
|
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);
|
console.log('electron will open', url);
|
||||||
|
|
||||||
app.on('ready', () => installDevExtensions(isDev).then(() => {
|
app.on('ready', () => installDevExtensions(isDev).then(() => {
|
||||||
function createWindow(fn) {
|
function createWindow(fn, options = {}) {
|
||||||
let cfg = plugins.getDecoratedConfig();
|
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');
|
const {screen} = require('electron');
|
||||||
|
|
||||||
let startX = 50;
|
const winPos = options.position;
|
||||||
let startY = 50;
|
|
||||||
|
|
||||||
// Open the new window roughly the height of the header away from the
|
// Open the new window roughly the height of the header away from the
|
||||||
// previous window. This also ensures in multi monitor setups that the
|
// previous window. This also ensures in multi monitor setups that the
|
||||||
// new terminal is on the correct screen.
|
// new terminal is on the correct screen.
|
||||||
const focusedWindow = BrowserWindow.getFocusedWindow() || app.getLastFocusedWindow();
|
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 points = focusedWindow.getPosition();
|
||||||
const currentScreen = screen.getDisplayNearestPoint({x: points[0], y: points[1]});
|
const currentScreen = screen.getDisplayNearestPoint({x: points[0], y: points[1]});
|
||||||
|
|
||||||
|
|
@ -222,7 +227,6 @@ app.on('ready', () => installDevExtensions(isDev).then(() => {
|
||||||
|
|
||||||
rpc.on('exit', ({uid}) => {
|
rpc.on('exit', ({uid}) => {
|
||||||
const session = sessions.get(uid);
|
const session = sessions.get(uid);
|
||||||
|
|
||||||
if (session) {
|
if (session) {
|
||||||
session.exit();
|
session.exit();
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -317,6 +321,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
|
||||||
win.on('close', () => {
|
win.on('close', () => {
|
||||||
|
app.config.window.recordState(win);
|
||||||
windowSet.delete(win);
|
windowSet.delete(win);
|
||||||
rpc.destroy();
|
rpc.destroy();
|
||||||
deleteSessions();
|
deleteSessions();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue