Skip to content

Commit

Permalink
Enabled updating via gui
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverschwendener committed Sep 23, 2018
1 parent b92d954 commit f46bcb9
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 48 deletions.
22 changes: 22 additions & 0 deletions main.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,28 @@
</g>
</svg>
<h1>App Settings</h1>
<div class="setting-group">
<div class="setting-title">Info</div>
<div class="setting">
<div>ueli: {{ version }}</div>
<div>Electron: {{ process.versions.electron }}</div>
<div>Chrome: {{ process.versions.chrome }}</div>
<div>Node: {{ process.versions.node }}</div>
<div>V8: {{ process.versions.v8 }}</div>
</div>
</div>
<div class="setting-group">
<div class="setting-title">Update</div>
<div class="setting">
<button v-if="(updateAvailable || noUpdateFound) === false" v-on:click="handleCheckForUpdateButtonClick" class="setting-button">Check for update</button>
<div v-if="updateAvailable">
<button v-if="updateAvailable && !downloadingUpdate" v-on:click="handleDownloadUpdateButtonClick" class="setting-button">Download & install update</button>
<button v-if="updateAvailable && downloadingUpdate" class="setting-button">Downloading...</button>
</div>
<div v-if="noUpdateFound">Your are running the latest version</div>
<div v-if="errorOnUpdateCheck">There was an error while checking for updates</div>
</div>
</div>
<div class="setting-group">
<div class="setting-title">Config file path</div>
<div class="setting">
Expand Down
5 changes: 1 addition & 4 deletions src/ts/declarations.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
declare module "*.scss" {
const content: string;
export default content;
}
// Typescript type declarations
2 changes: 2 additions & 0 deletions src/ts/ipc-channels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export class IpcChannels {
public static readonly ueliCheckForUpdates = `${UeliHelpers.ueliCommandPrefix}check-for-updates`;
public static readonly ueliUpdateUeli = `${UeliHelpers.ueliCommandPrefix}update`;
public static readonly ueliUpdateWasFound = "update-was-found";
public static readonly ueliNoUpdateWasFound = "no-update-was-found";
public static readonly ueliUpdateCheckError = "ueli-update-check-error";
public static readonly exitCommandLineTool = "exit-command-line-tool";
public static readonly resetCommandlineOutput = "reset-commandline-output";
public static readonly resetUserInput = "reset-user-input";
Expand Down
43 changes: 11 additions & 32 deletions src/ts/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { app, BrowserWindow, globalShortcut, ipcMain, Menu, MenuItem, Tray, screen, ipcRenderer } from "electron";
import { app, BrowserWindow, globalShortcut, ipcMain, Menu, MenuItem, Tray, screen } from "electron";
import { autoUpdater } from "electron-updater";
import { join } from "path";
import { FilePathExecutionArgumentValidator } from "./execution-argument-validators/file-path-execution-argument-validator";
Expand Down Expand Up @@ -87,10 +87,6 @@ function createMainWindow(): void {
}

function createTrayIcon(): void {
if (trayIcon !== undefined && !trayIcon.isDestroyed()) {
trayIcon.destroy();
}

trayIcon = new Tray(Injector.getTrayIconPath(platform(), join(__dirname, "../")));
trayIcon.setToolTip(UeliHelpers.productName);
trayIcon.setContextMenu(Menu.buildFromTemplate([
Expand Down Expand Up @@ -123,36 +119,21 @@ function downloadUpdate(): void {
}

autoUpdater.on("update-available", (): void => {
addUpdateStatusToTrayIcon("Update is available");
ipcMain.emit(IpcChannels.ueliUpdateWasFound);
mainWindow.webContents.send(IpcChannels.ueliUpdateWasFound);
});

autoUpdater.on("update-not-available", (): void => {
addUpdateStatusToTrayIcon(`${UeliHelpers.productName} is up to date`);
mainWindow.webContents.send(IpcChannels.ueliNoUpdateWasFound);
});

autoUpdater.on("error", (): void => {
addUpdateStatusToTrayIcon("Update check failed");
mainWindow.webContents.send(IpcChannels.ueliUpdateCheckError);
});

autoUpdater.on("update-downloaded", (): void => {
autoUpdater.quitAndInstall();
});

function addUpdateStatusToTrayIcon(label: string, clickHandler?: any): void {
const updateItem = clickHandler === undefined
? { label }
: { label, click: clickHandler } as MenuItem;

if (trayIcon !== undefined) {
trayIcon.setContextMenu(Menu.buildFromTemplate([
updateItem,
{ click: toggleWindow, label: "Show/Hide" },
{ click: quitApp, label: "Exit" },
]));
}
}

function setAutostartSettings() {
app.setLoginItemSettings({
args: [],
Expand Down Expand Up @@ -199,7 +180,7 @@ function hideMainWindow(): void {
}, delayWhenHidingCommandlineOutputInMs); // to give user input and command line output time to reset properly delay hiding window
}

function reloadApp(): void {
function reloadApp(preventMainWindowReload?: boolean): void {
config = new ConfigFileRepository(defaultConfig, appConfigRepository.getAppConfig().userSettingsFilePath).getConfig();
inputValidationService = new InputValidationService(config, new InputValidatorSearcherCombinationManager(config).getCombinations());
executionService = new ExecutionService(
Expand All @@ -208,16 +189,13 @@ function reloadApp(): void {
config,
ipcEmitter);

mainWindow.reload();
resetWindowToDefaultSizeAndPosition();
if (!preventMainWindowReload) {
mainWindow.reload();
resetWindowToDefaultSizeAndPosition();
}

unregisterAllGlobalShortcuts();
registerGlobalHotKey();

if (config.showTrayIcon) {
createTrayIcon();
} else {
destroyTrayIcon();
}
}

function destroyTrayIcon(): void {
Expand Down Expand Up @@ -304,4 +282,5 @@ ipcMain.on(IpcChannels.updateAppConfig, (event: Electron.Event, updatedAppConfig
ipcMain.on(IpcChannels.updateUserConfig, (event: Electron.Event, updatedUserConfig: ConfigOptions) => {
config = updatedUserConfig;
userConfigRepository.saveConfig(updatedUserConfig);
reloadApp(true);
});
39 changes: 36 additions & 3 deletions src/ts/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { CustomCommand } from "./custom-shortcut";
import { FileSearchOption } from "./file-search-option";
import { Shortcut } from "./shortcut";
import { WebSearch } from "./web-search";
import * as packageJson from "../../package.json";

const appConfigRepository = new ElectronStoreAppConfigRepository();
const config = new ConfigFileRepository(defaultConfig, appConfigRepository.getAppConfig().userSettingsFilePath).getConfig();
Expand All @@ -39,18 +40,27 @@ const vue = new Vue({
commandLineOutput: [] as string[],
config,
configEdit,
downloadingUpdate: false,
errorOnUpdateCheck: false,
noUpdateFound: false,
searchIcon: iconSet.searchIcon,
searchResults: [] as SearchResultItemViewModel[],
settingsVisible: false,
updateAvailable: false,
userInput: "",
userStylesheet: `file:///${config.userStylesheet}`,
userStylesheetIsAvailable: config.userStylesheet !== undefined && config.userStylesheet.length > 0,
version: packageJson.version,
},
el: "#vue-root",
methods: {
colorTheme: (): string => {
return `./styles/${config.colorTheme}.css`;
},
handleCheckForUpdateButtonClick: (): void => {
ipcRenderer.send(IpcChannels.ueliCheckForUpdates);
vue.downloadingUpdate = true;
},
handleClick: (): void => {
if (config.allowMouseInteraction) {
handleEnterPress();
Expand All @@ -60,6 +70,9 @@ const vue = new Vue({
handleCloseSettingsIconClick: (): void => {
hideSettings();
},
handleDownloadUpdateButtonClick: (): void => {
ipcRenderer.send(IpcChannels.ueliUpdateUeli);
},
handleMouseEnter: (index: number): void => {
if (config.allowMouseInteraction) {
changeActiveItemByIndex(index);
Expand Down Expand Up @@ -126,9 +139,11 @@ const vue = new Vue({
configEdit.newCustomCommand = {};
},
settingsActionAddFallbackWebSearch: (newFallbackWebSearch: string): void => {
config.fallbackWebSearches.push(newFallbackWebSearch);
vue.updateUserConfig();
configEdit.newFallbackWebSearch = "";
if (newFallbackWebSearch.length > 0) {
config.fallbackWebSearches.push(newFallbackWebSearch);
vue.updateUserConfig();
configEdit.newFallbackWebSearch = "";
}
},
settingsActionAddFileSearchOption: (newFileSearchOption: FileSearchOption): void => {
config.fileSearchOptions.push(newFileSearchOption);
Expand Down Expand Up @@ -213,6 +228,24 @@ ipcRenderer.on(IpcChannels.commandLineOutput, (event: Electron.Event, arg: strin
handleCommandLineOutput(arg);
});

ipcRenderer.on(IpcChannels.ueliUpdateWasFound, () => {
vue.updateAvailable = true;
vue.noUpdateFound = false;
vue.errorOnUpdateCheck = false;
});

ipcRenderer.on(IpcChannels.ueliNoUpdateWasFound, (): void => {
vue.updateAvailable = false;
vue.noUpdateFound = true;
vue.errorOnUpdateCheck = false;
});

ipcRenderer.on(IpcChannels.ueliUpdateCheckError, (): void => {
vue.updateAvailable = false;
vue.noUpdateFound = false;
vue.errorOnUpdateCheck = true;
});

ipcRenderer.on(IpcChannels.resetCommandlineOutput, resetCommandLineOutput);
ipcRenderer.on(IpcChannels.resetUserInput, resetUserInput);
ipcRenderer.on(IpcChannels.hideSettings, hideSettings);
Expand Down
4 changes: 0 additions & 4 deletions src/ts/search-plugins/ueli-commands-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ export class UeliCommandsSearchPlugin implements SearchPlugin {
executionArgument: IpcChannels.showSettingsFromMain,
name: "Edit configuration",
},
{
executionArgument: IpcChannels.ueliCheckForUpdates,
name: "Check for updates",
},
];

public getAllItems(): SearchResultItem[] {
Expand Down
27 changes: 23 additions & 4 deletions styles/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

--font-family: "Segoe UI", "Helvetica";
--font-family-mono: "Consolas", "Courier", monospace;
--settings-font-size: 0.85rem;
}

body {
Expand Down Expand Up @@ -137,6 +138,7 @@ span.search-result-description.active {
div.settings-container {
padding: 0 var(--side-padding);
position: relative;
font-size: var(--settings-font-size);
}

div.setting-group {
Expand All @@ -151,7 +153,7 @@ div.setting-group:last-child {
}

div.setting-title {
font-size: 0.85rem;
font-size: var(--settings-font-size):
padding-right: var(--side-padding);
display: flex;
align-items: center;
Expand All @@ -174,7 +176,7 @@ input.setting-text-input {
outline: none;
color: var(--text-color);
width: 100%;
font-size: 0.85rem;
font-size: var(--settings-font-size);
padding: 5px;
margin-bottom: 5px;
box-sizing: border-box;
Expand All @@ -197,7 +199,7 @@ select.setting-select {
border: 1px solid var(--scrollbar-foreground-color);
padding: 5px;
color: var(--text-color);
font-size: 1rem;
font-size: var(--settings-font-size);
outline: none;
}

Expand All @@ -214,7 +216,7 @@ svg.setting-action-icon:hover {
}

table.setting-table {
font-size: 0.85rem;
font-size: var(--settings-font-size);
text-align: left;
width: 100%;
}
Expand All @@ -237,6 +239,23 @@ svg.close-settings-icon:hover {
opacity: 0.5;
}

button.setting-button {
cursor: pointer;
transition: all var(--transition-speed) ease-in-out;
padding: 5px 15px;
background-color: var(--scrollbar-background-color);
color: var(--text-color);
border: 1px solid var(--scrollbar-foreground-color);
}

button.setting-button:hover {
background-color: var(--scrollbar-foreground-color);
}

button.setting-button:focus {
outline: none;
}

::-webkit-scrollbar {
width: var(--scrollbar-size);
height: var(--scrollbar-size);
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
/* Strict Type-Checking Options */
"strict": false, /* Enable all strict type-checking options. */
"noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
"strictNullChecks": true /* Enable strict null checks. */
"strictNullChecks": true, /* Enable strict null checks. */
"resolveJsonModule": true
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
/* Additional Checks */
Expand Down

0 comments on commit f46bcb9

Please sign in to comment.