@@ -60,8 +60,32 @@ impl Plugin for NuPluginDbus {
6060 result: None
6161 } ,
6262 PluginExample {
63- example: "dbus call --dest=org.mpris.MediaPlayer2.spotify \
64- /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties Get \
63+ example: "dbus call --dest=org.freedesktop.Notifications \
64+ /org/freedesktop/Notifications org.freedesktop.Notifications \
65+ Notify \" Floppy disks\" 0 \" media-floppy\" \" Rarely seen\" \
66+ \" But sometimes still used\" [] {} 5000". into( ) ,
67+ description: "Show a notification on the desktop for 5 seconds" . into( ) ,
68+ result: None
69+ } ,
70+ ] ) ,
71+ PluginSignature :: build( "dbus get" )
72+ . is_dbus_command( )
73+ . accepts_dbus_client_options( )
74+ . usage( "Get a D-Bus property" )
75+ . named( "timeout" , SyntaxShape :: Duration , "How long to wait for a response" , None )
76+ . required_named( "dest" , SyntaxShape :: String ,
77+ "The name of the connection to read the property from" ,
78+ None )
79+ . required( "object" , SyntaxShape :: String ,
80+ "The path to the object to read the property from" )
81+ . required( "interface" , SyntaxShape :: String ,
82+ "The name of the interface the property belongs to" )
83+ . required( "property" , SyntaxShape :: String ,
84+ "The name of the property to read" )
85+ . plugin_examples( vec![
86+ PluginExample {
87+ example: "dbus get --dest=org.mpris.MediaPlayer2.spotify \
88+ /org/mpris/MediaPlayer2 \
6589 org.mpris.MediaPlayer2.Player Metadata". into( ) ,
6690 description: "Get the currently playing song in Spotify" . into( ) ,
6791 result: Some ( Value :: record( nu_protocol:: record!(
@@ -73,13 +97,60 @@ impl Plugin for NuPluginDbus {
7397 "xesam:url" => str !( "https://open.spotify.com/track/51748BvzeeMs4PIdPuyZmv" ) ,
7498 ) , Span :: unknown( ) ) )
7599 } ,
100+ ] ) ,
101+ PluginSignature :: build( "dbus get-all" )
102+ . is_dbus_command( )
103+ . accepts_dbus_client_options( )
104+ . usage( "Get all D-Bus property for the given objects" )
105+ . named( "timeout" , SyntaxShape :: Duration , "How long to wait for a response" , None )
106+ . required_named( "dest" , SyntaxShape :: String ,
107+ "The name of the connection to read the property from" ,
108+ None )
109+ . required( "object" , SyntaxShape :: String ,
110+ "The path to the object to read the property from" )
111+ . required( "interface" , SyntaxShape :: String ,
112+ "The name of the interface the property belongs to" )
113+ . plugin_examples( vec![
76114 PluginExample {
77- example: "dbus call --dest=org.freedesktop.Notifications \
78- /org/freedesktop/Notifications org.freedesktop.Notifications \
79- Notify \" Floppy disks\" 0 \" media-floppy\" \" Rarely seen\" \
80- \" But sometimes still used\" [] {} 5000". into( ) ,
81- description: "Show a notification on the desktop for 5 seconds" . into( ) ,
82- result: None
115+ example: "dbus get-all --dest=org.mpris.MediaPlayer2.spotify \
116+ /org/mpris/MediaPlayer2 \
117+ org.mpris.MediaPlayer2.Player". into( ) ,
118+ description: "Get the current player state of Spotify" . into( ) ,
119+ result: Some ( Value :: record( nu_protocol:: record!(
120+ "CanPlay" => Value :: bool ( true , Span :: unknown( ) ) ,
121+ "Volume" => Value :: float( 0.43 , Span :: unknown( ) ) ,
122+ "PlaybackStatus" => str !( "Paused" ) ,
123+ ) , Span :: unknown( ) ) )
124+ } ,
125+ ] ) ,
126+ PluginSignature :: build( "dbus set" )
127+ . is_dbus_command( )
128+ . accepts_dbus_client_options( )
129+ . usage( "Get all D-Bus property for the given objects" )
130+ . named( "timeout" , SyntaxShape :: Duration , "How long to wait for a response" , None )
131+ . named( "signature" , SyntaxShape :: String ,
132+ "Signature of the value to set, in D-Bus format.\n \
133+ If not provided, it will be determined from introspection.\n \
134+ If --no-introspect is specified and this is not provided, it will \
135+ be guessed (poorly)", None )
136+ . required_named( "dest" , SyntaxShape :: String ,
137+ "The name of the connection to write the property on" ,
138+ None )
139+ . required( "object" , SyntaxShape :: String ,
140+ "The path to the object to write the property on" )
141+ . required( "interface" , SyntaxShape :: String ,
142+ "The name of the interface the property belongs to" )
143+ . required( "property" , SyntaxShape :: String ,
144+ "The name of the property to write" )
145+ . required( "value" , SyntaxShape :: Any ,
146+ "The value to write to the property" )
147+ . plugin_examples( vec![
148+ PluginExample {
149+ example: "dbus set --dest=org.mpris.MediaPlayer2.spotify \
150+ /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player \
151+ Volume 0.5". into( ) ,
152+ description: "Set the volume of Spotify to 50%" . into( ) ,
153+ result: None ,
83154 } ,
84155 ] ) ,
85156 ]
@@ -99,6 +170,9 @@ impl Plugin for NuPluginDbus {
99170 } ) ,
100171
101172 "dbus call" => self . call ( call) ,
173+ "dbus get" => self . get ( call) ,
174+ "dbus get-all" => self . get_all ( call) ,
175+ "dbus set" => self . set ( call) ,
102176
103177 _ => Err ( LabeledError {
104178 label : "Plugin invoked with unknown command name" . into ( ) ,
@@ -156,4 +230,39 @@ impl NuPluginDbus {
156230 _ => Ok ( Value :: list ( values, Span :: unknown ( ) ) )
157231 }
158232 }
233+
234+ fn get ( & self , call : & EvaluatedCall ) -> Result < Value , LabeledError > {
235+ let config = DbusClientConfig :: try_from ( call) ?;
236+ let dbus = DbusClient :: new ( config) ?;
237+ dbus. get (
238+ & call. get_flag ( "dest" ) ?. unwrap ( ) ,
239+ & call. req ( 0 ) ?,
240+ & call. req ( 1 ) ?,
241+ & call. req ( 2 ) ?,
242+ )
243+ }
244+
245+ fn get_all ( & self , call : & EvaluatedCall ) -> Result < Value , LabeledError > {
246+ let config = DbusClientConfig :: try_from ( call) ?;
247+ let dbus = DbusClient :: new ( config) ?;
248+ dbus. get_all (
249+ & call. get_flag ( "dest" ) ?. unwrap ( ) ,
250+ & call. req ( 0 ) ?,
251+ & call. req ( 1 ) ?,
252+ )
253+ }
254+
255+ fn set ( & self , call : & EvaluatedCall ) -> Result < Value , LabeledError > {
256+ let config = DbusClientConfig :: try_from ( call) ?;
257+ let dbus = DbusClient :: new ( config) ?;
258+ dbus. set (
259+ & call. get_flag ( "dest" ) ?. unwrap ( ) ,
260+ & call. req ( 0 ) ?,
261+ & call. req ( 1 ) ?,
262+ & call. req ( 2 ) ?,
263+ call. get_flag ( "signature" ) ?. as_ref ( ) ,
264+ & call. req ( 3 ) ?,
265+ ) ?;
266+ Ok ( Value :: nothing ( Span :: unknown ( ) ) )
267+ }
159268}
0 commit comments