@@ -36,6 +36,32 @@ proc onClose*(e: js) =
3636 mainWindow.webContents.send " CODETRACER::close" , js{}
3737 close = true
3838
39+ proc setupSecureContext * (win: JsObject ) =
40+ # Prevent opening new windows or popups
41+ win.webContents.setWindowOpenHandler (proc : js =
42+ return js{
43+ " action" : " deny"
44+ }
45+ )
46+
47+ # Disable webview tags
48+ electron_vars.app.on (
49+ " web-contents-created" ,
50+ proc (evt: js, contents: js) =
51+ contents.on (" will-attach-webview" , proc (event: js) =
52+ event.preventDefault ()
53+ )
54+ )
55+
56+ # Disable window navigation
57+ win.on (
58+ " will-navigate" ,
59+ proc (e: js, url: js) =
60+ let current = win.getURL ()
61+ if url != current:
62+ e.preventDefault ()
63+ )
64+
3965proc createMainWindow * : js =
4066 when not defined (server):
4167 # TODO load from config
@@ -72,13 +98,16 @@ proc createMainWindow*: js =
7298
7399 let win = jsnew electron.BrowserWindow (initInfo)
74100 win.on (" maximize" , proc () =
75- win.webContents.executeJavaScript (" document.body.style.backgroundColor = 'black';" ))
101+ win.webContents.send " CODETRACER::maximize" , js{}
102+ )
76103 win.on (" unmaximize" , proc () =
77- win.webContents.executeJavaScript (" document.body.style.backgroundColor = 'transparent';" ))
104+ win.webContents.send " CODETRACER::unmaximize" , js{}
105+ )
78106 win.maximize ()
79- let url = " file://" & $ codetracerExeDir & " /index.html"
80107
81- win.loadURL (cstring (url))
108+ let url = $ codetracerExeDir & " /index.html"
109+ win.loadFile (url)
110+ setupSecureContext (win)
82111
83112 win.on (" close" , onClose)
84113 # TODO : eventually add a shortcut and ipc message that lets us
0 commit comments