Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/buddy/electron/main/app/DesktopIntegrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ export class DesktopIntegrations {
this.#tray = createDesktopTray({
appName: paths.appName,
iconPath: trayIconPath,
profile: paths.profile,
language: runtime.language,
onOpenDesktop: () => windows.show(),
onQuit: this.#requestQuit,
Expand Down
7 changes: 5 additions & 2 deletions apps/buddy/electron/main/tray.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import type { BuddyRuntimeProfile } from '../../shared/runtime/profile'
import type { LexoraConfig } from '../shared/desktopApi'
import { Menu, nativeImage, Tray } from 'electron'
import { Menu, Tray } from 'electron'
import { translateDesktopNative } from './desktopNativeI18n'
import { createDesktopTrayImage } from './trayIcon'

export interface CreateDesktopTrayOptions {
appName: string
iconPath: string
profile: BuddyRuntimeProfile
language: LexoraConfig['desktop']['language']
onOpenDesktop: () => void
onQuit: () => void
Expand All @@ -17,7 +20,7 @@ export interface DesktopTrayController {
}

export function createDesktopTray(options: CreateDesktopTrayOptions): DesktopTrayController {
const tray = new Tray(nativeImage.createFromPath(options.iconPath))
const tray = new Tray(createDesktopTrayImage(options.iconPath, options.profile))
let language = options.language

const rebuildMenu = () => {
Expand Down
31 changes: 31 additions & 0 deletions apps/buddy/electron/main/trayIcon.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import type { NativeImage } from 'electron'
import type { BuddyRuntimeProfile } from '../../shared/runtime/profile'
import { readFileSync } from 'node:fs'
import process from 'node:process'
import { nativeImage } from 'electron'
import developmentTray from '../../resources/icons/macos/tray-icon-dev.png?asset'
import developmentTray2x from '../../resources/icons/macos/tray-icon-dev@2x.png?asset'
import testTray from '../../resources/icons/macos/tray-icon-test.png?asset'
import testTray2x from '../../resources/icons/macos/tray-icon-test@2x.png?asset'
import stableTray from '../../resources/icons/macos/tray-icon.png?asset'
import stableTray2x from '../../resources/icons/macos/tray-icon@2x.png?asset'

const macosTrayIcons: Record<BuddyRuntimeProfile, readonly [string, string]> = {
stable: [stableTray, stableTray2x],
development: [developmentTray, developmentTray2x],
test: [testTray, testTray2x],
}

export function createDesktopTrayImage(iconPath: string, profile: BuddyRuntimeProfile): NativeImage {
if (process.platform !== 'darwin')
return nativeImage.createFromPath(iconPath)

const image = nativeImage.createEmpty()
for (const [index, path] of macosTrayIcons[profile].entries()) {
image.addRepresentation({
scaleFactor: index + 1,
dataURL: `data:image/png;base64,${readFileSync(path).toString('base64')}`,
})
}
return image
}
Binary file added apps/buddy/resources/icons/macos/tray-icon-dev.png
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.
Binary file added apps/buddy/resources/icons/macos/tray-icon-test.png
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.
Binary file added apps/buddy/resources/icons/macos/tray-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added apps/buddy/resources/icons/macos/tray-icon@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading