Skip to content

Commit

Permalink
setup new plugin development kit (wasm addons)
Browse files Browse the repository at this point in the history
  • Loading branch information
tsirysndr committed Aug 23, 2024
1 parent cf01ae4 commit 1a004fe
Show file tree
Hide file tree
Showing 23 changed files with 576 additions and 21 deletions.
291 changes: 276 additions & 15 deletions Cargo.lock

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ members = [
"types",
"webui",
"webui/musicplayer/src-tauri",
"addons/chromecast",
"addons/dlna",
"addons/kodi",
"addons/local",
"addons/mopidy",
"addons/mpd",
"addons/mpris",
"addons/squeezebox",
"addons/tunein",
"pdk",
]

[[bin]]
Expand Down
11 changes: 11 additions & 0 deletions addons/chromecast/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
edition = "2021"
name = "chromecast"
version = "0.1.0"

[lib]
crate-type = ["cdylib"]

[dependencies]
extism-pdk = "1.2.1"
music-player-pdk = {version = "0.1.0", path = "../../pdk"}
10 changes: 10 additions & 0 deletions addons/chromecast/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use extism_pdk::*;
use music_player_pdk::{addon, Capability};

#[plugin_fn]

Check warning on line 4 in addons/chromecast/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

addons/chromecast/src/lib.rs#L4

Added line #L4 was not covered by tests
pub fn setup() -> FnResult<()> {
addon()
.register("chromecast")?
.with_capabilities(vec![Capability::Player])?;
Ok(())
}
11 changes: 11 additions & 0 deletions addons/dlna/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
edition = "2021"
name = "dlna"
version = "0.1.0"

[lib]
crate-type = ["cdylib"]

[dependencies]
extism-pdk = "1.2.1"
music-player-pdk = {version = "0.1.0", path = "../../pdk"}
10 changes: 10 additions & 0 deletions addons/dlna/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use extism_pdk::*;
use music_player_pdk::{addon, Capability};

#[plugin_fn]

Check warning on line 4 in addons/dlna/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

addons/dlna/src/lib.rs#L4

Added line #L4 was not covered by tests
pub fn setup() -> FnResult<()> {
addon()
.register("dlna")?
.with_capabilities(vec![Capability::Player, Capability::Browse])?;
Ok(())
}
11 changes: 11 additions & 0 deletions addons/kodi/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
edition = "2021"
name = "kodi"
version = "0.1.0"

[lib]
crate-type = ["cdylib"]

[dependencies]
extism-pdk = "1.2.1"
music-player-pdk = {version = "0.1.0", path = "../../pdk"}
10 changes: 10 additions & 0 deletions addons/kodi/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use extism_pdk::*;
use music_player_pdk::{addon, Capability};

#[plugin_fn]

Check warning on line 4 in addons/kodi/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

addons/kodi/src/lib.rs#L4

Added line #L4 was not covered by tests
pub fn setup() -> FnResult<()> {
addon()
.register("kodi")?
.with_capabilities(vec![Capability::Player, Capability::Browse])?;
Ok(())
}
11 changes: 11 additions & 0 deletions addons/local/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
edition = "2021"
name = "local"
version = "0.1.0"

[lib]
crate-type = ["cdylib"]

[dependencies]
extism-pdk = "1.2.1"
music-player-pdk = {version = "0.1.0", path = "../../pdk"}
10 changes: 10 additions & 0 deletions addons/local/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use extism_pdk::*;
use music_player_pdk::{addon, Capability};

#[plugin_fn]

Check warning on line 4 in addons/local/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

addons/local/src/lib.rs#L4

Added line #L4 was not covered by tests
pub fn setup() -> FnResult<()> {
addon()
.register("local")?
.with_capabilities(vec![Capability::Player, Capability::Browse])?;
Ok(())
}
11 changes: 11 additions & 0 deletions addons/mopidy/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
edition = "2021"
name = "mopidy"
version = "0.1.0"

[lib]
crate-type = ["cdylib"]

[dependencies]
extism-pdk = "1.2.1"
music-player-pdk = {version = "0.1.0", path = "../../pdk"}
10 changes: 10 additions & 0 deletions addons/mopidy/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use extism_pdk::*;
use music_player_pdk::{addon, Capability};

