Skip to content

Commit 1bf6b9f

Browse files
committed
frameless-window: add buttons to minimize, maximize, toggle developer tools
1 parent ce80709 commit 1bf6b9f

2 files changed

Lines changed: 44 additions & 8 deletions

File tree

frameless-window/frameless_window.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@
2727
<br/>
2828
<br/>
2929
<button id="close-window-button">Close Window</button>
30+
<br/>
31+
<button id="minimize-window-button">Minimize</button>
32+
<br/>
33+
<button id="maximize-window-button">Maximize</button>
34+
35+
<br/>
36+
<button id="open-inspector-button">Open Developer Tools</button>
3037

3138
</div>
3239

frameless-window/frameless_window.js

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
var gui = require("nw.gui");
2+
3+
// Extend application menu for Mac OS
4+
if (process.platform == "darwin") {
5+
var menu = new gui.Menu({type: "menubar"});
6+
menu.createMacBuiltin && menu.createMacBuiltin(window.document.title);
7+
gui.Window.get().menu = menu;
8+
}
9+
110
function updateCheckbox() {
211
var top_checkbox = document.getElementById("top-box");
312
var bottom_checkbox = document.getElementById("bottom-box");
@@ -36,27 +45,47 @@ function initCheckbox(checkboxId, titlebar_name, titlebar_icon_url, titlebar_tex
3645
window.onfocus = function() {
3746
console.log("focus");
3847
focusTitlebars(true);
39-
}
48+
};
4049

4150
window.onblur = function() {
4251
console.log("blur");
4352
focusTitlebars(false);
44-
}
53+
};
4554

4655
window.onresize = function() {
4756
updateContentStyle();
48-
}
57+
};
4958

5059
window.onload = function() {
60+
5161
initCheckbox("top-box", "top-titlebar", "top-titlebar.png", "Top Titlebar");
5262
initCheckbox("bottom-box", "bottom-titlebar", "bottom-titlebar.png", "Bottom Titlebar");
5363
initCheckbox("left-box", "left-titlebar", "left-titlebar.png", "Left Titlebar");
5464
initCheckbox("right-box", "right-titlebar", "right-titlebar.png", "Right Titlebar");
55-
65+
5666
document.getElementById("close-window-button").onclick = function() {
5767
window.close();
58-
}
59-
68+
};
69+
70+
document.querySelector('#minimize-window-button').onclick = function () {
71+
gui.Window.get().minimize();
72+
};
73+
74+
document.querySelector('#maximize-window-button').onclick = function () {
75+
gui.Window.get().maximize();
76+
};
77+
78+
document.querySelector('#open-inspector-button').onclick = function () {
79+
var win = gui.Window.get();
80+
if (win.isDevToolsOpen()) {
81+
win.closeDevTools();
82+
this.innerText = "Open Developer Tools";
83+
} else {
84+
win.showDevTools();
85+
this.innerText = "Close Developer Tools";
86+
}
87+
};
88+
6089
updateContentStyle();
61-
require("nw.gui").Window.get().show();
62-
}
90+
gui.Window.get().show();
91+
};

0 commit comments

Comments
 (0)