This repository has been archived by the owner on Dec 31, 2024. It is now read-only.
forked from oliverschwendener/ueli
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
115f27c
commit 71f28a7
Showing
18 changed files
with
232 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
import { GeneralOptions } from "./general-options"; | ||
|
||
export const defaultGeneralOptions: GeneralOptions = { | ||
maxSearchResults: 8, | ||
hotKey: "alt+space", | ||
maxSearchResults: 32, | ||
maxSearchResultsPerPage: 8, | ||
refreshIntervalInSeconds: 60, | ||
searchResultHeight: 40, | ||
searchResultHeight: 50, | ||
userInputHeight: 60, | ||
windowWidth: 600, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
export interface GeneralOptions { | ||
windowWidth: number; | ||
maxSearchResults: number; | ||
maxSearchResultsPerPage: number; | ||
refreshIntervalInSeconds: number; | ||
searchResultHeight: number; | ||
userInputHeight: number; | ||
hotKey: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
import { PluginType } from "../main/plugin-type"; | ||
|
||
export interface SearchResultItem { | ||
executionArgument: string; | ||
icon: string; | ||
name: string; | ||
originPluginType: PluginType; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export enum PluginType { | ||
ApplicationSearchPlugin = "application-search-plugin", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
import { SearchResultItem } from "../common/search-result-item"; | ||
import { PluginType } from "./plugin-type"; | ||
|
||
export interface SearchPlugin { | ||
pluginType: PluginType; | ||
getAll(): Promise<SearchResultItem[]>; | ||
execute(searchResultItem: SearchResultItem): Promise<void>; | ||
refreshIndex(): Promise<void>; | ||
clearCache(): Promise<void>; | ||
} |
32 changes: 32 additions & 0 deletions
32
src/main/search-plugins/application-search-plugin/application-execution.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { SearchResultItem } from "../../../common/search-result-item"; | ||
import { exec } from "child_process"; | ||
|
||
const executeCommand = (command: string): Promise<void> => { | ||
return new Promise((resolve, reject) => { | ||
exec(command, (err): void => { | ||
if (err) { | ||
reject(err); | ||
} else { | ||
resolve(); | ||
} | ||
}); | ||
}); | ||
}; | ||
|
||
export function executeMacApp(searchResultItem: SearchResultItem): Promise<void> { | ||
return new Promise((resolve, reject) => { | ||
const command = `open "${searchResultItem.executionArgument}"`; | ||
executeCommand(command) | ||
.then(() => resolve()) | ||
.catch((err) => reject(err)); | ||
}); | ||
} | ||
|
||
export function executeWindowsApp(searchResultItem: SearchResultItem): Promise<void> { | ||
return new Promise((resolve, reject) => { | ||
const command = `start "" "${searchResultItem.executionArgument}"`; | ||
executeCommand(command) | ||
.then(() => resolve()) | ||
.catch((err) => reject(err)); | ||
}); | ||
} |
55 changes: 29 additions & 26 deletions
55
src/main/search-plugins/application-search-plugin/application-search-plugin.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,57 @@ | ||
import { SearchPlugin } from "../../search-plugin"; | ||
import { SearchResultItem } from "../../../common/search-result-item"; | ||
import { ApplicationRepository } from "./application-repository"; | ||
import { PluginType } from "../../plugin-type"; | ||
import { Application } from "./application"; | ||
|
||
export class ApplicationSearchPlugin implements SearchPlugin { | ||
public readonly pluginType = PluginType.ApplicationSearchPlugin; | ||
private readonly applicationRepository: ApplicationRepository; | ||
private readonly executeApplication: (searchResultItem: SearchResultItem) => Promise<void>; | ||
|
||
constructor(applicationRepository: ApplicationRepository) { | ||
constructor(applicationRepository: ApplicationRepository, executeApplication: (searchResultItem: SearchResultItem) => Promise<void>) { | ||
this.applicationRepository = applicationRepository; | ||
this.executeApplication = executeApplication; | ||
} | ||
|
||
public getAll(): Promise<SearchResultItem[]> { | ||
return new Promise((resolve, reject) => { | ||
this.applicationRepository.getAll() | ||
.then((applications) => { | ||
const result = applications.map((application): SearchResultItem => { | ||
return { | ||
executionArgument: application.filePath, | ||
icon: application.icon, | ||
name: application.name, | ||
}; | ||
}); | ||
resolve(result); | ||
}) | ||
.catch((err) => { | ||
reject(err); | ||
}); | ||
.then((applications) => resolve(applications.map((application) => this.createSearchResultItemFromApplication(application)))) | ||
.catch((err) => reject(err)); | ||
}); | ||
} | ||
|
||
public execute(searchResultItem: SearchResultItem): Promise<void> { | ||
return new Promise((resolve, reject) => { | ||
this.executeApplication(searchResultItem) | ||
.then(() => resolve()) | ||
.catch((err) => reject(err)); | ||
}); | ||
} | ||
|
||
public refreshIndex(): Promise<void> { | ||
return new Promise((resolve, reject) => { | ||
this.applicationRepository.refreshIndex() | ||
.then(() => { | ||
resolve(); | ||
}) | ||
.catch((err) => { | ||
reject(err); | ||
}); | ||
.then(() => resolve()) | ||
.catch((err) => reject(err)); | ||
}); | ||
} | ||
|
||
public clearCache(): Promise<void> { | ||
return new Promise((resolve, reject) => { | ||
this.applicationRepository.clearCache() | ||
.then(() => { | ||
resolve(); | ||
}) | ||
.catch((err) => { | ||
reject(`Error while trying to clear application repository cache: ${err}`); | ||
}); | ||
.then(() => resolve()) | ||
.catch((err) => reject(`Error while trying to clear application repository cache: ${err}`)); | ||
}); | ||
} | ||
|
||
private createSearchResultItemFromApplication(application: Application): SearchResultItem { | ||
return { | ||
executionArgument: application.filePath, | ||
icon: application.icon, | ||
name: application.name, | ||
originPluginType: this.pluginType, | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.