Skip to content

Commit

Permalink
Added final touches to settings view
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverschwendener committed Sep 23, 2018
1 parent 18a034f commit 6f18f4c
Show file tree
Hide file tree
Showing 17 changed files with 72 additions and 91 deletions.
18 changes: 8 additions & 10 deletions src/tests/integration/search-plugins/file-search-plugin.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { FileSearchPlugin } from "../../../ts/search-plugins/file-search-plugin";
import { mkdirSync, writeFileSync, unlinkSync, rmdirSync } from "fs";
import { join } from "path";
import { Injector } from "../../../ts/injector";
import { platform } from "os";
import { FileSearchOption } from "../../../ts/file-search-option";
import { testIconSet } from "../../../ts/icon-sets/test-icon-set";

describe(FileSearchPlugin.name, (): void => {
const parentFolders = [
Expand Down Expand Up @@ -73,7 +72,7 @@ describe(FileSearchPlugin.name, (): void => {
recursive: recursiveSearch,
};
});
const plugin = new FileSearchPlugin(options);
const plugin = new FileSearchPlugin(options, testIconSet);
const actual = plugin.getAllItems();
const actualLength = actual.length;
const expectedLength = (testFiles.length + subFolders.length) * parentFolders.length;
Expand All @@ -89,7 +88,7 @@ describe(FileSearchPlugin.name, (): void => {
recursive: recursiveSearch,
};
});
const plugin = new FileSearchPlugin(options);
const plugin = new FileSearchPlugin(options, testIconSet);
const actual = plugin.getAllItems();
const actualLength = actual.length;
const expectedLength = (parentFolders.length * subFolders.length * testFiles.length) + (parentFolders.length * testFiles.length);
Expand All @@ -104,7 +103,7 @@ describe(FileSearchPlugin.name, (): void => {
recursive: false,
};
});
const plugin = new FileSearchPlugin(options);
const plugin = new FileSearchPlugin(options, testIconSet);
const actual = plugin.getAllItems();

for (const item of actual) {
Expand All @@ -122,24 +121,23 @@ describe(FileSearchPlugin.name, (): void => {
recursive: false,
};
});
const iconSet = Injector.getIconSet(platform());
const plugin = new FileSearchPlugin(options);
const plugin = new FileSearchPlugin(options, testIconSet);
const actual = plugin.getAllItems();

const actualFiles = actual.filter((a) => {
return a.icon === iconSet.fileIcon;
return a.icon === testIconSet.fileIcon;
});

const actualFolders = actual.filter((a) => {
return a.icon === iconSet.folderIcon;
return a.icon === testIconSet.folderIcon;
});

expect(actualFiles.length).toBe(testFiles.length * parentFolders.length);
expect(actualFolders.length).toBe(subFolders.length * parentFolders.length);
});

it("should return an empty array if no folders are specified", (): void => {
const plugin = new FileSearchPlugin([]);
const plugin = new FileSearchPlugin([], testIconSet);
const acutal = plugin.getAllItems();

expect(acutal.length).toBe(0);
Expand Down
12 changes: 0 additions & 12 deletions src/tests/unit/injector.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { Injector } from "../../ts/injector";
import { WindowsIconSet } from "../../ts/icon-sets/windows-icon-set";
import { MacOsIconSet } from "../../ts/icon-sets/mac-os-icon-set";
import { Windows10SettingsSearchPlugin } from "../../ts/search-plugins/windows-10-settings-plugin";
import { MacOsSettingsPlugin } from "../../ts/search-plugins/mac-os-settings-plugin";
import { DirectorySeparator } from "../../ts/directory-separator";
Expand Down Expand Up @@ -57,16 +55,6 @@ describe(Injector.name, () => {
});
});

describe(Injector.getIconSet.name, () => {
it("should return an icon manager", () => {
const actualWin = Injector.getIconSet(win);
const acutalMac = Injector.getIconSet(mac);

expect(actualWin instanceof WindowsIconSet).toBe(true);
expect(acutalMac instanceof MacOsIconSet).toBe(true);
});
});

