Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add auto-updating #65

Merged
merged 12 commits into from
May 22, 2020
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,15 @@ jobs:

- name: Build with electron-builder
run: |
export GH_TOKEN=${{ secrets.GH_TOKEN }}
yarn --frozen-lockfile
yarn dist --publish=never

yarn deploy

- name: Update cask and create PR
run: |
brew install vitorgalvao/tiny-scripts/cask-repair
yarn build-cask
yarn deploy-cask
style:

runs-on: macos-latest
Expand All @@ -59,4 +65,4 @@ jobs:
- name: Check style
run: |
yarn --frozen-lockfile
yarn clean-check
yarn clean-check
File renamed without changes.
1 change: 0 additions & 1 deletion app.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// Modules to control application life and create native browser window
const { BrowserWindow, ipcMain, nativeTheme, app } = require("electron");

const store = require("./src/helpers/store");
Expand Down
3 changes: 3 additions & 0 deletions dev-app-update.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
owner: alexkim205
repo: G-Desktop-Suite
provider: github
17 changes: 14 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
{
"name": "gdesktopsuite",
"productName": "G Desktop Suite",
"version": "0.2.2",
"version": "0.3.0",
"description": "A Google Suite desktop app made with Electron",
"copyright": "Copyright © 2018-2020 Alex Gyujin Kim",
"main": "app.js",
"scripts": {
"start": "electron .",
"dev": "cross-env NODE_ENV=development electron .",
"pack": "electron-builder --dir && yarn update-cask",
"dist": "electron-builder -mwl",
"update-cask": "./Casks/update.sh $npm_package_version",
"build": "electron-builder -mwl -p never",
"deploy": "electron-builder -mwl -p onTagOrDraft",
"build-cask": "./Casks/update.sh $npm_package_version",
"deploy-cask": "cask-repair g-desktop-suite -v $npm_package_version -b",
"clean": "concurrently \"prettier './**/*.js' --write\" \"eslint ./**/*.js --fix\"",
"clean-check": "concurrently \"prettier './**/*.js' --list-different\" \"eslint ./**/*.js\""
},
Expand Down Expand Up @@ -40,6 +42,13 @@
"build": {
"appId": "com.alexgyujinkim.GDesktopSuite",
"copyright": "Copyright © 2018-2020 Alex Gyujin Kim",
"publish": [
{
"provider": "github",
"repo": "G-Desktop-Suite",
"owner": "alexkim205"
}
],
"files": [
"./build/**/*",
"./src/**/*",
Expand Down Expand Up @@ -78,6 +87,7 @@
"del": "^5.1.0",
"electron": "^8.2.5",
"electron-builder": "^22.6.0",
"electron-log": "^4.1.4",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably want to remove dependencies from README and move it to a DEPENDENCIES.md file because might get to hard to manage listing all these dependencies

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good point, however I don't think this is within the scope of this PR, so I'll create another PR just for reorganizing docs.

"eslint": "^7.0.0",
"eslint-config-prettier": "^6.11.0",
"eslint-plugin-prettier": "^3.1.3",
Expand All @@ -89,6 +99,7 @@
"darkreader": "^4.9.2",
"electron-localshortcut": "https://github.com/alexkim205/electron-localshortcut/tarball/master",
"electron-store": "^5.1.1",
"electron-updater": "^4.3.1",
"electron-window-state": "^5.0.1",
"file-system": "^2.2.2"
}
Expand Down
50 changes: 50 additions & 0 deletions src/helpers/updater.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
const { dialog } = require("electron");
const { autoUpdater } = require("electron-updater");

// Send update info to main window.
autoUpdater.on("update-available", () => {
console.log("update avaliable");
dialog.showMessageBox(
{
type: "info",
title: "Found Updates",
message: "Found updates, do you want update now?",
buttons: ["Sure", "No"],
},
(buttonIndex) => {
if (buttonIndex === 0) {
autoUpdater.downloadUpdate();
} else {
updater.enabled = true;
updater = null;
}
}
);
});
autoUpdater.on("update-not-available", () => {
console.log("update not avaliable");
dialog.showMessageBox({
title: "No Updates",
message: "Current version is up-to-date.",
});
updater.enabled = true;
updater = null;
});

autoUpdater.on("update-downloaded", () => {
dialog.showMessageBox(
{
title: "Install Updates",
message: "Updates downloaded, application will close for an update...",
},
() => {
setImmediate(() => autoUpdater.quitAndInstall());
}
);
});

const checkForUpdates = () => {
autoUpdater.checkForUpdates();
};

module.exports = { checkForUpdates };
4 changes: 4 additions & 0 deletions src/js/mainwindow.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const path = require("path");

const { signInURL, userAgent, isDev } = require("../helpers/config");
const { TITLE_BAR_HEIGHT } = require("../helpers/util");
const { checkForUpdates } = require("../helpers/updater");
const { createChildWindow } = require("./childwindow");
var { template } = require("./menu");

Expand Down Expand Up @@ -89,6 +90,9 @@ var createMainWindow = () => {
view.webContents.once("did-finish-load", () => {
win.show();
view.webContents.focus();

// Check for updates when main window is ready
checkForUpdates();
});

// On new window, create child window
Expand Down
3 changes: 3 additions & 0 deletions src/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@
<div id="titlebar"></div>
</body>
</html>



Loading