Skip to content

Commit 4f2994e

Browse files
authored
chore: separate import (#700)
* chore: seprate import * chore: type BrowserWindowConstructorOptions
1 parent f3e3f9f commit 4f2994e

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

src/main/index.ts

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
import electron from "electron";
1+
import electron, {
2+
type BrowserWindowConstructorOptions,
3+
app,
4+
net,
5+
protocol,
6+
session,
7+
} from "electron";
28
import { dirname, join } from "path";
39
import { CONFIG_PATHS } from "src/util.mjs";
410
import 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!
3036
class 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;
7278
require.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

Comments
 (0)