Skip to content

Commit b9ad27a

Browse files
committed
window visible and title tests
1 parent 8a6227d commit b9ad27a

File tree

4 files changed

+130
-112
lines changed

4 files changed

+130
-112
lines changed

.eslintrc.js

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -81,45 +81,48 @@ module.exports = {
8181
],
8282
rules: {
8383
"arrow-body-style": 0,
84-
"react/jsx-filename-extension": 0,
84+
"class-methods-use-this": 0,
8585
"comma-dangle": 0,
86-
"no-use-before-define": 0,
87-
"no-console": 0,
88-
"func-names": 0,
89-
"no-undef": 0,
90-
"no-unused-vars": 0,
91-
strict: 0,
9286
"dot-notation": 0,
87+
"func-names": 0,
9388
"import/extensions": 0,
9489
"import/no-extraneous-dependencies": 0,
90+
"import/no-unresolved": 0,
9591
"max-len": 0,
92+
"no-console": 0,
93+
"no-param-reassign": 0,
94+
"no-plusplus": 0,
95+
"no-restricted-syntax": 0,
96+
"no-shadow": 0,
97+
"no-undef": 0,
98+
"no-unused-vars": 0,
99+
"no-use-before-define": 0,
96100
"no-useless-constructor": 0,
97101
"no-underscore-dangle": 0,
102+
"no-unused-expressions": 0,
103+
"no-return-assign": 0,
98104
quotes: 0,
99-
"react/prefer-stateless-function": 0,
100-
"react/prop-types": 0,
105+
"prefer-const": 1,
106+
"prefer-destructuring": 0,
107+
"prefer-template": 1,
101108
"react/destructuring-assignment": 0,
102-
"react/no-array-index-key": 0,
103-
"react/no-did-update-set-state": 0,
104-
"no-restricted-syntax": 0,
105109
"react/forbid-prop-types": 0,
106-
"react/no-access-state-in-setstate": 0,
110+
"react/jsx-filename-extension": 0,
107111
"react/jsx-no-duplicate-props": 0,
108-
"no-plusplus": 0,
109-
"no-param-reassign": 0,
110-
"no-unused-expressions": 0,
111-
"import/no-unresolved": 0,
112+
"react/no-access-state-in-setstate": 0,
113+
"react/no-array-index-key": 0,
114+
"react/no-did-update-set-state": 0,
112115
"react/no-unused-state": 0,
113-
"no-shadow": 0,
114-
"no-return-assign": 0,
115-
"class-methods-use-this": 0,
116-
"brace-style": [2, "stroustrup"],
116+
"react/prefer-stateless-function": 0,
117117
"react/sort-comp": [
118118
2,
119119
{
120120
order: ["lifecycle", "everything-else", "rendering"],
121121
},
122122
],
123+
"react/prop-types": 0,
124+
"spaced-comment": 0,
125+
strict: 0,
123126
},
124127
// setting: {
125128
// "import/parsers": {

main.js

Lines changed: 59 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -10,37 +10,39 @@ process.env.NODE_TLS_REJECT_UNAUTHORIZED = 0;
1010
// Import parts of electron to use
1111
// app - Control your application's event lifecycle
1212
// ipcMain - Communicate asynchronously from the main process to renderer processes
13+
14+
// npm libraries
1315
const { app, BrowserWindow, TouchBar, ipcMain, dialog } = require("electron");
14-
const path = require("path");
15-
const url = require("url");
16-
const fs = require("fs");
1716
const {
1817
default: installExtension,
1918
REACT_DEVELOPER_TOOLS,
2019
REDUX_DEVTOOLS,
2120
} = require("electron-devtools-installer");
22-
2321
// Import Auto-Updater- Swell will update itself
2422
const { autoUpdater } = require("electron-updater");
25-
const log = require("electron-log");
2623
// TouchBarButtons are our nav buttons(ex: Select All, Deselect All, Open Selected, Close Selected, Clear All)
2724
const { TouchBarButton, TouchBarSpacer } = TouchBar;
2825

26+
const path = require("path");
27+
const url = require("url");
28+
const fs = require("fs");
29+
const log = require("electron-log");
30+
2931
// basic http cookie parser
3032
const cookie = require("cookie");
3133
// node-fetch for the fetch request
3234
const fetch2 = require("node-fetch");
3335

