Skip to content

Commit

Permalink
remove electron-util dep
Browse files Browse the repository at this point in the history
  • Loading branch information
szTheory committed Jun 30, 2020
1 parent 8f7340d commit 1afbf38
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 81 deletions.
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@
"dependencies": {
"electron-context-menu": "^0.15.0",
"electron-unhandled": "^3.0.0",
"electron-util": "^0.14.2",
"node-exiftool": "^2.3.0",
"serialize-javascript": "^2.1.1",
"source-map-support": "^0.5.19",
"spectre.css": "^0.5.8"
},
"devDependencies": {
Expand All @@ -43,7 +42,6 @@
"np": "^5.0.3",
"prettier": "1.19.1",
"sass-loader": "^8.0.0",
"source-map-support": "^0.5.19",
"typescript": "^3.8.3",
"webpack": "^4.41.2",
"webpack-cli": "^3.3.10",
Expand Down
27 changes: 27 additions & 0 deletions src/main/menu_about_window.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { app } from "electron";
import { isLinux } from "../common/platform";
import path from "path";

export function showAboutWindow(author: string, websiteUrl: string): void {
let aboutPanelOptions = {
applicationName: app.getName(),
applicationVersion: app.getVersion(),
copyright: `Copyright © ${author}`,
version: app.getVersion(),
// credits: author, //optional
// authors: [author], //optional
website: websiteUrl,
iconPath: iconPath()
};

app.setAboutPanelOptions(aboutPanelOptions);
app.showAboutPanel();
}

function iconPath(): string {
if (isLinux()) {
return path.join(__dirname, "..", "..", "exifcleaner.png");
} else {
return path.join(__dirname, "static", "icon.png");
}
}
85 changes: 43 additions & 42 deletions src/main/menu_help.ts
Original file line number Diff line number Diff line change
@@ -1,45 +1,27 @@
import path from "path";
import {
aboutMenuItem,
openUrlMenuItem,
openNewGitHubIssue,
debugInfo
} from "electron-util";
import { MenuItemConstructorOptions } from "electron";
import { isMac, isLinux } from "../common/platform";
import { shell, app, MenuItemConstructorOptions } from "electron";
import os from "os";
import { isMac } from "../common/platform";
import { showAboutWindow } from "./menu_about_window";
import { openUrlMenuItem } from "./menu_item_open_url";

const WEBSITE_URL = "https://exifcleaner.com";
const GITHUB_USERNAME = "szTheory";
const GITHUB_PROJECTNAME = "exifcleaner";
const SOURCE_CODE_URL = `https://github.com/${GITHUB_USERNAME}/${GITHUB_PROJECTNAME}`;
const COPYRIGHT_TEXT = `Copyright © ${GITHUB_USERNAME}`;

export function buildHelpSubmenu(): MenuItemConstructorOptions[] {
let submenu = [
openUrlMenuItem({
label: "Website",
url: WEBSITE_URL
}),
openUrlMenuItem({
label: "Source Code",
url: SOURCE_CODE_URL
}),
openUrlMenuItem("Website", WEBSITE_URL),
openUrlMenuItem("Source Code", SOURCE_CODE_URL),
{
label: "Report an Issue…",
click() {
const body = `
<!-- Please succinctly describe your issue and steps to reproduce it. -->
---
${debugInfo()}`;

openNewGitHubIssue({
user: GITHUB_USERNAME,
repo: GITHUB_PROJECTNAME,
body
});
const url = newGithubIssueUrl(
GITHUB_USERNAME,
GITHUB_PROJECTNAME,
newGithubIssueBody()
);
shell.openExternal(url);
}
}
];
Expand All @@ -49,21 +31,40 @@ export function buildHelpSubmenu(): MenuItemConstructorOptions[] {
{
type: "separator"
},
aboutMenuItem({
website: WEBSITE_URL,
icon: aboutMenuIconPath(),
copyright: COPYRIGHT_TEXT
})
{
label: `About ${app.getName()}`,
click() {
showAboutWindow(GITHUB_USERNAME, WEBSITE_URL);
}
}
);
}

return submenu;
}

