@@ -10,7 +10,6 @@ import { PNG } from "pngjs";
1010import { Readable } from "stream" ;
1111import { RpcApi } from "../frontend/app/store/wshclientapi" ;
1212import { getWebServerEndpoint } from "../frontend/util/endpoints" ;
13- import * as keyutil from "../frontend/util/keyutil" ;
1413import { fireAndForget , parseDataUrl } from "../frontend/util/util" ;
1514import {
1615 incrementTermCommandsDurable ,
@@ -22,16 +21,13 @@ import {
2221import { createBuilderWindow , getAllBuilderWindows , getBuilderWindowByWebContentsId } from "./emain-builder" ;
2322import { callWithOriginalXdgCurrentDesktopAsync , unamePlatform } from "./emain-platform" ;
2423import { getWaveTabViewByWebContentsId } from "./emain-tabview" ;
25- import { handleCtrlShiftState } from "./emain-util" ;
24+ import { setWebviewKeys } from "./emain-util" ;
2625import { getWaveVersion } from "./emain-wavesrv" ;
2726import { createNewWaveWindow , getWaveWindowByWebContentsId } from "./emain-window" ;
2827import { ElectronWshClient } from "./emain-wsh" ;
2928
3029const electronApp = electron . app ;
3130
32- let webviewFocusId : number = null ;
33- let webviewKeys : string [ ] = [ ] ;
34-
3531export function openBuilderWindow ( appId ?: string ) {
3632 const normalizedAppId = appId || "" ;
3733 const existingBuilderWindows = getAllBuilderWindows ( ) ;
@@ -236,6 +232,14 @@ export function initIpcHandlers() {
236232 menu . popup ( ) ;
237233 } ) ;
238234
235+ electron . ipcMain . on ( "webview-mouse-navigate" , ( event : electron . IpcMainEvent , direction : string ) => {
236+ if ( direction === "back" ) {
237+ event . sender . goBack ( ) ;
238+ } else if ( direction === "forward" ) {
239+ event . sender . goForward ( ) ;
240+ }
241+ } ) ;
242+
239243 electron . ipcMain . on ( "download" , ( event , payload ) => {
240244 const baseName = encodeURIComponent ( path . basename ( payload . filePath ) ) ;
241245 const streamingUrl =
@@ -280,48 +284,12 @@ export function initIpcHandlers() {
280284 event . returnValue = event . sender . getZoomFactor ( ) ;
281285 } ) ;
282286
283- const hasBeforeInputRegisteredMap = new Map < number , boolean > ( ) ;
284-
285- electron . ipcMain . on ( "webview-focus" , ( event : Electron . IpcMainEvent , focusedId : number ) => {
286- webviewFocusId = focusedId ;
287+ electron . ipcMain . on ( "webview-focus" , ( _event : Electron . IpcMainEvent , focusedId : number ) => {
287288 console . log ( "webview-focus" , focusedId ) ;
288- if ( focusedId == null ) {
289- return ;
290- }
291- const parentWc = event . sender ;
292- const webviewWc = electron . webContents . fromId ( focusedId ) ;
293- if ( webviewWc == null ) {
294- webviewFocusId = null ;
295- return ;
296- }
297- if ( ! hasBeforeInputRegisteredMap . get ( focusedId ) ) {
298- hasBeforeInputRegisteredMap . set ( focusedId , true ) ;
299- webviewWc . on ( "before-input-event" , ( e , input ) => {
300- let waveEvent = keyutil . adaptFromElectronKeyEvent ( input ) ;
301- handleCtrlShiftState ( parentWc , waveEvent ) ;
302- if ( webviewFocusId != focusedId ) {
303- return ;
304- }
305- if ( input . type != "keyDown" ) {
306- return ;
307- }
308- for ( let keyDesc of webviewKeys ) {
309- if ( keyutil . checkKeyPressed ( waveEvent , keyDesc ) ) {
310- e . preventDefault ( ) ;
311- parentWc . send ( "reinject-key" , waveEvent ) ;
312- console . log ( "webview reinject-key" , keyDesc ) ;
313- return ;
314- }
315- }
316- } ) ;
317- webviewWc . on ( "destroyed" , ( ) => {
318- hasBeforeInputRegisteredMap . delete ( focusedId ) ;
319- } ) ;
320- }
321289 } ) ;
322290
323291 electron . ipcMain . on ( "register-global-webview-keys" , ( event , keys : string [ ] ) => {
324- webviewKeys = keys ?? [ ] ;
292+ setWebviewKeys ( keys ) ;
325293 } ) ;
326294
327295 electron . ipcMain . on ( "set-keyboard-chord-mode" , ( event ) => {
0 commit comments