#[plugin_fn]

Check warning on line 4 in addons/mopidy/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

addons/mopidy/src/lib.rs#L4

Added line #L4 was not covered by tests
pub fn setup() -> FnResult<()> {
addon()
.register("mopidy")?
.with_capabilities(vec![Capability::Player])?;
Ok(())
}
11 changes: 11 additions & 0 deletions addons/mpd/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
edition = "2021"
name = "mpd"
version = "0.1.0"

[lib]
crate-type = ["cdylib"]

[dependencies]
extism-pdk = "1.2.1"
music-player-pdk = {version = "0.1.0", path = "../../pdk"}
10 changes: 10 additions & 0 deletions addons/mpd/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use extism_pdk::*;
use music_player_pdk::{addon, Capability};

#[plugin_fn]

Check warning on line 4 in addons/mpd/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

addons/mpd/src/lib.rs#L4

Added line #L4 was not covered by tests
pub fn setup() -> FnResult<()> {
addon()
.register("mpd")?
.with_capabilities(vec![Capability::Player])?;
Ok(())
}
11 changes: 11 additions & 0 deletions addons/mpris/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
edition = "2021"
name = "mpris"
version = "0.1.0"

[lib]
crate-type = ["cdylib"]

[dependencies]
extism-pdk = "1.2.1"
music-player-pdk = {version = "0.1.0", path = "../../pdk"}
10 changes: 10 additions & 0 deletions addons/mpris/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use extism_pdk::*;
use music_player_pdk::{addon, Capability};

#[plugin_fn]

Check warning on line 4 in addons/mpris/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

addons/mpris/src/lib.rs#L4

Added line #L4 was not covered by tests
pub fn setup() -> FnResult<()> {
addon()
.register("mpris")?
.with_capabilities(vec![Capability::Player])?;
Ok(())
}
11 changes: 11 additions & 0 deletions addons/squeezebox/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
edition = "2021"
name = "squeezebox"
version = "0.1.0"

[lib]
crate-type = ["cdylib"]

[dependencies]
extism-pdk = "1.2.1"
music-player-pdk = {version = "0.1.0", path = "../../pdk"}
10 changes: 10 additions & 0 deletions addons/squeezebox/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use extism_pdk::*;
use music_player_pdk::{addon, Capability};

#[plugin_fn]

Check warning on line 4 in addons/squeezebox/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

addons/squeezebox/src/lib.rs#L4

Added line #L4 was not covered by tests
pub fn setup() -> FnResult<()> {
addon()
.register("squeezebox")?
.with_capabilities(vec![Capability::Player])?;
Ok(())
}
11 changes: 11 additions & 0 deletions addons/tunein/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
edition = "2021"
name = "tunein"
version = "0.1.0"

[lib]
crate-type = ["cdylib"]

[dependencies]
extism-pdk = "1.2.1"
music-player-pdk = {version = "0.1.0", path = "../../pdk"}
10 changes: 10 additions & 0 deletions addons/tunein/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use extism_pdk::*;
use music_player_pdk::{addon, Capability};

#[plugin_fn]

Check warning on line 4 in addons/tunein/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

addons/tunein/src/lib.rs#L4

Added line #L4 was not covered by tests
pub fn setup() -> FnResult<()> {
addon()
.register("tunein")?
.with_capabilities(vec![Capability::Player, Capability::Browse])?;
Ok(())
}
8 changes: 8 additions & 0 deletions pdk/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
edition = "2021"
name = "music-player-pdk"
version = "0.1.0"

[dependencies]
extism-pdk = "1.2.1"
serde = {version = "1.0.208", features = ["serde_derive", "derive"]}
89 changes: 89 additions & 0 deletions pdk/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
use extism_pdk::*;
use serde::{Deserialize, Serialize};

#[host_fn]

Check warning on line 4 in pdk/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

pdk/src/lib.rs#L4