describe(Injector.getOpenUrlWithDefaultBrowserCommand.name, () => {
it("should return an command to open up default browser with URL", () => {
const actualWin = Injector.getOpenUrlWithDefaultBrowserCommand(win, testUrl);
Expand Down
3 changes: 2 additions & 1 deletion src/tests/unit/search-plugins/programs-plugin.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Program } from "../../../ts/programs-plugin/program";
import { FakeProgramRepository } from "./../../../ts/programs-plugin/fake-program-repository";
import { ProgramsPlugin } from "./../../../ts/search-plugins/programs-plugin";
import { testIconSet } from "../../../ts/icon-sets/test-icon-set";

function getTestPrograms(programNames: string[]) {
return programNames.map((p): Program => {
Expand All @@ -23,7 +24,7 @@ describe("ProgramsPlugin", (): void => {
]);

const fakeProgramRepository = new FakeProgramRepository(fakePrograms);
const programsPlugin = new ProgramsPlugin(fakeProgramRepository);
const programsPlugin = new ProgramsPlugin(fakeProgramRepository, testIconSet);

const actual = programsPlugin.getAllItems();

Expand Down
4 changes: 2 additions & 2 deletions src/ts/executors/file-path-executor.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as childProcess from "child_process";
import { exec } from "child_process";
import { Injector } from "../injector";
import { Executor } from "./executor";
import { platform } from "os";
Expand Down Expand Up @@ -27,7 +27,7 @@ export class FilePathExecutor implements Executor {
}

private handleExecution(command: string): void {
childProcess.exec(command, (err) => {
exec(command, (err) => {
if (err) {
throw err;
}
Expand Down
4 changes: 2 additions & 2 deletions src/ts/executors/web-url-executor.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as childProcess from "child_process";
import { exec } from "child_process";
import { Injector } from "../injector";
import { Executor } from "./executor";
import { platform } from "os";
Expand All @@ -22,7 +22,7 @@ export class WebUrlExecutor implements Executor {
}

private handleCommandExecution(command: string): void {
childProcess.exec(command, (err) => {
exec(command, (err) => {
if (err) {
throw err;
}
Expand Down
6 changes: 3 additions & 3 deletions src/ts/icon-sets/icon-set.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
export interface IconSet {
folderIcon: string;
fileIcon: string;
appIcon: string;
searchIcon: string;
emailIcon: string;
fileIcon: string;
folderIcon: string;
searchIcon: string;
shortcutIcon: string;
}
10 changes: 10 additions & 0 deletions src/ts/icon-sets/test-icon-set.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { IconSet } from "./icon-set";

export const testIconSet: IconSet = {
appIcon: "app-icon",
emailIcon: "email-icon",
fileIcon: "file-icon",
folderIcon: "folder-icon",
searchIcon: "search-icon",
shortcutIcon: "shortcut-icon",
};
10 changes: 0 additions & 10 deletions src/ts/injector.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import { IconSet } from "./icon-sets/icon-set";
import { MacOsIconSet } from "./icon-sets/mac-os-icon-set";
import { WindowsIconSet } from "./icon-sets/windows-icon-set";
import { OperatingSystem } from "./operating-system";
import { MacOsSettingsPlugin } from "./search-plugins/mac-os-settings-plugin";
import { SearchPlugin } from "./search-plugins/search-plugin";
Expand All @@ -18,13 +15,6 @@ export class Injector {
return new RegExp(/^((https?:)?[/]{2})?([a-z0-9]+[.])+[a-z]+.*$/i, "gi");
}

public static getIconSet(platform: string): IconSet {
switch (OperatingSystemHelpers.getOperatingSystemFromString(platform)) {
case OperatingSystem.Windows: return new WindowsIconSet();
case OperatingSystem.macOS: return new MacOsIconSet();
}
}

public static getOpenUrlWithDefaultBrowserCommand(platform: string, url: string): string {
switch (OperatingSystemHelpers.getOperatingSystemFromString(platform)) {
case OperatingSystem.Windows:
Expand Down
11 changes: 4 additions & 7 deletions src/ts/production/production-searchers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { platform } from "os";
import { CalculatorSearcher } from "./../searcher/calculator-searcher";
import { CalculatorInputValidator } from "./../input-validators/calculator-input-validator";
import { FilePathSearcher } from "./../searcher/file-path-searcher";
Expand All @@ -18,13 +17,11 @@ import { UeliHelpers } from "./../helpers/ueli-helpers";
import { UserConfigOptions } from "./../user-config/user-config-options";
import { CountManager } from "./../count/count-manager";
import { CountFileRepository } from "./../count/count-file-repository";
import { Injector } from "./../injector";
import { CustomCommandSearcher } from "./../searcher/custom-command-searcher";
import { CustomCommandInputValidator } from "./../input-validators/custom-command-input-validator";

export class ProductionSearchers {
public static getCombinations(config: UserConfigOptions): InputValidatorSearcherCombination[] {
const iconSet = Injector.getIconSet(platform());
const countManager = new CountManager(new CountFileRepository(UeliHelpers.countFilePath));
const environmentVariableCollection = process.env as { [key: string]: string };

Expand All @@ -34,7 +31,7 @@ export class ProductionSearchers {
validator: new CalculatorInputValidator(),
},
{
searcher: new FilePathSearcher(config),
searcher: new FilePathSearcher(config.searchEngineThreshold, config.iconSet),
validator: new FilePathInputValidator(),
},
{
Expand All @@ -46,19 +43,19 @@ export class ProductionSearchers {
validator: new WebSearchInputValidator(config.webSearches),
},
{
searcher: new EmailAddressSearcher(),
searcher: new EmailAddressSearcher(config.iconSet),
validator: new EmailAddressInputValidator(),
},
{
searcher: new WebUrlSearcher(),
validator: new WebUrlInputValidator(),
},
{
searcher: new CustomCommandSearcher(config.customCommands, iconSet.shortcutIcon),
searcher: new CustomCommandSearcher(config.customCommands, config.iconSet.shortcutIcon),
validator: new CustomCommandInputValidator(config.customCommands),
},
{
searcher: new SearchPluginsSearcher(config, countManager, iconSet, environmentVariableCollection),
searcher: new SearchPluginsSearcher(config, countManager, config.iconSet, environmentVariableCollection),
validator: new SearchPluginsInputValidator(),
},
];
Expand Down
4 changes: 2 additions & 2 deletions src/ts/programs-plugin/program-file-repository.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as path from "path";
import { basename } from "path";
import { FileHelpers } from "../helpers/file-helpers";
import { Program } from "./program";
import { ProgramRepository } from "./program-repository";
Expand Down Expand Up @@ -26,7 +26,7 @@ export class ProgramFileRepository implements ProgramRepository {
if (file.endsWith(applicationFileExtension)) {
result.push({
executionArgument: file,
name: path.basename(file).replace(applicationFileExtension, ""),
name: basename(file).replace(applicationFileExtension, ""),
} as Program);
}
}
Expand Down
11 changes: 5 additions & 6 deletions src/ts/renderer.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
import { SearchResultItemViewModel } from "./search-result-item-view-model";
import { IpcChannels } from "./ipc-channels";
import { platform } from "os";
import { ipcRenderer } from "electron";
import { UserConfigFileRepository } from "./user-config/user-config-file-repository";
import { defaultConfig } from "./user-config/default-config";
import { UserInputHistoryManager } from "./user-input-history-manager";
import { Injector } from "./injector";
import { ElectronStoreAppConfigRepository } from "./app-config/electorn-store-app-config-repository";
import { availableColorThemes } from "./available-color-themes";
import Vue from "vue";
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";
import { version } from "../../package.json";

const appConfigRepository = new ElectronStoreAppConfigRepository();
const config = new UserConfigFileRepository(defaultConfig, appConfigRepository.getAppConfig().userSettingsFilePath).getConfig();
Expand All @@ -28,7 +26,6 @@ const configEdit = {
};
const appConfig = new ElectronStoreAppConfigRepository().getAppConfig();
const userInputHistoryManager = new UserInputHistoryManager();
const iconSet = Injector.getIconSet(platform());

document.addEventListener("keyup", handleGlobalKeyPress);

Expand All @@ -43,14 +40,13 @@ const vue = new Vue({
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,
version,
},
el: "#vue-root",
methods: {
Expand Down Expand Up @@ -202,6 +198,9 @@ const vue = new Vue({
config.webSearches.splice(indexToRemove, 1);
vue.updateUserConfig();
},
settingsActionUpdateIconSet: (): void => {
vue.updateUserConfig();
},
updateAppConfig: (): void => {
ipcRenderer.send(IpcChannels.updateAppConfig, appConfig);
},
Expand Down
4 changes: 2 additions & 2 deletions src/ts/search-plugin-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ export class SearchPluginManager {

public constructor(config: UserConfigOptions, iconSet: IconSet, environmentVariableCollection: { [key: string]: string }) {
this.plugins = [
new ProgramsPlugin(new ProgramFileRepository(config.applicationFolders, config.applicationFileExtensions)),
new FileSearchPlugin(config.fileSearchOptions),
new ProgramsPlugin(new ProgramFileRepository(config.applicationFolders, config.applicationFileExtensions), config.iconSet),
new FileSearchPlugin(config.fileSearchOptions, config.iconSet),
new UeliCommandsSearchPlugin(),
new ShortcutsPlugin(config.shortcuts, iconSet.shortcutIcon),
];
Expand Down
14 changes: 6 additions & 8 deletions src/ts/search-plugins/file-search-plugin.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import * as fs from "fs";
import * as os from "os";
import * as path from "path";
import { lstatSync } from "fs";
import { basename } from "path";
import { FileHelpers } from "../helpers/file-helpers";
import { IconSet } from "../icon-sets/icon-set";
import { Injector } from "../injector";
import { SearchResultItem } from "../search-result-item";
import { SearchPlugin } from "./search-plugin";
import { FileSearchOption } from "../file-search-option";
Expand All @@ -14,9 +12,9 @@ export class FileSearchPlugin implements SearchPlugin {
private items: SearchResultItem[];
private iconSet: IconSet;

public constructor(fileSearchOptions: FileSearchOption[]) {
public constructor(fileSearchOptions: FileSearchOption[], iconSet: IconSet) {
this.fileSearchOptions = fileSearchOptions;
this.iconSet = Injector.getIconSet(os.platform());
this.iconSet = iconSet;
this.items = this.loadFilesAndFolders();
}

Expand All @@ -34,8 +32,8 @@ export class FileSearchPlugin implements SearchPlugin {
: FileHelpers.getFilesFromFolder(option.folderPath);

for (const filePath of filePaths) {
const stats = fs.lstatSync(filePath);
const fileName = path.basename(filePath);
const stats = lstatSync(filePath);
const fileName = basename(filePath);

result.push({
description: FilePathDescriptionBuilder.buildFilePathDescription(filePath),
Expand Down
6 changes: 2 additions & 4 deletions src/ts/search-plugins/programs-plugin.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import * as os from "os";
import { IconSet } from "../icon-sets/icon-set";
import { Injector } from "../injector";
import { Program } from "../programs-plugin/program";
import { ProgramRepository } from "../programs-plugin/program-repository";
import { SearchResultItem } from "../search-result-item";
Expand All @@ -11,8 +9,8 @@ export class ProgramsPlugin implements SearchPlugin {
private programs: Program[];
private iconSet: IconSet;

public constructor(programRepository: ProgramRepository) {
this.iconSet = Injector.getIconSet(os.platform());
public constructor(programRepository: ProgramRepository, iconSet: IconSet) {
this.iconSet = iconSet;
this.programs = programRepository.getPrograms();
}

Expand Down
6 changes: 2 additions & 4 deletions src/ts/searcher/email-address-searcher.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import { Searcher } from "./searcher";
import { SearchResultItem } from "../search-result-item";
import { Injector } from "../injector";
import { IconSet } from "../icon-sets/icon-set";
import { platform } from "os";

export class EmailAddressSearcher implements Searcher {
private iconSet: IconSet;

constructor() {
this.iconSet = Injector.getIconSet(platform());
constructor(iconSet: IconSet) {
this.iconSet = iconSet;
}

public getSearchResult(userInput: string): SearchResultItem[] {
Expand Down
Loading

0 comments on commit 6f18f4c

Please sign in to comment.