File tree Expand file tree Collapse file tree 5 files changed +116
-0
lines changed Expand file tree Collapse file tree 5 files changed +116
-0
lines changed Original file line number Diff line number Diff line change @@ -16,6 +16,8 @@ export default class App {
16
16
require ( './updator' ) ( this ) ;
17
17
} else if ( action === 'electron-webview-schedule' ) {
18
18
require ( './webview-schedule' ) ( this ) ;
19
+ } else if ( action === 'electron-windows-titlebar' ) {
20
+ require ( './windows-titlebar' ) ( this ) ;
19
21
}
20
22
} ) ;
21
23
}
Original file line number Diff line number Diff line change
1
+ 'use strict' ;
2
+
3
+ const url = require ( 'url' ) ;
4
+ const path = require ( 'path' ) ;
5
+ const _ = require ( 'lodash' ) ;
6
+ const { ipcMain } = require ( 'electron' ) ;
7
+ const windowTitleBar = require ( 'electron-windows-titlebar' ) ;
8
+
9
+ module . exports = ( app : any ) => {
10
+ const windowUrl = url . format ( {
11
+ pathname : path . join ( __dirname , 'renderer' , 'main.html' ) ,
12
+ protocol : 'file:' ,
13
+ } ) ;
14
+ const loadingUrl = url . format ( {
15
+ pathname : path . join ( __dirname , 'renderer' , 'loading.html' ) ,
16
+ protocol : 'file:' ,
17
+ } ) ;
18
+
19
+ const window = app . windowManager . create ( {
20
+ name : Date . now ( ) ,
21
+ loadingView : {
22
+ url : loadingUrl ,
23
+ } ,
24
+ browserWindow : {
25
+ webPreferences : {
26
+ nodeIntegration : true ,
27
+ webSecurity : true ,
28
+ webviewTag : true ,
29
+ preload : path . join ( __dirname , 'renderer' , 'preload.js' ) ,
30
+ } ,
31
+ } ,
32
+ } ) ;
33
+ const hwnd = window ?. getNativeWindowHandle ( ) ;
34
+ ipcMain . on ( 'switch-theme-mode' , ( _ , params ) => {
35
+ const { dark } = params ;
36
+ if ( hwnd ) {
37
+ dark ? windowTitleBar . switchDarkMode ( hwnd ) : windowTitleBar . switchLightMode ( hwnd ) ;
38
+ }
39
+ } ) ;
40
+ window . loadURL ( windowUrl ) ;
41
+ } ;
Original file line number Diff line number Diff line change
1
+ <!DOCTYPE html>
2
+ < html >
3
+ < head >
4
+ < meta charset ="UTF-8 ">
5
+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 ">
6
+ < title > Loading</ title >
7
+ < style >
8
+ ::-webkit-scrollbar {
9
+ display : none;
10
+ }
11
+ * {
12
+ overflow : hidden;
13
+ box-sizing : border-box;
14
+ }
15
+ html ,
16
+ body {
17
+ background-color : white;
18
+ width : 100% ;
19
+ height : 100% ;
20
+ margin : 0 ;
21
+ padding : 0 ;
22
+ }
23
+ .wrapper {
24
+ text-align : center;
25
+ padding-top : 100px ;
26
+ }
27
+ </ style >
28
+ </ head >
29
+ < body >
30
+ < div class ="wrapper ">
31
+ < div class ="loading ">
32
+ loading...
33
+ </ div >
34
+ </ div >
35
+ </ body >
36
+ </ html >
Original file line number Diff line number Diff line change
1
+ <!DOCTYPE html>
2
+ < html >
3
+ < head >
4
+ < meta charset ="UTF-8 ">
5
+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 ">
6
+ < title > Addon Demo</ title >
7
+ </ head >
8
+ < body >
9
+ < h1 > Titlebar Addon Demo</ h1 >
10
+ < p > Print handle of current window < span id ="electron-window "> </ span > </ p >
11
+ < button id ="switch-dark-mode "> switch dark mode</ button >
12
+ < button id ="switch-light-mode "> switch light mode</ button >
13
+ </ body >
14
+ </ html >
Original file line number Diff line number Diff line change
1
+ 'use strict' ;
2
+
3
+ const { contextBridge, ipcRenderer } = require ( 'electron' ) ;
4
+
5
+ contextBridge . exposeInMainWorld ( 'electron' , {
6
+ ipcRenderer : {
7
+ send : ( channel , ...args ) => ipcRenderer . send ( channel , ...args ) ,
8
+ } ,
9
+ } ) ;
10
+
11
+ window . addEventListener ( 'DOMContentLoaded' , ( ) => {
12
+ document . getElementById ( 'switch-dark-mode' ) . addEventListener ( 'click' , ( ) => {
13
+ ipcRenderer . send ( 'switch-theme-mode' , {
14
+ dark : true ,
15
+ } ) ;
16
+ } ) ;
17
+
18
+ document . getElementById ( 'switch-light-mode' ) . addEventListener ( 'click' , ( ) => {
19
+ ipcRenderer . send ( 'switch-theme-mode' , {
20
+ dark : false ,
21
+ } ) ;
22
+ } ) ;
23
+ } ) ;
You can’t perform that action at this time.
0 commit comments