mirror of
https://github.com/stablyai/orca.git
synced 2026-11-16 10:58:10 +00:00
Adds a Custom… option to the App Icon switcher. The picked PNG/JPEG is header-checked before decoding (square, 64–2048 px, ≤10 MB), re-encoded as PNG into userData, and applied to the macOS Dock and every window icon. It persists across restarts and can be removed, which resets to Classic. Closes #13316
42 lines
1.3 KiB
TypeScript
42 lines
1.3 KiB
TypeScript
export const APP_ICON_OPTIONS = [
|
|
{ id: 'classic', label: 'Classic Orca' },
|
|
{ id: 'watercolor', label: 'Watercolor Orca' },
|
|
{ id: 'blue', label: 'Blue Orca' }
|
|
] as const
|
|
|
|
export type BuiltInAppIconId = (typeof APP_ICON_OPTIONS)[number]['id']
|
|
|
|
// Why one id, not a stored path: the imported image always lives at a fixed userData location.
|
|
export const CUSTOM_APP_ICON_ID = 'custom'
|
|
|
|
export type AppIconId = BuiltInAppIconId | typeof CUSTOM_APP_ICON_ID
|
|
|
|
export const DEFAULT_APP_ICON_ID: BuiltInAppIconId = 'classic'
|
|
|
|
function isAppIconId(value: unknown): value is AppIconId {
|
|
return value === CUSTOM_APP_ICON_ID || APP_ICON_OPTIONS.some((option) => option.id === value)
|
|
}
|
|
|
|
export function normalizeAppIconId(value: unknown): AppIconId {
|
|
return isAppIconId(value) ? value : DEFAULT_APP_ICON_ID
|
|
}
|
|
|
|
export const CUSTOM_APP_ICON_MAX_BYTES = 10 * 1024 * 1024
|
|
export const CUSTOM_APP_ICON_MIN_SIDE = 64
|
|
// Why 2048: decoding runs on the main process, and the stored copy is downscaled to 1024 anyway.
|
|
export const CUSTOM_APP_ICON_MAX_SIDE = 2048
|
|
|
|
export type CustomAppIconImportFailureCode =
|
|
| 'unsupportedFormat'
|
|
| 'unreadable'
|
|
| 'tooLarge'
|
|
| 'notSquare'
|
|
| 'tooSmall'
|
|
| 'tooBig'
|
|
| 'undecodable'
|
|
| 'saveFailed'
|
|
|
|
export type CustomAppIconImportResult =
|
|
| { ok: true; previewDataUrl: string }
|
|
| { ok: false; code: CustomAppIconImportFailureCode }
|