Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,14 @@ declare namespace windowStateKeeper {
file?: string;
/** Should we automatically maximize the window, if it was last closed maximized. Defaults to `true`. */
maximize?: boolean;
/** The default background color, if one is not available. Defaults to `#fff` */
defaultBackgroundColor?: string;
}

interface State {
/** The saved background color of the loaded state. `#fff` if the state has not been saved yet. */
backgroundColor: string;
/** Display bounds. Used for matching which display the window is on. */
displayBounds: {
height: number;
width: number;
Expand Down
27 changes: 15 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,12 @@ module.exports = function (options) {

// Reset state to default values on the primary display
state = {
width: config.defaultWidth || 800,
backgroundColor: '#fff',
displayBounds,
height: config.defaultHeight || 600,
width: config.defaultWidth || 800,
x: 0,
y: 0,
displayBounds
y: 0
};
}

Expand Down Expand Up @@ -85,16 +86,17 @@ module.exports = function (options) {
}
// Don't throw an error when window was closed
try {
state.backgroundColor = win.getBackgroundColor();
const winBounds = win.getBounds();
state.displayBounds = screen.getDisplayMatching(winBounds).bounds;
if (isNormal(win)) {
state.height = winBounds.height;
state.width = winBounds.width;
state.x = winBounds.x;
state.y = winBounds.y;
state.width = winBounds.width;
state.height = winBounds.height;
}
state.isMaximized = win.isMaximized();
state.isFullScreen = win.isFullScreen();
state.displayBounds = screen.getDisplayMatching(winBounds).bounds;
state.isMaximized = win.isMaximized();
} catch (err) {}
}

Expand Down Expand Up @@ -171,13 +173,14 @@ module.exports = function (options) {
}, state);

return {
get x() { return state.x; },
get y() { return state.y; },
get width() { return state.width; },
get height() { return state.height; },
get backgroundColor() { return state.backgroundColor; },
get displayBounds() { return state.displayBounds; },
get isMaximized() { return state.isMaximized; },
get height() { return state.height; },
get isFullScreen() { return state.isFullScreen; },
get isMaximized() { return state.isMaximized; },
get width() { return state.width; },
get x() { return state.x; },
get y() { return state.y; },
saveState,
unmanage,
manage,
Expand Down
Loading