Skip to content
This repository has been archived by the owner on Dec 31, 2024. It is now read-only.

Commit

Permalink
Added option in settings to open log file
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverschwendener committed Apr 29, 2019
1 parent 65e2cbc commit 55d948e
Show file tree
Hide file tree
Showing 13 changed files with 46 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/common/ipc-channels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ export enum IpcChannels {
clearExecutionLogConfirmed = "clear-execution-log-confirmed",
executionLogClearingSucceeded = "execution-log-clearing-succeeded",
executionLogClearingErrored = "execution-log-clearing-errored",
openDebugLogRequested = "open-debug-log-requested",
}
1 change: 1 addition & 0 deletions src/common/logger/logger.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export interface Logger {
debug(message: string): void;
error(message: string): void;
openLog(): Promise<void>;
}
9 changes: 8 additions & 1 deletion src/common/logger/production-logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ import * as Winston from "winston";

export class ProductionLogger implements Logger {
private readonly logger: Winston.Logger;
private readonly fileOpener: (filePath: string) => Promise<void>;

constructor(fileOpener: (filePath: string, privileged?: boolean) => Promise<void>) {
this.fileOpener = fileOpener;

constructor() {
const { combine, timestamp, printf } = Winston.format;

// tslint:disable-next-line: no-shadowed-variable
Expand Down Expand Up @@ -38,4 +41,8 @@ export class ProductionLogger implements Logger {
public error(message: string): void {
this.logger.error(message);
}

public openLog(): Promise<void> {
return this.fileOpener("debug.log");
}
}
1 change: 1 addition & 0 deletions src/common/translation/english-translation-set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export const englishTranslationSet: TranslationSet = {
generalSettingsImportErrorInvalidConfig: "Settings import failed: file content seems to be invalid",
generalSettingsResetAllSettings: "Reset all settings to default",
clearExecutionLog: "Clear execution log",
openDebugLog: "Open debug log",

appearanceSettings: "Appearance",
appearanceSettingsWindowWidth: "Window width (in pixels)",
Expand Down
1 change: 1 addition & 0 deletions src/common/translation/german-translation-set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export const germanTranslationSet: TranslationSet = {
generalSettingsImportErrorInvalidConfig: "Einstellungsimport fehlgeschlagen: Dateiinhalt scheint ungültig zu sein",
generalSettingsResetAllSettings: "Alle Einstellungen auf Standard zurücksetzen",
clearExecutionLog: "Ausführungslog löschen",
openDebugLog: "Debug log öffnen",

appearanceSettings: "Erscheinungsbild",
appearanceSettingsWindowWidth: "Fensterbreite (in Pixel)",
Expand Down
1 change: 1 addition & 0 deletions src/common/translation/translation-set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export interface TranslationSet {
generalSettingsImportErrorInvalidConfig: string;
generalSettingsResetAllSettings: string;
clearExecutionLog: string;
openDebugLog: string;

appearanceSettings: string;
appearanceSettingsWindowWidth: string;
Expand Down
11 changes: 7 additions & 4 deletions src/main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,11 @@ import { FileHelpers } from "./helpers/file-helpers";
import { ueliTempFolder } from "../common/helpers/ueli-helpers";
import { getTranslationSet } from "../common/translation/translation-set-manager";
import { trayIconPathWindows, trayIconPathMacOs } from "./helpers/tray-icon-helpers";
import { ProductionLogger } from "../common/logger/production-logger";

if (!FileHelpers.fileExistsSync(ueliTempFolder)) {
FileHelpers.createFolderSync(ueliTempFolder);
}

const logger = new ProductionLogger();
const configRepository = new ElectronStoreConfigRepository(cloneDeep(defaultUserConfigOptions));
const currentOperatingSystem = platform() === "darwin" ? OperatingSystem.macOS : OperatingSystem.Windows;
const windowIconFilePath = join(__dirname, "..", "assets", "ueli-black-on-white-logo.png");
Expand All @@ -42,7 +40,8 @@ let settingsWindow: BrowserWindow;

let config = configRepository.getConfig();
let translationSet = getTranslationSet(config.generalOptions.language);
let searchEngine = getProductionSearchEngine(config, translationSet, logger);
let searchEngine = getProductionSearchEngine(config, translationSet);
const logger = searchEngine.getLogger();

let rescanInterval = config.generalOptions.rescanEnabled
? setInterval(() => refreshAllIndexes(), Number(config.generalOptions.rescanIntervalInSeconds) * 1000)
Expand Down Expand Up @@ -210,7 +209,7 @@ function updateMainWindowSize(searchResultCount: number, appearanceOptions: Appe

function reloadApp() {
updateMainWindowSize(0, config.appearanceOptions);
searchEngine = getProductionSearchEngine(config, translationSet, logger);
searchEngine = getProductionSearchEngine(config, translationSet);
mainWindow.reload();
}

Expand Down Expand Up @@ -504,6 +503,10 @@ function registerAllIpcListeners() {
.catch((err) => notifyRenderer(IpcChannels.executionLogClearingErrored, err));
});

ipcMain.on(IpcChannels.openDebugLogRequested, (event: Electron.Event) => {
logger.openLog();
});

ipcMain.on(IpcChannels.ueliCommandExecuted, (command: UeliCommand) => {
switch (command.executionArgument) {
case UeliCommandExecutionArgument.Exit:
Expand Down
6 changes: 3 additions & 3 deletions src/main/production/production-search-engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import { TranslationPlugin } from "../plugins/translation-plugin/translation-plu
import { executeFilePathLocationMacOs, executeFilePathLocationWindows } from "../executors/file-path-location-executor";
import { TranslationSet } from "../../common/translation/translation-set";
import { WebSearchPlugin } from "../plugins/websearch-plugin/websearch-plugin";
import { Logger } from "../../common/logger/logger";
import { FileBrowserExecutionPlugin } from "../plugins/filebrowser-plugin/filebrowser-plugin";
import { isValidWindowsFilePath, isValidMacOsFilePath } from "../../common/helpers/file-path-validators";
import { getFileIconDataUrl } from "../../common/icon/generate-file-icon";
Expand All @@ -32,14 +31,15 @@ import { EmailPlugin } from "../plugins/email-plugin/email-plugin";
import { ElectronStoreFavoriteRepository } from "../favorites/electron-store-favorite-repository";
import { CurrencyConverterPlugin } from "../plugins/currency-converter-plugin/currency-converter-plugin";
import { executeCommand } from "../executors/command-executor";
import { ProductionLogger } from "../../common/logger/production-logger";

const filePathValidator = isWindows(platform()) ? isValidWindowsFilePath : isValidMacOsFilePath;
const filePathExecutor = isWindows(platform()) ? executeFilePathWindows : executeFilePathMacOs;
const filePathLocationExecutor = isWindows(platform()) ? executeFilePathLocationWindows : executeFilePathLocationMacOs;
const urlExecutor = isWindows(platform()) ? executeUrlWindows : executeUrlMacOs;
const appIconGenerator = isWindows(platform()) ? generateWindowsAppIcons : generateMacAppIcons;

export const getProductionSearchEngine = (userConfig: UserConfigOptions, translationSet: TranslationSet, logger: Logger): SearchEngine => {
export const getProductionSearchEngine = (userConfig: UserConfigOptions, translationSet: TranslationSet): SearchEngine => {
const operatingSystemCommandRepository = isWindows(platform())
? new WindowsOperatingSystemCommandRepository(translationSet)
: new MacOsOperatingSystemCommandRepository(translationSet);
Expand Down Expand Up @@ -110,7 +110,7 @@ export const getProductionSearchEngine = (userConfig: UserConfigOptions, transla
fallbackPlugins,
userConfig,
translationSet,
logger,
new ProductionLogger(filePathExecutor),
new ElectronStoreFavoriteRepository(),
);
};
6 changes: 5 additions & 1 deletion src/main/search-engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ export class SearchEngine {
private readonly fallbackPlugins: ExecutionPlugin[];
private translationSet: TranslationSet;
private config: UserConfigOptions;
private readonly logger: Logger;
private readonly favoriteManager: FavoriteManager;
private readonly logger: Logger;

constructor(
plugins: SearchPlugin[],
Expand Down Expand Up @@ -159,6 +159,10 @@ export class SearchEngine {
return this.favoriteManager.clearExecutionLog();
}

public getLogger(): Logger {
return this.logger;
}

private getSearchPluginsResult(userInput: string): Promise<SearchResultItem[]> {
return new Promise((resolve, reject) => {
const pluginPromises = this.searchPlugins
Expand Down
4 changes: 4 additions & 0 deletions src/renderer/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ new Vue({
ipcRenderer.send(IpcChannels.clearExecutionLogConfirmed);
});

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

ipcRenderer.on(IpcChannels.appearanceOptionsUpdated, (event: Electron.Event, updatedAppearanceOptions: AppearanceOptions) => {
vueEventDispatcher.$emit(VueEventChannels.appearanceOptionsUpdated, updatedAppearanceOptions);
});
Expand Down
7 changes: 7 additions & 0 deletions src/renderer/settings/general-settings-component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ export const generalSettingsComponent = Vue.extend({
.then(() => this.dropdownVisible = false);
});
},
openDebugLog() {
vueEventDispatcher.$emit(VueEventChannels.openDebugLogRequested);
},
resetAll() {
const config: UserConfigOptions = this.config;
config.generalOptions = cloneDeep(defaultGeneralOptions);
Expand Down Expand Up @@ -125,6 +128,10 @@ export const generalSettingsComponent = Vue.extend({
<span class="icon"><i class="fas fa-trash"></i></span>
<span>{{ translations.clearExecutionLog }}</span>
</a>
<a class="dropdown-item" @click="openDebugLog">
<span class="icon"><i class="fas fa-bug"></i></span>
<span>{{ translations.openDebugLog }}</span>
</a>
</div>
</div>
</div>
Expand Down
1 change: 1 addition & 0 deletions src/renderer/vue-event-channels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,5 @@ export enum VueEventChannels {
saveColor = "save-color",
favoritesRequested = "favorites-requested",
clearExecutionLogConfirmed = "clear-execution-log-confirmed",
openDebugLogRequested = "open-debug-log-requested",
}
6 changes: 6 additions & 0 deletions src/tests/test-logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ export class TestLogger implements Logger {
});
}

public openLog(): Promise<void> {
return new Promise((resolve) => {
resolve();
});
}

public getAllMessages(): LogMessage[] {
return this.messages;
}
Expand Down

0 comments on commit 55d948e

Please sign in to comment.