Skip to content

Commit

Permalink
Merge pull request #45 from KL13NT/auto-update
Browse files Browse the repository at this point in the history
feat(#40): auto update
  • Loading branch information
KL13NT authored Feb 14, 2021
2 parents 445d392 + d00a13d commit 8a907d1
Show file tree
Hide file tree
Showing 11 changed files with 205 additions and 382 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,4 @@ typings/

# Electron-Forge
out/
dist/
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ This project is *minimal*. Features include:
- Select and delete multiple entries
- Select and copy multiple text entries
- Complete keyboard navigation
- Seamlessly download updates in the background and apply then when wanted

## Getting Started

Expand Down
1 change: 1 addition & 0 deletions assets/cloud-download-outline.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
314 changes: 0 additions & 314 deletions dist/render.prod.js

This file was deleted.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"dev:forge": "electron-forge start",
"dev:render": "webpack --config ./webpack.renderer.config.js --watch --mode development",
"package": "npm-run-all -s build && electron-forge package",
"prepackage": "npm-run-all -s lint pretty test build",
"build": "webpack --config ./webpack.renderer.config.js --mode production",
"make": "electron-forge make",
"premake": "npm-run-all -s lint pretty test build",
Expand Down
11 changes: 6 additions & 5 deletions src/about.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,23 @@ <h2>Tutorial</h2>
Left Click an entry to copy it back.
</li>
<li>
Right Click an entry to remove it from the log.
Hover over an entry to view actions for that entry
</li>
<li>
Click `Clear clipboard only` to clear your system's clipboard only,
Click `Clear clipboard only` or `CTRL + Delete` to clear your system's clipboard only,
leaving the log as is.
</li>
<li>
Click `Clear log` to clear the log. You'll be prompted to clear your
Click `Clear log` or `CTRL + SHIFT + Delete` to clear the log. You'll be prompted to clear your
system's clipboard as well.
</li>
<li>
Click the `pin` icon next to each entry to pin/unpin it to/from the top of the log.
Hold `SHIFT` and Left Click multiple entries to select them then click
`Copy Selection` or `CTRL + C` to bulk copy your selections. Works with text only.
</li>
<li>
Hold `SHIFT` and Left Click multiple entries to select them then click
`Copy Selection` to bulk copy your selections. Works with text only.
`Delete Selection` or `Delete` to bulk copy your selections. Works with text only.
</li>
</ul>
</body>
Expand Down
46 changes: 43 additions & 3 deletions src/index.css
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
html {
background: #f1f1f1;
}

body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
font-family: Roboto, -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica,
Arial, sans-serif;
margin: auto;
max-width: 38rem;
padding: 2rem;
padding: 4rem 2rem;
}

