Add mpris daemon

This commit is contained in:
Alexander Bantyev 2020-09-18 12:17:59 +03:00
parent 640e6dd6bf
commit 449a3912bd
Signed by: balsoft
GPG Key ID: E081FF12ADCB4AD5
7 changed files with 1522 additions and 17 deletions

359
Cargo.lock generated
View File

@ -1,5 +1,20 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "addr2line"
version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1b6a2d3371669ab3ca9797670853d61402b03d0b4b9ebf33d677dfa720203072"
dependencies = [
"gimli",
]
[[package]]
name = "adler"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ee2a4ec343196209d6594e19543ae87a39f96d5534d7174822a3ad825dd6ed7e"
[[package]]
name = "autocfg"
version = "1.0.1"
@ -12,6 +27,20 @@ version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1dd1f0fb2c34052222f8937bd7ab412c664e8436e2c775d1b64836974889f21"
[[package]]
name = "backtrace"
version = "0.3.50"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "46254cf2fdcdf1badb5934448c1bcbe046a56537b3987d96c51a7afc5d03f293"
dependencies = [
"addr2line",
"cfg-if",
"libc",
"miniz_oxide",
"object",
"rustc-demangle",
]
[[package]]
name = "battery"
version = "0.7.6"
@ -40,7 +69,7 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b1bc2df4d0f1d373b324672d9966aca3f5ba1f03d69edad6240144774539ea59"
dependencies = [
"dbus",
"dbus 0.6.5",
"hex",
]
@ -72,6 +101,39 @@ version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b3a71ab494c0b5b860bdc8407ae08978052417070c2ced38573a9157ad75b8ac"
[[package]]
name = "darling"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ebfa6e6eb98ba452aaea6415e529e4890ab09a36aaf03c71146acf9f0eab89f6"
dependencies = [
"darling_core",
"darling_macro",
]
[[package]]
name = "darling_core"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c8af196b04f843cd6f1d979c2b3697de0d33050892662efba69112ee7b1fc968"
dependencies = [
"ident_case",
"proc-macro2 0.3.8",
"quote 0.5.2",
"syn 0.13.11",
]
[[package]]
name = "darling_macro"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0619148430511a3ecf5e52752a9c948879207ab3096276a5a9ecf8b1e7fbe010"
dependencies = [
"darling_core",
"quote 0.5.2",
"syn 0.13.11",
]
[[package]]
name = "dbus"
version = "0.6.5"
@ -82,6 +144,86 @@ dependencies = [
"libdbus-sys",
]
[[package]]
name = "dbus"
version = "0.8.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5cd9e78c210146a1860f897db03412fd5091fd73100778e43ee255cca252cf32"
dependencies = [
"libc",
"libdbus-sys",
]
[[package]]
name = "derive_is_enum_variant"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d0ac8859845146979953797f03cc5b282fb4396891807cdb3d04929a88418197"
dependencies = [
"heck",
"quote 0.3.15",
"syn 0.11.11",
]
[[package]]
name = "enum-kinds"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d0f21c374dea848c19071b1504ca5ad03c9ad0d03d2e509e68f6623b8fcac4b5"
dependencies = [
"quote 0.4.2",
"syn 0.12.15",
]
[[package]]
name = "error-chain"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ff511d5dc435d703f4971bc399647c9bc38e20cb41452e3b9feb4765419ed3f3"
[[package]]
name = "failure"
version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d32e9bd16cc02eae7db7ef620b392808b89f6a5e16bb3497d159c6b92a0f4f86"
dependencies = [
"backtrace",
"failure_derive",
]
[[package]]
name = "failure_derive"
version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aa4da3c766cd7a0db8242e326e9e4e081edd567072893ed320008189715366a4"
dependencies = [
"proc-macro2 1.0.21",
"quote 1.0.7",
"syn 1.0.41",
"synstructure",
]
[[package]]
name = "from_variants"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2b7b3795d7bd0d40e33224cbb46adb76a88b72c52143e7bcaad33bd8b6e89e32"
dependencies = [
"from_variants_impl",
]
[[package]]
name = "from_variants_impl"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d54d084040e9757536fee724381a270bc650a9ca05dcf63a0ad3aaecb1e5b9c0"
dependencies = [
"darling",
"error-chain",
"quote 0.5.2",
"syn 0.13.11",
]
[[package]]
name = "gdk-pixbuf"
version = "0.3.0"
@ -109,6 +251,12 @@ dependencies = [
"pkg-config",
]
[[package]]
name = "gimli"
version = "0.22.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aaf91faf136cb47367fa430cd46e37a788775e7fa104f8b4bcb3861dc389b724"
[[package]]
name = "gio-sys"
version = "0.5.0"
@ -158,12 +306,27 @@ dependencies = [
"pkg-config",
]
[[package]]
name = "heck"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "20564e78d53d2bb135c343b3f47714a56af2061f1c928fdb541dc7b9fdd94205"
dependencies = [
"unicode-segmentation",
]
[[package]]
name = "hex"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "805026a5d0141ffc30abb3be3173848ad46a1b1664fe632428479619a3644d77"
[[package]]
name = "ident_case"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39"
[[package]]
name = "lazy_static"
version = "1.4.0"
@ -250,6 +413,30 @@ dependencies = [
"libc",
]
[[package]]
name = "miniz_oxide"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c60c0dfe32c10b43a144bad8fc83538c52f58302c92300ea7ec7bf7b38d5a7b9"
dependencies = [
"adler",
"autocfg",
]
[[package]]
name = "mpris"
version = "2.0.0-rc2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "195e67e2b467af5146f517b0d988b5894e425a77c52a9bb5a065513ef3c2e711"
dependencies = [
"dbus 0.8.4",
"derive_is_enum_variant",
"enum-kinds",
"failure",
"failure_derive",
"from_variants",
]
[[package]]
name = "num-traits"
version = "0.2.12"
@ -259,12 +446,84 @@ dependencies = [
"autocfg",
]
[[package]]
name = "object"
version = "0.20.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1ab52be62400ca80aa00285d25253d7f7c437b7375c4de678f5405d3afe82ca5"
[[package]]
name = "pkg-config"
version = "0.3.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d36492546b6af1463394d46f0c834346f31548646f6ba10849802c9c9a27ac33"
[[package]]
name = "proc-macro2"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cd07deb3c6d1d9ff827999c7f9b04cdfd66b1b17ae508e14fe47b620f2282ae0"
dependencies = [
"unicode-xid 0.1.0",
]
[[package]]
name = "proc-macro2"
version = "0.3.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1b06e2f335f48d24442b35a19df506a835fb3547bc3c06ef27340da9acf5cae7"
dependencies = [
"unicode-xid 0.1.0",
]
[[package]]
name = "proc-macro2"
version = "1.0.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "36e28516df94f3dd551a587da5357459d9b36d945a7c37c3557928c1c2ff2a2c"
dependencies = [
"unicode-xid 0.2.1",
]
[[package]]
name = "quote"
version = "0.3.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a6e920b65c65f10b2ae65c831a81a073a89edd28c7cce89475bff467ab4167a"
[[package]]
name = "quote"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1eca14c727ad12702eb4b6bfb5a232287dcf8385cb8ca83a3eeaf6519c44c408"
dependencies = [
"proc-macro2 0.2.3",
]
[[package]]
name = "quote"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9949cfe66888ffe1d53e6ec9d9f3b70714083854be20fd5e271b232a017401e8"
dependencies = [
"proc-macro2 0.3.8",
]
[[package]]
name = "quote"
version = "1.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aa563d17ecb180e500da1cfd2b028310ac758de548efdd203e18f283af693f37"
dependencies = [
"proc-macro2 1.0.21",
]
[[package]]
name = "rustc-demangle"
version = "0.1.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4c691c0e608126e00913e33f0ccf3727d5fc84573623b8d65b2df340b5201783"
[[package]]
name = "simple-osd-battery"
version = "0.1.0"
@ -298,6 +557,15 @@ dependencies = [
"xdg",
]
[[package]]
name = "simple-osd-mpris"
version = "0.1.0"
dependencies = [
"libpulse-binding",
"mpris",
"simple-osd-common",
]
[[package]]
name = "simple-osd-pulseaudio"
version = "0.1.0"
@ -306,12 +574,101 @@ dependencies = [
"simple-osd-common",
]
[[package]]
name = "syn"
version = "0.11.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d3b891b9015c88c576343b9b3e41c2c11a51c219ef067b264bd9c8aa9b441dad"
dependencies = [
"quote 0.3.15",
"synom",
"unicode-xid 0.0.4",
]
[[package]]
name = "syn"
version = "0.12.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c97c05b8ebc34ddd6b967994d5c6e9852fa92f8b82b3858c39451f97346dcce5"
dependencies = [
"proc-macro2 0.2.3",
"quote 0.4.2",
"unicode-xid 0.1.0",
]
[[package]]
name = "syn"
version = "0.13.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "14f9bf6292f3a61d2c716723fdb789a41bbe104168e6f496dc6497e531ea1b9b"
dependencies = [
"proc-macro2 0.3.8",
"quote 0.5.2",
"unicode-xid 0.1.0",
]
[[package]]
name = "syn"
version = "1.0.41"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6690e3e9f692504b941dc6c3b188fd28df054f7fb8469ab40680df52fdcc842b"
dependencies = [
"proc-macro2 1.0.21",
"quote 1.0.7",
"unicode-xid 0.2.1",
]
[[package]]
name = "synom"
version = "0.11.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a393066ed9010ebaed60b9eafa373d4b1baac186dd7e008555b0f702b51945b6"
dependencies = [
"unicode-xid 0.0.4",
]
[[package]]
name = "synstructure"
version = "0.12.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b834f2d66f734cb897113e34aaff2f1ab4719ca946f9a7358dba8f8064148701"
dependencies = [
"proc-macro2 1.0.21",
"quote 1.0.7",
"syn 1.0.41",
"unicode-xid 0.2.1",
]
[[package]]
name = "typenum"
version = "1.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "373c8a200f9e67a0c95e62a4f52fbf80c23b4381c05a17845531982fa99e6b33"
[[package]]
name = "unicode-segmentation"
version = "1.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e83e153d1053cbb5a118eeff7fd5be06ed99153f00dbcd8ae310c5fb2b22edc0"
[[package]]
name = "unicode-xid"
version = "0.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8c1f860d7d29cf02cb2f3f359fd35991af3d30bac52c57d265a3c461074cb4dc"
[[package]]
name = "unicode-xid"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc"
[[package]]
name = "unicode-xid"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564"
[[package]]
name = "uom"
version = "0.29.0"

