added api for swaymsg to greg-ng (untested)
This commit is contained in:
parent
74f5316121
commit
0769229419
23
Cargo.lock
generated
23
Cargo.lock
generated
@ -625,6 +625,7 @@ dependencies = [
|
|||||||
"sd-notify",
|
"sd-notify",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
|
"swayipc",
|
||||||
"systemd-journal-logger",
|
"systemd-journal-logger",
|
||||||
"tempfile",
|
"tempfile",
|
||||||
"tokio",
|
"tokio",
|
||||||
@ -1501,6 +1502,28 @@ version = "0.11.1"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
|
checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "swayipc"
|
||||||
|
version = "3.0.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "2b8c50cb2e98e88b52066a35ef791fffd8f6fa631c3a4983de18ba41f718c736"
|
||||||
|
dependencies = [
|
||||||
|
"serde",
|
||||||
|
"serde_json",
|
||||||
|
"swayipc-types",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "swayipc-types"
|
||||||
|
version = "1.4.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "551233c60323e87cfb8194c21cc44577ab848d00bb7fa2d324a2c7f52609eaff"
|
||||||
|
dependencies = [
|
||||||
|
"serde",
|
||||||
|
"serde_json",
|
||||||
|
"thiserror 1.0.69",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "syn"
|
name = "syn"
|
||||||
version = "2.0.90"
|
version = "2.0.90"
|
||||||
|
@ -9,6 +9,7 @@ readme = "README.md"
|
|||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
swayipc = "3.0"
|
||||||
anyhow = "1.0.82"
|
anyhow = "1.0.82"
|
||||||
axum = { version = "0.7.7", features = ["macros", "ws"] }
|
axum = { version = "0.7.7", features = ["macros", "ws"] }
|
||||||
clap = { version = "4.4.1", features = ["derive"] }
|
clap = { version = "4.4.1", features = ["derive"] }
|
||||||
|
11
module.nix
11
module.nix
@ -11,6 +11,8 @@ in
|
|||||||
mpvPackage = lib.mkPackageOption pkgs "mpv" { };
|
mpvPackage = lib.mkPackageOption pkgs "mpv" { };
|
||||||
|
|
||||||
enableSway = lib.mkEnableOption "sway as the main window manager";
|
enableSway = lib.mkEnableOption "sway as the main window manager";
|
||||||
|
|
||||||
|
enableFirefox = lib.mkEnableOption "include fiorefox browser for external urls";
|
||||||
|
|
||||||
enablePipewire = lib.mkEnableOption "pipewire" // { default = true; };
|
enablePipewire = lib.mkEnableOption "pipewire" // { default = true; };
|
||||||
|
|
||||||
@ -166,6 +168,14 @@ in
|
|||||||
wrapperFeatures.gtk = true;
|
wrapperFeatures.gtk = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
(lib.mkIf (cfg.enable && cfg.enableFirefox) {
|
||||||
|
programs.firefox = {
|
||||||
|
enable = true;
|
||||||
|
preferences = {
|
||||||
|
media.autoplay.default = "0";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
xdg.portal = {
|
xdg.portal = {
|
||||||
enable = true;
|
enable = true;
|
||||||
wlr.enable = true;
|
wlr.enable = true;
|
||||||
@ -176,6 +186,7 @@ in
|
|||||||
users.greg = {
|
users.greg = {
|
||||||
isNormalUser = true;
|
isNormalUser = true;
|
||||||
group = "greg";
|
group = "greg";
|
||||||
|
extraGroups [ "audio" "video" "input" ];
|
||||||
uid = 2000;
|
uid = 2000;
|
||||||
description = "loud gym bro";
|
description = "loud gym bro";
|
||||||
};
|
};
|
||||||
|
@ -170,3 +170,15 @@ pub async fn playlist_set_looping(mpv: Mpv, r#loop: bool) -> anyhow::Result<()>
|
|||||||
.await
|
.await
|
||||||
.map_err(|e| e.into())
|
.map_err(|e| e.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
use swayipc::{Connection, Fallible};
|
||||||
|
|
||||||
|
pub async fn run_sway_command(command: String) -> Fallible<()> {
|
||||||
|
tokio::task::spawn_blocking(move || -> Fallible<()> {
|
||||||
|
let mut connection = Connection::new()?;
|
||||||
|
connection.run_command(&command)?;
|
||||||
|
Ok(())
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
.map_err(|e| swayipc::Error::CommandFailed(e.to_string()))?
|
||||||
|
}
|
@ -32,6 +32,7 @@ pub fn rest_api_routes(mpv: Mpv) -> Router {
|
|||||||
.route("/playlist/shuffle", post(shuffle))
|
.route("/playlist/shuffle", post(shuffle))
|
||||||
.route("/playlist/loop", get(playlist_get_looping))
|
.route("/playlist/loop", get(playlist_get_looping))
|
||||||
.route("/playlist/loop", post(playlist_set_looping))
|
.route("/playlist/loop", post(playlist_set_looping))
|
||||||
|
.route("/sway/command", post(sway_command))
|
||||||
.with_state(mpv)
|
.with_state(mpv)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -401,3 +402,23 @@ async fn playlist_set_looping(
|
|||||||
) -> RestResponse {
|
) -> RestResponse {
|
||||||
base::playlist_set_looping(mpv, query.r#loop).await.into()
|
base::playlist_set_looping(mpv, query.r#loop).await.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[derive(serde::Deserialize, utoipa::IntoParams)]
|
||||||
|
struct SwayCommandArgs {
|
||||||
|
command: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Execute a sway command
|
||||||
|
#[utoipa::path(
|
||||||
|
post,
|
||||||
|
path = "/sway/command",
|
||||||
|
params(SwayCommandArgs),
|
||||||
|
responses(
|
||||||
|
(status = 200, description = "Success", body = EmptySuccessResponse),
|
||||||
|
(status = 500, description = "Internal server error", body = ErrorResponse),
|
||||||
|
)
|
||||||
|
)]
|
||||||
|
async fn sway_command(Query(query): Query<SwayCommandArgs>) -> RestResponse {
|
||||||
|
base::run_sway_command(query.command).await.map_err(anyhow::Error::new).into()
|
||||||
|
}
|
||||||
|
@ -25,6 +25,8 @@ use tokio::{select, sync::watch};
|
|||||||
|
|
||||||
use crate::util::IdPool;
|
use crate::util::IdPool;
|
||||||
|
|
||||||
|
use super::base;
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
struct WebsocketState {
|
struct WebsocketState {
|
||||||
mpv: Mpv,
|
mpv: Mpv,
|
||||||
@ -355,6 +357,7 @@ pub enum WSCommand {
|
|||||||
Shuffle,
|
Shuffle,
|
||||||
SetSubtitleTrack { track: Option<usize> },
|
SetSubtitleTrack { track: Option<usize> },
|
||||||
SetLooping { value: bool },
|
SetLooping { value: bool },
|
||||||
|
SwayCommand { command: String },
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn handle_message(
|
async fn handle_message(
|
||||||
@ -445,5 +448,9 @@ async fn handle_message(
|
|||||||
.await?;
|
.await?;
|
||||||
Ok(None)
|
Ok(None)
|
||||||
}
|
}
|
||||||
|
WSCommand::SwayCommand { command } => {
|
||||||
|
base::run_sway_command(command).await?;
|
||||||
|
Ok(None)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user