(webPreferences: Electron.WebPreferences)
| 124 | } |
| 125 | |
| 126 | recreateWCVWithDifferentWebPreferences(webPreferences: Electron.WebPreferences) { |
| 127 | const currentBounds = this.wcv.getBounds() |
| 128 | const currentNavigationHistory = this.wcv.webContents.navigationHistory.getAllEntries() |
| 129 | const currentNavigationHistoryIndex = this.wcv.webContents.navigationHistory.getActiveIndex() |
| 130 | |
| 131 | this.eventListeners.forEach((unsub) => unsub()) |
| 132 | this.wcv.webContents.removeAllListeners() |
| 133 | this.wcv.webContents.close() |
| 134 | |
| 135 | log.log('[main] webcontentsview-recreate: re-creating WebContentsView with new preferences') |
| 136 | |
| 137 | const wcvSession = session.fromPartition('persist:horizon') |
| 138 | |
| 139 | // Get user theme to set initial background color and prevent white flash |
| 140 | const userConfig = getUserConfig() |
| 141 | const isDarkMode = userConfig.settings?.app_style === 'dark' |
| 142 | const backgroundColor = isDarkMode ? '#1a1a1a' : '#ffffff' |
| 143 | |
| 144 | this.wcv = new WebContentsView({ |
| 145 | webPreferences: { |
| 146 | session: wcvSession, |
| 147 | nodeIntegration: false, |
| 148 | contextIsolation: true, |
| 149 | sandbox: true, |
| 150 | webSecurity: !isDev, |
| 151 | scrollBounce: true, |
| 152 | defaultFontSize: 16, |
| 153 | autoplayPolicy: 'document-user-activation-required', |
| 154 | preload: this.opts.preload || path.resolve(__dirname, '../preload/webcontents.js'), |
| 155 | additionalArguments: this.opts.additionalArguments || [], |
| 156 | transparent: this.opts.transparent, |
| 157 | backgroundColor, |
| 158 | ...webPreferences |
| 159 | } |
| 160 | }) |
| 161 | |
| 162 | if (currentBounds) { |
| 163 | this.wcv.setBounds(currentBounds) |
| 164 | } |
| 165 | |
| 166 | if (currentNavigationHistory.length > 0 && currentNavigationHistoryIndex >= 0) { |
| 167 | this.wcv.webContents.navigationHistory.restore({ |
| 168 | index: currentNavigationHistoryIndex, |
| 169 | entries: currentNavigationHistory |
| 170 | }) |
| 171 | } |
| 172 | this.manager.recreatedWCV(this) |
| 173 | } |
| 174 | loadRightPreload(newUrl: string, oldUrl: string) { |
| 175 | log.log('[main] webcontentsview: check if we need to re-create WCV', newUrl, oldUrl) |
| 176 |
no test coverage detected