-
-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
electron-window-state #9
Comments
👍 I could use this too. I think localStorage would be best as with the filesystem you might get permissions errors and other annoying things. |
I could also use this. This would be pretty simple with it just handled size/position. I'm not sure how to best handle multi-monitors (I don't use them anymore, so I couldn't test). Also, it was my initial inclination to use localStorage as well, but would files be better since on the restoration of the window ( |
One of the boilerplates mentioned in awesome-electron has a module that does this: // Simple module to help you remember the size and position of windows.
// Can be used for more than one window, just construct many
// instances of it and give each different name.
'use strict';
var app = require('app');
var jetpack = require('fs-jetpack');
module.exports = function (name, defaults) {
var userDataDir = jetpack.cwd(app.getPath('userData'));
var stateStoreFile = 'window-state-' + name +'.json';
var state = userDataDir.read(stateStoreFile, 'json') || {
width: defaults.width,
height: defaults.height
};
var saveState = function (win) {
if (!win.isMaximized() && !win.isMinimized()) {
var position = win.getPosition();
var size = win.getSize();
state.x = position[0];
state.y = position[1];
state.width = size[0];
state.height = size[1];
}
state.isMaximized = win.isMaximized();
userDataDir.write(stateStoreFile, state, { atomic: true });
};
return {
get x() { return state.x; },
get y() { return state.y; },
get width() { return state.width; },
get height() { return state.height; },
get isMaximized() { return state.isMaximized; },
saveState: saveState
};
}; Maybe that can be built as an npm module (without any dependencies like |
So I went ahead and gave this a try: https://github.com/mawie81/electron-window-state |
Thanks @mawie81! Heading to vacation for the week, but when I return I can try multiple monitors. |
Problem
Electron does not save/restore window size and position between loads.
Solution
A library for storing and loading window state.
Some logic might be required for plugging in and unplugging from a multi-monitor setup.
Electron lets you save state in files or localStorage. I'm not sure if one is better than the other.
The text was updated successfully, but these errors were encountered: