Skip to content

Instantly share code, notes, and snippets.

@getaclue00
Created November 11, 2018 14:39
Show Gist options
  • Save getaclue00/9480c41ef3ec850420208e2245221f83 to your computer and use it in GitHub Desktop.
Save getaclue00/9480c41ef3ec850420208e2245221f83 to your computer and use it in GitHub Desktop.
window electron sample notion
function createWindow(urlPath) {
if (urlPath === void 0) { urlPath = ""; }
var windowState = windowStateKeeper({
defaultWidth: 1320,
defaultHeight: 860,
});
var rect = {
x: windowState.x,
y: windowState.y,
width: windowState.width,
height: windowState.height,
};
var focusedWindow = electron_1.BrowserWindow.getFocusedWindow();
if (focusedWindow) {
var _a = focusedWindow.getPosition(), x = _a[0], y = _a[1];
rect.x = x + 20;
rect.y = y + 20;
var _b = focusedWindow.getSize(), width = _b[0], height = _b[1];
rect.width = width;
rect.height = height;
}
var window = new electron_1.BrowserWindow(__assign({}, rect, { titleBarStyle: "hiddenInset", webPreferences: {
preload: path.resolve(__dirname, "../renderer/index.js"),
} }));
if (focusedWindow) {
if (focusedWindow.isFullScreen()) {
window.setFullScreen(true);
}
}
else {
if (windowState.isFullScreen) {
window.setFullScreen(true);
}
}
window.on("close", function () {
windowState.saveState(window);
});
window.loadURL(getUrl(urlPath));
window.webContents.on("new-window", function (event, url) {
if (!url.startsWith(config_1.default.baseURL)) {
event.preventDefault();
electron_1.shell.openExternal(url);
}
});
return window;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment