Compare commits

..

No commits in common. "e1af99648203fd99a1f3418cbbed3f2a479b42e5" and "39236357039686e891a45cc4253c62d19ef47163" have entirely different histories.

11 changed files with 138 additions and 386 deletions

119
Cargo.lock generated
View file

@ -214,7 +214,6 @@ dependencies = [
"serde",
"tokio",
"url",
"zbus 5.0.1",
]
[[package]]
@ -1597,9 +1596,9 @@ dependencies = [
"serde",
"sha2",
"subtle",
"zbus 4.4.0",
"zbus",
"zeroize",
"zvariant 4.2.0",
"zvariant",
]
[[package]]
@ -2741,44 +2740,9 @@ dependencies = [
"uds_windows",
"windows-sys 0.52.0",
"xdg-home",
"zbus_macros 4.4.0",
"zbus_names 3.0.0",
"zvariant 4.2.0",
]
[[package]]
name = "zbus"
version = "5.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "333be40ef37976542e10832ba961e3e44ea215a6b1e2673066b303ee3e0ede10"
dependencies = [
"async-broadcast",
"async-executor",
"async-fs",
"async-io",
"async-lock",
"async-process",
"async-recursion",
"async-task",
"async-trait",
"blocking",
"enumflags2",
"event-listener",
"futures-core",
"futures-util",
"hex",
"nix",
"ordered-stream",
"serde",
"serde_repr",
"static_assertions",
"tracing",
"uds_windows",
"windows-sys 0.59.0",
"xdg-home",
"zbus_macros 5.0.1",
"zbus_names 4.0.0",
"zvariant 5.0.1",
"zbus_macros",
"zbus_names",
"zvariant",
]
[[package]]
@ -2791,20 +2755,7 @@ dependencies = [
"proc-macro2",
"quote",
"syn",
"zvariant_utils 2.1.0",
]
[[package]]
name = "zbus_macros"
version = "5.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "381be624000c82e716c2a45d9213fabacf82177591fa8a6ff655d2825450601a"
dependencies = [
"proc-macro-crate",
"proc-macro2",
"quote",
"syn",
"zvariant_utils 3.0.1",
"zvariant_utils",
]
[[package]]
@ -2815,18 +2766,7 @@ checksum = "4b9b1fef7d021261cc16cba64c351d291b715febe0fa10dc3a443ac5a5022e6c"
dependencies = [
"serde",
"static_assertions",
"zvariant 4.2.0",
]
[[package]]
name = "zbus_names"
version = "4.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cdc27fbd3593ff015cef906527a2ec4115e2e3dbf6204a24d952ac4975c80614"
dependencies = [
"serde",
"static_assertions",
"zvariant 5.0.1",
"zvariant",
]
[[package]]
@ -2880,21 +2820,7 @@ dependencies = [
"enumflags2",
"serde",
"static_assertions",
"zvariant_derive 4.2.0",
]
[[package]]
name = "zvariant"
version = "5.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c690a1da8858fd4377b8cc3134a753b0bea1d8ebd78ad6e5897fab821c5e184e"
dependencies = [
"endi",
"enumflags2",
"serde",
"static_assertions",
"zvariant_derive 5.0.1",
"zvariant_utils 3.0.1",
"zvariant_derive",
]
[[package]]
@ -2907,20 +2833,7 @@ dependencies = [
"proc-macro2",
"quote",
"syn",
"zvariant_utils 2.1.0",
]
[[package]]
name = "zvariant_derive"
version = "5.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "83b6ddc1fed08493e4f2bd9350e7d00a3383467228735f3f169a9f8820fde755"
dependencies = [
"proc-macro-crate",
"proc-macro2",
"quote",
"syn",
"zvariant_utils 3.0.1",
"zvariant_utils",
]
[[package]]
@ -2933,17 +2846,3 @@ dependencies = [
"quote",
"syn",
]
[[package]]
name = "zvariant_utils"
version = "3.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6f8d85190ba70bc7b9540430df078bb529620b1464ed4a606010de584e27094d"
dependencies = [
"proc-macro2",
"quote",
"serde",
"static_assertions",
"syn",
"winnow",
]

View file

