Skip to content

Commit

Permalink
remove esm dep. fix dev env
Browse files Browse the repository at this point in the history
  • Loading branch information
szTheory committed Jan 18, 2020
1 parent b86a5ab commit 072b1c4
Show file tree
Hide file tree
Showing 10 changed files with 74 additions and 50 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Built with [Electron](https://electronjs.org). Uses [node-exiftool](https://www.

```
$ npm install
$ npm start
$ npm run dev #this command is set up to give you HMR in dev
```

### Publish
Expand Down
6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
"description": "Clean exif data from images",
"license": "MIT",
"repository": "github:szTheory/exifcleaner",
"type": "module",
"main": "src/main/entrypoint.js",
"main": "src/main/index.js",
"author": {
"name": "szTheory",
"email": "[email protected]",
Expand All @@ -33,15 +32,14 @@
"electron-unhandled": "^3.0.0",
"electron-updater": "^4.2.0",
"electron-util": "^0.13.0",
"esm": "^3.2.25",
"js-yaml": "^3.13.1",
"node-exiftool": "^2.3.0",
"serialize-javascript": "^2.1.1",
"source-map-support": "^0.5.16",
"spectre.css": "^0.5.8"
},
"devDependencies": {
"electron": "7.1.8",
"electron": "7.1.9",
"electron-builder": "^22.2.0",
"electron-webpack": "^2.7.4",
"node-sass": "^4.13.0",
Expand Down
12 changes: 8 additions & 4 deletions src/main/app_setup.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { app } from "electron";
import { is } from "electron-util";
import { createMainWindow } from "./window_setup";
const { app } = require("electron");
const { is } = require("electron-util");
const { createMainWindow } = require("./window_setup");

function preventMultipleAppInstances() {
if (!app.requestSingleInstanceLock()) {
Expand Down Expand Up @@ -35,9 +35,13 @@ function createWindowOnActivate({ win }) {
});
}

export const setupApp = function({ win }) {
const setupApp = function({ win }) {
preventMultipleAppInstances();
openMinimizedIfAlreadyExists({ win: win });
quitOnWindowsAllClosed();
createWindowOnActivate({ win: win });
};

module.exports = {
setupApp
};
12 changes: 8 additions & 4 deletions src/main/auto_update.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { is } from "electron-util";
import { autoUpdater } from "electron-updater";
import logger from "electron-log";
const { is } = require("electron-util");
const { autoUpdater } = require("electron-updater");
const logger = require("electron-log");

const FOUR_HOURS = 1000 * 60 * 60 * 4;

Expand All @@ -19,7 +19,7 @@ function checkNow() {
autoUpdater.checkForUpdates();
}

export const setupAutoUpdate = function() {
const setupAutoUpdate = function() {
if (is.development) {
return;
}
Expand All @@ -28,3 +28,7 @@ export const setupAutoUpdate = function() {
checkPeriodically();
checkNow();
};

module.exports = {
setupAutoUpdate
};
2 changes: 0 additions & 2 deletions src/main/entrypoint.js

This file was deleted.

10 changes: 5 additions & 5 deletions src/main/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// electron-webpack HMR for development
import { is } from "electron-util";
const is = require("electron-util");
if (is.development && module.hot) {
module.hot.accept();
}

import { app } from "electron";
import { setupMenu } from "./menu";
import { init } from "./init";
import { createMainWindow, setupMainWindow } from "./window_setup";
const { app } = require("electron");
const { setupMenu } = require("./menu");
const { init } = require("./init");
const { createMainWindow, setupMainWindow } = require("./window_setup");

// Maintain reference to window to
// prevent it from being garbage collected
Expand Down
12 changes: 8 additions & 4 deletions src/main/init.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { app } from "electron";
const { app } = require("electron");
const unhandled = require("electron-unhandled");
const debug = require("electron-debug");
const contextMenu = require("electron-context-menu");
const packageJson = require("../../package.json");
import { setupAutoUpdate } from "./auto_update";
import { setupApp } from "./app_setup";
const { setupAutoUpdate } = require("./auto_update");
const { setupApp } = require("./app_setup");

function setupErrorHandling() {
unhandled();
Expand All @@ -23,11 +23,15 @@ function setupUserModelId() {
app.setAppUserModelId(packageJson.build.appId);
}

export const init = function({ win }) {
const init = function({ win }) {
setupErrorHandling();
setupDevTools();
setupContextMenu();
setupUserModelId();
setupAutoUpdate();
setupApp({ win: win });
};

module.exports = {
init
};
6 changes: 5 additions & 1 deletion src/main/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,10 @@ function buildMenu() {
return Menu.buildFromTemplate(template);
}

export const setupMenu = function() {
const setupMenu = function() {
Menu.setApplicationMenu(buildMenu());
};

module.exports = {
setupMenu
};
49 changes: 33 additions & 16 deletions src/main/window_setup.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { BrowserWindow, ipcMain, app } from "electron";
import { is } from "electron-util";
import url from "url";
import path from "path";
const { BrowserWindow, ipcMain, app } = require("electron");
const { is } = require("electron-util");
const url = require("url");
const path = require("path");

const DEFAULT_WINDOW_WIDTH = 580;
const DEFAULT_WINDOW_HEIGHT = 312;
Expand All @@ -10,28 +10,40 @@ function setupMainWindowClose({ win }) {
win.on("closed", () => {
// Dereference the window
// For multiple windows store them in an array
win = undefined;
win = null;
});
}

function showWindowOnReady({ win }) {
win.on("ready-to-show", () => {
win.once("ready-to-show", () => {
win.show();
});
}

function urlForLoad() {
if (is.development) {
const port = process.env.ELECTRON_WEBPACK_WDS_PORT;
if (!port) {
throw "No Electron webpack WDS port set for dev. Try running `yarn run dev` instead for development mode.";
}

return `http://localhost:${port}`;
} else {
return url.format({
pathname: path.join(__dirname, "index.html"),
protocol: "file",
slashes: true
});
}
}

function mainWindowLoadUrl({ win }) {
const urlForLoad = is.development
? `http://localhost:${process.env.ELECTRON_WEBPACK_WDS_PORT}`
: url.format({
pathname: path.join(__dirname, "index.html"),
protocol: "file",
slashes: true
});
win.loadURL(urlForLoad);
const url = urlForLoad();

win.loadURL(url);
}

export const createMainWindow = async function() {
const createMainWindow = async function() {
return new BrowserWindow({
title: app.name,
show: false,
Expand All @@ -41,8 +53,13 @@ export const createMainWindow = async function() {
});
};

export const setupMainWindow = function({ win }) {
const setupMainWindow = function({ win }) {
setupMainWindowClose({ win: win });
showWindowOnReady({ win: win });
mainWindowLoadUrl({ win: win });
};

module.exports = {
createMainWindow,
setupMainWindow
};
13 changes: 4 additions & 9 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3223,10 +3223,10 @@ electron-webpack@^2.7.4:
webpack-merge "^4.2.1"
yargs "^13.2.4"

[email protected].8:
version "7.1.8"
resolved "https://registry.yarnpkg.com/electron/-/electron-7.1.8.tgz#7cd50fdf42c55c9de86ab126e983d23fd89d5d99"
integrity sha512-1cWT7toVcSTKu3HdnhDQpbTmI5QCSKtIbg+wHUkSZCdAqjPcuH+dpm+j21g38LbE2DoIzdryaN0RTZOqTPebMA==
[email protected].9:
version "7.1.9"
resolved "https://registry.yarnpkg.com/electron/-/electron-7.1.9.tgz#5053195d2e476a3ecd881ece4edf64f0a8c32fa3"
integrity sha512-gkzDr08XxRaNZhwPLRXYNXDaPuiAeCrRPcClowlDVfCLKi+kRNhzekZpfYUBq8DdZCD29D3rCtgc9IHjD/xuHw==
dependencies:
"@electron/get" "^1.0.1"
"@types/node" "^12.0.12"
Expand Down Expand Up @@ -3622,11 +3622,6 @@ eslint@^6.4.0:
text-table "^0.2.0"
v8-compile-cache "^2.0.3"

esm@^3.2.25:
version "3.2.25"
resolved "https://registry.yarnpkg.com/esm/-/esm-3.2.25.tgz#342c18c29d56157688ba5ce31f8431fbb795cc10"
integrity sha512-U1suiZ2oDVWv4zPO56S0NcR5QriEahGtdN2OR6FiOG4WJvcjBVFB0qI4+eKoWFH483PKGuLuu6V8Z4T5g63UVA==

espree@^6.0.0, espree@^6.1.1, espree@^6.1.2:
version "6.1.2"
resolved "https://registry.yarnpkg.com/espree/-/espree-6.1.2.tgz#6c272650932b4f91c3714e5e7b5f5e2ecf47262d"
Expand Down

0 comments on commit 072b1c4

Please sign in to comment.