1- import { app , session , BrowserWindow , BrowserView , ipcMain , dialog } from 'electron' ;
1+ import { app , session , BrowserWindow , BrowserView , ipcMain , dialog , autoUpdater } from 'electron' ;
22import { ElectronRecorder } from './electron-recorder' ;
33
44import { ElectronReplayApp , STATIC_PREFIX } from 'replaywebpage/src/electron-replay-app' ;
@@ -9,9 +9,13 @@ import { PassThrough } from 'stream';
99import fs from 'fs' ;
1010import util from 'util' ;
1111
12+
1213import { checkPins , ipfsAddWithReplay , ipfsUnpinAll } from '../utils' ;
1314
1415
16+ app . commandLine . appendSwitch ( 'disable-features' , 'CrossOriginOpenerPolicy' ) ;
17+
18+
1519// ===========================================================================
1620class ElectronRecorderApp extends ElectronReplayApp
1721{
@@ -55,7 +59,7 @@ class ElectronRecorderApp extends ElectronReplayApp
5559 this . ipfsUnpin ( event , reqId , pinList ) ;
5660 } ) ;
5761
58- require ( '@electron/remote/main' ) . initialize ( ) ;
62+ // require('@electron/remote/main').initialize();
5963
6064 super . onAppReady ( ) ;
6165 }
@@ -112,73 +116,35 @@ class ElectronRecorderApp extends ElectronReplayApp
112116
113117 const recWindow = new BrowserWindow ( {
114118 width : this . screenSize . width ,
115- height : this . screenSize . height - 1 ,
119+ height : this . screenSize . height ,
116120 isMaximized : true ,
117121 show : true ,
118122 webPreferences : {
119- enableRemoteModule : true ,
120- nodeIntegration : true ,
121- contextIsolation : false
122- }
123- } ) ;
124-
125- const view = new BrowserView ( { webPreferences : {
126- partition : "persist:wr" ,
127- plugins : false ,
128123 contextIsolation : true ,
124+ webviewTag : true ,
125+ preload : path . join ( __dirname , "rec-preload.js" )
129126 }
130127 } ) ;
131128
132- const id = view . webContents . id ;
133-
134- recWindow . loadURL ( STATIC_PREFIX + "locbar.html#" + id ) ;
135-
136- const HEADER_HEIGHT = 73 ;
137- recWindow . addBrowserView ( view ) ;
138- view . setBounds ( { x : 0 , y : HEADER_HEIGHT , width : this . screenSize . width , height : this . screenSize . height - HEADER_HEIGHT } ) ;
139- view . setAutoResize ( { width : true , height : true } ) ;
140- recWindow . setSize ( this . screenSize . width , this . screenSize . height ) ;
141-
142- recWindow . maximize ( ) ;
143-
144- const popupView = new BrowserView ( { webPreferences : {
145- nodeIntegration : true ,
146- contextIsolation : false
147- } } ) ;
129+ recWindow . webContents . on ( "did-attach-webview" , ( event , contents ) => {
130+ this . initRecorder ( recWindow , contents , url , collId , startRec ) ;
131+ } ) ;
148132
149- let popupShown = false ;
133+ recWindow . loadURL ( STATIC_PREFIX + "rec-window.html" ) ;
150134
151- function setPopupBounds ( ) {
152- const bounds = recWindow . getBounds ( ) ;
153- popupView . setBounds ( { x : bounds . width - 400 , y : HEADER_HEIGHT - 22 , width : 400 , height : 300 } ) ;
154- //popupView.webContents.openDevTools();
155- }
135+ return recWindow ;
136+ }
156137
157- ipcMain . on ( "popup-toggle-" + id , ( event ) => {
158- if ( ! popupShown ) {
159- recWindow . addBrowserView ( popupView ) ;
160- setPopupBounds ( ) ;
161- popupView . webContents . loadURL ( STATIC_PREFIX + "app-popup.html#" + id ) . then ( ( ) => {
162- popupView . webContents . send ( "popup" , {
163- type : "status" ,
164- recording : false ,
165- collId,
166- pageUrl : url } ) ;
167- } ) ;
168- } else {
169- recWindow . removeBrowserView ( popupView ) ;
170- }
171- popupShown = ! popupShown ;
172- } ) ;
138+ checkUpdates ( ) {
139+ autoUpdater . allowPrerelease = true ;
140+ super . checkUpdates ( ) ;
141+ }
173142
174- recWindow . on ( 'resize' , ( event ) => {
175- if ( popupShown ) {
176- setPopupBounds ( ) ;
177- }
178- } ) ;
143+ async initRecorder ( recWindow , recWebContents , url , collId , startRec , popupView = null ) {
144+ const id = recWebContents . id ;
179145
180146 const recorder = new ElectronRecorder ( {
181- recWC : view . webContents ,
147+ recWC : recWebContents ,
182148 appWC : this . mainWindow . webContents ,
183149 recWindow,
184150 collId,
@@ -194,7 +160,9 @@ class ElectronRecorderApp extends ElectronReplayApp
194160 } ) ;
195161 } ) ;
196162
197- popupView . webContents . on ( "new-window" , ( event , url , frameName , disposition , options , additionalFeatures , referrer ) => {
163+ const newWinContents = popupView ? popupView . webContents : recWindow . webContents ;
164+
165+ newWinContents . on ( "new-window" , ( event , url ) => {
198166 event . preventDefault ( ) ;
199167 if ( url . startsWith ( STATIC_PREFIX ) ) {
200168 this . mainWindow . loadURL ( url ) ;
@@ -206,7 +174,7 @@ class ElectronRecorderApp extends ElectronReplayApp
206174 switch ( msg . type ) {
207175 case "startRecording" :
208176 await recorder . attach ( ) ;
209- view . webContents . reload ( ) ;
177+ recWebContents . reload ( ) ;
210178 break ;
211179
212180 case "stopRecording" :
@@ -215,37 +183,41 @@ class ElectronRecorderApp extends ElectronReplayApp
215183 }
216184 } ) ;
217185
218- view . webContents . on ( "new-window" , ( event , url , frameName , disposition , options , additionalFeatures , referrer ) => {
186+ recWebContents . on ( "new-window" , ( event , url , frameName , disposition , options , additionalFeatures , referrer ) => {
219187 event . preventDefault ( ) ;
220188 event . newGuest = this . createRecordWindow ( url , collId , startRec ) ;
221189 console . log ( "new-window" , url , frameName , disposition , options , additionalFeatures , referrer ) ;
222190 } ) ;
223191
224- view . webContents . on ( "destroyed" , ( ) => {
192+ recWebContents . on ( "destroyed" , ( ) => {
225193 this . recorders . delete ( id ) ;
226194 } ) ;
227195
228- ( async ( ) => {
229- await view . webContents . loadURL ( "about:blank" ) ;
196+ //await recWebContents.loadURL("about:blank");
230197
231- view . webContents . clearHistory ( ) ;
232- this . recorders . set ( id , recorder ) ;
233- if ( startRec ) {
234- await recorder . attach ( ) ;
235- }
198+ recWebContents . clearHistory ( ) ;
236199
237- if ( process . env . NODE_ENV === "development" ) {
238- view . webContents . openDevTools ( ) ;
239- }
200+ this . recorders . set ( id , recorder ) ;
201+ if ( startRec ) {
202+ await recorder . attach ( ) ;
203+ } else {
204+ newWinContents . send ( "stats" , {
205+ type : "status" ,
206+ recording : false ,
207+ collId,
208+ pageUrl : url
209+ } ) ;
210+ }
240211
241- try {
242- view . webContents . loadURL ( url ) ;
243- } catch ( e ) {
244- console . warn ( "Load Failed" , e ) ;
245- }
246- } ) ( ) ;
212+ if ( process . env . NODE_ENV === "development" ) {
213+ //recWebContents.openDevTools();
214+ }
247215
248- return recWindow ;
216+ try {
217+ recWebContents . loadURL ( url ) ;
218+ } catch ( e ) {
219+ console . warn ( "Load Failed" , e ) ;
220+ }
249221 }
250222
251223 async ipfsStart ( validPins ) {
0 commit comments