ags: update to new syntax

This commit is contained in:
end-4
2024-01-11 16:50:12 +07:00
parent c61db15a88
commit 85704218e3
74 changed files with 2155 additions and 1898 deletions
@@ -1,11 +1,6 @@
const { Gio, GLib, Gtk } = imports.gi;
import { App, Service, Utils, Widget } from '../../imports.js';
const { exec, execAsync } = Utils;
import Mpris from 'resource:///com/github/Aylur/ags/service/mpris.js';
import Widget from 'resource:///com/github/Aylur/ags/widget.js';
const { Box, EventBox, Icon, Scrollable, Label, Button, Revealer } = Widget;
import { AnimatedCircProg } from "../../lib/animatedcircularprogress.js";
import { MaterialIcon } from '../../lib/materialicon.js';
import { showColorScheme } from '../../variables.js';
const ColorBox = ({
@@ -1,13 +1,12 @@
// This file is for brightness/volume indicators
const { GLib, Gtk } = imports.gi;
import { App, Service, Utils, Widget } from '../../imports.js';
import Widget from 'resource:///com/github/Aylur/ags/widget.js';
import Audio from 'resource:///com/github/Aylur/ags/service/audio.js';
const { Box, Label, ProgressBar, Revealer } = Widget;
import { MarginRevealer } from '../../lib/advancedwidgets.js';
import Brightness from '../../services/brightness.js';
import Indicator from '../../services/indicator.js';
const OsdValue = (name, labelConnections, progressConnections, props = {}) => Box({ // Volume
const OsdValue = (name, labelSetup, progressSetup, props = {}) => Box({ // Volume
...props,
vertical: true,
className: 'osd-bg osd-value',
@@ -23,8 +22,7 @@ const OsdValue = (name, labelConnections, progressConnections, props = {}) => Bo
}),
Label({
hexpand: false, className: 'osd-value-txt',
label: '100',
connections: labelConnections,
setup: labelSetup,
}),
]
}),
@@ -32,41 +30,49 @@ const OsdValue = (name, labelConnections, progressConnections, props = {}) => Bo
className: 'osd-progress',
hexpand: true,
vertical: false,
connections: progressConnections,
setup: progressSetup,
})
],
});
const brightnessIndicator = OsdValue('Brightness',
[[Brightness, self => {
self.label = `${Math.round(Brightness.screen_value * 100)}`;
}, 'notify::screen-value']],
[[Brightness, (progress) => {
const updateValue = Brightness.screen_value;
progress.value = updateValue;
}, 'notify::screen-value']],
(self) => self
.hook(Brightness, self => {
self.label = `${Math.round(Brightness.screen_value * 100)}`;
}, 'notify::screen-value')
,
(self) => self
.hook(Brightness, (progress) => {
const updateValue = Brightness.screen_value;
progress.value = updateValue;
}, 'notify::screen-value')
,
)
const volumeIndicator = OsdValue('Volume',
[[Audio, (label) => {
label.label = `${Math.round(Audio.speaker?.volume * 100)}`;
}]],
[[Audio, (progress) => {
const updateValue = Audio.speaker?.volume;
if (!isNaN(updateValue)) progress.value = updateValue;
}]],
(self) => self
.hook(Audio, (label) => {
label.label = `${Math.round(Audio.speaker?.volume * 100)}`;
})
,
(self) => self
.hook(Audio, (progress) => {
const updateValue = Audio.speaker?.volume;
if (!isNaN(updateValue)) progress.value = updateValue;
})
,
);
export default () => MarginRevealer({
transition: 'slide_down',
showClass: 'osd-show',
hideClass: 'osd-hide',
connections: [
[Indicator, (revealer, value) => {
if(value > -1) revealer._show();
else revealer._hide();
}, 'popup'],
],
extraSetup: (self) => self
.hook(Indicator, (revealer, value) => {
if (value > -1) revealer.attribute.show();
else revealer.attribute.hide();
}, 'popup')
,
child: Box({
hpack: 'center',
vertical: false,
+1 -1
View File
@@ -1,4 +1,4 @@
import { Widget } from '../../imports.js';
import Widget from 'resource:///com/github/Aylur/ags/widget.js';
import Indicator from '../../services/indicator.js';
import IndicatorValues from './indicatorvalues.js';
import MusicControls from './musiccontrols.js';
+40 -47
View File
@@ -1,5 +1,7 @@
const { Gio, GLib, Gtk } = imports.gi;
import { App, Service, Utils, Widget } from '../../imports.js';
const { Gio, GLib } = imports.gi;
import App from 'resource:///com/github/Aylur/ags/app.js';
import Widget from 'resource:///com/github/Aylur/ags/widget.js';
import * as Utils from 'resource:///com/github/Aylur/ags/utils.js';
const { exec, execAsync } = Utils;
import Mpris from 'resource:///com/github/Aylur/ags/service/mpris.js';
@@ -92,10 +94,10 @@ const TrackProgress = ({ player, ...rest }) => {
...rest,
className: 'osd-music-circprog',
vpack: 'center',
connections: [ // Update on change/once every 3 seconds
[Mpris, _updateProgress],
[3000, _updateProgress]
],
extraSetup: (self) => self
.hook(Mpris, _updateProgress)
.poll(3000, _updateProgress)
,
})
}
@@ -106,13 +108,13 @@ const TrackTitle = ({ player, ...rest }) => Label({
truncate: 'end',
// wrap: true,
className: 'osd-music-title',
connections: [[player, (self) => {
setup: (self) => self.hook(player, (self) => {
// Player name
self.label = player.trackTitle.length > 0 ? trimTrackTitle(player.trackTitle) : 'No media';
// Font based on track/artist
const fontForThisTrack = getTrackfont(player);
self.css = `font-family: ${fontForThisTrack}, ${DEFAULT_MUSIC_FONT};`;
}, 'notify::track-title']]
}, 'notify::track-title'),
});
const TrackArtists = ({ player, ...rest }) => Label({
@@ -120,9 +122,9 @@ const TrackArtists = ({ player, ...rest }) => Label({
xalign: 0,
className: 'osd-music-artists',
truncate: 'end',
connections: [[player, (self) => {
setup: (self) => self.hook(player, (self) => {
self.label = player.trackArtists.length > 0 ? player.trackArtists.join(', ') : '';
}, 'notify::track-artists']]
}, 'notify::track-artists'),
})
const CoverArt = ({ player, ...rest }) => Box({
@@ -140,8 +142,8 @@ const CoverArt = ({ player, ...rest }) => Box({
}),
overlays: [ // Real
Box({
properties: [
['updateCover', (self) => {
attribute: {
'updateCover': (self) => {
const player = Mpris.getPlayer();
// Player closed
@@ -177,11 +179,11 @@ const CoverArt = ({ player, ...rest }) => Box({
App.applyCss(`${stylePath}`);
})
.catch(print);
}],
],
},
},
className: 'osd-music-cover-art',
connections: [
[player, (self) => self._updateCover(self), 'notify::cover-path']
$: [
[player, (self) => self.attribute.updateCover(self), 'notify::cover-path']
],
})
]
@@ -218,13 +220,13 @@ const TrackControls = ({ player, ...rest }) => Widget.Revealer({
}),
],
}),
connections: [[Mpris, (self) => {
setup: (self) => szelf.hook(Mpris, (self) => {
const player = Mpris.getPlayer();
if (!player)
self.revealChild = false;
else
self.revealChild = true;
}, 'notify::play-back-status']]
}, 'notify::play-back-status'),
});
const TrackSource = ({ player, ...rest }) => Widget.Revealer({
@@ -240,19 +242,19 @@ const TrackSource = ({ player, ...rest }) => Widget.Revealer({
hpack: 'fill',
justification: 'center',
className: 'icon-nerd',
connections: [[player, (self) => {
setup: (self) => self.hook(player, (self) => {
self.label = detectMediaSource(player.trackCoverUrl);
}, 'notify::cover-path']]
}, 'notify::cover-path'),
}),
],
}),
connections: [[Mpris, (self) => {
setup: (self) => self.hook(Mpris, (self) => {
const mpris = Mpris.getPlayer('');
if (!mpris)
self.revealChild = false;
else
self.revealChild = true;
}]]
}),
});
const TrackTime = ({ player, ...rest }) => {
@@ -266,28 +268,26 @@ const TrackTime = ({ player, ...rest }) => {
className: 'osd-music-pill spacing-h-5',
children: [
Label({
connections: [[1000, (self) => {
setup: (self) => self.poll(1000, (self) => {
const player = Mpris.getPlayer();
if (!player) return;
self.label = lengthStr(player.position);
}]]
}),
}),
Label({ label: '/' }),
Label({
connections: [[Mpris, (self) => {
setup: (self) => self.hook(Mpris, (self) => {
const player = Mpris.getPlayer();
if (!player) return;
self.label = lengthStr(player.length);
}]]
}),
}),
],
}),
connections: [[Mpris, (self) => {
if (!player)
self.revealChild = false;
else
self.revealChild = true;
}]]
setup: (self) => self.hook(Mpris, (self) => {
if (!player) self.revealChild = false;
else self.revealChild = true;
}),
})
}
@@ -306,15 +306,12 @@ const PlayState = ({ player }) => {
justification: 'center',
hpack: 'fill',
vpack: 'center',
connections: [[player, (label) => {
setup: (self) => self.hook(player, (label) => {
label.label = `${player.playBackStatus == 'Playing' ? 'pause' : 'play_arrow'}`;
}, 'notify::play-back-status']],
}, 'notify::play-back-status'),
}),
}),
],
// setup: self => Utils.timeout(1, () => {
// self.set_overlay_pass_through(self.get_children()[1], true);
// }),
passThrough: true,
})
});
@@ -358,19 +355,17 @@ export default () => MarginRevealer({
showClass: 'osd-show',
hideClass: 'osd-hide',
child: Box({
connections: [[Mpris, box => {
setup: (self) => self.hook(Mpris, box => {
let foundPlayer = false;
Mpris.players.forEach((player, i) => {
if (isRealPlayer(player)) {
foundPlayer = true;
box._player = player;
box.children = [MusicControlsWidget(player)];
}
});
if (!foundPlayer) {
box._player = null;
const children = box.get_children();
for (let i = 0; i < children.length; i++) {
const child = children[i];
@@ -378,12 +373,10 @@ export default () => MarginRevealer({
}
return;
}
}, 'notify::players']],
}, 'notify::players'),
}),
setup: (self) => self.hook(showMusicControls, (revealer) => {
if (showMusicControls.value) revealer.attribute.show();
else revealer.attribute.hide();
}),
connections: [
[showMusicControls, (revealer) => {
if (showMusicControls.value) revealer._show();
else revealer._hide();
}],
],
})
@@ -1,9 +1,7 @@
// This file is for popup notifications
const { GLib, Gtk } = imports.gi;
import { App, Service, Utils, Widget } from '../../imports.js';
import Audio from 'resource:///com/github/Aylur/ags/service/audio.js';
import Widget from 'resource:///com/github/Aylur/ags/widget.js';
import Notifications from 'resource:///com/github/Aylur/ags/service/notifications.js';
const { Box, EventBox, Icon, Scrollable, Label, Button, Revealer } = Widget;
const { Box } = Widget;
import Notification from '../../lib/notification.js';
const PopupNotification = (notifObject) => Widget.Box({
@@ -39,41 +37,39 @@ const naiveNotifPopupList = Widget.Box({
const notifPopupList = Box({
vertical: true,
className: 'osd-notifs spacing-v-5-revealer',
properties: [
['map', new Map()],
['dismiss', (box, id, force = false) => {
if (!id || !box._map.has(id) || box._map.get(id)._hovered && !force)
attribute: {
'map': new Map(),
'dismiss': (box, id, force = false) => {
if (!id || !box.attribute.map.has(id) || box.attribute.map.get(id).attribute.hovered && !force)
return;
const notif = box._map.get(id);
const notif = box.attribute.map.get(id);
notif.revealChild = false;
notif._destroyWithAnims();
}],
['notify', (box, id) => {
// console.log('new notiffy', id, Notifications.getNotification(id))
notif.attribute.destroyWithAnims();
box.attribute.map.delete(id);
},
'notify': (box, id) => {
if (!id || Notifications.dnd) return;
if (!Notifications.getNotification(id)) return;
box._map.delete(id);
box.attribute.map.delete(id);
const notif = Notifications.getNotification(id);
const newNotif = Notification({
notifObject: notif,
isPopup: true,
});
box._map.set(id, newNotif);
box.pack_end(box._map.get(id), false, false, 0);
box.attribute.map.set(id, newNotif);
box.pack_end(box.attribute.map.get(id), false, false, 0);
box.show_all();
// box.children = Array.from(box._map.values()).reverse();
}],
],
// box.children = Array.from(box.attribute.map.values()).reverse();
},
},
setup: (self) => self
.hook(Notifications, (box, id) => box._notify(box, id), 'notified')
.hook(Notifications, (box, id) => box._dismiss(box, id), 'dismissed')
.hook(Notifications, (box, id) => box._dismiss(box, id, true), 'closed')
.hook(Notifications, (box, id) => box.attribute.notify(box, id), 'notified')
.hook(Notifications, (box, id) => box.attribute.dismiss(box, id), 'dismissed')
.hook(Notifications, (box, id) => box.attribute.dismiss(box, id, true), 'closed')
,
});