34-
// require menu file
35-
require("./menu/mainMenu");
36-
3736
// GraphQL imports
3837
const { ApolloClient } = require("apollo-client");
3938
const gql = require("graphql-tag");
4039
const { InMemoryCache } = require("apollo-cache-inmemory");
4140
const { createHttpLink } = require("apollo-link-http");
4241
const { ApolloLink } = require("apollo-link");
4342

43+
// require menu file
44+
require("./menu/mainMenu");
45+
4446
// configure logging
4547
autoUpdater.logger = log;
4648
autoUpdater.logger.transports.file.level = "info";
@@ -127,23 +129,31 @@ const touchBar = new TouchBar([
127129
tbClearAllButton,
128130
]);
129131

130-
// Keep a reference for dev mode
131-
let dev = false;
132-
console.log("process.defaultApp ->", process.defaultApp);
133-
console.log("process.execPath -> ", process.execPath);
134-
if (
135-
process.defaultApp ||
136-
/[\\/]electron-prebuilt[\\/]/.test(process.execPath) ||
137-
/[\\/]electron[\\/]/.test(process.execPath)
138-
) {
139-
dev = true;
140-
}
141-
console.log(
142-
"current regex test -> ",
143-
/[\\/]electron-prebuilt[\\/]/.test(process.execPath)
144-
);
145-
if (dev) console.log("dev is TRUE");
146-
if (dev === false) console.log("dev is FALSE");
132+
// -----------------------------------------------
133+
// prod / dev mode determined by boolean 'isDev'
134+
// -----------------------------------------------
135+
136+
let isDev;
137+
process.argv.includes("--noDevServer") ? (isDev = false) : (isDev = true);
138+
139+
console.log("isDev->", isDev);
140+
// let isDev = false;
141+
// console.log("process.defaultApp ->", process.defaultApp);
142+
// console.log("process.execPath -> ", process.execPath);
143+
144+
// if (
145+
// process.defaultApp ||
146+
// /[\\/]electron-prebuilt[\\/]/.test(process.execPath) ||
147+
// /[\\/]electron[\\/]/.test(process.execPath)
148+
// ) {
149+
// isDev = true;
150+
// }
151+
// console.log(
152+
// "current regex test -> ",
153+
// /[\\/]electron-prebuilt[\\/]/.test(process.execPath)
154+
// );
155+
// if (isDev) console.log("isDev is TRUE");
156+
// if (isDev === false) console.log("isDev is FALSE");
147157
// Temporary fix broken high-dpi scale factor on Windows (125% scaling)
148158
// info: https://github.com/electron/electron/issues/9691
149159
if (process.platform === "win32") {
@@ -152,6 +162,10 @@ if (process.platform === "win32") {
152162
app.commandLine.appendSwitch("force-device-scale-factor", "1");
153163
}
154164

165+
/***********************************************
166+
******* createWindow function declaration ******
167+
***********************************************/
168+
155169
function createWindow() {
156170
// Create the new browser window instance.
157171
mainWindow = new BrowserWindow({
@@ -171,7 +185,7 @@ function createWindow() {
171185
icon: `${__dirname}/src/assets/icons/64x64.png`,
172186
});
173187

174-
if (dev) {
188+
if (isDev) {
175189
// If we are in developer mode Add React & Redux DevTools to Electon App
176190
installExtension(REACT_DEVELOPER_TOOLS)
177191
.then((name) => console.log(`Added Extension: ${name}`))
@@ -185,7 +199,7 @@ function createWindow() {
185199
// and load the index.html of the app.
186200
let indexPath;
187201

188-
if (dev && process.argv.indexOf("--noDevServer") === -1) {
202+
if (isDev && process.argv.indexOf("--noDevServer") === -1) {
189203
// if we are in dev mode load up 'http://localhost:8080/index.html'
190204
indexPath = url.format({
191205
protocol: "http:",
@@ -215,7 +229,7 @@ function createWindow() {
215229
mainWindow.once("ready-to-show", () => {
216230
mainWindow.show();
217231
// Open the DevTools automatically if developing
218-
if (dev) {
232+
if (isDev) {
219233
mainWindow.webContents.openDevTools();
220234
}
221235
});
@@ -233,13 +247,21 @@ function createWindow() {
233247
// moved require mainmenu to top
234248
}
235249

236-
// This method will be called when Electron has finished
250+
/********* end of createWindow declaration ******/
251+
252+
/****************************************
253+
************** EVENT LISTENERS **********
254+
****************************************/
255+
256+
// app.on('ready') will be called when Electron has finished
237257
// initialization and is ready to create browser windows.
238258
// Some APIs can only be used after this event occurs.
259+
260+
// if in prod mode, checkForUpdates after the window is created
239261
app.on("ready", () => {
240262
// createLoadingScreen();
241263
createWindow();
242-
if (!dev) {
264+
if (!isDev) {
243265
autoUpdater.checkForUpdates();
244266
}
245267
});
@@ -264,7 +286,7 @@ const sendStatusToWindow = (text) => {
264286

265287
ipcMain.on("check-for-update", () => {
266288
//listens to ipcRenderer in UpdatePopUpContainer.jsx
267-
if (!dev) autoUpdater.checkForUpdates();
289+
if (!isDev) autoUpdater.checkForUpdates();
268290
});
269291
// autoUpdater.on('checking-for-update', () => {
270292
// sendStatusToWindow('Checking for update...');
@@ -276,7 +298,7 @@ ipcMain.on("check-for-update", () => {
276298
// sendStatusToWindow('Update not available.');
277299
// });
278300
autoUpdater.on("error", (err) => {
279-
console.error(err);
301+
console.error("autoUpdater error -> ", err);
280302
sendStatusToWindow(`Error in auto-updater`);
281303
});
282304
autoUpdater.on("download-progress", (progressObj) => {
@@ -316,7 +338,7 @@ app.on("activate", () => {
316338

317339
// export collection ipc now promise-based
318340
ipcMain.on("export-collection", (event, args) => {
319-
let content = JSON.stringify(args.collection);
341+
const content = JSON.stringify(args.collection);
320342
dialog.showSaveDialog(null).then((resp) => {
321343
if (resp.filePath === undefined) {
322344
console.log("You didn't save the file");
@@ -326,7 +348,7 @@ ipcMain.on("export-collection", (event, args) => {
326348
// fileName is a string that contains the path and filename created in the save file dialog.
327349
fs.writeFile(resp.filePath, content, (err) => {
328350
if (err) {
329-
console.log("An error ocurred creating the file " + err.message);
351+
console.log("An error ocurred creating the file ", err.message);
330352
}
331353
});
332354
});
@@ -351,7 +373,7 @@ ipcMain.on("import-collection", (event, args) => {
351373
}
352374

353375
// get first file path - not dynamic for multiple files
354-
let filepath = fileNames.filePaths[0];
376+
const filepath = fileNames.filePaths[0];
355377

356378
// get file extension
357379
const ext = path.extname(filepath);
@@ -366,7 +388,7 @@ ipcMain.on("import-collection", (event, args) => {
366388

367389
fs.readFile(filepath, "utf-8", (err, data) => {
368390
if (err) {
369-
alert("An error ocurred reading the file :" + err.message);
391+
alert("An error ocurred reading the file :", err.message);
370392
return;
371393
}
372394

@@ -464,7 +486,7 @@ ipcMain.on("open-gql", (event, args) => {
464486
return forward(operation).map((response) => {
465487
const context = operation.getContext();
466488
const headers = context.response.headers.entries();
467-
for (let headerItem of headers) {
489+
for (const headerItem of headers) {
468490
const key = headerItem[0]
469491
.split("-")
470492
.map((item) => item[0].toUpperCase() + item.slice(1))

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"test": "jest",
99
"test-mocha": "mocha",
1010
"prod": "webpack --mode production --config webpack.build.config.js && electron --noDevServer .",
11-
"start": "webpack-dev-server --hot --host 0.0.0.0 --config=./webpack.dev.config.js --mode development",
11+
"start": "webpack-dev-server --mode development --hot --host 0.0.0.0 --config=./webpack.dev.config.js ",
1212
"build": "webpack --config webpack.build.config.js --mode production",
1313
"server": "nodemon test-server/server.js",
1414
"package-mac": "electron-builder build --x64 --mac",

0 commit comments

Comments
 (0)