Skip to content

Commit

Permalink
remove electron-util NPM dep
Browse files Browse the repository at this point in the history
  • Loading branch information
szTheory committed Jun 30, 2020
1 parent 87e24bc commit 2b428d2
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 33 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
"dependencies": {
"electron-context-menu": "^0.15.0",
"electron-unhandled": "^3.0.0",
"electron-util": "^0.14.0",
"js-yaml": "^3.13.1",
"node-exiftool": "^2.3.0",
"serialize-javascript": "^2.1.1",
Expand Down
2 changes: 1 addition & 1 deletion src/common/binaries.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import path from "path";
import { remote } from "electron";
import { getPlatform, Platform } from "./get_platform";
import { getPlatform, Platform } from "./platform";

const IS_PROD = process.env.NODE_ENV === "production";
const { isPackaged, getAppPath } = remote.app;
Expand Down
14 changes: 14 additions & 0 deletions src/common/is_dev.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const electron = require("electron");

if (typeof electron === "string") {
throw new TypeError("Not running in an Electron environment!");
}

const app = electron.app || electron.remote.app;

const isEnvSet = "ELECTRON_IS_DEV" in process.env;
const getFromEnv = process.env.ELECTRON_IS_DEV
? parseInt(process.env.ELECTRON_IS_DEV, 10) === 1
: false;

export const isDev = isEnvSet ? getFromEnv : !app.isPackaged;
10 changes: 10 additions & 0 deletions src/common/get_platform.ts → src/common/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@ export enum Platform {
MAC
}

export function isMac() {
return getPlatform() == Platform.MAC;
}
export function isWindows() {
return getPlatform() == Platform.WIN;
}
export function isLinux() {
return getPlatform() == Platform.NIX;
}

export function getPlatform(): Platform {
const currentPlatform = platform();

Expand Down
4 changes: 2 additions & 2 deletions src/main/app_setup.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { app, BrowserWindow } from "electron";
import { createMainWindow } from "./window_setup";
import { is } from "electron-util";
import { isMac } from "../common/platform";

function preventMultipleAppInstances(): void {
if (!app.requestSingleInstanceLock()) {
Expand Down Expand Up @@ -30,7 +30,7 @@ function quitOnWindowsAllClosed(): void {
// open even when all windows are closed. so that for
// example they can relaunch the app from the dock
// or still use the drag to dock features
if (!is.macos) {
if (!isMac()) {
app.quit();
}
});
Expand Down
4 changes: 2 additions & 2 deletions src/main/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { is } from "electron-util";
import { BrowserWindow } from "electron";
import { isDev } from "../common/is_dev";

// electron-webpack HMR for development
if (is.development && module.hot) {
if (isDev && module.hot) {
module.hot.accept();
}

Expand Down
6 changes: 3 additions & 3 deletions src/main/menu_help.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import path from "path";
import {
is,
aboutMenuItem,
openUrlMenuItem,
openNewGitHubIssue,
debugInfo
} from "electron-util";
import { MenuItemConstructorOptions } from "electron";
import { isMac, isLinux } from "../common/platform";

const WEBSITE_URL = "https://exifcleaner.com";
const GITHUB_USERNAME = "szTheory";
Expand Down Expand Up @@ -44,7 +44,7 @@ export function buildHelpSubmenu(): MenuItemConstructorOptions[] {
}
];

if (!is.macos) {
if (!isMac()) {
submenu.push(
{
type: "separator"
Expand All @@ -61,7 +61,7 @@ export function buildHelpSubmenu(): MenuItemConstructorOptions[] {
}

function aboutMenuIconPath(): string {
if (is.linux) {
if (isLinux()) {
return path.join(__dirname, "..", "..", "exifcleaner.png");
} else {
return path.join(__dirname, "static", "icon.png");
Expand Down
9 changes: 5 additions & 4 deletions src/main/window_setup.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { BrowserWindow, app } from "electron";
import { is } from "electron-util";
import url from "url";
import path from "path";
import { isMac, isLinux } from "../common/platform";
import { isDev } from "../common/is_dev";

const DEFAULT_WINDOW_WIDTH = 580;
const DEFAULT_WINDOW_HEIGHT = 312;
Expand All @@ -12,7 +13,7 @@ function setupMainWindowClose({ win }: { win: BrowserWindow }) {
// open even when all windows are closed. so that for
// example they can relaunch the app from the dock
// or still use the drag to dock features
if (!is.macos) {
if (!isMac()) {
// quit application on window close
app.quit();
}
Expand All @@ -27,7 +28,7 @@ function showWindowOnReady({ win }: { win: BrowserWindow }) {
}

function urlForLoad() {
if (is.development) {
if (isDev) {
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.";
Expand Down Expand Up @@ -64,7 +65,7 @@ export function createMainWindow(): BrowserWindow {
backgroundColor: WINDOW_BACKGROUND_COLOR
};

if (is.linux) {
if (isLinux()) {
options = Object.assign({}, options, {
icon: path.join(__dirname, "..", "..", "exifcleaner.png")
});
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import unhandled from "electron-unhandled";
import { isDev } from "../common/is_dev";

// electron-webpack HMR
import { is } from "electron-util";
if (is.development && module.hot) {
if (isDev && module.hot) {
module.hot.accept();
}

Expand Down
18 changes: 0 additions & 18 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3057,11 +3057,6 @@ electron-is-dev@^1.0.1:
resolved "https://registry.yarnpkg.com/electron-is-dev/-/electron-is-dev-1.1.0.tgz#b15a2a600bdc48a51a857d460e05f15b19a2522c"
integrity sha512-Z1qA/1oHNowGtSBIcWk0pcLEqYT/j+13xUw/MYOrBUOL4X7VN0i0KCTf5SqyvMPmW5pSPKbo28wkxMxzZ20YnQ==

electron-is-dev@^1.1.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/electron-is-dev/-/electron-is-dev-1.2.0.tgz#2e5cea0a1b3ccf1c86f577cee77363ef55deb05e"
integrity sha512-R1oD5gMBPS7PVU8gJwH6CtT0e6VSoD0+SzSnYpNm+dBkcijgA+K7VAMHDfnRq/lkKPZArpzplTW6jfiMYosdzw==

electron-publish@21.2.0:
version "21.2.0"
resolved "https://registry.yarnpkg.com/electron-publish/-/electron-publish-21.2.0.tgz#cc225cb46aa62e74b899f2f7299b396c9802387d"
Expand Down Expand Up @@ -3103,14 +3098,6 @@ electron-unhandled@^3.0.0:
ensure-error "^2.0.0"
lodash.debounce "^4.0.8"

electron-util@^0.14.0:
version "0.14.1"
resolved "https://registry.yarnpkg.com/electron-util/-/electron-util-0.14.1.tgz#047095c9ac76582612e7e496b0b9c70b73e9ca6c"
integrity sha512-MvwYywBZ+8P3pSILIEuWHVcykxsaRZOE3iSfHZibfDem/lEK5L1V9UfykmCJJBVL2voJM0o+LdjfuKxtH5kjOQ==
dependencies:
electron-is-dev "^1.1.0"
new-github-issue-url "^0.2.1"

electron-webpack-js@~2.4.1:
version "2.4.1"
resolved "https://registry.yarnpkg.com/electron-webpack-js/-/electron-webpack-js-2.4.1.tgz#5389cc22f34c71f6416d5ba1e043f9b0fd6130af"
Expand Down Expand Up @@ -6421,11 +6408,6 @@ neo-async@^2.5.0, neo-async@^2.6.1:
resolved "https://registry.yarnpkg.com/neo-async/-/neo-async-2.6.1.tgz#ac27ada66167fa8849a6addd837f6b189ad2081c"
integrity sha512-iyam8fBuCUpWeKPGpaNMetEocMt364qkCsfL9JuhjXX6dRnguRVOfk2GZaDpPjcOKiiXCPINZC1GczQ7iTq3Zw==

new-github-issue-url@^0.2.1:
version "0.2.1"
resolved "https://registry.yarnpkg.com/new-github-issue-url/-/new-github-issue-url-0.2.1.tgz#e17be1f665a92de465926603e44b9f8685630c1d"
integrity sha512-md4cGoxuT4T4d/HDOXbrUHkTKrp/vp+m3aOA7XXVYwNsUNMK49g3SQicTSeV5GIz/5QVGAeYRAOlyp9OvlgsYA==

nice-try@^1.0.4:
version "1.0.5"
resolved "https://registry.yarnpkg.com/nice-try/-/nice-try-1.0.5.tgz#a3378a7696ce7d223e88fc9b764bd7ef1089e366"
Expand Down

0 comments on commit 2b428d2

Please sign in to comment.