Added line #L4 was not covered by tests
extern "ExtismHost" {
fn open_media(url: String);
fn browse(url: &str);
fn register_addon(name: String);
fn currently_playing_song();
fn next();
fn previous();
fn pause();
fn play();
fn stop();
fn seek(time: u32);
fn position_ms() -> u32;
fn playlist();
fn playlists();
fn main_playlists();
fn recent_playlists();
fn folder();
fn folders();
fn create_playlist(args: Json<CreatePlaylistOpt>);
fn delete_playlist(id: String);
fn add_to_playlist(args: Json<AddToPlaylistOpt>);
fn remove_from_playlist(args: Json<RemoveFromPlaylistOpt>);
fn rename_playlist(args: Json<RenamePlaylistOpt>);
fn with_capabilities(capabilities: Json<Vec<String>>);
}

pub enum Capability {
Player,
Browse,
Share,
}

impl Capability {
pub fn to_string(&self) -> String {
match self {
Capability::Player => "player".into(),
Capability::Browse => "browse".into(),
Capability::Share => "share".into(),

Check warning on line 42 in pdk/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

pdk/src/lib.rs#L38-L42

Added lines #L38 - L42 were not covered by tests
}
}

Check warning on line 44 in pdk/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

pdk/src/lib.rs#L44

Added line #L44 was not covered by tests
}

#[derive(Serialize, Deserialize)]

Check warning on line 47 in pdk/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

pdk/src/lib.rs#L47

Added line #L47 was not covered by tests
pub struct CreatePlaylistOpt {
pub name: String,
pub description: String,
pub folder_id: String,
}

#[derive(Serialize, Deserialize)]

Check warning on line 54 in pdk/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

pdk/src/lib.rs#L54

Added line #L54 was not covered by tests
pub struct AddToPlaylistOpt {
pub playlist_id: String,
pub song_id: String,
}

#[derive(Serialize, Deserialize)]

Check warning on line 60 in pdk/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

pdk/src/lib.rs#L60

Added line #L60 was not covered by tests
pub struct RemoveFromPlaylistOpt {
pub playlist_id: String,
pub song_id: String,
}

#[derive(Serialize, Deserialize)]

Check warning on line 66 in pdk/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

pdk/src/lib.rs#L66

Added line #L66 was not covered by tests
pub struct RenamePlaylistOpt {
pub playlist_id: String,
pub name: String,
}

pub fn addon() -> Addon {
Addon {}
}

Check warning on line 74 in pdk/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

pdk/src/lib.rs#L72-L74

Added lines #L72 - L74 were not covered by tests

pub struct Addon {}

impl Addon {
pub fn register(&self, name: &str) -> Result<&Addon, Error> {
unsafe { register_addon(name.into())? };
Ok(self)
}

Check warning on line 82 in pdk/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

pdk/src/lib.rs#L79-L82

Added lines #L79 - L82 were not covered by tests

pub fn with_capabilities(&self, capabilities: Vec<Capability>) -> Result<&Addon, Error> {
let capabilities: Vec<String> = capabilities.iter().map(|c| c.to_string()).collect();
unsafe { with_capabilities(Json(capabilities))? };
Ok(self)
}

Check warning on line 88 in pdk/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

pdk/src/lib.rs#L84-L88

Added lines #L84 - L88 were not covered by tests
}
10 changes: 4 additions & 6 deletions settings/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ pub struct Settings {

pub fn read_settings() -> Result<Config, ConfigError> {
let path = match env::consts::OS {
"android" => {
"/storage/emulated/0/Android/data/com.tsirysndr.songbird/files".to_owned()
},
"android" => "/storage/emulated/0/Android/data/com.tsirysndr.songbird/files".to_owned(),
_ => {
let config_dir = dirs::config_dir().unwrap();
format!("{}/music-player", config_dir.to_str().unwrap())
Expand All @@ -40,9 +38,9 @@ pub fn read_settings() -> Result<Config, ConfigError> {
let music_directory = match env::consts::OS {
"android" => "/storage/emulated/0/Music".to_owned(),
_ => {
let mut tmp = PathBuf::new();
tmp.push("/tmp");
let music_dir = dirs::audio_dir().unwrap_or(tmp);
let mut home = dirs::home_dir().unwrap();
home.push("Music");
let music_dir = dirs::audio_dir().unwrap_or(home);
music_dir.to_str().unwrap().to_owned()
}
};
Expand Down

0 comments on commit 1a004fe

Please sign in to comment.