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.
feat(SystemSettings): Added Windows support
- Loading branch information
1 parent
1d08a3a
commit 85d5b04
Showing
10 changed files
with
99 additions
and
13 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
3 changes: 2 additions & 1 deletion
3
src/main/Extensions/SystemSettings/MacOsSystemSettingRepository.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
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,5 @@ | ||
import type { SearchResultItem } from "@common/Core"; | ||
|
||
export interface SystemSetting { | ||
toSearchResultItem(): SearchResultItem; | ||
} |
5 changes: 5 additions & 0 deletions
5
src/main/Extensions/SystemSettings/SystemSettingRepository.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,5 @@ | ||
import type { SystemSetting } from "./SystemSetting"; | ||
|
||
export interface SystemSettingRepository { | ||
getAll(): SystemSetting[]; | ||
} |
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
18 changes: 13 additions & 5 deletions
18
src/main/Extensions/SystemSettings/SystemSettingsModule.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,21 +1,29 @@ | ||
import type { Dependencies } from "@Core/Dependencies"; | ||
import type { DependencyRegistry } from "@Core/DependencyRegistry"; | ||
import type { OperatingSystem } from "@common/Core"; | ||
import type { ExtensionBootstrapResult } from "../ExtensionBootstrapResult"; | ||
import type { ExtensionModule } from "../ExtensionModule"; | ||
import { MacOsSystemSettingRepository } from "./MacOsSystemSettingRepository"; | ||
import type { SystemSettingRepository } from "./SystemSettingRepository"; | ||
import { SystemSettingsExtension } from "./SystemSettingsExtension"; | ||
import { WindowsSystemSettingsRepository } from "./WindowsSystemRepository"; | ||
import { WindowsSystemSettingActionHandler } from "./WindowsSystemSettingActionHandler"; | ||
|
||
export class SystemSettingsModule implements ExtensionModule { | ||
public bootstrap(dependencyRegistry: DependencyRegistry<Dependencies>): ExtensionBootstrapResult { | ||
const operatingSystem = dependencyRegistry.get("OperatingSystem"); | ||
const assetPathResolver = dependencyRegistry.get("AssetPathResolver"); | ||
const systemSettingRepositories: Record<OperatingSystem, SystemSettingRepository> = { | ||
Linux: null, // not supported | ||
macOS: new MacOsSystemSettingRepository(dependencyRegistry.get("AssetPathResolver")), | ||
Windows: new WindowsSystemSettingsRepository(dependencyRegistry.get("AssetPathResolver")), | ||
}; | ||
|
||
return { | ||
extension: new SystemSettingsExtension( | ||
operatingSystem, | ||
new MacOsSystemSettingRepository(assetPathResolver), | ||
assetPathResolver, | ||
dependencyRegistry.get("OperatingSystem"), | ||
systemSettingRepositories[dependencyRegistry.get("OperatingSystem")], | ||
dependencyRegistry.get("AssetPathResolver"), | ||
), | ||
actionHandlers: [new WindowsSystemSettingActionHandler(dependencyRegistry.get("PowershellUtility"))], | ||
}; | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/Extensions/SystemSettings/WindowsSystemRepository.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,16 @@ | ||
import type { AssetPathResolver } from "@Core/AssetPathResolver"; | ||
import type { SystemSetting } from "./SystemSetting"; | ||
import type { SystemSettingRepository } from "./SystemSettingRepository"; | ||
import { WindowsSystemSetting } from "./WindowsSystemSetting"; | ||
|
||
export class WindowsSystemSettingsRepository implements SystemSettingRepository { | ||
public constructor(private readonly assetPathResolver: AssetPathResolver) {} | ||
|
||
public getAll(): SystemSetting[] { | ||
return [new WindowsSystemSetting("System Settings", "ms-settings:", this.getGenericImageFilePath())]; | ||
} | ||
|
||
private getGenericImageFilePath(): string { | ||
return this.assetPathResolver.getExtensionAssetPath("SystemSettings", "windows-11-settings.png"); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/main/Extensions/SystemSettings/WindowsSystemSetting.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,31 @@ | ||
import { type SearchResultItem } from "@common/Core"; | ||
import type { SystemSetting } from "./SystemSetting"; | ||
|
||
export class WindowsSystemSetting implements SystemSetting { | ||
public constructor( | ||
private readonly name: string, | ||
private readonly settingsUrl: string, | ||
private readonly imageFilePath: string, | ||
) {} | ||
|
||
public toSearchResultItem(): SearchResultItem { | ||
return { | ||
defaultAction: { | ||
argument: this.settingsUrl, | ||
description: "Open System Settings", | ||
handlerId: "WindowsSystemSetting", | ||
hideWindowAfterInvocation: true, | ||
}, | ||
description: "System Setting", | ||
id: this.getId(), | ||
image: { | ||
url: `file://${this.imageFilePath}`, | ||
}, | ||
name: this.name, | ||
}; | ||
} | ||
|
||
private getId(): string { | ||
return `WindowsSystemSetting:${this.name}`; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/Extensions/SystemSettings/WindowsSystemSettingActionHandler.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,13 @@ | ||
import type { ActionHandler } from "@Core/ActionHandler"; | ||
import type { PowershellUtility } from "@Core/PowershellUtility"; | ||
import type { SearchResultItemAction } from "@common/Core"; | ||
|
||
export class WindowsSystemSettingActionHandler implements ActionHandler { | ||
public readonly id = "WindowsSystemSetting"; | ||
|
||
public constructor(private readonly powershellUtility: PowershellUtility) {} | ||
|
||
public async invokeAction({ argument }: SearchResultItemAction): Promise<void> { | ||
await this.powershellUtility.executeCommand(`Start-Process "${argument}"`); | ||
} | ||
} |