Skip to content

Commit 9c7346c

Browse files
authored
New: Frameless window (Full only in Windows and macOS)
1 parent 0f7cb19 commit 9c7346c

15 files changed

+460
-52
lines changed

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"url": "git+https://github.com/ollm/OpenComic.git"
2424
},
2525
"scripts": {
26-
"start": "npm run prebuild && electron --trace-warnings --enable-logging scripts/main.js",
26+
"start": "npm run prebuild && electron scripts/main.js",
2727
"rebuild": "electron-rebuild -f -w sharp",
2828
"rebuild2": "electron-builder node-gyp-rebuild",
2929
"prebuild": "node scripts/build.js && node themes/material-design/colors/generate-colors.js && node languages/fill-languages.js",
@@ -87,7 +87,7 @@
8787
},
8888
"devDependencies": {
8989
"@electron/rebuild": "^3.2.13",
90-
"electron": "^27.0.0",
90+
"electron": "^25.9.1",
9191
"electron-builder": "^24.6.3",
9292
"node-abi": "^3.46.0",
9393
"node-yaml": "^4.0.1",

scripts/dom.js

+2
Original file line numberDiff line numberDiff line change
@@ -1257,6 +1257,8 @@ function nightMode()
12571257
handlebarsContext.nightMode = true;
12581258
storage.updateVar('config', 'nightMode', true);
12591259
}
1260+
1261+
titleBar.setColors();
12601262
}
12611263

12621264
// Show the comic context menu

scripts/dom/search.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -354,8 +354,8 @@ function setResults(results)
354354

355355
let height = (len * 56);
356356

357-
if(height > window.innerHeight - 136)
358-
height = window.innerHeight - 136;
357+
if(height > window.innerHeight - 136 - titleBar.height())
358+
height = window.innerHeight - 136 - titleBar.height();
359359

360360
searchBarResults.style.height = height+'px';
361361
searchBarResults.innerHTML = template.load('search.results.html');

scripts/gamepad.js

+1-6
Original file line numberDiff line numberDiff line change
@@ -786,12 +786,7 @@ setButtonEvent('fullscreen', 11, function(key) {
786786

787787
if(!onReading)
788788
{
789-
let win = electronRemote.getCurrentWindow();
790-
let isFullScreen = win.isFullScreen();
791-
792-
reading.hideContent(!isFullScreen);
793-
win.setFullScreen(!isFullScreen);
794-
win.setMenuBarVisibility(isFullScreen);
789+
fullScreen();
795790
}
796791

797792
});

scripts/main.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@ function createWindow() {
4040
backgroundThrottling: false,
4141
nativeWindowOpen: false,
4242
},
43+
titleBarStyle: 'hidden',
44+
titleBarOverlay: {
45+
color: '#242a3000',
46+
symbolColor: '#c2c7cf',
47+
height: 29,
48+
},
49+
backgroundColor: '#242a30',
4350
//icon: __dirname + '/icon.svg',
4451
});
4552