* {
Expand Down Expand Up @@ -64,7 +68,7 @@ body {
#container > ul > li > div.entry-actions {
display: none;
position: absolute;
background: #fff;
background: #f1f1f1;
border: solid 1px rgba(0, 0, 0, 0.5);
border-radius: 10px;
width: 160px;
Expand Down Expand Up @@ -114,3 +118,39 @@ body {
button {
margin-right: 6px;
}

.navbar {
position: fixed;
top: 0;
left: 0;
width: 100%;
min-height: 60px;
display: flex;
justify-content: space-between;
padding: 20px 30px;
margin: 0;
}

.navbar button,
.navbar span {
background: transparent;
border: none;
font-size: 16px;
vertical-align: middle;
}
.navbar button {
cursor: pointer;
}

.navbar button.update {
margin-right: 20px;
padding: 0;
}

.navbar button.update > img {
height: 30px;
width: 30px;
margin: 0;
padding: 0;
vertical-align: middle;
}
94 changes: 69 additions & 25 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/** @import * from "./shared/typedefs.js" */

const isDev = require("electron-is-dev");
const path = require("path");
const {
Expand All @@ -10,6 +12,7 @@ const {
ipcMain,
nativeImage,
Menu,
autoUpdater,
} = require("electron");
const { nanoid } = require("nanoid");
const { pathToFileURL } = require("url");
Expand All @@ -19,6 +22,10 @@ const {
CLIPBOARD_EVENT,
CLIPBOARD_CLEAR,
CLIPBOARD_BULK_COPY,
OPEN_ABOUT_PAGE,
AUTO_UPDATE_URL,
UPDATE_APPLY,
UPDATE_AVAILABLE,
} = require("./shared/constants");

app.setLoginItemSettings({
Expand All @@ -27,12 +34,6 @@ app.setLoginItemSettings({

if (require("electron-squirrel-startup")) app.quit();

/**
* defining tray globally to avoid GC bug
* https://www.electronjs.org/docs/faq#my-apps-windowtray-disappeared-after-a-few-minutes
* @type {Tray} */
let tray = null;

/** @type {Electron.BrowserWindowConstructorOptions} */
const DEFAULT_WINDOW_OPTIONS = {
enableLargerThanScreen: false,
Expand All @@ -56,10 +57,17 @@ const DEFAULT_PAGE_OPTIONS = {
titleBarStyle: "hidden",
};

/**
* defining tray globally to avoid GC bug
* https://www.electronjs.org/docs/faq#my-apps-windowtray-disappeared-after-a-few-minutes
* @type {Tray} */
let tray = null;
/** @type {BrowserWindow} */
let mainWindow = null;
/** @type {BrowserWindow} */
let aboutWindow = null;
/** @type {UpdateInfo} */
const updateInfo = null;

const minimize = () => {
mainWindow.hide();
Expand Down Expand Up @@ -203,9 +211,30 @@ const preventNavigation = (e) => {
e.preventDefault();
};

const openAboutPage = () => {
aboutWindow.show();
};

const applyUpdate = () => {
const { releaseNotes } = updateInfo;
const dialogOpts = {
type: "info",
buttons: ["Restart", "Later"],
title: "Application Update",
message: releaseNotes,
detail:
"A new version has been downloaded. Restart the application to apply the updates.",
};

const response = dialog.showMessageBoxSync(dialogOpts);
if (response === 0) autoUpdater.quitAndInstall();
};

ipcMain.handle(CLIPBOARD_CLEAR, clear);
ipcMain.on(CLIPBOARD_EVENT, handleIPCCopy);
ipcMain.on(CLIPBOARD_BULK_COPY, handleIPCBulk);
ipcMain.on(OPEN_ABOUT_PAGE, openAboutPage);
ipcMain.on(UPDATE_APPLY, applyUpdate);

/**
* @param {Object} config
Expand All @@ -224,6 +253,26 @@ const createPage = ({ title, options, url }) => {
return window;
};

const feed = `${AUTO_UPDATE_URL}/update/${
process.platform
}/${app.getVersion()}`;

autoUpdater.setFeedURL(feed);

if (!isDev) {
const updateInterval = setInterval(() => {
autoUpdater.checkForUpdates();
}, 5 * 60 * 1000 /* Every 5 minutes */);

autoUpdater.on("update-available", () => {
clearInterval(updateInterval);
});

autoUpdater.on("update-downloaded", () => {
mainWindow.webContents.send(UPDATE_AVAILABLE);
});
}

const createWindow = () => {
try {
mainWindow = createPage({
Expand All @@ -232,6 +281,7 @@ const createWindow = () => {
url: path.resolve(__dirname, "./index.html"),
});

mainWindow.removeMenu();
mainWindow.maximize();
mainWindow.on("close", handleExit);
mainWindow.on("minimize", handleMinimize);
Expand All @@ -253,27 +303,21 @@ const createWindow = () => {

tray.setContextMenu(trayMenu);

const mainMenu = Menu.buildFromTemplate([
{
label: "About",
click: () => {
aboutWindow = createPage({
title: "About",
url: path.resolve(__dirname, "./about.html"),
options: {
...DEFAULT_PAGE_OPTIONS,
parent: mainWindow,
},
});

aboutWindow.removeMenu();
aboutWindow.webContents.on("will-navigate", preventNavigation);
aboutWindow.webContents.on("new-window", aboutLinkHandler);
},
aboutWindow = createPage({
title: "About",
url: path.resolve(__dirname, "./about.html"),
options: {
...DEFAULT_PAGE_OPTIONS,
parent: mainWindow,
},
]);
});

aboutWindow.hide();
aboutWindow.removeMenu();
aboutWindow.webContents.on("will-navigate", preventNavigation);

app.applicationMenu = mainMenu;
aboutWindow.on("close", (e) => e.preventDefault() || aboutWindow.hide());
aboutWindow.webContents.on("new-window", aboutLinkHandler);

pingClipboardChanges();
} catch (error) {
Expand Down
Loading

0 comments on commit 8a907d1

Please sign in to comment.