Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(tray): add support for tray icon themes #2809

Open
wants to merge 34 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
8392b07
refactor(assets): update tray icons
yilmazcabuk Dec 30, 2024
10743b3
refactor: update tray icon
yilmazcabuk Dec 30, 2024
0111eaf
refactor(tray): improve tray setup and icon handling
yilmazcabuk Dec 30, 2024
86fc1a9
Merge branch 'th-ch:master' into master
yilmazcabuk Dec 31, 2024
082ebcc
feat(tray): add support for tray icon themes
yilmazcabuk Dec 31, 2024
1a9372f
Merge remote-tracking branch 'origin/master'
yilmazcabuk Dec 31, 2024
da71433
refactor(tray): update tray tooltip to use SongInfo type
yilmazcabuk Dec 31, 2024
4f7ffe9
Merge branch 'th-ch:master' into master
yilmazcabuk Dec 31, 2024
b0af7fc
refactor(tray): streamline tray icon management
yilmazcabuk Jan 1, 2025
25a2787
refactor(tray): improve handling and encapsulate logic
yilmazcabuk Jan 1, 2025
594abd1
Merge branch 'th-ch:master' into master
yilmazcabuk Jan 1, 2025
7a1260e
Merge branch 'th-ch:master' into master
yilmazcabuk Jan 2, 2025
781a49a
refactor(tray): simplify tray icon and menu setup
yilmazcabuk Jan 2, 2025
bfb9bfd
Merge branch 'th-ch:master' into master
yilmazcabuk Jan 3, 2025
437d805
fix(tray): standardize setUpTray argument structure
yilmazcabuk Jan 3, 2025
d6ba730
Merge remote-tracking branch 'origin/master'
yilmazcabuk Jan 3, 2025
3f6efc5
fix(tray): correct tooltip update logic
yilmazcabuk Jan 3, 2025
ab0440f
Merge branch 'th-ch:master' into master
yilmazcabuk Jan 4, 2025
c9f1d1c
Merge branch 'th-ch:master' into master
yilmazcabuk Jan 5, 2025
fcdca3a
Merge branch 'th-ch:master' into master
yilmazcabuk Jan 8, 2025
f0c579c
Merge branch 'th-ch:master' into master
yilmazcabuk Jan 9, 2025
8c0db3f
Merge branch 'th-ch:master' into master
yilmazcabuk Jan 10, 2025
0c8c732
Merge branch 'th-ch:master' into master
yilmazcabuk Jan 12, 2025
581e01c
Merge branch 'th-ch:master' into master
yilmazcabuk Jan 17, 2025
e1a864d
Merge branch 'th-ch:master' into master
yilmazcabuk Jan 18, 2025
585f074
Merge branch 'th-ch:master' into master
yilmazcabuk Jan 19, 2025
f645577
Merge branch 'th-ch:master' into master
yilmazcabuk Jan 19, 2025
f286024
Merge branch 'th-ch:master' into master
yilmazcabuk Jan 23, 2025
8ecc5be
Merge branch 'th-ch:master' into master
yilmazcabuk Jan 24, 2025
54e5c24
Merge branch 'th-ch:master' into master
yilmazcabuk Jan 28, 2025
7946c78
Merge branch 'th-ch:master' into master
yilmazcabuk Feb 3, 2025
b93bca6
Merge branch 'th-ch:master' into master
yilmazcabuk Feb 11, 2025
33e7c62
Merge branch 'th-ch:master' into master
yilmazcabuk Feb 16, 2025
bf98cbc
Merge branch 'th-ch:master' into master
yilmazcabuk Feb 21, 2025
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
Prev Previous commit
Next Next commit
refactor(tray): streamline tray icon management
- Added the IconSet interface to group play and pause icons.
- Replaced `createTrayIcons` with `createTrayIconSet` for better readability and maintainability.
- Adjusted functions to leverage IconSet, simplifying code and improving parameter handling.
yilmazcabuk committed Jan 1, 2025
commit b0af7fcf5bb1ce2bfe188de8bfaebe9aa8c39dbd
30 changes: 17 additions & 13 deletions src/tray.ts
Original file line number Diff line number Diff line change
@@ -24,6 +24,11 @@ import type { MenuTemplate } from './menu';
*/
let tray: Electron.Tray | undefined;

export interface IconSet {
play: Electron.NativeImage;
pause: Electron.NativeImage;
}

type TrayEvent = (
event: Electron.KeyboardEvent,
bounds: Electron.Rectangle,
@@ -59,14 +64,17 @@ const getTrayIcon = (
height: 16 * pixelRatio,
});

const createTrayIcons = (theme: TrayIconTheme, pixelRatio: number) => {
export const createTrayIconSet = (
theme: TrayIconTheme,
pixelRatio: number,
): IconSet => {
const { play: playIconPath, pause: pauseIconPath } = getIcons(theme);

return {
playTrayIcon: getTrayIcon(playIconPath, pixelRatio),
pauseTrayIcon: getTrayIcon(pauseIconPath, pixelRatio),
play: getTrayIcon(playIconPath, pixelRatio),
pause: getTrayIcon(pauseIconPath, pixelRatio),
};
};

const createTrayMenu = (
playPause: () => void,
next: () => void,
@@ -108,16 +116,15 @@ const createTrayMenu = (
const updateTrayTooltip = (
trayInstance: Electron.Tray,
songInfo: SongInfo,
playTrayIcon: Electron.NativeImage,
pauseTrayIcon: Electron.NativeImage,
iconSet: IconSet,
): void => {
trayInstance.setToolTip(
t('main.tray.tooltip.with-song-info', {
artist: songInfo.artist,
title: songInfo.title,
}),
);
trayInstance.setImage(songInfo.isPaused ? playTrayIcon : pauseTrayIcon);
trayInstance.setImage(songInfo.isPaused ? iconSet.play : iconSet.pause);
};

const handleTrayClick = (
@@ -174,13 +181,10 @@ export const setUpTray = (
const pixelRatio = getPixelRatio();
const trayIconTheme =
config.get('options.trayIconTheme') || TrayIconTheme.Default;
const { playTrayIcon, pauseTrayIcon } = createTrayIcons(
trayIconTheme,
pixelRatio,
);
const iconSet = createTrayIconSet(trayIconTheme, pixelRatio);

tray?.destroy();
tray = new Tray(playTrayIcon);
tray = new Tray(iconSet.play);
setMacSpecificTraySettings(tray);

const showWindow = () => {
@@ -196,6 +200,6 @@ export const setUpTray = (

registerCallback((songInfo, event) => {
if (!tray || event === SongInfoEvent.TimeChanged) return;
updateTrayTooltip(tray, songInfo, playTrayIcon, pauseTrayIcon);
updateTrayTooltip(tray, songInfo, iconSet);
});
};