Skip to content

Commit

Permalink
Add menu entry to resize main window
Browse files Browse the repository at this point in the history
  • Loading branch information
mjacobus committed Nov 26, 2021
1 parent 62e64f9 commit 7a71224
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 10 deletions.
21 changes: 21 additions & 0 deletions src/ApplicationMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,27 @@ class ApplicationMenu {
},
],
},
{
label: "Main Window",
submenu: [
{
label: "Resize",
submenu: [
{ ratio: "16x9", width: 640, height: 360 },
{ ratio: "16x9", width: 800, height: 450 },
{ ratio: "16x9", width: 1200, height: 675 },
{ ratio: "9x16", width: 360, height: 640 },
{ ratio: "9x16", width: 450, height: 800 },
{ ratio: "9x16", width: 675, height: 1200 },
].map((item) => {
return {
label: `${item.width}x${item.height} (${item.ratio})`,
click: () => driver.mainWindow.resize(item.width, item.height),
};
}),
},
],
},
{
label: "DevTools",
submenu: [
Expand Down
12 changes: 2 additions & 10 deletions src/ControlWindow.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,8 @@ const Window = require("./Window");

class ControlWindow extends Window {
constructor(app) {
super({
app: app,
width: 600,
// it will not be higher then the display
height: 1600,
x: 900,
y: 0,
});

this.app = app;
super({ app, x: 900, y: 0 });
this.resize(600, 1600); // it will cap to screen height
this.loadAppFile("controls.html");
this.onFinishLoad();
}
Expand Down
1 change: 1 addition & 0 deletions src/MainWindow.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const Window = require("./Window");
class MainWindow extends Window {
constructor(app) {
super({ app });
this.resize(800, 450);

this.loadAppFile("main.html");

Expand Down
6 changes: 6 additions & 0 deletions src/Window.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ class BaseWindow extends BrowserWindow {
moveToDisplay(display) {
this.setPosition(display.bounds.x, display.bounds.y);
}

resize(width, height) {
this.setSize(width, height);
const diff = height - this.getContentSize()[1];
this.setSize(width, height + diff);
}
}

module.exports = BaseWindow;

0 comments on commit 7a71224

Please sign in to comment.