@ -14,7 +14,6 @@ reqwest = { version = "0.12.9", features = ["json"] }
serde = { version = "1.0.214", features = ["derive"] }
tokio = { version = "1", features = ["rt-multi-thread"] }
url = "2.5.2"
zbus = "5.0.1"
[build-dependencies]
bindgen = "0.70.1"

View file

@ -20,32 +20,7 @@ mod imp {
fn activate(&self) {
self.parent_activate();
match self.obj().active_window() {
None => {
let window = ui::Window::new(self.obj().as_ref());
window.present();
let mpris = crate::Mpris::new(&window);
let mpris_player = crate::mpris::Player::new();
glib::spawn_future_local(async {
// run this in glib's main loop
let conn = zbus::connection::Builder::session()
.expect("could not create dbus connection builder")
.internal_executor(false)
.name("org.mpris.MediaPlayer2.audrey")
.expect("could not register name in session bus")
.serve_at("/org/mpris/MediaPlayer2", mpris)
.expect("could not serve mpris")
.serve_at("/org/mpris/MediaPlayer2", mpris_player)
.expect("could not serve mpris player")
.build()
.await
.expect("could not build dbus connection");
loop {
conn.executor().tick().await;
}
});
}
None => ui::Window::new(self.obj().as_ref()).present(),
Some(win) => win.present(),
}
}

48
src/application.vala Normal file
View file

@ -0,0 +1,48 @@
public class Audrey.Application : Adw.Application {
public Application () {
Object (
application_id: "eu.callcc.audrey",
flags: ApplicationFlags.DEFAULT_FLAGS
);
}
construct {
GLib.ActionEntry[] action_entries = {
{ "about", this.on_about_action },
{ "preferences", this.on_preferences_action },
{ "quit", this.quit }
};
this.add_action_entries (action_entries, this);
this.set_accels_for_action ("app.quit", {"<primary>q"});
}
public override void activate () {
base.activate ();
// if this.active_window not null, this isnt the primary instance
var win = this.active_window ?? new Ui.Window (this);
win.present ();
}
private void on_about_action () {
string[] developers = { "Erica Z" };
var about = new Adw.AboutDialog () {
application_name = "audrey",
application_icon = "eu.callcc.audrey",
developer_name = "Erica Z",
translator_credits = _("translator-credits"),
version = "0.1.0", // AUDREY_VERSION
developers = developers,
copyright = "© 2024 Erica Z",
};
about.present (this.active_window);
}
private void on_preferences_action () {
message ("app.preferences action activated");
}
~Application () {
debug ("destroying application");
}
}

View file

@ -1,4 +1,5 @@
audrey_sources = [
'application.vala',
'globalconf.vala',
'mpris.vala',
'playbin.vala',

View file

@ -1,108 +1,30 @@
mod player;
pub use player::Player;
use adw::prelude::*;
use async_channel::Sender;
mod ffi {
use gtk::glib;
pub struct Mpris {
// needs to be Send, so can't store handle to the window...
raise_send: Sender<()>,
quit_send: Sender<()>,
#[repr(C)]
pub struct AudreyMpris {
parent_instance: glib::gobject_ffi::GObject,
}
impl Mpris {
pub fn new(window: &crate::ui::Window) -> Self {
let (raise_send, raise_recv) = async_channel::bounded(1);
let (quit_send, quit_recv) = async_channel::bounded(1);
#[repr(C)]
pub struct AudreyMprisClass {
parent_class: glib::gobject_ffi::GObjectClass,
}
glib::spawn_future_local(glib::clone!(
#[weak]
window,
async move {
while let Ok(()) = raise_recv.recv().await {
window.present();
}
}
));
glib::spawn_future_local(glib::clone!(
#[weak]
window,
async move {
while let Ok(()) = quit_recv.recv().await {
window.close();
}
}
));
Self {
raise_send: raise_send,
quit_send: quit_send,
}
extern "C" {
pub fn audrey_mpris_get_type() -> glib::ffi::GType;
}
}
#[zbus::interface(name = "org.mpris.MediaPlayer2")]
impl Mpris {
async fn raise(&self) {
// FIXME: don't unwrap
self.raise_send.send(()).await.unwrap()
}
use gtk::glib;
async fn quit(&self) {
// FIXME: don't unwrap
self.quit_send.send(()).await.unwrap()
}
glib::wrapper! {
pub struct Mpris(Object<ffi::AudreyMpris, ffi::AudreyMprisClass>);
#[zbus(property)]
fn can_quit(&self) -> bool {
true
}
#[zbus(property)]
fn fullscreen(&self) -> bool {
false
}
#[zbus(property)]
// TODO: report that if the argument is just _ the attribute panics
async fn set_fullscreen(&self, _fullscreen: bool) -> zbus::Result<()> {
Err(zbus::Error::Unsupported)
}
#[zbus(property)]
fn can_set_fullscreen(&self) -> bool {
false
}
#[zbus(property)]
fn can_raise(&self) -> bool {
true
}
#[zbus(property)]
fn has_track_list(&self) -> bool {
false // TODO?
}
#[zbus(property)]
fn identity(&self) -> String {
"audrey".to_string()
}
#[zbus(property)]
fn desktop_entry(&self) -> String {
crate::APP_ID.to_string()
}
#[zbus(property)]
fn supported_uri_schemes(&self) -> Vec<String> {
vec![]
}
#[zbus(property)]
fn supported_mime_types(&self) -> Vec<String> {
vec![]
match fn {
type_ => || ffi::audrey_mpris_get_type(),
}
}

View file

@ -1,3 +1,36 @@
[DBus (name = "org.mpris.MediaPlayer2")]
class Audrey.Mpris : Object {
internal signal void on_raise ();
internal signal void on_quit ();
public bool can_raise { get { return true; } }
public void raise () throws Error {
this.on_raise ();
}
public bool can_quit { get { return true; } }
public void quit () throws Error {
this.on_quit ();
}
public bool can_set_fullscreen { get { return false; } }
public bool fullscreen { get { return false; } set { assert (false); } }
public bool has_track_list { get { return false; } }
public string identity { owned get { return "audrey"; } }
public string desktop_entry { owned get { return "eu.callcc.audrey"; } }
public string[] supported_uri_schemes { owned get { return {}; } }
public string[] supported_mime_types { owned get { return {}; } }
internal Mpris (Ui.Window window) {
this.on_raise.connect (() => window.present ());
this.on_quit.connect (() => window.close ());
}
~Mpris () {
debug ("destroying mpris");
}
}
[DBus (name = "org.mpris.MediaPlayer2.Player")]
class Audrey.MprisPlayer : Object {
internal signal void on_next ();

View file

@ -1,147 +1,27 @@
use zbus::object_server::SignalEmitter;
use zbus::zvariant::{ObjectPath, Value};
mod ffi {
use gtk::glib;
pub struct Player {}
#[repr(C)]
pub struct AudreyMprisPlayer {
parent_instance: glib::gobject_ffi::GObject,
}
impl Player {
pub fn new() -> Self {
Self {}
#[repr(C)]
pub struct AudreyMprisClassPlayer {
parent_class: glib::gobject_ffi::GObjectClass,
}
extern "C" {
pub fn audrey_mpris_player_get_type() -> glib::ffi::GType;
}
}
#[zbus::interface(name = "org.mpris.MediaPlayer2.Player")]
impl Player {
fn next(&self) {
todo!()
}
use gtk::glib;
fn previous(&self) {
todo!()
}
glib::wrapper! {
pub struct Player(Object<ffi::AudreyMprisPlayer, ffi::AudreyMprisClassPlayer>);
fn pause(&self) {
todo!()
}
fn play_pause(&self) {
todo!()
}
fn stop(&self) {
todo!()
}
fn play(&self) {
todo!()
}
fn seek(&self, _offset: i64) {
todo!()
}
fn set_position(&self, _track_id: ObjectPath<'_>, _position: i64) {
todo!()
}
fn open_uri(&self, _s: &str) {
todo!()
}
#[zbus(signal)]
async fn seeked(signal_emitter: &SignalEmitter<'_>, position: i64) -> zbus::Result<()>;
#[zbus(property)]
fn playback_status(&self) -> String {
"Stopped".into() // TODO
}
#[zbus(property)]
fn loop_status(&self) -> String {
"None".into() // TODO
}
#[zbus(property)]
fn set_loop_status(&self, _loop_status: &str) {
todo!()
}
#[zbus(property)]
fn playback_rate(&self) -> f64 {
1.0
}
#[zbus(property)]
fn set_playback_rate(&self, _playback_rate: f64) {
todo!()
}
#[zbus(property)]
fn shuffle(&self) -> zbus::fdo::Result<bool> {
Err(zbus::fdo::Error::NotSupported("Shuffle".into()))
}
#[zbus(property)]
fn set_shuffle(&self, _shuffle: bool) {
todo!()
}
#[zbus(property)]
fn metadata(&self) -> Vec<(String, Value)> {
vec![] // TODO
}
#[zbus(property)]
fn volume(&self) -> f64 {
1.0 // TODO
}
#[zbus(property)]
fn set_volume(&self, _volume: f64) {
todo!()
}
#[zbus(property(emits_changed_signal = "false"))]
fn position(&self) -> i64 {
0 // TODO
}
#[zbus(property)]
fn minimum_rate(&self) -> f64 {
1.0
}
#[zbus(property)]
fn maximum_rate(&self) -> f64 {
1.0
}
#[zbus(property)]
fn can_go_next(&self) -> bool {
false // TODO
}
#[zbus(property)]
fn can_go_previous(&self) -> bool {
false // TODO
}
#[zbus(property)]
fn can_play(&self) -> bool {
false // TODO
}
#[zbus(property)]
fn can_pause(&self) -> bool {
false // TODO
}
#[zbus(property)]
fn can_seek(&self) -> bool {
false // TODO
}
#[zbus(property(emits_changed_signal = "const"))]
fn can_control(&self) -> bool {
false // TODO
match fn {
type_ => || ffi::audrey_mpris_player_get_type(),
}
}

View file

@ -1,6 +1,5 @@
#include <glib-object.h>
#include <glib.h>
#include <gio/gio.h>
// ui::playbar
typedef void AudreyUiPlaybar;
@ -19,8 +18,3 @@ void audrey_ui_play_queue_song_unbind(AudreyUiPlayQueueSong *self);
// ui::PlayQueue
typedef void AudreyUiPlayQueue;
// Mpris
typedef void AudreyMpris;
AudreyMpris *audrey_mpris_new(void *window);
guint audrey_mpris_register_object(AudreyMpris *self, GDBusConnection *conn, const gchar *object_path, GError **error);

View file

@ -1,4 +1,4 @@
pub mod ffi {
mod ffi {
use gtk::glib;
#[repr(C)]

View file

@ -1,5 +1,5 @@
[GtkTemplate (ui = "/eu/callcc/audrey/window.ui")]
public class Audrey.Ui.Window : Adw.ApplicationWindow {
class Audrey.Ui.Window : Adw.ApplicationWindow {
[GtkChild] public unowned PlayQueue play_queue;
[GtkChild] public unowned Playbar playbar;
//[GtkChild] public unowned Adw.ButtonRow shuffle_all_tracks;
@ -29,6 +29,7 @@ public class Audrey.Ui.Window : Adw.ApplicationWindow {
Object (application: app);
}
private Mpris mpris;
private MprisPlayer mpris_player;
private void now_playing (PlaybinSong song) {
@ -58,15 +59,16 @@ public class Audrey.Ui.Window : Adw.ApplicationWindow {
}
construct {
/*
Bus.own_name (
BusType.SESSION,
"org.mpris.MediaPlayer2.audrey",
BusNameOwnerFlags.NONE,
(conn) => {
try {
this.mpris = new Mpris (this);
this.mpris_player = new MprisPlayer (conn, this.playbin);
conn.register_object ("/org/mpris/MediaPlayer2", this.mpris);
conn.register_object ("/org/mpris/MediaPlayer2", this.mpris_player);
} catch (IOError e) {
error ("could not register dbus service: %s", e.message);
@ -74,14 +76,13 @@ public class Audrey.Ui.Window : Adw.ApplicationWindow {
},
() => {},
() => { error ("could not acquire dbus name"); });
*/
this.setup = new Setup ();
this.setup.connected.connect ((api) => {
this.api = api;
this.playbin.api = api;
//this.mpris_player.api = api;
this.mpris_player.api = api;
this.can_click_shuffle_all = true;
});
this.setup.load ();