@@ -13,7 +13,8 @@ import {
1313 CLOSETAB ,
1414 FOCUSTAB ,
1515 CLOSEALLTAB ,
16- MAINTAB
16+ MAINTAB ,
17+ SETTITLE
1718} from "../utils" ;
1819
1920interface IWindowManager {
@@ -37,26 +38,37 @@ class WindowManager implements IWindowManager {
3738 this . mainWindow = new E . BrowserWindow ( options ) ;
3839 this . mainWindow . loadURL ( isDev ? winUrlDev : winUrlProd ) ;
3940
40- E . session . defaultSession ! . setPermissionRequestHandler ( ( webContents , permission , callback ) => {
41- const whitelist = [
42- 'fullscreen' ,
43- 'pointerLock' ,
44- ] ;
45- callback ( ! ! whitelist . indexOf ( permission ) ) ;
46- } ) ;
47-
4841 const tab = Tabs . newTab ( `${ home } /login` , {
4942 x : 0 ,
5043 y : parseInt ( ( 28 * await this . getZoom ( ) + '' ) . substr ( 0 , 4 ) ) ,
5144 width : this . mainWindow . getContentBounds ( ) . width ,
5245 height : this . mainWindow . getContentBounds ( ) . height - parseInt ( ( 28 * await this . getZoom ( ) + '' ) . substr ( 0 , 4 ) )
53- } , 'web.js' ) ;
54- tab . webContents . on ( 'will-navigate' , this . onMainWindowWillNavigate ) ;
55-
46+ } , 'loadMainContetnt.js' ) ;
47+
5648 this . mainWindow . setBrowserView ( tab ) ;
49+ tab . webContents . on ( 'will-navigate' , this . onMainWindowWillNavigate ) ;
50+ tab . webContents . on ( 'new-window' , ( event : Event , url : string , fileName : string , disposition , options , additionalFeatures ) => {
51+ // console.log('mainWindow.webContents will-navigate: ', url, fileName, disposition, options, additionalFeatures);
52+ let view ;
53+
54+ this . getZoom ( ) . then ( zoom => {
55+ view = Tabs . newTab ( `${ url } ` , {
56+ x : 0 ,
57+ y : parseInt ( ( 28 * zoom + '' ) . substr ( 0 , 4 ) ) ,
58+ width : this . mainWindow . getContentBounds ( ) . width ,
59+ height : this . mainWindow . getContentBounds ( ) . height - parseInt ( ( 28 * zoom + '' ) . substr ( 0 , 4 ) )
60+ } , 'loadContetnt.js' ) ;
61+
62+ view . webContents . on ( 'will-navigate' , this . onMainWindowWillNavigate ) ;
63+
64+ this . mainWindow . setBrowserView ( view ) ;
65+ this . mainWindow . webContents . send ( TABADDED , { id : view . id , url} ) ;
66+ } )
67+ } ) ;
5768 this . mainWindow . on ( 'resize' , this . onResize ) ;
5869 this . mainWindow . on ( 'maximize' , ( e : Event ) => setTimeout ( ( ) => this . onResize ( e ) , 100 ) ) ;
5970 this . mainWindow . on ( 'unmaximize' , ( e : Event ) => setTimeout ( ( ) => this . onResize ( e ) , 100 ) ) ;
71+ this . mainWindow . on ( 'move' , ( e : Event ) => setTimeout ( ( ) => this . onResize ( e ) , 100 ) ) ;
6072 this . mainWindow . on ( 'close' , this . onWindowAllClosed ) ;
6173
6274 shortcuts ( ) ;
@@ -67,7 +79,7 @@ class WindowManager implements IWindowManager {
6779 } , 600 ) ;
6880
6981 if ( isDev ) this . devtools ( ) ;
70- // if (isDev) this.mainWindow.webContents.toggleDevTools();
82+ if ( isDev ) this . mainWindow . webContents . toggleDevTools ( ) ;
7183 } ) ;
7284 E . app . on ( 'window-all-closed' , this . onWindowAllClosed ) ;
7385
@@ -96,7 +108,7 @@ class WindowManager implements IWindowManager {
96108 y : parseInt ( ( 28 * await this . getZoom ( ) + '' ) . substr ( 0 , 4 ) ) ,
97109 width : this . mainWindow . getContentBounds ( ) . width ,
98110 height : this . mainWindow . getContentBounds ( ) . height - parseInt ( ( 28 * await this . getZoom ( ) + '' ) . substr ( 0 , 4 ) )
99- } , 'web .js' ) ;
111+ } , 'loadMainContetnt .js' ) ;
100112 this . mainWindow . setBrowserView ( view ) ;
101113 view . webContents . on ( 'will-navigate' , this . onMainWindowWillNavigate ) ;
102114
@@ -121,6 +133,9 @@ class WindowManager implements IWindowManager {
121133 E . ipcMain . on ( CLOSEALLTAB , ( ) => {
122134 console . log ( 'Close all tab' ) ;
123135 } ) ;
136+ E . ipcMain . on ( SETTITLE , ( event : Event , title : string ) => {
137+ this . mainWindow . webContents . send ( SETTITLE , { id : this . mainWindow . getBrowserView ( ) ! . id , title } )
138+ } ) ;
124139 }
125140
126141
@@ -154,7 +169,6 @@ class WindowManager implements IWindowManager {
154169 if ( response . statusCode >= 200 && response . statusCode <= 299 ) {
155170
156171 E . session . defaultSession ! . cookies . flushStore ( ( ) => {
157-
158172 const view = Tabs . focus ( 1 ) ;
159173 this . mainWindow . setBrowserView ( view ) ;
160174 view . webContents . reload ( ) ;
@@ -190,13 +204,6 @@ class WindowManager implements IWindowManager {
190204 private onResize = async ( event ?: Event ) => {
191205 const browserViews = E . BrowserView . getAllViews ( ) ;
192206
193- console . log ( 'onResize, event: ' , event && event ! . target ) ;
194- console . log ( 'onResize, bounds: ' , {
195- x : 0 ,
196- y : parseInt ( ( 28 * await this . getZoom ( ) + '' ) . substr ( 0 , 4 ) ) ,
197- width : this . mainWindow . getContentBounds ( ) . width ,
198- height : this . mainWindow . getContentBounds ( ) . height - parseInt ( ( 28 * await this . getZoom ( ) + '' ) . substr ( 0 , 4 ) )
199- } ) ;
200207 browserViews . forEach ( async bw => bw . setBounds ( {
201208 x : 0 ,
202209 y : parseInt ( ( 28 * await this . getZoom ( ) + '' ) . substr ( 0 , 4 ) ) ,
0 commit comments