1- import electron from "electron" ;
1+ import electron , {
2+ type BrowserWindowConstructorOptions ,
3+ app ,
4+ net ,
5+ protocol ,
6+ session ,
7+ } from "electron" ;
28import { dirname , join } from "path" ;
39import { CONFIG_PATHS } from "src/util.mjs" ;
410import type { PackageJson } from "type-fest" ;
@@ -28,7 +34,7 @@ Object.defineProperty(global, "appSettings", {
2834// https://github.com/discord/electron/blob/13-x-y/lib/browser/api/browser-window.ts#L60-L62
2935// Thank you, Ven, for pointing this out!
3036class BrowserWindow extends electron . BrowserWindow {
31- public constructor ( opts : electron . BrowserWindowConstructorOptions ) {
37+ public constructor ( opts : BrowserWindowConstructorOptions ) {
3238 const titleBarSetting = getSetting < boolean > ( "dev.replugged.Settings" , "titleBar" , false ) ;
3339 if ( opts . frame && process . platform === "linux" && titleBarSetting ) opts . frame = void 0 ;
3440
@@ -72,13 +78,13 @@ delete require.cache[electronPath]!.exports;
7278require . cache [ electronPath ] ! . exports = electronExports ;
7379
7480(
75- electron . app as typeof electron . app & {
81+ app as typeof app & {
7682 setAppPath : ( path : string ) => void ;
7783 }
7884) . setAppPath ( discordPath ) ;
79- // electron. app.name = discordPackage.name;
85+ // app.name = discordPackage.name;
8086
81- electron . protocol . registerSchemesAsPrivileged ( [
87+ protocol . registerSchemesAsPrivileged ( [
8288 {
8389 scheme : "replugged" ,
8490 privileges : {
@@ -93,13 +99,13 @@ function loadReactDevTools(): void {
9399 const rdtSetting = getSetting < boolean > ( "dev.replugged.Settings" , "reactDevTools" , false ) ;
94100
95101 if ( rdtSetting ) {
96- void electron . session . defaultSession . loadExtension ( CONFIG_PATHS [ "react-devtools" ] ) ;
102+ void session . defaultSession . loadExtension ( CONFIG_PATHS [ "react-devtools" ] ) ;
97103 }
98104}
99105
100106// Copied from old codebase
101- electron . app . once ( "ready" , ( ) => {
102- electron . session . defaultSession . webRequest . onBeforeRequest (
107+ app . once ( "ready" , ( ) => {
108+ session . defaultSession . webRequest . onBeforeRequest (
103109 {
104110 urls : [
105111 "https://*/api/v*/science" ,
@@ -115,7 +121,7 @@ electron.app.once("ready", () => {
115121 } ,
116122 ) ;
117123 // @todo : Whitelist a few domains instead of removing CSP altogether; See #386
118- electron . session . defaultSession . webRequest . onHeadersReceived ( ( { responseHeaders } , done ) => {
124+ session . defaultSession . webRequest . onHeadersReceived ( ( { responseHeaders } , done ) => {
119125 if ( ! responseHeaders ) {
120126 done ( { } ) ;
121127 return ;
@@ -149,7 +155,7 @@ electron.app.once("ready", () => {
149155 } ) ;
150156
151157 // TODO: Eventually in the future, this should be migrated to IPC for better performance
152- electron . protocol . handle ( "replugged" , ( request ) => {
158+ protocol . handle ( "replugged" , ( request ) => {
153159 let filePath = "" ;
154160 const reqUrl = new URL ( request . url ) ;
155161 switch ( reqUrl . hostname ) {
@@ -169,7 +175,7 @@ electron.app.once("ready", () => {
169175 filePath = join ( CONFIG_PATHS . plugins , reqUrl . pathname ) ;
170176 break ;
171177 }
172- return electron . net . fetch ( pathToFileURL ( filePath ) . toString ( ) ) ;
178+ return net . fetch ( pathToFileURL ( filePath ) . toString ( ) ) ;
173179 } ) ;
174180
175181 loadReactDevTools ( ) ;
0 commit comments