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.
Add operating system specific ap icon
- Loading branch information
1 parent
db4cde8
commit faa30ed
Showing
8 changed files
with
99 additions
and
0 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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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,60 @@ | ||
import type { AssetPathResolver } from "@Core/AssetPathResolver"; | ||
import type { NativeTheme } from "electron"; | ||
import { describe, expect, it, vi } from "vitest"; | ||
import { getAppIconFilePath } from "./getAppIconFilePath"; | ||
|
||
describe(getAppIconFilePath, () => { | ||
it("it should return the correct app icon file path on Windows' dark theme", () => { | ||
const getModuleAssetPathMock = vi.fn().mockReturnValue("windows-dark-theme-icon.png"); | ||
const assetPathResolver = <AssetPathResolver>{ getModuleAssetPath: (m, a) => getModuleAssetPathMock(m, a) }; | ||
const nativeTheme = <NativeTheme>{ shouldUseDarkColors: true }; | ||
|
||
expect(getAppIconFilePath(nativeTheme, assetPathResolver, "Windows")).toBe("windows-dark-theme-icon.png"); | ||
expect(getModuleAssetPathMock).toHaveBeenCalledWith("BrowserWindow", "app-icon-dark-transparent.png"); | ||
}); | ||
|
||
it("it should return the correct app icon file path on Windows' light theme", () => { | ||
const getModuleAssetPathMock = vi.fn().mockReturnValue("windows-light-theme-icon.png"); | ||
const assetPathResolver = <AssetPathResolver>{ getModuleAssetPath: (m, a) => getModuleAssetPathMock(m, a) }; | ||
const nativeTheme = <NativeTheme>{ shouldUseDarkColors: false }; | ||
|
||
expect(getAppIconFilePath(nativeTheme, assetPathResolver, "Windows")).toBe("windows-light-theme-icon.png"); | ||
expect(getModuleAssetPathMock).toHaveBeenCalledWith("BrowserWindow", "app-icon-light-transparent.png"); | ||
}); | ||
|
||
it("it should return the correct app icon file path on macOS' dark theme", () => { | ||
const getModuleAssetPathMock = vi.fn().mockReturnValue("macos-dark-theme-icon.png"); | ||
const assetPathResolver = <AssetPathResolver>{ getModuleAssetPath: (m, a) => getModuleAssetPathMock(m, a) }; | ||
const nativeTheme = <NativeTheme>{ shouldUseDarkColors: true }; | ||
|
||
expect(getAppIconFilePath(nativeTheme, assetPathResolver, "macOS")).toBe("macos-dark-theme-icon.png"); | ||
expect(getModuleAssetPathMock).toHaveBeenCalledWith("BrowserWindow", "app-icon-dark.png"); | ||
}); | ||
|
||
it("it should return the correct app icon file path on macOS' light theme", () => { | ||
const getModuleAssetPathMock = vi.fn().mockReturnValue("macos-light-theme-icon.png"); | ||
const assetPathResolver = <AssetPathResolver>{ getModuleAssetPath: (m, a) => getModuleAssetPathMock(m, a) }; | ||
const nativeTheme = <NativeTheme>{ shouldUseDarkColors: false }; | ||
|
||
expect(getAppIconFilePath(nativeTheme, assetPathResolver, "macOS")).toBe("macos-light-theme-icon.png"); | ||
expect(getModuleAssetPathMock).toHaveBeenCalledWith("BrowserWindow", "app-icon-light.png"); | ||
}); | ||
|
||
it("it should return the correct app icon file path on Linux' dark theme", () => { | ||
const getModuleAssetPathMock = vi.fn().mockReturnValue("linux-dark-theme-icon.png"); | ||
const assetPathResolver = <AssetPathResolver>{ getModuleAssetPath: (m, a) => getModuleAssetPathMock(m, a) }; | ||
const nativeTheme = <NativeTheme>{ shouldUseDarkColors: true }; | ||
|
||
expect(getAppIconFilePath(nativeTheme, assetPathResolver, "macOS")).toBe("linux-dark-theme-icon.png"); | ||
expect(getModuleAssetPathMock).toHaveBeenCalledWith("BrowserWindow", "app-icon-dark.png"); | ||
}); | ||
|
||
it("it should return the correct app icon file path on Linux' light theme", () => { | ||
const getModuleAssetPathMock = vi.fn().mockReturnValue("linux-light-theme-icon.png"); | ||
const assetPathResolver = <AssetPathResolver>{ getModuleAssetPath: (m, a) => getModuleAssetPathMock(m, a) }; | ||
const nativeTheme = <NativeTheme>{ shouldUseDarkColors: false }; | ||
|
||
expect(getAppIconFilePath(nativeTheme, assetPathResolver, "macOS")).toBe("linux-light-theme-icon.png"); | ||
expect(getModuleAssetPathMock).toHaveBeenCalledWith("BrowserWindow", "app-icon-light.png"); | ||
}); | ||
}); |
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,21 @@ | ||
import type { AssetPathResolver } from "@Core/AssetPathResolver"; | ||
import type { OperatingSystem } from "@common/Core"; | ||
import type { NativeTheme } from "electron"; | ||
|
||
export const getAppIconFilePath = ( | ||
nativeTheme: NativeTheme, | ||
assetPathResolver: AssetPathResolver, | ||
operatingSystem: OperatingSystem, | ||
): string => { | ||
const fileNames: Record<OperatingSystem, { dark: string; light: string }> = { | ||
Linux: { dark: "app-icon-dark.png", light: "app-icon-light.png" }, | ||
macOS: { dark: "app-icon-dark.png", light: "app-icon-light.png" }, | ||
Windows: { dark: "app-icon-dark-transparent.png", light: "app-icon-light-transparent.png" }, | ||
}; | ||
|
||
const filename = nativeTheme.shouldUseDarkColors | ||
? fileNames[operatingSystem].dark | ||
: fileNames[operatingSystem].light; | ||
|
||
return assetPathResolver.getModuleAssetPath("BrowserWindow", filename); | ||
}; |