fix music widget yessssssssssssss

This commit is contained in:
end-4
2024-02-07 09:56:32 +07:00
parent b2dffd1815
commit f3e870d3d4
2 changed files with 65 additions and 19 deletions
+2 -2
View File
@@ -1,7 +1,7 @@
import Widget from 'resource:///com/github/Aylur/ags/widget.js'; import Widget from 'resource:///com/github/Aylur/ags/widget.js';
import Indicator from '../../services/indicator.js'; import Indicator from '../../services/indicator.js';
import IndicatorValues from './indicatorvalues.js'; import IndicatorValues from './indicatorvalues.js';
// import MusicControls from './musiccontrols.js'; import MusicControls from './musiccontrols.js';
import ColorScheme from './colorscheme.js'; import ColorScheme from './colorscheme.js';
import NotificationPopups from './notificationpopups.js'; import NotificationPopups from './notificationpopups.js';
@@ -23,7 +23,7 @@ export default (monitor = 0) => Widget.Window({
css: 'min-height: 2px;', css: 'min-height: 2px;',
children: [ children: [
IndicatorValues(), IndicatorValues(),
// MusicControls(), MusicControls(),
NotificationPopups(), NotificationPopups(),
ColorScheme(), ColorScheme(),
] ]
+63 -17
View File
@@ -27,8 +27,8 @@ var lastCoverPath = '';
function isRealPlayer(player) { function isRealPlayer(player) {
return ( return (
!player.busName.startsWith('org.mpris.MediaPlayer2.firefox') && !player.busName.startsWith('org.mpris.MediaPlayer2.firefox') && // Firefox mpris dbus is useless
!player.busName.startsWith('org.mpris.MediaPlayer2.playerctld') !player.busName.startsWith('org.mpris.MediaPlayer2.playerctld') // Doesn't have cover art
); );
} }
@@ -69,7 +69,7 @@ function getTrackfont(player) {
return DEFAULT_MUSIC_FONT; return DEFAULT_MUSIC_FONT;
} }
function trimTrackTitle(title) { function trimTrackTitle(title) {
if(!title) return ''; if (!title) return '';
const cleanRegexes = [ const cleanRegexes = [
/【[^】]*】/, // Touhou n weeb stuff /【[^】]*】/, // Touhou n weeb stuff
/\[FREE DOWNLOAD\]/, // F-777 /\[FREE DOWNLOAD\]/, // F-777
@@ -140,6 +140,7 @@ const CoverArt = ({ player, ...rest }) => Box({
attribute: { attribute: {
'updateCover': (self) => { 'updateCover': (self) => {
const player = Mpris.getPlayer(); const player = Mpris.getPlayer();
console.log('cover!');
// Player closed // Player closed
// Note that cover path still remains, so we're checking title // Note that cover path still remains, so we're checking title
@@ -152,13 +153,13 @@ const CoverArt = ({ player, ...rest }) => Box({
const coverPath = player.coverPath; const coverPath = player.coverPath;
const stylePath = `${player.coverPath}${lightDark}${COVER_COLORSCHEME_SUFFIX}`; const stylePath = `${player.coverPath}${lightDark}${COVER_COLORSCHEME_SUFFIX}`;
if (player.coverPath == lastCoverPath) { // Since 'notify::cover-path' emits on cover download complete if (player.coverPath == lastCoverPath) { // Since 'notify::cover-path' emits on cover download complete
self.css = `background-image: url('${coverPath}');`; Utils.timeout(200, () => { self.css = `background-image: url('${coverPath}');`; });
} }
lastCoverPath = player.coverPath; lastCoverPath = player.coverPath;
// If a colorscheme has already been generated, skip generation // If a colorscheme has already been generated, skip generation
if (fileExists(stylePath)) { if (fileExists(stylePath)) {
self.css = `background-image: url('${coverPath}');`; Utils.timeout(200, () => { self.css = `background-image: url('${coverPath}');`; });
App.applyCss(stylePath); App.applyCss(stylePath);
return; return;
} }
@@ -177,9 +178,11 @@ const CoverArt = ({ player, ...rest }) => Box({
}, },
}, },
className: 'osd-music-cover-art', className: 'osd-music-cover-art',
$: [ setup: (self) => self
[player, (self) => self.attribute.updateCover(self), 'notify::cover-path'] .hook(player, (self) => {
], self.attribute.updateCover(self);
}, 'notify::cover-path')
,
}) })
] ]
}) })
@@ -215,7 +218,7 @@ const TrackControls = ({ player, ...rest }) => Widget.Revealer({
}), }),
], ],
}), }),
setup: (self) => szelf.hook(Mpris, (self) => { setup: (self) => self.hook(Mpris, (self) => {
const player = Mpris.getPlayer(); const player = Mpris.getPlayer();
if (!player) if (!player)
self.revealChild = false; self.revealChild = false;
@@ -313,7 +316,7 @@ const PlayState = ({ player }) => {
} }
const MusicControlsWidget = (player) => Box({ const MusicControlsWidget = (player) => Box({
className: 'osd-music spacing-h-20', className: 'osd-music spacing-h-20 test',
children: [ children: [
CoverArt({ player: player, vpack: 'center' }), CoverArt({ player: player, vpack: 'center' }),
Box({ Box({
@@ -344,23 +347,28 @@ const MusicControlsWidget = (player) => Box({
] ]
}) })
export default () => MarginRevealer({ export default () => Revealer({
transition: 'slide_down', transition: 'slide_down',
transitionDuration: 150,
revealChild: false, revealChild: false,
showClass: 'osd-show',
hideClass: 'osd-hide',
child: Box({ child: Box({
setup: (self) => self.hook(Mpris, box => { setup: (self) => self.hook(Mpris, box => {
let foundPlayer = false; let foundPlayer = false;
Mpris.players.forEach((player, i) => { Mpris.players.forEach((player, i) => {
if (isRealPlayer(player)) { if (isRealPlayer(player)) {
console.log('Found player', player);
foundPlayer = true; foundPlayer = true;
box.children = [MusicControlsWidget(player)]; box.children.forEach(child => {
child.destroy();
child = null;
});
const newInstance = MusicControlsWidget(player);
box.children = [newInstance];
} }
}); });
if (!foundPlayer) { if (!foundPlayer) {
console.log('No players found');
const children = box.get_children(); const children = box.get_children();
for (let i = 0; i < children.length; i++) { for (let i = 0; i < children.length; i++) {
const child = children[i]; const child = children[i];
@@ -372,7 +380,45 @@ export default () => MarginRevealer({
}, 'notify::players'), }, 'notify::players'),
}), }),
setup: (self) => self.hook(showMusicControls, (revealer) => { setup: (self) => self.hook(showMusicControls, (revealer) => {
if (showMusicControls.value) revealer.attribute.show(); revealer.revealChild = showMusicControls.value;
else revealer.attribute.hide();
}), }),
}) })
// export default () => MarginRevealer({
// transition: 'slide_down',
// revealChild: false,
// showClass: 'osd-show',
// hideClass: 'osd-hide',
// child: Box({
// setup: (self) => self.hook(Mpris, box => {
// let foundPlayer = false;
// Mpris.players.forEach((player, i) => {
// if (isRealPlayer(player)) {
// console.log('Found player', player);
// foundPlayer = true;
// box.children.forEach(child => {
// child.destroy();
// child = null;
// });
// const newInstance = MusicControlsWidget(player);
// box.children = [newInstance];
// }
// });
// if (!foundPlayer) {
// console.log('No players found');
// const children = box.get_children();
// for (let i = 0; i < children.length; i++) {
// const child = children[i];
// child.destroy();
// child = null;
// }
// return;
// }
// }, 'notify::players'),
// }),
// setup: (self) => self.hook(showMusicControls, (revealer) => {
// if (showMusicControls.value) revealer.attribute.show();
// else revealer.attribute.hide();
// }),
// })