@@ -59,8 +66,6 @@ function createWindow() {
5966
var menu = Menu.buildFromTemplate(menuTemplate);
6067
win.setMenu(menu);
6168

62-
// win.webContents.openDevTools();
63-
6469
win.removeMenu();
6570

6671
// and load the index.html of the app.

scripts/opencomic.js

+28-14
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,21 @@ window.onerror = function(msg, url, linenumber) {
99
1010
}*/
1111

12+
function fullScreen(force = null)
13+
{
14+
if(force === null)
15+
{
16+
win = electronRemote.getCurrentWindow();
17+
force = !win.isFullScreen();
18+
}
19+
20+
titleBar.setFullScreen(force);
21+
22+
reading.hideContent(force);
23+
win.setFullScreen(force);
24+
// win.setMenuBarVisibility(!force);
25+
}
26+
1227
document.addEventListener("keydown", event => {
1328

1429
if(event.key == 'Escape')
@@ -18,9 +33,7 @@ document.addEventListener("keydown", event => {
1833

1934
if(isFullScreen)
2035
{
21-
reading.hideContent(false);
22-
win.setFullScreen(false);
23-
win.setMenuBarVisibility(true);
36+
fullScreen(false);
2437
}
2538
else
2639
{
@@ -223,6 +236,7 @@ const app = require(p.join(appDir, 'scripts/app.js')),
223236
queue = require(p.join(appDir, 'scripts/queue.js')),
224237
templates = require(p.join(appDir, 'scripts/builded/templates.js')),
225238
template = require(p.join(appDir, 'scripts/template.js')),
239+
titleBar = require(p.join(appDir, 'scripts/title-bar.js')),
226240
gamepad = require(p.join(appDir, 'scripts/gamepad.js')),
227241
dom = require(p.join(appDir, 'scripts/dom.js')),
228242
events = require(p.join(appDir, 'scripts/events.js')),
@@ -261,6 +275,9 @@ window.onload = function() {
261275

262276
template.loadInQuery('body', 'body.html');
263277

278+
titleBar.start();
279+
titleBar.setColors();
280+
264281
startApp();
265282

266283
});
@@ -364,11 +381,7 @@ async function startApp()
364381
let isFullScreen = win.isFullScreen();
365382

366383
if(!isFullScreen)
367-
{
368-
reading.hideContent(true);
369-
win.setFullScreen(true);
370-
win.setMenuBarVisibility(false);
371-
}
384+
fullScreen(true);
372385
}
373386

374387
$('body .app').css('display', 'block');
@@ -611,7 +624,7 @@ function generateAppMenu(force = false)
611624
{label: language.menu.file.addFile, click: function(){addComic()}},
612625
{label: language.menu.file.addFolder, click: function(){addComic(true)}},
613626
{type: 'separator'},
614-
{role: 'quit', label: language.menu.file.quit},
627+
{role: 'quit', label: language.menu.file.quit, click: function(){electronRemote.getCurrentWindow().close();}},
615628
]
616629
},
617630
{
@@ -622,7 +635,7 @@ function generateAppMenu(force = false)
622635
{label: language.menu.view.zoomIn, click: function(){zoomIn(); generateAppMenu();}, accelerator: 'CmdOrCtrl+=', visible: false, acceleratorWorksWhenHidden: true},
623636
{label: language.menu.view.zoomOut, click: function(){zoomOut(); generateAppMenu();}, accelerator: 'CmdOrCtrl+-'},
624637
{type: 'separator'},
625-
{label: language.menu.view.toggleFullScreen, click: function(){var win = electronRemote.getCurrentWindow(); reading.hideContent(!win.isFullScreen()); win.setFullScreen(!win.isFullScreen()); win.setMenuBarVisibility(!win.isFullScreen());}, accelerator: 'F11'},
638+
{label: language.menu.view.toggleFullScreen, click: function(){fullScreen();}, accelerator: 'F11'},
626639
]
627640
},
628641
{
@@ -638,9 +651,9 @@ function generateAppMenu(force = false)
638651
{
639652
label: language.menu.debug.main,
640653
submenu: [
641-
{role: 'reload', label: language.menu.debug.reload},
642-
{role: 'forceReload', label: language.menu.debug.forceReload},
643-
{role: 'toggleDevTools', label: language.menu.debug.toggleDevTools},
654+
{label: language.menu.debug.reload, click: function(){electronRemote.getCurrentWindow().webContents.reload();}, accelerator: 'CmdOrCtrl+R'},
655+
{label: language.menu.debug.forceReload, click: function(){electronRemote.getCurrentWindow().webContents.reloadIgnoringCache();}, accelerator: 'CmdOrCtrl+Shift+R'},
656+
{label: language.menu.debug.toggleDevTools, click: function(){electronRemote.getCurrentWindow().webContents.toggleDevTools();}, accelerator: 'CmdOrCtrl+Shift+I'},
644657
]
645658
},
646659
{
@@ -656,7 +669,8 @@ function generateAppMenu(force = false)
656669

657670
var menu = electronRemote.Menu.buildFromTemplate(menuTemplate);
658671
currentWindow.setMenu(menu);
659-
// currentWindow.setMenuBarVisibility(false);
672+
currentWindow.setMenuBarVisibility(false);
673+
titleBar.setMenu(menuTemplate);
660674
}
661675
}
662676

scripts/reading.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -1903,7 +1903,7 @@ function notCrossZoomLimits(x, y, scale = false)
19031903
else if(y < minY)
19041904
y = minY;
19051905

1906-
return {x: x, y: y, maxX: maxX, maxY: maxY};
1906+
return {x: x, y: y, maxX: maxX, maxY: maxY, height: indexSize.height, width: indexSize.width};
19071907
}
19081908

19091909
// Drag zoom
@@ -1962,12 +1962,13 @@ function startScrollWithMouse()
19621962
if(config.readingScrollWithMouse)
19631963
{
19641964
let content = template._contentRight().firstElementChild;
1965+
let rect = template._barHeader().getBoundingClientRect();
19651966

19661967
scrollWithMouseStatus = {
19671968
active: true,
19681969
content: content,
19691970
scrollTop: content.scrollTop,
1970-
headerHeight: template._barHeader().getBoundingClientRect().height,
1971+
headerHeight: rect.height + rect.top,
19711972
};
19721973

19731974
scrollWithMouse();
@@ -3264,6 +3265,7 @@ function pointermove(event)
32643265
let widthM = contentRightRect.width / 2;
32653266
let heightM = contentRightRect.height / 2;
32663267

3268+
// Calculate multipler (1.5) from withLimits.height and withLimits.width
32673269
let x = -(pageX - zoomMoveData.x) * (withLimits.maxX / widthM * 1.5);
32683270
let y = -(pageY - zoomMoveData.y) * (withLimits.maxY / heightM * 1.5);
32693271

@@ -3451,7 +3453,7 @@ function pointermove(event)
34513453
contentLeftRect = template._contentLeft().getBoundingClientRect();
34523454
}
34533455

3454-
if(shownBarHeader && pageY > barHeaderRect.height + 48)
3456+
if(shownBarHeader && pageY > barHeaderRect.height + titleBar.height() + 48 && !document.querySelector('.menu-simple.a'))
34553457
{
34563458
clearTimeout(hideContentST);
34573459

scripts/shortcuts.js

+1-9
Original file line numberDiff line numberDiff line change
@@ -226,16 +226,8 @@ function loadShortcuts()
226226
fullscreen: {
227227
name: language.menu.view.toggleFullScreen,
228228
function: function(){
229-
230229
if(inputIsFocused()) return false;
231-
232-
let win = electronRemote.getCurrentWindow();
233-
let isFullScreen = win.isFullScreen();
234-
235-
reading.hideContent(!isFullScreen);
236-
win.setFullScreen(!isFullScreen);
237-
win.setMenuBarVisibility(isFullScreen);
238-
230+
fullScreen();
239231
return true;
240232
},
241233
},

scripts/theme.js

+2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ function setColor(color)
2727
app.classList.add(color);
2828

2929
storage.updateVar('config', 'themeColor', color);
30+
31+
titleBar.setColors();
3032
}
3133

3234
function start()

0 commit comments

Comments
 (0)