Skip to content

Commit

Permalink
Merge a952078 into 47f1e95
Browse files Browse the repository at this point in the history
  • Loading branch information
khanhas committed Jun 7, 2018
2 parents 47f1e95 + a952078 commit a981556
Show file tree
Hide file tree
Showing 12 changed files with 146 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/tests/unit/input-validators/variable-input-validator.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { VariableInputValidator } from "../../../ts/input-validators/variable-input-validator";

describe(VariableInputValidator.name, (): void => {
const validator = new VariableInputValidator();
describe(validator.isValidForSearchResults.name, (): void => {
it("Should return true if user input has $ as prefix", (): void => {
expect(validator.isValidForSearchResults("$ayyyy")).toBe(true);
});
it("Should return false if user input doesn't have $ as prefix", (): void => {
expect(validator.isValidForSearchResults(">yoooo")).toBe(false);
expect(validator.isValidForSearchResults("!aklsdjflks")).toBe(false);
expect(validator.isValidForSearchResults("asdasdsad")).toBe(false);
});
});
});
43 changes: 43 additions & 0 deletions src/tests/unit/searcher/variable-searcher.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { VariableSearcher } from "../../../ts/searcher/variable-searcher";
import { ConfigOptions } from "../../../ts/config-options";
import { Injector } from "../../../ts/injector";
import { InputValidator } from "../../../ts/input-validators/input-validator";

const defaultConfig = {
directoryVariables: [
{
name: "custom",
path: "F:\\Custom\\Path",
},
],
} as ConfigOptions;

class FilePathInputValidator implements InputValidator {
public isValidForSearchResults(userInput: string): boolean {
const regex = Injector.getFilePathRegExp("win32");
return regex.test(userInput);
}
}

describe(VariableSearcher.name, (): void => {
const fakeVariables = {
Gallery: "E:\\Camera\\DCIM",
notAPath: "420",
topsecretfolder: "D:\\Softwares\\Installers\\temp\\LoliPic",
};
const searcher = new VariableSearcher(defaultConfig, new FilePathInputValidator(), fakeVariables);

describe(searcher.getSearchResult.name, (): void => {
it("Should return directory path as execution argument", (): void => {
expect(searcher.getSearchResult("topsecretfolder")[0].executionArgument).toBe(fakeVariables.topsecretfolder);
});

it("Should return original name", (): void => {
expect(searcher.getSearchResult("GALLERY")[0].name).toBe("Gallery");
});

it("Should not return variable that isn't a path", (): void => {
expect(searcher.getSearchResult("notAPath").length).toBe(0);
});
});
});
2 changes: 2 additions & 0 deletions src/ts/config-options.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { WebSearch } from "./web-search";
import { CustomCommand } from "./custom-command";
import { Variable } from "./variable";

