1 | const { globalShortcut, BrowserWindow } = require('electron'); |
||
2 | |||
3 | module.exports = class Window { |
||
4 | constructor(app) { |
||
5 | |||
6 | this.app = app; |
||
7 | |||
8 | // Load screen data |
||
9 | const { screen } = require('electron'); |
||
10 | |||
11 | // Create Window |
||
12 | const win = this.win = new BrowserWindow({ |
||
0 ignored issues
–
show
|
|||
13 | width: screen.getPrimaryDisplay().workAreaSize.width, |
||
14 | height: screen.getPrimaryDisplay().workAreaSize.height, |
||
15 | show: false, |
||
16 | simpleFullscreen: true, |
||
17 | icon: app.icon |
||
18 | }); |
||
19 | |||
20 | // Always allow opening dev tools in any build or platform |
||
21 | // In production the dev tools menu item will be removed but the dev tools |
||
22 | // themselves will always be openable with the same shortcut. |
||
23 | // This means your average user won't have to concern over it but developers |
||
24 | // or tinkerers can still access it if desired |
||
25 | globalShortcut.register('CommandOrControl+Shift+I', this.toggleDevTools.bind(this)); |
||
0 ignored issues
–
show
The variable
globalShortcut seems to be never declared. If this is a global, consider adding a /** global: globalShortcut */ comment.
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed. To learn more about declaring variables in Javascript, see the MDN. ![]() |
|||
26 | |||
27 | // Load contents depending on development enviroment or not |
||
28 | if (app.isDev) |
||
29 | win.loadURL('http://localhost:4200'); |
||
0 ignored issues
–
show
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.
Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later. Consider: if (a > 0)
b = 42;
If you or someone else later decides to put another statement in, only the first statement will be executed. if (a > 0)
console.log("a > 0");
b = 42;
In this case the statement if (a > 0) {
console.log("a > 0");
b = 42;
}
ensures that the proper code will be executed conditionally no matter how many statements are added or removed. ![]() |
|||
30 | else |
||
31 | win.loadFile('./dist/pokered-save-editor/index.html'); |
||
32 | |||
33 | // Hook into events |
||
34 | win.on('closed', this.onClosed.bind(this)); |
||
35 | win.once('ready-to-show', this.onReadyToShow.bind(this)); |
||
36 | app.on('ipcTo', this.onIpcTo.bind(this)); |
||
37 | } |
||
38 | |||
39 | // Certain events can be hooked into and echoed to the ipcTo channel |
||
40 | // which will be relayed directly to the window |
||
41 | relayTo(event, ...args) { |
||
42 | app.emit(`ipcTo`, event, ...args); |
||
43 | } |
||
44 | |||
45 | toggleDevTools() { |
||
46 | this.win.webContents.toggleDevTools(); |
||
47 | } |
||
48 | |||
49 | reOpen() { |
||
50 | if (this.win.isMinimized()) this.win.restore(); |
||
0 ignored issues
–
show
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.
Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later. Consider: if (a > 0)
b = 42;
If you or someone else later decides to put another statement in, only the first statement will be executed. if (a > 0)
console.log("a > 0");
b = 42;
In this case the statement if (a > 0) {
console.log("a > 0");
b = 42;
}
ensures that the proper code will be executed conditionally no matter how many statements are added or removed. ![]() |
|||
51 | this.win.focus(); |
||
52 | } |
||
53 | |||
54 | onIpcTo(event, ...args) { |
||
55 | |||
56 | const appName = this.app.app.getName(); |
||
57 | |||
58 | // Jump in on certain events |
||
59 | if (event === "pathChange" && args[0] !== "") |
||
60 | this.win.setTitle(`${appName} - ${args[0]}`); |
||
0 ignored issues
–
show
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.
Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later. Consider: if (a > 0)
b = 42;
If you or someone else later decides to put another statement in, only the first statement will be executed. if (a > 0)
console.log("a > 0");
b = 42;
In this case the statement if (a > 0) {
console.log("a > 0");
b = 42;
}
ensures that the proper code will be executed conditionally no matter how many statements are added or removed. ![]() |
|||
61 | else if (event === "pathChange") |
||
62 | this.win.setTitle(`${appName} - New File`); |
||
0 ignored issues
–
show
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.
Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later. Consider: if (a > 0)
b = 42;
If you or someone else later decides to put another statement in, only the first statement will be executed. if (a > 0)
console.log("a > 0");
b = 42;
In this case the statement if (a > 0) {
console.log("a > 0");
b = 42;
}
ensures that the proper code will be executed conditionally no matter how many statements are added or removed. ![]() |
|||
63 | |||
64 | this.win.webContents.send(event, ...args); |
||
65 | } |
||
66 | |||
67 | onClosed() { |
||
68 | this.win = null; |
||
69 | } |
||
70 | |||
71 | onReadyToShow() { |
||
72 | this.win.show(); |
||
73 | this.app.emit("window-ready"); |
||
74 | } |
||
75 | } |
||
76 |
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.