Skip to content

Commit

Permalink
Added basic structure for auto update functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverschwendener committed Jul 11, 2019
1 parent 67d15cc commit 14b777d
Show file tree
Hide file tree
Showing 8 changed files with 195 additions and 4 deletions.
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "ueli",
"productName": "ueli",
"version": "7.2.5",
"version": "7.0.0",
"license": "MIT",
"repository": {
"type": "git",
Expand Down Expand Up @@ -34,7 +34,8 @@
"lint:fix": "./node_modules/.bin/tslint --project tsconfig.json --config tslint.json --fix",
"test": "./node_modules/.bin/jest --config jest.json --silent .",
"tsc:validate": "./node_modules/.bin/tsc --noEmit",
"package:dir": "./node_modules/.bin/electron-builder --dir --config electron-builder-config.yml --publish never"
"package:dir": "./node_modules/.bin/electron-builder --dir --config electron-builder-config.yml --publish never",
"package": "./node_modules/.bin/electron-builder --config electron-builder-config.yml --publish never"
},
"devDependencies": {
"@types/jest": "^24.0.13",
Expand All @@ -46,6 +47,7 @@
"electron": "^5.0.5",
"electron-builder": "^20.40.2",
"electron-store": "^3.2.0",
"electron-updater": "^4.0.14",
"fuse.js": "^3.4.4",
"jest": "^24.8.0",
"lodash": "^4.17.11",
Expand Down
3 changes: 3 additions & 0 deletions src/common/ipc-channels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,7 @@ export enum IpcChannels {
openTempFolderRequested = "open-temp-folder-requested",
notification = "notification",
selectInputHistoryItem = "select-input-history-item",
checkForUpdate = " check-for-update",
checkForUpdateResponse = "check-for-update-response",
downloadUpdate = "download-update",
}
5 changes: 5 additions & 0 deletions src/common/update-check-result.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export enum UpdateCheckResult {
Error = "error",
NoUpdateAvailable = "no-update-available",
UpdateAvailable = "update-available",
}
47 changes: 46 additions & 1 deletion src/main/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { app, BrowserWindow, ipcMain, globalShortcut, dialog, Tray, Menu, screen, MenuItemConstructorOptions, WebContents } from "electron";
import { autoUpdater } from "electron-updater";
import { join } from "path";
import { IpcChannels } from "../common/ipc-channels";
import { SearchResultItem } from "../common/search-result-item";
Expand Down Expand Up @@ -26,6 +27,7 @@ import { UserInputHistoryManager } from "./user-input-history-manager";
import { isWindows } from "../common/helpers/operating-system-helpers";
import { executeFilePathWindows, executeFilePathMacOs } from "./executors/file-path-executor";
import { WindowPosition } from "../common/window-position";
import { UpdateCheckResult } from "../common/update-check-result";

if (!FileHelpers.fileExistsSync(ueliTempFolder)) {
FileHelpers.createFolderSync(ueliTempFolder);
Expand All @@ -37,6 +39,8 @@ const filePathExecutor = currentOperatingSystem === OperatingSystem.Windows ? ex
const windowIconFilePath = join(__dirname, "..", "assets", "ueli-white-on-black-logo-circle.png");
const userInputHistoryManager = new UserInputHistoryManager();

autoUpdater.autoDownload = false;

if (currentOperatingSystem === OperatingSystem.macOS) {
app.dock.hide();
}
Expand Down Expand Up @@ -451,8 +455,9 @@ function openSettings() {
settingsWindow.setMenu(null);
settingsWindow.loadFile(join(__dirname, "..", "settings.html"));
settingsWindow.on("close", onSettingsClose);
settingsWindow.webContents.openDevTools();
if (isDev()) {
settingsWindow.webContents.openDevTools();
//
}
} else {
settingsWindow.focus();
Expand Down Expand Up @@ -617,6 +622,20 @@ function registerAllIpcListeners() {
break;
}
});

ipcMain.on(IpcChannels.checkForUpdate, (event: Electron.Event) => {
logger.debug("Check for updates");
if (isDev()) {
//
} else {
autoUpdater.checkForUpdates();
}
});

ipcMain.on(IpcChannels.downloadUpdate, (event: Electron.Event) => {
logger.debug("Downloading updated");
autoUpdater.downloadUpdate();
});
}