export interface ConfigOptions {
applicationFileExtensions: string[];
Expand All @@ -19,6 +20,7 @@ export interface ConfigOptions {
searchResultNameFontSize: number;
userInputHeight: number;
userInputFontSize: number;
directoryVariables: Variable[];
webSearches: WebSearch[];
windowWith: number;
}
6 changes: 6 additions & 0 deletions src/ts/default-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ export const defaultConfig: ConfigOptions = {
autoStartApp: true,
colorTheme: "dark",
customCommands: [],
directoryVariables: [
{
name: "home",
path: homedir(),
},
],
fileSearchFolders: [homedir()],
hotKey: "alt+space",
logExecution: true,
Expand Down
1 change: 1 addition & 0 deletions src/ts/icon-sets/icon-set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ export interface IconSet {
searchIcon: string;
emailIcon: string;
customShortCutIcon: string;
variableIcon: string;
}
6 changes: 6 additions & 0 deletions src/ts/icon-sets/mac-os-icon-set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,10 @@ export class MacOsIconSet implements IconSet {
<path d="M 28.875 11 C 28.371094 11.0625 27.996094 11.492188 28 12 L 28 19.0625 C 16.488281 19.414063 10.28125 25.507813 7.21875 31.5625 C 4.113281 37.699219 4.003906 43.683594 4 43.875 C 4 43.875 4 43.9375 4 43.9375 L 4 44 C 3.984375 44.550781 4.417969 45.015625 4.96875 45.03125 C 5.519531 45.046875 5.984375 44.613281 6 44.0625 C 6 44.0625 6 44 6 44 C 6.007813 43.90625 6.230469 40.878906 9.09375 37.65625 C 11.90625 34.496094 17.394531 31.308594 28 31.09375 L 28 38 C 28 38.382813 28.21875 38.734375 28.566406 38.902344 C 28.914063 39.070313 29.324219 39.023438 29.625 38.78125 L 45.625 25.78125 C 45.863281 25.589844 46 25.304688 46 25 C 46 24.695313 45.863281 24.410156 45.625 24.21875 L 29.625 11.21875 C 29.414063 11.046875 29.144531 10.96875 28.875 11 Z M 30 14.09375 L 43.40625 25 L 30 35.90625 L 30 30 C 30 29.449219 29.550781 29 29 29 C 17.246094 29 10.910156 32.613281 7.59375 36.34375 C 7.46875 36.484375 7.398438 36.609375 7.28125 36.75 C 7.703125 35.375 8.257813 33.90625 9 32.4375 C 11.917969 26.671875 17.488281 21 29 21 C 29.550781 21 30 20.550781 30 20 Z "></path>
</g>
</svg>`;

public variableIcon = `<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 32 32" version="1.1">
<g id="surface1">
<path d=" M 17.856 20.106 L 17.856 20.106 L 17.856 20.106 Q 17.866 19.218 17.207 18.583 L 17.207 18.583 L 17.207 18.583 Q 16.548 17.948 15.112 17.479 L 15.112 17.479 L 15.112 17.479 Q 14.204 17.196 13.472 16.825 L 13.472 16.825 L 13.472 16.825 Q 12.739 16.454 12.217 15.941 L 12.217 15.941 L 12.217 15.941 Q 11.694 15.429 11.411 14.765 L 11.411 14.765 L 11.411 14.765 Q 11.128 14.101 11.128 13.231 L 11.128 13.231 L 11.128 13.231 Q 11.128 12.411 11.377 11.747 L 11.377 11.747 L 11.377 11.747 Q 11.626 11.083 12.08 10.59 L 12.08 10.59 L 12.08 10.59 Q 12.534 10.097 13.184 9.794 L 13.184 9.794 L 13.184 9.794 Q 13.833 9.491 14.624 9.394 L 14.624 9.394 L 14.624 7.245 L 16.079 7.245 L 16.079 9.394 L 16.079 9.394 Q 17.72 9.618 18.628 10.775 L 18.628 10.775 L 18.628 10.775 Q 19.536 11.933 19.546 13.925 L 19.546 13.925 L 17.749 13.925 L 17.749 13.925 Q 17.749 13.271 17.588 12.719 L 17.588 12.719 L 17.588 12.719 Q 17.427 12.167 17.119 11.771 L 17.119 11.771 L 17.119 11.771 Q 16.812 11.376 16.362 11.151 L 16.362 11.151 L 16.362 11.151 Q 15.913 10.927 15.337 10.927 L 15.337 10.927 L 15.337 10.927 Q 14.155 10.927 13.55 11.542 L 13.55 11.542 L 13.55 11.542 Q 12.944 12.157 12.935 13.202 L 12.935 13.202 L 12.935 13.202 Q 12.935 13.69 13.091 14.071 L 13.091 14.071 L 13.091 14.071 Q 13.247 14.452 13.584 14.765 L 13.584 14.765 L 13.584 14.765 Q 13.921 15.077 14.453 15.346 L 14.453 15.346 L 14.453 15.346 Q 14.985 15.614 15.737 15.868 L 15.737 15.868 L 15.737 15.868 Q 16.655 16.171 17.388 16.542 L 17.388 16.542 L 17.388 16.542 Q 18.12 16.913 18.628 17.411 L 18.628 17.411 L 18.628 17.411 Q 19.136 17.909 19.404 18.563 L 19.404 18.563 L 19.404 18.563 Q 19.673 19.218 19.673 20.087 L 19.673 20.087 L 19.673 20.087 Q 19.673 20.937 19.404 21.61 L 19.404 21.61 L 19.404 21.61 Q 19.136 22.284 18.647 22.768 L 18.647 22.768 L 18.647 22.768 Q 18.159 23.251 17.461 23.544 L 17.461 23.544 L 17.461 23.544 Q 16.763 23.837 15.913 23.925 L 15.913 23.925 L 15.913 25.8 L 14.458 25.8 L 14.458 23.935 L 14.458 23.935 Q 13.696 23.856 12.998 23.583 L 12.998 23.583 L 12.998 23.583 Q 12.3 23.31 11.763 22.787 L 11.763 22.787 L 11.763 22.787 Q 11.226 22.265 10.903 21.474 L 10.903 21.474 L 10.903 21.474 Q 10.581 20.683 10.581 19.579 L 10.581 19.579 L 12.388 19.579 L 12.388 19.579 Q 12.388 20.399 12.632 20.941 L 12.632 20.941 L 12.632 20.941 Q 12.876 21.483 13.262 21.806 L 13.262 21.806 L 13.262 21.806 Q 13.647 22.128 14.136 22.265 L 14.136 22.265 L 14.136 22.265 Q 14.624 22.401 15.122 22.401 L 15.122 22.401 L 15.122 22.401 Q 15.757 22.401 16.265 22.245 L 16.265 22.245 L 16.265 22.245 Q 16.772 22.089 17.124 21.791 L 17.124 21.791 L 17.124 21.791 Q 17.476 21.493 17.666 21.068 L 17.666 21.068 L 17.666 21.068 Q 17.856 20.644 17.856 20.106 Z "></path>
</g>
</svg>`;
}
6 changes: 6 additions & 0 deletions src/ts/icon-sets/windows-icon-set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,10 @@ export class WindowsIconSet implements IconSet {
<path d="M 19.71875 5.28125 L 18.28125 6.71875 L 24.5625 13 L 11 13 C 7.144531 13 4 16.144531 4 20 C 4 23.855469 7.144531 27 11 27 L 11 25 C 8.226563 25 6 22.773438 6 20 C 6 17.226563 8.226563 15 11 15 L 24.5625 15 L 18.28125 21.28125 L 19.71875 22.71875 L 27.71875 14.71875 L 28.40625 14 L 27.71875 13.28125 Z "></path>
</g>
</svg>`;

public variableIcon = `<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 32 32" version="1.1">
<g id="surface1">
<path d=" M 17.856 20.106 L 17.856 20.106 L 17.856 20.106 Q 17.866 19.218 17.207 18.583 L 17.207 18.583 L 17.207 18.583 Q 16.548 17.948 15.112 17.479 L 15.112 17.479 L 15.112 17.479 Q 14.204 17.196 13.472 16.825 L 13.472 16.825 L 13.472 16.825 Q 12.739 16.454 12.217 15.941 L 12.217 15.941 L 12.217 15.941 Q 11.694 15.429 11.411 14.765 L 11.411 14.765 L 11.411 14.765 Q 11.128 14.101 11.128 13.231 L 11.128 13.231 L 11.128 13.231 Q 11.128 12.411 11.377 11.747 L 11.377 11.747 L 11.377 11.747 Q 11.626 11.083 12.08 10.59 L 12.08 10.59 L 12.08 10.59 Q 12.534 10.097 13.184 9.794 L 13.184 9.794 L 13.184 9.794 Q 13.833 9.491 14.624 9.394 L 14.624 9.394 L 14.624 7.245 L 16.079 7.245 L 16.079 9.394 L 16.079 9.394 Q 17.72 9.618 18.628 10.775 L 18.628 10.775 L 18.628 10.775 Q 19.536 11.933 19.546 13.925 L 19.546 13.925 L 17.749 13.925 L 17.749 13.925 Q 17.749 13.271 17.588 12.719 L 17.588 12.719 L 17.588 12.719 Q 17.427 12.167 17.119 11.771 L 17.119 11.771 L 17.119 11.771 Q 16.812 11.376 16.362 11.151 L 16.362 11.151 L 16.362 11.151 Q 15.913 10.927 15.337 10.927 L 15.337 10.927 L 15.337 10.927 Q 14.155 10.927 13.55 11.542 L 13.55 11.542 L 13.55 11.542 Q 12.944 12.157 12.935 13.202 L 12.935 13.202 L 12.935 13.202 Q 12.935 13.69 13.091 14.071 L 13.091 14.071 L 13.091 14.071 Q 13.247 14.452 13.584 14.765 L 13.584 14.765 L 13.584 14.765 Q 13.921 15.077 14.453 15.346 L 14.453 15.346 L 14.453 15.346 Q 14.985 15.614 15.737 15.868 L 15.737 15.868 L 15.737 15.868 Q 16.655 16.171 17.388 16.542 L 17.388 16.542 L 17.388 16.542 Q 18.12 16.913 18.628 17.411 L 18.628 17.411 L 18.628 17.411 Q 19.136 17.909 19.404 18.563 L 19.404 18.563 L 19.404 18.563 Q 19.673 19.218 19.673 20.087 L 19.673 20.087 L 19.673 20.087 Q 19.673 20.937 19.404 21.61 L 19.404 21.61 L 19.404 21.61 Q 19.136 22.284 18.647 22.768 L 18.647 22.768 L 18.647 22.768 Q 18.159 23.251 17.461 23.544 L 17.461 23.544 L 17.461 23.544 Q 16.763 23.837 15.913 23.925 L 15.913 23.925 L 15.913 25.8 L 14.458 25.8 L 14.458 23.935 L 14.458 23.935 Q 13.696 23.856 12.998 23.583 L 12.998 23.583 L 12.998 23.583 Q 12.3 23.31 11.763 22.787 L 11.763 22.787 L 11.763 22.787 Q 11.226 22.265 10.903 21.474 L 10.903 21.474 L 10.903 21.474 Q 10.581 20.683 10.581 19.579 L 10.581 19.579 L 12.388 19.579 L 12.388 19.579 Q 12.388 20.399 12.632 20.941 L 12.632 20.941 L 12.632 20.941 Q 12.876 21.483 13.262 21.806 L 13.262 21.806 L 13.262 21.806 Q 13.647 22.128 14.136 22.265 L 14.136 22.265 L 14.136 22.265 Q 14.624 22.401 15.122 22.401 L 15.122 22.401 L 15.122 22.401 Q 15.757 22.401 16.265 22.245 L 16.265 22.245 L 16.265 22.245 Q 16.772 22.089 17.124 21.791 L 17.124 21.791 L 17.124 21.791 Q 17.476 21.493 17.666 21.068 L 17.666 21.068 L 17.666 21.068 Q 17.856 20.644 17.856 20.106 Z "></path>
</g>
</svg>`;
}
6 changes: 6 additions & 0 deletions src/ts/input-validator-searcher-combination-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import { WebUrlInputValidator } from "./input-validators/web-url-input-validator
import { SearchPluginsSearcher } from "./searcher/search-plugins-searcher";
import { SearchPluginsInputValidator } from "./input-validators/search-plugins-input-validator";
import { InputValidatorSearcherCombination } from "./input-validator-searcher-combination";
import { VariableSearcher } from "./searcher/variable-searcher";
import { VariableInputValidator } from "./input-validators/variable-input-validator";
import { defaultConfig } from "./default-config";
import { UeliHelpers } from "./helpers/ueli-helpers";
import { ConfigOptions } from "./config-options";
Expand All @@ -34,6 +36,10 @@ export class InputValidatorSearcherCombinationManager {
searcher: new FilePathSearcher(config),
validator: new FilePathInputValidator(),
},
{
searcher: new VariableSearcher(config, new FilePathInputValidator(), process.env),
validator: new VariableInputValidator(),
},
{
searcher: new CommandLineSearcher(),
validator: new CommandLineInputValidator(),
Expand Down
10 changes: 10 additions & 0 deletions src/ts/input-validators/variable-input-validator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Injector } from "../injector";
import { InputValidator } from "./input-validator";
import { platform } from "os";

export class VariableInputValidator implements InputValidator {
public readonly variablePrefix = "$";
public isValidForSearchResults(userInput: string): boolean {
return userInput.startsWith(this.variablePrefix);
}
}
1 change: 1 addition & 0 deletions src/ts/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { ConfigFileRepository } from "./config-file-repository";
import { CountManager } from "./count-manager";
import { CountFileRepository } from "./count-file-repository";
import { ProductionIpcEmitter } from "./production-ipc-emitter";
import { VariableInputValidator } from "./input-validators/variable-input-validator";

let mainWindow: BrowserWindow;
let trayIcon: Tray;
Expand Down
46 changes: 46 additions & 0 deletions src/ts/searcher/variable-searcher.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { Searcher } from "./searcher";
import { ConfigOptions } from "../config-options";
import { Injector } from "../injector";
import { FilePathInputValidator } from "../input-validators/file-path-input-validator";
import { SearchEngine } from "../search-engine";
import { SearchResultItem } from "../search-result-item";
import { homedir, platform } from "os";

export class VariableSearcher implements Searcher {
private config: ConfigOptions;
private collection: SearchResultItem[];

constructor(config: ConfigOptions, pathValidator: FilePathInputValidator, environmentVariables: { [key: string]: string }) {
this.config = config;
this.collection = [];

const validator = pathValidator;
const icon = Injector.getIconSet(platform()).variableIcon;
for (const variableName of Object.keys(environmentVariables)) {
const value = environmentVariables[variableName];
if (validator.isValidForSearchResults(value)) {
this.collection.push({
executionArgument: value,
icon,
name: `${variableName}`,
tags: [],
});
}
}

const customVariable = this.config.directoryVariables;
customVariable.forEach((variable) => {
this.collection.push({
executionArgument: variable.path,
icon,
name: `${variable.name}`,
tags: [],
});
});
}

public getSearchResult(userInput: string): SearchResultItem[] {
const searchEngine = new SearchEngine(this.collection, this.config.searchEngineThreshold);
return searchEngine.search(userInput);
}
}
4 changes: 4 additions & 0 deletions src/ts/variable.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export class Variable {
public name: string;
public path: string;
}

0 comments on commit a981556

Please sign in to comment.