function aboutMenuIconPath(): string {
if (isLinux()) {
return path.join(__dirname, "..", "..", "exifcleaner.png");
} else {
return path.join(__dirname, "static", "icon.png");
}
function newGithubIssueUrl(user: string, repo: string, body: string): string {
const url = new URL(`https://github.com/${user}/${repo}/issues/new`);
url.searchParams.set("body", body);

return url.toString();
}

function newGithubIssueBody(): string {
return `
<!-- Please succinctly describe your issue and steps to reproduce it. -->
---
${debugInfo()}`;
}

function debugInfo(): string {
return `
${app.getName()} ${app.getVersion()}
Electron ${process.versions.electron}
${process.platform} ${os.release()}
Locale: ${app.getLocale()}
`.trim();
}
13 changes: 13 additions & 0 deletions src/main/menu_item_open_url.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { shell, MenuItemConstructorOptions } from "electron";

export function openUrlMenuItem(
label: string,
url: string
): MenuItemConstructorOptions {
return {
label: label,
click: function() {
shell.openExternal(url);
}
};
}
45 changes: 33 additions & 12 deletions src/main/menu_mac.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,41 @@
import { buildHelpSubmenu } from "./menu_help";
import { appMenu } from "electron-util";
import { fileMenuOpenItem } from "./menu_file_open";
import { MenuItemConstructorOptions } from "electron";
import { MenuItemConstructorOptions, app } from "electron";

export function buildMacOsTemplate(): MenuItemConstructorOptions[] {
return [
appMenu([
// No preferences menu for now
// {
// label: "Preferences…",
// accelerator: "Command+,",
// click() {
// showPreferences();
// }
// }
]),
{
label: app.getName(),
submenu: [
{
role: "about"
},
{
type: "separator"
},
{
role: "services"
},
{
type: "separator"
},
{
role: "hide"
},
{
role: "hideOthers"
},
{
role: "unhide"
},
{
type: "separator"
},
{
role: "quit"
}
]
},
{
role: "fileMenu",
type: "submenu",
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<i class="icon icon-photo icon-3x"></i>
</div>
<p class="empty-title h5">No files selected</p>
<p class="empty-subtitle">Drag and drop images, videos, or PDF files here to automatically remove metadata.</p>
<p class="empty-subtitle">Drag and drop images, videos, or PDF files to automatically remove metadata.</p>
<div class="empty-action"></div>
</div>
</div>
Expand Down
23 changes: 0 additions & 23 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==

[email protected]:
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.2:
version "0.14.2"
resolved "https://registry.yarnpkg.com/electron-util/-/electron-util-0.14.2.tgz#793ebd61f75435363b0dbbba61dddb0f17812fb1"
integrity sha512-pnnRJiWajDcTtEAS33RgP3XVO+9cJjOlBA0BKk6cABjcPxihgCwiGWplCOHc0lH43f68ZJZweiunwomJC+TWng==
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 Expand Up @@ -8260,11 +8242,6 @@ serialize-javascript@^1.7.0:
resolved "https://registry.yarnpkg.com/serialize-javascript/-/serialize-javascript-1.9.1.tgz#cfc200aef77b600c47da9bb8149c943e798c2fdb"
integrity sha512-0Vb/54WJ6k5v8sSWN09S0ora+Hnr+cX40r9F170nT+mSkaxltoE/7R3OrIdBSUv1OoiobH1QoWQbCnAO+e8J1A==

serialize-javascript@^2.1.1:
version "2.1.2"
resolved "https://registry.yarnpkg.com/serialize-javascript/-/serialize-javascript-2.1.2.tgz#ecec53b0e0317bdc95ef76ab7074b7384785fa61"
integrity sha512-rs9OggEUF0V4jUSecXazOYsLfu7OGK2qIn3c7IPBiffz32XniEp/TX9Xmc9LQfK2nQ2QKHvZ2oygKUGU0lG4jQ==

serialize-javascript@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/serialize-javascript/-/serialize-javascript-3.0.0.tgz#492e489a2d77b7b804ad391a5f5d97870952548e"
Expand Down

0 comments on commit 1afbf38

Please sign in to comment.