app.on("ready", () => {
Expand All @@ -631,3 +650,29 @@ app.on("ready", () => {

app.on("window-all-closed", quitApp);
app.on("quit", app.quit);

autoUpdater.on("update-available", () => {
logger.debug("Update check result: update available");
if (settingsWindow && !settingsWindow.isDestroyed()) {
settingsWindow.webContents.send(IpcChannels.checkForUpdateResponse, UpdateCheckResult.UpdateAvailable);
}
});

autoUpdater.on("update-not-available", () => {
logger.debug("Update check result: update not available");
if (settingsWindow && !settingsWindow.isDestroyed()) {
settingsWindow.webContents.send(IpcChannels.checkForUpdateResponse, UpdateCheckResult.NoUpdateAvailable);
}
});

autoUpdater.on("error", (error) => {
logger.error(`Update check result: ${error}`);
if (settingsWindow && !settingsWindow.isDestroyed()) {
settingsWindow.webContents.send(IpcChannels.checkForUpdateResponse, UpdateCheckResult.Error);
}
});

autoUpdater.on("update-downloaded", () => {
logger.debug("Update downloaded");
autoUpdater.quitAndInstall();
});
13 changes: 13 additions & 0 deletions src/renderer/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import { GeneralOptions } from "../common/config/general-options";
import { simpleFolderSearchEditingModalComponent } from "./settings/modals/simple-folder-search-editing-modal-component";
import { operatingSystemSettingsSettingsComponent } from "./settings/operating-system-settings-settings-component";
import { userConfirmationDialog } from "./settings/modals/user-confirmation-component";
import { UpdateCheckResult } from "../common/update-check-result";

Vue.component("user-input", userInputComponent);
Vue.component("search-results", searchResultsComponent);
Expand Down Expand Up @@ -153,6 +154,14 @@ const app = new Vue({
ipcRenderer.send(IpcChannels.selectInputHistoryItem, direction);
});

vueEventDispatcher.$on(VueEventChannels.checkForUpdate, () => {
ipcRenderer.send(IpcChannels.checkForUpdate);
});

vueEventDispatcher.$on(VueEventChannels.downloadUpdate, () => {
ipcRenderer.send(IpcChannels.downloadUpdate);
});

ipcRenderer.on(IpcChannels.appearanceOptionsUpdated, (event: Electron.Event, updatedAppearanceOptions: AppearanceOptions) => {
vueEventDispatcher.$emit(VueEventChannels.appearanceOptionsUpdated, updatedAppearanceOptions);
});
Expand Down Expand Up @@ -196,6 +205,10 @@ const app = new Vue({
ipcRenderer.on(IpcChannels.refreshIndexesCompleted, (event: Electron.Event, message: string) => {
vueEventDispatcher.$emit(VueEventChannels.loadingCompleted);
});

ipcRenderer.on(IpcChannels.checkForUpdateResponse, (event: Electron.Event, updateCheckResult: UpdateCheckResult) => {
vueEventDispatcher.$emit(VueEventChannels.checkForUpdateResponse, updateCheckResult);
});
},
methods: {
mainWindowGlobalKeyPress(event: KeyboardEvent) {
Expand Down
89 changes: 89 additions & 0 deletions src/renderer/settings/general-settings-component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,24 @@ import { isValidUserConfig, mergeUserConfigWithDefault } from "../../common/help
import { defaultUserConfigOptions } from "../../common/config/default-user-config-options";
import { GeneralSettings } from "./general-settings";
import { UserConfirmationDialogParams, UserConfirmationDialogType } from "./modals/user-confirmation-dialog-params";
import { UpdateCheckResult } from "../../common/update-check-result";
import { isDev } from "../../common/is-dev";

interface UpdateStatus {
checking: boolean;
downloading: boolean;
errorOnUpdateCheck: boolean;
latestVersionRunning: boolean;
updateAvailable: boolean;
}

const initialUpdateStatus: UpdateStatus = {
checking: true,
downloading: false,
errorOnUpdateCheck: false,
latestVersionRunning: false,
updateAvailable: false,
};

export const generalSettingsComponent = Vue.extend({
data() {
Expand All @@ -24,7 +42,9 @@ export const generalSettingsComponent = Vue.extend({
dropdownVisible: false,
globalHotKeyKeys: Object.values(GlobalHotKeyKey).map((key) => key),
globalHotKeyModifiers: Object.values(GlobalHotKeyModifier).map((modifier) => modifier),
isDev: isDev(),
settingName: GeneralSettings.General,
updateStatus: cloneDeep(initialUpdateStatus),
visible: false,
};
},
Expand Down Expand Up @@ -183,6 +203,42 @@ export const generalSettingsComponent = Vue.extend({
}
vueEventDispatcher.$emit(VueEventChannels.configUpdated, this.config, needsIndexRefresh);
},
checkForUpdate() {
vueEventDispatcher.$emit(VueEventChannels.checkForUpdate);
},
downloadUpdate() {
vueEventDispatcher.$emit(VueEventChannels.downloadUpdate);
const updateStatus: UpdateStatus = this.updateStatus;
updateStatus.checking = false;
updateStatus.downloading = true;
updateStatus.errorOnUpdateCheck = false;
updateStatus.latestVersionRunning = false;
updateStatus.updateAvailable = false;
},
changeUpdateStatus(result: UpdateCheckResult) {
const updateStatus: UpdateStatus = this.updateStatus;
if (result === UpdateCheckResult.Error) {
updateStatus.checking = false;
updateStatus.downloading = false;
updateStatus.errorOnUpdateCheck = true;
updateStatus.latestVersionRunning = false;
updateStatus.updateAvailable = false;
}
if (result === UpdateCheckResult.NoUpdateAvailable) {
updateStatus.checking = false;
updateStatus.downloading = false;
updateStatus.errorOnUpdateCheck = false;
updateStatus.latestVersionRunning = true;
updateStatus.updateAvailable = false;
}
if (result === UpdateCheckResult.UpdateAvailable) {
updateStatus.checking = false;
updateStatus.downloading = false;
updateStatus.errorOnUpdateCheck = false;
updateStatus.latestVersionRunning = false;
updateStatus.updateAvailable = true;
}
},
},
mounted() {
vueEventDispatcher.$on(VueEventChannels.showSetting, (settingName: string) => {
Expand All @@ -192,6 +248,14 @@ export const generalSettingsComponent = Vue.extend({
this.visible = false;
}
});

vueEventDispatcher.$on(VueEventChannels.checkForUpdateResponse, (updateCheckResult: UpdateCheckResult) => {
this.changeUpdateStatus(updateCheckResult);
});

setTimeout(() => {
this.checkForUpdate();
}, 500);
},
props: ["config", "translations"],
template: `
Expand Down Expand Up @@ -417,6 +481,31 @@ export const generalSettingsComponent = Vue.extend({
</div>
</div>
<div class="settings__option">
<div class="settings__option-name">Update</div>
<div class="settings__option-content">
<div class="field has-addons has-addons-right vertical-center">
<div class="control">
<button class="button" v-if="updateStatus.checking" disabled>
Checking..
</button>
<button class="button" :disabled="isDev" v-if="updateStatus.updateAvailable" @click="downloadUpdate">
Download update
</button>
<button class="button" disabled v-if="updateStatus.downloading">
Downloading...
</button>
<button class="button" v-if="updateStatus.latestVersionRunning" disabled>
You are running the latest version!
</button>
<button class="button" v-if="updateStatus.errorOnUpdateCheck" disabled>
Error while checking for update
</button>
</div>
</div>
</div>
</div>
</div>
</div>
Expand Down
3 changes: 3 additions & 0 deletions src/renderer/vue-event-channels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,7 @@ export enum VueEventChannels {
openSimpleFolderSearchEditingModal = "open-simple-folder-search-editing-modal",
simpleFolderSearchOptionSaved = "simple-folder-search-option-saved",
settingsConfirmation = "settings-confirmation",
checkForUpdate = "check-for-update",
checkForUpdateResponse = "check-for-update-response",
downloadUpdate = "download-update",
}
33 changes: 32 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,11 @@
resolved "https://registry.yarnpkg.com/@types/node/-/node-10.14.10.tgz#e491484c6060af8d461e12ec81c0da8a3282b8de"
integrity sha512-V8wj+w2YMNvGuhgl/MA5fmTxgjmVHVoasfIaxMMZJV6Y8Kk+Ydpi1z2whoShDCJ2BuNVoqH/h1hrygnBxkrw/Q==

"@types/semver@^6.0.1":
version "6.0.1"
resolved "https://registry.yarnpkg.com/@types/semver/-/semver-6.0.1.tgz#a984b405c702fa5a7ec6abc56b37f2ba35ef5af6"
integrity sha512-ffCdcrEE5h8DqVxinQjo+2d1q+FV5z7iNtPofw3JsrltSoSVlOGaW0rY8XxtO9XukdTn8TaCGWmk2VFGhI70mg==

"@types/stack-utils@^1.0.1":
version "1.0.1"
resolved "https://registry.yarnpkg.com/@types/stack-utils/-/stack-utils-1.0.1.tgz#0a851d3bd96498fa25c33ab7278ed3bd65f06c3e"
Expand Down Expand Up @@ -1987,6 +1992,22 @@ electron-store@^3.2.0:
conf "^4.1.0"
type-fest "^0.3.1"

electron-updater@^4.0.14:
version "4.0.14"
resolved "https://registry.yarnpkg.com/electron-updater/-/electron-updater-4.0.14.tgz#0043c317a1a475f016f997ace0ddbba87b8f1129"
integrity sha512-4gLUvdsmOopxG6ItlwbgmRGrMdKtX2LURF+fYK/44X3m7In/g1kYzWZ3TG4sLVGJakllfLY/iclqvEk4Kkk5Zw==
dependencies:
"@types/semver" "^6.0.1"
bluebird-lst "^1.0.9"
builder-util-runtime "8.2.5"
fs-extra-p "^8.0.2"
js-yaml "^3.13.1"
lazy-val "^1.0.4"
lodash.isequal "^4.5.0"
pako "^1.0.10"
semver "^6.1.2"
source-map-support "^0.5.12"

electron@^5.0.5:
version "5.0.5"
resolved "https://registry.yarnpkg.com/electron/-/electron-5.0.5.tgz#2d04499064d3f6c89c4642e47cfe9ea151d794eb"
Expand Down Expand Up @@ -3817,6 +3838,11 @@ locate-path@^3.0.0:
p-locate "^3.0.0"
path-exists "^3.0.0"

lodash.isequal@^4.5.0:
version "4.5.0"
resolved "https://registry.yarnpkg.com/lodash.isequal/-/lodash.isequal-4.5.0.tgz#415c4478f2bcc30120c22ce10ed3226f7d3e18e0"
integrity sha1-QVxEePK8wwEgwizhDtMib30+GOA=

lodash.sortby@^4.7.0:
version "4.7.0"
resolved "https://registry.yarnpkg.com/lodash.sortby/-/lodash.sortby-4.7.0.tgz#edd14c824e2cc9c1e0b0a1b42bb5210516a42438"
Expand Down Expand Up @@ -4560,7 +4586,7 @@ package-json@^6.3.0:
registry-url "^5.0.0"
semver "^6.1.1"

pako@~1.0.5:
pako@^1.0.10, pako@~1.0.5:
version "1.0.10"
resolved "https://registry.yarnpkg.com/pako/-/pako-1.0.10.tgz#4328badb5086a426aa90f541977d4955da5c9732"
integrity sha512-0DTvPVU3ed8+HNXOu5Bs+o//Mbdj9VNQMUOe9oKCwh8l0GNwpTDMKCWbRjgtD291AWnkAgkqA/LOnQS8AmS1tw==
Expand Down Expand Up @@ -5317,6 +5343,11 @@ semver@^6.0.0, semver@^6.1.1:
resolved "https://registry.yarnpkg.com/semver/-/semver-6.1.1.tgz#53f53da9b30b2103cd4f15eab3a18ecbcb210c9b"
integrity sha512-rWYq2e5iYW+fFe/oPPtYJxYgjBm8sC4rmoGdUOgBB7VnwKt6HrL793l2voH1UlsyYZpJ4g0wfjnTEO1s1NP2eQ==

semver@^6.1.2:
version "6.2.0"
resolved "https://registry.yarnpkg.com/semver/-/semver-6.2.0.tgz#4d813d9590aaf8a9192693d6c85b9344de5901db"
integrity sha512-jdFC1VdUGT/2Scgbimf7FSx9iJLXoqfglSF+gJeuNWVpiE37OIbc1jywR/GJyFdz3mnkz2/id0L0J/cr0izR5A==

serialize-javascript@^1.7.0:
version "1.7.0"
resolved "https://registry.yarnpkg.com/serialize-javascript/-/serialize-javascript-1.7.0.tgz#d6e0dfb2a3832a8c94468e6eb1db97e55a192a65"
Expand Down

0 comments on commit 14b777d

Please sign in to comment.