1 | const { Menu } = require('electron'); |
||
2 | const menuStructure = require("./data/menu.json"); |
||
0 ignored issues
–
show
Unused Code
introduced
by
![]() |
|||
3 | const _ = require("lodash"); |
||
0 ignored issues
–
show
|
|||
4 | |||
5 | module.exports = class AppMenu { |
||
6 | constructor(app) { |
||
7 | this.app = app; |
||
8 | this.rebuildMenu(); |
||
9 | |||
10 | app.store.onDidChange('recentDocs', this.onRecentDocsChange.bind(this)); |
||
11 | } |
||
12 | |||
13 | // Determines if a menu item can completely skip check or not |
||
14 | doMenuItemSkip(obj) { |
||
15 | // Is it not the wrong platform |
||
16 | if (obj.platform !== undefined && |
||
17 | process.platform !== obj.platform) |
||
18 | return true; |
||
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. ![]() |
|||
19 | |||
20 | if (obj.notPlatform !== undefined && |
||
21 | process.platform === obj.notPlatform) |
||
22 | return true; |
||
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. ![]() |
|||
23 | |||
24 | // Is it the wrong build |
||
25 | if (obj.env === "dev" && |
||
26 | this.app.isDev !== true) |
||
27 | return true; |
||
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. ![]() |
|||
28 | |||
29 | if (obj.env === "prod" && |
||
30 | this.app.isDev === true) |
||
31 | return true; |
||
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. ![]() |
|||
32 | |||
33 | return false; |
||
34 | } |
||
35 | |||
36 | _rebuildMenu(arr) { |
||
37 | for (var i = 0; i < arr.length; i++) { |
||
38 | const obj = arr[i]; |
||
39 | |||
40 | // Is not designated platform |
||
41 | if (this.doMenuItemSkip(obj)) { |
||
42 | arr.splice(i, 1); |
||
43 | i--; |
||
0 ignored issues
–
show
|
|||
44 | continue; |
||
45 | } |
||
46 | |||
47 | if (obj.placeholder !== undefined) { |
||
48 | arr.splice(i, 1); |
||
49 | i--; |
||
0 ignored issues
–
show
|
|||
50 | |||
51 | if (obj.placeholder === "recentList") |
||
52 | arr.splice(i + 1, 0, ...this.recentFilesStructure); |
||
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. ![]() |
|||
53 | |||
54 | continue; |
||
55 | } |
||
56 | |||
57 | if (obj.trigger !== undefined) { |
||
58 | obj.click = () => { |
||
59 | if (Array.isArray(obj.triggerData)) |
||
60 | this.app.emit(`menu-${obj.trigger}`, ...obj.triggerData); |
||
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 |
||
62 | this.app.emit(`menu-${obj.trigger}`, obj.triggerData); |
||
63 | } |
||
64 | } |
||
65 | |||
66 | if (obj.submenu !== undefined) { |
||
67 | this._rebuildMenu(obj.submenu); |
||
68 | } |
||
69 | } |
||
70 | } |
||
71 | |||
72 | get recentFilesStructure() { |
||
73 | const store = this.app.store; |
||
74 | const structure = []; |
||
75 | |||
76 | // Grab recent docs list |
||
77 | const recentDocs = store.get('recentDocs', []); |
||
78 | |||
79 | for (let i = 0; i < recentDocs.length; i++) { |
||
80 | const recentDoc = recentDocs[i]; |
||
81 | |||
82 | structure.push({ |
||
83 | label: `${recentDoc}`, |
||
84 | trigger: "openRecentDocs", |
||
85 | triggerData: i, |
||
86 | accelerator: `CommandOrControl+Shift+${i}` |
||
87 | }); |
||
88 | } |
||
89 | |||
90 | return structure; |
||
91 | } |
||
92 | |||
93 | rebuildMenu() { |
||
94 | this.menuStructure = _.cloneDeep(menuStructure); |
||
0 ignored issues
–
show
The variable
_ seems to be never declared. If this is a global, consider adding a /** global: _ */ 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. ![]() The variable
menuStructure seems to be never declared. If this is a global, consider adding a /** global: menuStructure */ 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. ![]() |
|||
95 | this._rebuildMenu(this.menuStructure); |
||
96 | |||
97 | let menu = Menu.buildFromTemplate(this.menuStructure); |
||
0 ignored issues
–
show
The variable
Menu seems to be never declared. If this is a global, consider adding a /** global: Menu */ 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. ![]() |
|||
98 | Menu.setApplicationMenu(menu); |
||
99 | } |
||
100 | |||
101 | onRecentDocsChange(newVal, oldVal) { |
||
0 ignored issues
–
show
|
|||
102 | this.rebuildMenu(); |
||
103 | } |
||
104 | } |
||
105 |