900
Cargo.nix
View File

@ -68,6 +68,16 @@ rec {
# File a bug if you depend on any for non-debug work!
debug = internal.debugCrate { inherit packageId; };
};
"simple-osd-mpris" = rec {
packageId = "simple-osd-mpris";
build = internal.buildRustCrateWithFeatures {
packageId = "simple-osd-mpris";
};
# Debug support which might change between releases.
# File a bug if you depend on any for non-debug work!
debug = internal.debugCrate { inherit packageId; };
};
"simple-osd-pulseaudio" = rec {
packageId = "simple-osd-pulseaudio";
build = internal.buildRustCrateWithFeatures {
@ -100,6 +110,45 @@ rec {
# inject test dependencies into the build
crates = {
"addr2line" = rec {
crateName = "addr2line";
version = "0.13.0";
edition = "2015";
sha256 = "0wih40hagpvpsqrvz7jb1cyv00hlsr9hhrwpjz5b76k6f4rjsshv";
authors = [
"Nick Fitzgerald <fitzgen@gmail.com>"
"Philip Craig <philipjcraig@gmail.com>"
"Jon Gjengset <jon@thesquareplanet.com>"
"Noah Bergbauer <noah.bergbauer@tum.de>"
];
dependencies = [
{
name = "gimli";
packageId = "gimli";
usesDefaultFeatures = false;
features = [ "read" ];
}
];
features = {
"default" = [ "rustc-demangle" "cpp_demangle" "std-object" "fallible-iterator" "smallvec" ];
"rustc-dep-of-std" = [ "core" "alloc" "compiler_builtins" "gimli/rustc-dep-of-std" ];
"std" = [ "gimli/std" ];
"std-object" = [ "std" "object" "object/std" "object/compression" "gimli/endian-reader" ];
};
};
"adler" = rec {
crateName = "adler";
version = "0.2.3";
edition = "2015";
sha256 = "0zpdsrfq5bd34941gmrlamnzjfbsx0x586afb7b0jqhr8g1lwapf";
authors = [
"Jonas Schievink <jonasschievink@gmail.com>"
];
features = {
"default" = [ "std" ];
"rustc-dep-of-std" = [ "core" "compiler_builtins" ];
};
};
"autocfg" = rec {
crateName = "autocfg";
version = "1.0.1";
@ -120,6 +169,59 @@ rec {
];
};
"backtrace" = rec {
crateName = "backtrace";
version = "0.3.50";
edition = "2018";
sha256 = "14zj0dfzqyhsqnb7v65k6xjsaip0rcdqqi1lb7dvmwfdzpr4q9a6";
authors = [
"The Rust Project Developers"
];
dependencies = [
{
name = "addr2line";
packageId = "addr2line";
optional = true;
usesDefaultFeatures = false;
}
{
name = "cfg-if";
packageId = "cfg-if";
}
{
name = "libc";
packageId = "libc";
usesDefaultFeatures = false;
}
{
name = "miniz_oxide";
packageId = "miniz_oxide";
optional = true;
usesDefaultFeatures = false;
}
{
name = "object";
packageId = "object";
optional = true;
usesDefaultFeatures = false;
features = [ "read_core" "elf" "macho" "pe" "unaligned" ];
}
{
name = "rustc-demangle";
packageId = "rustc-demangle";
}
];
features = {
"default" = [ "std" "gimli-symbolize" ];
"gimli-symbolize" = [ "addr2line" "miniz_oxide" "object" "std" ];
"libbacktrace" = [ "backtrace-sys/backtrace-sys" ];
"rustc-dep-of-std" = [ "backtrace-sys/rustc-dep-of-std" "cfg-if/rustc-dep-of-std" "core" "compiler_builtins" "libc/rustc-dep-of-std" "rustc-demangle/rustc-dep-of-std" ];
"serialize-rustc" = [ "rustc-serialize" ];
"serialize-serde" = [ "serde" ];
"verify-winapi" = [ "winapi/dbghelp" "winapi/handleapi" "winapi/libloaderapi" "winapi/memoryapi" "winapi/minwindef" "winapi/processthreadsapi" "winapi/synchapi" "winapi/tlhelp32" "winapi/winbase" "winapi/winnt" ];
};
resolvedDefaultFeatures = [ "addr2line" "default" "gimli-symbolize" "miniz_oxide" "object" "std" ];
};
"battery" = rec {
crateName = "battery";
version = "0.7.6";
@ -200,7 +302,7 @@ rec {
dependencies = [
{
name = "dbus";
packageId = "dbus";
packageId = "dbus 0.6.5";
}
{
name = "hex";
@ -267,7 +369,84 @@ rec {
features = {
};
};
"dbus" = rec {
"darling" = rec {
crateName = "darling";
version = "0.5.0";
edition = "2015";
sha256 = "1xl9mc79zkva2iqkrw5a6sdb02l9whlya5b4xam5594bp5p6xypb";
authors = [
"Ted Driggs <ted.driggs@outlook.com>"
];
dependencies = [
{
name = "darling_core";
packageId = "darling_core";
}
{
name = "darling_macro";
packageId = "darling_macro";
}
];
};
"darling_core" = rec {
crateName = "darling_core";
version = "0.5.0";
edition = "2015";
sha256 = "0s693xxyw4lilvxjwrlj102k63fyjwv2p74p3mpwshzq0imikby8";
authors = [
"Ted Driggs <ted.driggs@outlook.com>"
];
dependencies = [
{
name = "ident_case";
packageId = "ident_case";
}
{
name = "proc-macro2";
packageId = "proc-macro2 0.3.8";
}
{
name = "quote";
packageId = "quote 0.5.2";
}
{
name = "syn";
packageId = "syn 0.13.11";
features = [ "extra-traits" ];
}
];
features = {
"default" = [ "syn/full" ];
};
resolvedDefaultFeatures = [ "default" ];
};
"darling_macro" = rec {
crateName = "darling_macro";
version = "0.5.0";
edition = "2015";
sha256 = "0470zgkv3y7cm6jpcqh9ndx20yc8jjf2lxajbv7kw6ji62218686";
procMacro = true;
authors = [
"Ted Driggs <ted.driggs@outlook.com>"
];
dependencies = [
{
name = "darling_core";
packageId = "darling_core";
}
{
name = "quote";
packageId = "quote 0.5.2";
}
{
name = "syn";
packageId = "syn 0.13.11";
}
];
};
"dbus 0.6.5" = rec {
crateName = "dbus";
version = "0.6.5";
edition = "2015";
@ -288,6 +467,194 @@ rec {
features = {
};
};
"dbus 0.8.4" = rec {
crateName = "dbus";
version = "0.8.4";
edition = "2018";
sha256 = "0cngaaicqmg27vj7h1qhfgyr2l7x28sb0zc91y3a2ih1466fgnaw";
authors = [
"David Henningsson <diwic@ubuntu.com>"
];
dependencies = [
{
name = "libc";
packageId = "libc";
}
{
name = "libdbus-sys";
packageId = "libdbus-sys";
}
];
features = {
};
};
"derive_is_enum_variant" = rec {
crateName = "derive_is_enum_variant";
version = "0.1.1";
edition = "2015";
sha256 = "15w18649m4h47pdpr04id0wv8br8bg606zvrafcrfijihicqib6h";
procMacro = true;
authors = [
"Nick Fitzgerald <fitzgen@gmail.com>"
];
dependencies = [
{
name = "heck";
packageId = "heck";
}
{
name = "quote";
packageId = "quote 0.3.15";
}
{
name = "syn";
packageId = "syn 0.11.11";
}
];
};
"enum-kinds" = rec {
crateName = "enum-kinds";
version = "0.4.1";
edition = "2015";
sha256 = "1df4ra7knqpnd2g50bixs389lg6hbb50858v0wcqr17a9lvirwnh";
procMacro = true;
authors = [
"Samuel Laurén <samuel.lauren@iki.fi>"
];
dependencies = [
{
name = "quote";
packageId = "quote 0.4.2";
}
{
name = "syn";
packageId = "syn 0.12.15";
}
];
features = {
};
resolvedDefaultFeatures = [ "default" ];
};
"error-chain" = rec {
crateName = "error-chain";
version = "0.11.0";
edition = "2015";
crateBin = [];
sha256 = "1wykkr0naizbkwxjwia1rch8xhwvgij9khqvjzs07mrmqifislgz";
authors = [
"Brian Anderson <banderson@mozilla.com>"
"Paul Colomiets <paul@colomiets.name>"
"Colin Kiegel <kiegel@gmx.de>"
"Yamakaky <yamakaky@yamaworld.fr>"
];
features = {
"default" = [ "backtrace" "example_generated" ];
};
};
"failure" = rec {
crateName = "failure";
version = "0.1.8";
edition = "2015";
sha256 = "11jg1wmbkijrs6bk9fqnbrm9zf0850whnqpgnxyswbn0dk8rnbnk";
authors = [
"Without Boats <boats@mozilla.com>"
];
dependencies = [
{
name = "backtrace";
packageId = "backtrace";
optional = true;
}
{
name = "failure_derive";
packageId = "failure_derive";
optional = true;
}
];
features = {
"default" = [ "std" "derive" ];
"derive" = [ "failure_derive" ];
"std" = [ "backtrace" ];
};
resolvedDefaultFeatures = [ "backtrace" "default" "derive" "failure_derive" "std" ];
};
"failure_derive" = rec {
crateName = "failure_derive";
version = "0.1.8";
edition = "2015";
sha256 = "1936adqqk080439kx2bjf1bds7h89sg6wcif4jw0syndcv3s6kda";
procMacro = true;
authors = [
"Without Boats <woboats@gmail.com>"
];
dependencies = [
{
name = "proc-macro2";
packageId = "proc-macro2 1.0.21";
}
{
name = "quote";
packageId = "quote 1.0.7";
}
{
name = "syn";
packageId = "syn 1.0.41";
}
{
name = "synstructure";
packageId = "synstructure";
}
];
features = {
};
};
"from_variants" = rec {
crateName = "from_variants";
version = "0.4.0";
edition = "2015";
sha256 = "0clyx2vdhfykmayffhr1qmr8pa3nvdmb9jr46bil03dxsyakfyrb";
authors = [
"Ted Driggs <ted.driggs@outlook.com>"
];
dependencies = [
{
name = "from_variants_impl";
packageId = "from_variants_impl";
}
];
};
"from_variants_impl" = rec {
crateName = "from_variants_impl";
version = "0.4.0";
edition = "2015";
sha256 = "1h5rwnqyrank18xgdp05ralm1ihb4wd3h977zqv7axg98100hkfm";
procMacro = true;
authors = [
"Ted Driggs <ted.driggs@outlook.com>"
];
dependencies = [
{
name = "darling";
packageId = "darling";
}
{
name = "error-chain";
packageId = "error-chain";
usesDefaultFeatures = false;
}
{
name = "quote";
packageId = "quote 0.5.2";
}
{
name = "syn";
packageId = "syn 0.13.11";
}
];
};
"gdk-pixbuf" = rec {
crateName = "gdk-pixbuf";
version = "0.3.0";
@ -372,6 +739,24 @@ rec {
"v2_36" = [ "v2_32" ];
};
};
"gimli" = rec {
crateName = "gimli";
version = "0.22.0";
edition = "2018";
sha256 = "095pi71iv1mkpjsgh151gxg7g2576xpd8323z9kp7d3c2fpizyda";
authors = [
"Nick Fitzgerald <fitzgen@gmail.com>"
"Philip Craig <philipjcraig@gmail.com>"
];
features = {
"default" = [ "read" "write" "std" "fallible-iterator" "endian-reader" ];
"endian-reader" = [ "stable_deref_trait" ];
"rustc-dep-of-std" = [ "core" "alloc" "compiler_builtins" ];
"std" = [ "fallible-iterator/std" "stable_deref_trait/std" ];
"write" = [ "indexmap" ];
};
resolvedDefaultFeatures = [ "read" ];
};
"gio-sys" = rec {
crateName = "gio-sys";
version = "0.5.0";
@ -536,6 +921,22 @@ rec {
"v2_54" = [ "v2_46" ];
};
};
"heck" = rec {
crateName = "heck";
version = "0.3.1";
edition = "2015";
sha256 = "01a2v7yvkiqxakdqz4hw3w3g4sm52ivz9cs3qcsv2arxsmw4wmi0";
authors = [
"Without Boats <woboats@gmail.com>"
];
dependencies = [
{
name = "unicode-segmentation";
packageId = "unicode-segmentation";
}
];
};
"hex" = rec {
crateName = "hex";
version = "0.3.2";
@ -547,6 +948,16 @@ rec {
features = {
};
};
"ident_case" = rec {
crateName = "ident_case";
version = "1.0.1";
edition = "2015";
sha256 = "0fac21q6pwns8gh1hz3nbq15j8fi441ncl6w4vlnd1cmc55kiq5r";
authors = [
"Ted Driggs <ted.driggs@outlook.com>"
];
};
"lazy_static" = rec {
crateName = "lazy_static";
version = "1.4.0";
@ -780,6 +1191,68 @@ rec {
};
resolvedDefaultFeatures = [ "default" ];
};
"miniz_oxide" = rec {
crateName = "miniz_oxide";
version = "0.4.2";
edition = "2018";
sha256 = "1fd7slw7pgy7gvm008y90a1zallcaf1zrn5s8jhl62y16bz0s366";
authors = [
"Frommi <daniil.liferenko@gmail.com>"
"oyvindln <oyvindln@users.noreply.github.com>"
];
dependencies = [
{
name = "adler";
packageId = "adler";
usesDefaultFeatures = false;
}
];
buildDependencies = [
{
name = "autocfg";
packageId = "autocfg";
}
];
features = {
"rustc-dep-of-std" = [ "core" "alloc" "compiler_builtins" "adler/rustc-dep-of-std" ];
};
};
"mpris" = rec {
crateName = "mpris";
version = "2.0.0-rc2";
edition = "2015";
sha256 = "04g7qbrkwlb5l2srnan5fxd44kl9nn4dkc0pym353bv7nki6fphr";
authors = [
"Magnus Bergmark <magnus.bergmark@gmail.com>"
];
dependencies = [
{
name = "dbus";
packageId = "dbus 0.8.4";
}
{
name = "derive_is_enum_variant";
packageId = "derive_is_enum_variant";
}
{
name = "enum-kinds";
packageId = "enum-kinds";
}
{
name = "failure";
packageId = "failure";
}
{
name = "failure_derive";
packageId = "failure_derive";
}
{
name = "from_variants";
packageId = "from_variants";
}
];
};
"num-traits" = rec {
crateName = "num-traits";
version = "0.2.12";
@ -799,6 +1272,28 @@ rec {
};
resolvedDefaultFeatures = [ "std" ];
};
"object" = rec {
crateName = "object";
version = "0.20.0";
edition = "2018";
sha256 = "199cx2px61alixkxxi3mfdxl6z3z7ljjap9802m81jh04kk2pd8s";
authors = [
"Nick Fitzgerald <fitzgen@gmail.com>"
"Philip Craig <philipjcraig@gmail.com>"
];
features = {
"all" = [ "read" "write" "std" "compression" "default" ];
"compression" = [ "flate2" "std" ];
"default" = [ "read" "compression" ];
"pe" = [ "coff" ];
"read" = [ "read_core" "coff" "elf" "macho" "pe" "wasm" "unaligned" ];
"rustc-dep-of-std" = [ "core" "compiler_builtins" "alloc" ];
"wasm" = [ "wasmparser" ];
"write" = [ "write_core" "coff" "elf" "macho" ];
"write_core" = [ "crc32fast" "indexmap" "std" ];
};
resolvedDefaultFeatures = [ "coff" "elf" "macho" "pe" "read_core" "unaligned" ];
};
"pkg-config" = rec {
crateName = "pkg-config";
version = "0.3.18";
@ -809,6 +1304,146 @@ rec {
];
};
"proc-macro2 0.2.3" = rec {
crateName = "proc-macro2";
version = "0.2.3";
edition = "2015";
sha256 = "1q1a53r21dj7zqa8wl5f2wdnpmnz9jqgkiwrg61gznfiqsrxw1yd";
authors = [
"Alex Crichton <alex@alexcrichton.com>"
];
dependencies = [
{
name = "unicode-xid";
packageId = "unicode-xid 0.1.0";
}
];
features = {
"default" = [ "proc-macro" ];
"nightly" = [ "proc-macro" ];
};
resolvedDefaultFeatures = [ "default" "proc-macro" ];
};
"proc-macro2 0.3.8" = rec {
crateName = "proc-macro2";
version = "0.3.8";
edition = "2015";
sha256 = "1ryaynnaj39l4zphcg5w8wszndd80vsrv89m5d2293gl6pry41hv";
authors = [
"Alex Crichton <alex@alexcrichton.com>"
];
dependencies = [
{
name = "unicode-xid";
packageId = "unicode-xid 0.1.0";
}
];
features = {
"default" = [ "proc-macro" ];
"nightly" = [ "proc-macro" ];
};
resolvedDefaultFeatures = [ "default" "proc-macro" ];
};
"proc-macro2 1.0.21" = rec {
crateName = "proc-macro2";
version = "1.0.21";
edition = "2018";
sha256 = "0b1azz1c2a3rap1kfz2sjinv7narfhssazaq39axvwwlvwb8bqin";
authors = [
"Alex Crichton <alex@alexcrichton.com>"
"David Tolnay <dtolnay@gmail.com>"
];
dependencies = [
{
name = "unicode-xid";
packageId = "unicode-xid 0.2.1";
}
];
features = {
"default" = [ "proc-macro" ];
};
resolvedDefaultFeatures = [ "default" "proc-macro" ];
};
"quote 0.3.15" = rec {
crateName = "quote";
version = "0.3.15";
edition = "2015";
sha256 = "0yhnnix4dzsv8y4wwz4csbnqjfh73al33j35msr10py6cl5r4vks";
authors = [
"David Tolnay <dtolnay@gmail.com>"
];
};
"quote 0.4.2" = rec {
crateName = "quote";
version = "0.4.2";
edition = "2015";
sha256 = "02648jf53xpa7qxai36bhn1wyz986aibbgxnnhp704md4z3i9jhy";
authors = [
"David Tolnay <dtolnay@gmail.com>"
];
dependencies = [
{
name = "proc-macro2";
packageId = "proc-macro2 0.2.3";
}
];
};
"quote 0.5.2" = rec {
crateName = "quote";
version = "0.5.2";
edition = "2015";
sha256 = "1s01fh0jl8qv4xggs85yahw0h507nzrxkjbf7vay3zw8d3kcyjcr";
authors = [
"David Tolnay <dtolnay@gmail.com>"
];
dependencies = [
{
name = "proc-macro2";
packageId = "proc-macro2 0.3.8";
usesDefaultFeatures = false;
}
];
features = {
"default" = [ "proc-macro" ];
"proc-macro" = [ "proc-macro2/proc-macro" ];
};
resolvedDefaultFeatures = [ "default" "proc-macro" ];
};
"quote 1.0.7" = rec {
crateName = "quote";
version = "1.0.7";
edition = "2018";
sha256 = "0drzd6pq7whq7qhdvvs8wn6pbb0hhc12pz8wv80fb05ixhbksmma";
authors = [
"David Tolnay <dtolnay@gmail.com>"
];
dependencies = [
{
name = "proc-macro2";
packageId = "proc-macro2 1.0.21";
usesDefaultFeatures = false;
}
];
features = {
"default" = [ "proc-macro" ];
"proc-macro" = [ "proc-macro2/proc-macro" ];
};
resolvedDefaultFeatures = [ "default" "proc-macro" ];
};
"rustc-demangle" = rec {
crateName = "rustc-demangle";
version = "0.1.16";
edition = "2015";
sha256 = "10qp42sl1wrdbgbbh8rnay2grm976z7hqgz32c4y09l1c071qsac";
authors = [
"Alex Crichton <alex@alexcrichton.com>"
];
features = {
"rustc-dep-of-std" = [ "core" "compiler_builtins" ];
};
};
"simple-osd-battery" = rec {
crateName = "simple-osd-battery";
version = "0.1.0";
@ -902,6 +1537,38 @@ rec {
];
};
"simple-osd-mpris" = rec {
crateName = "simple-osd-mpris";
version = "0.1.0";
edition = "2018";
crateBin = [
{ name = "simple-osd-mpris"; path = "src/main.rs"; }
];
src = (builtins.filterSource sourceFilter ./mpris);
authors = [
"Alexander Bantyev <balsoft@balsoft.ru>"
];
dependencies = [
{
name = "libpulse-binding";
packageId = "libpulse-binding";
optional = true;
}
{
name = "mpris";
packageId = "mpris";
}
{
name = "simple-osd-common";
packageId = "simple-osd-common";
}
];
features = {
"default" = [ "display_on_volume_changes" ];
"display_on_volume_changes" = [ "libpulse-binding" ];
};
resolvedDefaultFeatures = [ "default" "display_on_volume_changes" "libpulse-binding" ];
};
"simple-osd-pulseaudio" = rec {
crateName = "simple-osd-pulseaudio";
version = "0.1.0";
@ -925,6 +1592,184 @@ rec {
];
};
"syn 0.11.11" = rec {
crateName = "syn";
version = "0.11.11";
edition = "2015";
sha256 = "1b8x8jdsmj6r9ck7n1pg371526n1q90kx6rv6ivcb22w06wr3f6k";
authors = [
"David Tolnay <dtolnay@gmail.com>"
];
dependencies = [
{
name = "quote";
packageId = "quote 0.3.15";
optional = true;
}
{
name = "synom";
packageId = "synom";
optional = true;
}
{
name = "unicode-xid";
packageId = "unicode-xid 0.0.4";
optional = true;
}
];
features = {
"default" = [ "parsing" "printing" ];
"parsing" = [ "unicode-xid" "synom" ];
"printing" = [ "quote" ];
};
resolvedDefaultFeatures = [ "default" "parsing" "printing" "quote" "synom" "unicode-xid" ];
};
"syn 0.12.15" = rec {
crateName = "syn";
version = "0.12.15";
edition = "2015";
sha256 = "1rfcdls9f7s57668bcw2icpsjbw5x73db53rjrmxskf3xfw0az69";
authors = [
"David Tolnay <dtolnay@gmail.com>"
];
dependencies = [
{
name = "proc-macro2";
packageId = "proc-macro2 0.2.3";
}
{
name = "quote";
packageId = "quote 0.4.2";
optional = true;
}
{
name = "unicode-xid";
packageId = "unicode-xid 0.1.0";
}
];
features = {
"default" = [ "derive" "parsing" "printing" "clone-impls" ];
"printing" = [ "quote" ];
};
resolvedDefaultFeatures = [ "clone-impls" "default" "derive" "parsing" "printing" "quote" ];
};
"syn 0.13.11" = rec {
crateName = "syn";
version = "0.13.11";
edition = "2015";
sha256 = "16qvx8qyb5v4vjbg9rk8848bw6x4i6vzs8v7f4n1v9pkj9ibzy8l";
authors = [
"David Tolnay <dtolnay@gmail.com>"
];
dependencies = [
{
name = "proc-macro2";
packageId = "proc-macro2 0.3.8";
usesDefaultFeatures = false;
}
{
name = "quote";
packageId = "quote 0.5.2";
optional = true;
usesDefaultFeatures = false;
}
{
name = "unicode-xid";
packageId = "unicode-xid 0.1.0";
}
];
features = {
"default" = [ "derive" "parsing" "printing" "clone-impls" "proc-macro" ];
"printing" = [ "quote" ];
"proc-macro" = [ "proc-macro2/proc-macro" "quote/proc-macro" ];
};
resolvedDefaultFeatures = [ "clone-impls" "default" "derive" "extra-traits" "full" "parsing" "printing" "proc-macro" "quote" ];
};
"syn 1.0.41" = rec {
crateName = "syn";
version = "1.0.41";
edition = "2018";
sha256 = "0aw4rkym5pw00ss9limqgx7hbpr8zn4b3hy63na4nl4jyvly7436";
authors = [
"David Tolnay <dtolnay@gmail.com>"
];
dependencies = [
{
name = "proc-macro2";
packageId = "proc-macro2 1.0.21";
usesDefaultFeatures = false;
}
{
name = "quote";
packageId = "quote 1.0.7";
optional = true;
usesDefaultFeatures = false;
}
{
name = "unicode-xid";
packageId = "unicode-xid 0.2.1";
}
];
features = {
"default" = [ "derive" "parsing" "printing" "clone-impls" "proc-macro" ];
"printing" = [ "quote" ];
"proc-macro" = [ "proc-macro2/proc-macro" "quote/proc-macro" ];
"test" = [ "syn-test-suite/all-features" ];
};
resolvedDefaultFeatures = [ "clone-impls" "default" "derive" "extra-traits" "parsing" "printing" "proc-macro" "quote" "visit" ];
};
"synom" = rec {
crateName = "synom";
version = "0.11.3";
edition = "2015";
sha256 = "1dj536sh5xxhan2h0znxhv0sl6sb7lvzmsmrc3nvl3h1v5p0d4x3";
authors = [
"David Tolnay <dtolnay@gmail.com>"
];
dependencies = [
{
name = "unicode-xid";
packageId = "unicode-xid 0.0.4";
}
];
};
"synstructure" = rec {
crateName = "synstructure";
version = "0.12.4";
edition = "2018";
sha256 = "00c72ij813xsilssgya6m6f73d0s5zzsld1y26bvhk3kdzbg4d5q";
authors = [
"Nika Layzell <nika@thelayzells.com>"
];
dependencies = [
{
name = "proc-macro2";
packageId = "proc-macro2 1.0.21";
usesDefaultFeatures = false;
}
{
name = "quote";
packageId = "quote 1.0.7";
usesDefaultFeatures = false;
}
{
name = "syn";
packageId = "syn 1.0.41";
usesDefaultFeatures = false;
features = [ "derive" "parsing" "printing" "clone-impls" "visit" "extra-traits" ];
}
{
name = "unicode-xid";
packageId = "unicode-xid 0.2.1";
}
];
features = {
"default" = [ "proc-macro" ];
"proc-macro" = [ "proc-macro2/proc-macro" "syn/proc-macro" "quote/proc-macro" ];
};
resolvedDefaultFeatures = [ "default" "proc-macro" ];
};
"typenum" = rec {
crateName = "typenum";
version = "1.12.0";
@ -938,6 +1783,57 @@ rec {
features = {
};
};
"unicode-segmentation" = rec {
crateName = "unicode-segmentation";
version = "1.6.0";
edition = "2015";
sha256 = "1h7d48mzpi8hwf5cvnq07warkv86pvapzzzf32hvbjsk20yiagp8";
authors = [
"kwantam <kwantam@gmail.com>"
"Manish Goregaokar <manishsmail@gmail.com>"
];
features = {
};
};
"unicode-xid 0.0.4" = rec {
crateName = "unicode-xid";
version = "0.0.4";
edition = "2015";
sha256 = "1p5l9h3n3i53cp95fb65p8q3vbwib79ryd9z5z5h5kr9gl6qc7wc";
authors = [
"erick.tryzelaar <erick.tryzelaar@gmail.com>"
"kwantam <kwantam@gmail.com>"
];
features = {
};
resolvedDefaultFeatures = [ "default" ];
};
"unicode-xid 0.1.0" = rec {
crateName = "unicode-xid";
version = "0.1.0";
edition = "2015";
sha256 = "1z57lqh4s18rr4x0j4fw4fmp9hf9346h0kmdgqsqx0fhjr3k0wpw";
authors = [
"erick.tryzelaar <erick.tryzelaar@gmail.com>"
"kwantam <kwantam@gmail.com>"
];
features = {
};
resolvedDefaultFeatures = [ "default" ];
};
"unicode-xid 0.2.1" = rec {
crateName = "unicode-xid";
version = "0.2.1";
edition = "2015";
sha256 = "0r6mknipyy9vpz8mwmxvkx65ff2ha1n2pxqjj6f46lcn8yrhpzpp";
authors = [
"erick.tryzelaar <erick.tryzelaar@gmail.com>"
"kwantam <kwantam@gmail.com>"
];
features = {
};
resolvedDefaultFeatures = [ "default" ];
};
"uom" = rec {
crateName = "uom";
version = "0.29.0";

View File

@ -5,5 +5,6 @@ members = [
"battery",
"bluetooth",
"brightness",
"mpris",
"pulseaudio"
]

View File

@ -216,5 +216,9 @@ pub mod notify {
self.try_update().unwrap();
});
}
pub fn close(&mut self) {
self.notification.close().unwrap_or_else(|_| { eprintln!("Failed to close the notification"); });
}
}
}

View File

@ -2,9 +2,7 @@
# balsoft 2020
{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs";
};
inputs = { nixpkgs.url = "github:nixos/nixpkgs"; };
description = "A collection of simple on-screen-display daemons";
@ -18,16 +16,13 @@
project = import ./Cargo.nix {
inherit nixpkgs pkgs;
defaultCrateOverrides = pkgs.defaultCrateOverrides // {
simple-osd-battery = oa: {
buildInputs = commonDeps;
};
simple-osd-battery = oa: { buildInputs = commonDeps; };
simple-osd-bluetooth = oa: {
buildInputs = commonDeps ++ [ pkgs.dbus_tools.lib pkgs.dbus_tools.dev ];
buildInputs = commonDeps
++ [ pkgs.dbus_tools.lib pkgs.dbus_tools.dev ];
nativeBuildInputs = [ pkgs.pkg-config ];
};
simple-osd-brightness = oa: {
buildInputs = commonDeps;
};
simple-osd-brightness = oa: { buildInputs = commonDeps; };
# See https://github.com/kolloch/crate2nix/issues/149
libpulse-binding = oa: {
preBuild = "sed s/pulse::libpulse.so.0/pulse/ -i target/*link*";
@ -37,9 +32,16 @@
nativeBuildInputs = [ pkgs.pkg-config ];
preBuild = "sed s/pulse::libpulse.so.0/pulse/ -i target/*link*";
};
simple-osd-mpris = oa: {
buildInputs = commonDeps ++ [ pkgs.libpulseaudio ];
preBuild = "sed s/pulse::libpulse.so.0/pulse/ -i target/*link*";
};
};
};
membersList = builtins.attrValues (builtins.mapAttrs (name: member: { name = pkgs.lib.removePrefix "simple-osd-" name; value = member.build; }) project.workspaceMembers);
membersList = builtins.attrValues (builtins.mapAttrs (name: member: {
name = pkgs.lib.removePrefix "simple-osd-" name;
value = member.build;
}) project.workspaceMembers);
in builtins.listToAttrs membersList);
apps = builtins.mapAttrs (_:
builtins.mapAttrs (_: pkg: {
@ -53,8 +55,9 @@
paths = builtins.attrValues self.packages.${system};
}) nixpkgs.legacyPackages;
devShell = builtins.mapAttrs (system: pkgs: pkgs.mkShell {
inputsFrom = builtins.attrValues self.packages.${system};
}) nixpkgs.legacyPackages;
devShell = builtins.mapAttrs (system: pkgs:
pkgs.mkShell {
inputsFrom = builtins.attrValues self.packages.${system};
}) nixpkgs.legacyPackages;
};
}

16
mpris/Cargo.toml Normal file
View File

@ -0,0 +1,16 @@
[package]
name = "simple-osd-mpris"
version = "0.1.0"
authors = ["Alexander Bantyev <balsoft@balsoft.ru>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[features]
default = [ "display_on_volume_changes" ]
display_on_volume_changes = ["libpulse-binding"]
[dependencies]
simple-osd-common = { version = "0.1", path = "../common" }
mpris = "2.0.0-rc2"
libpulse-binding = { version = "2.16.2", optional = true }

228
mpris/src/main.rs Normal file
View File

@ -0,0 +1,228 @@
pub extern crate simple_osd_common as osd;
pub extern crate mpris;
pub use std::sync::{Arc, Mutex};
use std::ops::{Deref};
pub use osd::notify::{OSD, OSDContents, OSDProgressText};
pub use osd::config::Config;
use mpris::{PlaybackStatus, PlayerFinder};
pub use std::time::{Duration, SystemTime};
use std::vec::Vec;
fn format_duration(d: Duration) -> String {
let s = d.as_secs();
let secs = s % 60;
let mins = s / 60;
format!("{:02}:{:02}", mins, secs)
}
#[cfg(test)]
mod format_duration_tests {
use super::*;
#[test]
fn seconds() {
assert_eq!(&format_duration(Duration::from_secs(10)), "00:10");
}
#[test]
fn minutes_seconds() {
assert_eq!(&format_duration(Duration::from_secs(70)), "01:10");
}
#[test]
fn many_minutes_seconds() {
assert_eq!(&format_duration(Duration::from_secs(7210)), "120:10");
}
}
fn format_artists(artists: Vec<&str>) -> Option<String> {
let mut v = artists.clone();
v.reverse();
if v.len() < 2 {
return Some(v.pop()?.to_string())
}
let mut s = String::new();
for _ in 0..v.len()-2 {
s.push_str(v.pop()?);
s.push_str(", ")
}
s.push_str(v.pop()?);
s.push_str(" & ");
s.push_str(v.pop()?);
Some(s)
}
#[cfg(test)]
mod format_artists_test {
use super::*;
#[test]
fn none() {
assert_eq!(format_artists([].to_vec()), None);
}
#[test]
fn one() {
assert_eq!(format_artists(["John Doe"].to_vec()), Some("John Doe".to_string()));
}
#[test]
fn two() {
assert_eq!(format_artists(["John Doe", "Jane Doe"].to_vec()), Some("John Doe & Jane Doe".to_string()));
}
#[test]
fn many() {
assert_eq!(format_artists(["John Doe", "Jane Doe", "Chris P. Bacon", "Seymore Clevarge"].to_vec()),
Some("John Doe, Jane Doe, Chris P. Bacon & Seymore Clevarge".to_string()));
}
}
#[cfg(feature = "display_on_volume_changes")]
mod volume_changes {
extern crate libpulse_binding as pulse;
use super::*;
use pulse::mainloop::standard::Mainloop;
use pulse::mainloop::standard::IterateResult;
use pulse::context::Context;
use pulse::context::subscribe::{subscription_masks, Operation, Facility};
pub(super) struct VolumeMonitor {
mainloop: Arc<Mutex<Mainloop>>,
context: Arc<Mutex<Context>>
}
impl VolumeMonitor {
pub fn new(config: Arc<Mutex<Config>>, trigger: Arc<Mutex<SystemTime>>) -> VolumeMonitor {
let mainloop = Arc::new(Mutex::new
(Mainloop::new().expect("Failed to create mainloop")));
let context = Arc::new(Mutex::new(Context::new(
mainloop.lock().unwrap().deref(), osd::APPNAME
).expect("Failed to create new context")));
context.lock().unwrap().connect(config.lock().unwrap().get::<String>("pulseaudio", "server").as_deref(), 0, None)
.expect("Failed to connect context");
// Wait for context to be ready
loop {
match mainloop.lock().unwrap().iterate(false) {
IterateResult::Quit(_) |
IterateResult::Err(_) => {
panic!("Iterate state was not success, quitting...");
},
IterateResult::Success(_) => {},
}
match context.lock().unwrap().get_state() {
pulse::context::State::Ready => { break; },
pulse::context::State::Failed |
pulse::context::State::Unconnected |
pulse::context::State::Terminated => {
panic!("Context state failed/terminated, quitting...");
},
_ => {}
}
}
context.lock().unwrap().subscribe(subscription_masks::SINK, |success| {
if ! success {
eprintln!("failed to subscribe to events");
return;
}
});
let subscribe_callback = move |facility, operation, _index| {
if facility == Some(Facility::Sink) && operation == Some(Operation::Changed) {
*trigger.lock().unwrap() = SystemTime::now();
}
};
context.lock().unwrap().set_subscribe_callback(Some(Box::new(subscribe_callback)));
VolumeMonitor { mainloop, context }
}
pub fn tick(& self) {
match self.mainloop.lock().unwrap().iterate(false) {
IterateResult::Quit(_) |
IterateResult::Err(_) => {
panic!("Iterate state was not success, quitting...");
},
IterateResult::Success(_) => { },
}
}
}
}
fn main() {
let config = Arc::new(Mutex::new(Config::new("mpris")));
let mut osd = OSD::new();
let player = PlayerFinder::new().unwrap().find_active().unwrap();
let mut progress_tracker = player.track_progress(100).unwrap();
let update_on_volume_change = config.clone().lock().unwrap().get_default("default", "update on volume change", true);
let timeout = config.clone().lock().unwrap().get_default("default", "notification display time", 5);
let trigger = Arc::new(Mutex::new(SystemTime::now()));
#[cfg(feature = "display_on_volume_changes")]
let vc = if update_on_volume_change {
Some(volume_changes::VolumeMonitor::new(config.clone(), trigger.clone()))
} else { None };
drop(update_on_volume_change);
drop(config);
let mut title;
let mut old_title = "".to_string();
let mut playback_status;
let mut old_playback_status = PlaybackStatus::Stopped;
loop {
let progress = progress_tracker.tick().progress;
title = progress.metadata().title().unwrap_or("Unknown").to_string();
playback_status = progress.playback_status();
if title != old_title || playback_status != old_playback_status {
*trigger.lock().unwrap() = SystemTime::now();
}
let elapsed = trigger.lock().unwrap().elapsed().unwrap_or(Duration::from_secs(timeout + 1));
if elapsed.as_secs() < timeout && playback_status != PlaybackStatus::Stopped {
let metadata = progress.metadata();
let artists = metadata.artists().and_then(|artists| format_artists(artists)).unwrap_or("Unknown".to_string());
let position = progress.position();
let length = progress.length().unwrap_or(Duration::from_secs(100000000));
osd.title = Some(format!("{:?}: {} - {}", playback_status, title, artists));
let ratio = position.as_secs_f32() / length.as_secs_f32();
let text = format!("{} / {}", format_duration(position), format_duration(length));
osd.contents = OSDContents::Progress(ratio, OSDProgressText::Text(Some(text)));
osd.timeout = 1;
osd.icon = match playback_status {
PlaybackStatus::Playing => Some("media-playback-start".to_string()),
PlaybackStatus::Paused => Some("media-playback-pause".to_string()),
_ => None
};
osd.update();
} else { osd.close() }
old_title = title;
old_playback_status = playback_status;
#[cfg(feature = "display_on_volume_changes")]
vc.as_ref().map(|v| v.tick());
}
}