@@ -23,6 +23,36 @@ router.post('/resize', (req, res) => {
23
23
( _a = state . windows [ id ] ) === null || _a === void 0 ? void 0 : _a . setSize ( parseInt ( width ) , parseInt ( height ) ) ;
24
24
res . sendStatus ( 200 ) ;
25
25
} ) ;
26
+ router . post ( '/title' , ( req , res ) => {
27
+ var _a ;
28
+ const { id, title } = req . body ;
29
+ ( _a = state . windows [ id ] ) === null || _a === void 0 ? void 0 : _a . setTitle ( title ) ;
30
+ res . sendStatus ( 200 ) ;
31
+ } ) ;
32
+ router . post ( '/url' , ( req , res ) => {
33
+ var _a ;
34
+ const { id, url } = req . body ;
35
+ ( _a = state . windows [ id ] ) === null || _a === void 0 ? void 0 : _a . loadURL ( appendWindowIdToUrl ( url , id ) ) ;
36
+ res . sendStatus ( 200 ) ;
37
+ } ) ;
38
+ router . post ( '/closable' , ( req , res ) => {
39
+ var _a ;
40
+ const { id, closable } = req . body ;
41
+ ( _a = state . windows [ id ] ) === null || _a === void 0 ? void 0 : _a . setClosable ( closable ) ;
42
+ res . sendStatus ( 200 ) ;
43
+ } ) ;
44
+ router . post ( '/show-dev-tools' , ( req , res ) => {
45
+ var _a ;
46
+ const { id } = req . body ;
47
+ ( _a = state . windows [ id ] ) === null || _a === void 0 ? void 0 : _a . webContents . openDevTools ( ) ;
48
+ res . sendStatus ( 200 ) ;
49
+ } ) ;
50
+ router . post ( '/hide-dev-tools' , ( req , res ) => {
51
+ var _a ;
52
+ const { id } = req . body ;
53
+ ( _a = state . windows [ id ] ) === null || _a === void 0 ? void 0 : _a . webContents . closeDevTools ( ) ;
54
+ res . sendStatus ( 200 ) ;
55
+ } ) ;
26
56
router . post ( '/position' , ( req , res ) => {
27
57
var _a ;
28
58
const { id, x, y, animate } = req . body ;
@@ -50,33 +80,73 @@ router.post('/hide', (req, res) => {
50
80
}
51
81
return res . sendStatus ( 200 ) ;
52
82
} ) ;
83
+ router . post ( '/always-on-top' , ( req , res ) => {
84
+ var _a ;
85
+ const { id, alwaysOnTop } = req . body ;
86
+ ( _a = state . windows [ id ] ) === null || _a === void 0 ? void 0 : _a . setAlwaysOnTop ( alwaysOnTop ) ;
87
+ res . sendStatus ( 200 ) ;
88
+ } ) ;
53
89
router . get ( '/current' , ( req , res ) => {
54
90
const currentWindow = Object . values ( state . windows ) . find ( window => window . id === BrowserWindow . getFocusedWindow ( ) . id ) ;
55
91
const id = Object . keys ( state . windows ) . find ( key => state . windows [ key ] === currentWindow ) ;
56
- res . json ( {
92
+ res . json ( getWindowData ( id ) ) ;
93
+ } ) ;
94
+ router . get ( '/get/:id' , ( req , res ) => {
95
+ const { id } = req . params ;
96
+ if ( state . windows [ id ] === undefined ) {
97
+ res . sendStatus ( 404 ) ;
98
+ return ;
99
+ }
100
+ res . json ( getWindowData ( id ) ) ;
101
+ } ) ;
102
+ function appendWindowIdToUrl ( url , id ) {
103
+ return url + ( url . indexOf ( '?' ) === - 1 ? '?' : '&' ) + '_windowId=' + id ;
104
+ }
105
+ function getWindowData ( id ) {
106
+ const currentWindow = state . windows [ id ] ;
107
+ if ( state . windows [ id ] === undefined ) {
108
+ throw `Window [${ id } ] not found` ;
109
+ }
110
+ return {
57
111
id : id ,
58
112
x : currentWindow . getPosition ( ) [ 0 ] ,
59
113
y : currentWindow . getPosition ( ) [ 1 ] ,
60
114
width : currentWindow . getSize ( ) [ 0 ] ,
61
115
height : currentWindow . getSize ( ) [ 1 ] ,
62
116
title : currentWindow . getTitle ( ) ,
63
117
alwaysOnTop : currentWindow . isAlwaysOnTop ( ) ,
64
- } ) ;
65
- } ) ;
66
- router . post ( '/always-on-top' , ( req , res ) => {
67
- var _a ;
68
- const { id, alwaysOnTop } = req . body ;
69
- ( _a = state . windows [ id ] ) === null || _a === void 0 ? void 0 : _a . setAlwaysOnTop ( alwaysOnTop ) ;
70
- res . sendStatus ( 200 ) ;
71
- } ) ;
118
+ url : currentWindow . webContents . getURL ( ) ,
119
+ autoHideMenuBar : currentWindow . isMenuBarAutoHide ( ) ,
120
+ fullscreen : currentWindow . isFullScreen ( ) ,
121
+ fullscreenable : currentWindow . isFullScreenable ( ) ,
122
+ kiosk : currentWindow . isKiosk ( ) ,
123
+ devToolsOpen : currentWindow . webContents . isDevToolsOpened ( ) ,
124
+ resizable : currentWindow . isResizable ( ) ,
125
+ movable : currentWindow . isMovable ( ) ,
126
+ minimizable : currentWindow . isMinimizable ( ) ,
127
+ maximizable : currentWindow . isMaximizable ( ) ,
128
+ closable : currentWindow . isClosable ( ) ,
129
+ focusable : currentWindow . isFocusable ( ) ,
130
+ focused : currentWindow . isFocused ( ) ,
131
+ hasShadow : currentWindow . hasShadow ( ) ,
132
+ } ;
133
+ }
72
134
router . post ( '/open' , ( req , res ) => {
73
- let { id, x, y, frame, width, height, minWidth, minHeight, maxWidth, maxHeight, focusable, hasShadow, url, resizable, movable, minimizable, maximizable, closable, title, alwaysOnTop, titleBarStyle, trafficLightPosition, vibrancy, backgroundColor, transparency, showDevTools, fullscreen, fullscreenable, kiosk, autoHideMenuBar, } = req . body ;
135
+ let { id, x, y, frame, width, height, minWidth, minHeight, maxWidth, maxHeight, focusable, hasShadow, url, resizable, movable, minimizable, maximizable, closable, title, alwaysOnTop, titleBarStyle, trafficLightPosition, vibrancy, backgroundColor, transparency, showDevTools, fullscreen, fullscreenable, kiosk, autoHideMenuBar, webPreferences , } = req . body ;
74
136
if ( state . windows [ id ] ) {
75
137
state . windows [ id ] . show ( ) ;
76
138
state . windows [ id ] . focus ( ) ;
77
139
return res . sendStatus ( 200 ) ;
78
140
}
79
141
let preloadPath = join ( __dirname , '../../electron-plugin/dist/preload/index.js' ) ;
142
+ const defaultWebPreferences = {
143
+ backgroundThrottling : false ,
144
+ spellcheck : false ,
145
+ preload : preloadPath ,
146
+ sandbox : false ,
147
+ contextIsolation : false ,
148
+ nodeIntegration : true ,
149
+ } ;
80
150
let windowState = undefined ;
81
151
if ( req . body . rememberState === true ) {
82
152
windowState = windowStateKeeper ( {
@@ -97,14 +167,7 @@ router.post('/open', (req, res) => {
97
167
trafficLightPosition,
98
168
vibrancy,
99
169
focusable,
100
- autoHideMenuBar } , ( process . platform === 'linux' ? { icon : state . icon } : { } ) ) , { webPreferences : {
101
- backgroundThrottling : false ,
102
- spellcheck : false ,
103
- preload : preloadPath ,
104
- sandbox : false ,
105
- contextIsolation : false ,
106
- nodeIntegration : true ,
107
- } , fullscreen,
170
+ autoHideMenuBar } , ( process . platform === 'linux' ? { icon : state . icon } : { } ) ) , { webPreferences : Object . assign ( Object . assign ( { } , webPreferences ) , defaultWebPreferences ) , fullscreen,
108
171
fullscreenable,
109
172
kiosk } ) ) ;
110
173
if ( ( process . env . NODE_ENV === 'development' || showDevTools === true ) && showDevTools !== false ) {
@@ -168,11 +231,14 @@ router.post('/open', (req, res) => {
168
231
payload : [ id ]
169
232
} ) ;
170
233
} ) ;
171
- url += ( url . indexOf ( '?' ) === - 1 ? '?' : '&' ) + '_windowId=' + id ;
234
+ url = appendWindowIdToUrl ( url , id ) ;
172
235
window . loadURL ( url ) ;
173
236
window . webContents . on ( 'did-finish-load' , ( ) => {
174
237
window . show ( ) ;
175
238
} ) ;
239
+ window . webContents . on ( 'did-fail-load' , ( event ) => {
240
+ console . error ( 'failed to open window...' , event ) ;
241
+ } ) ;
176
242
state . windows [ id ] = window ;
177
243
res . sendStatus ( 200 ) ;
178
244
} ) ;
0 commit comments