File tree 1 file changed +9
-13
lines changed
1 file changed +9
-13
lines changed Original file line number Diff line number Diff line change @@ -107,25 +107,21 @@ impl Player {
107
107
}
108
108
109
109
/// Returns the player name part of the player's D-Bus bus name.
110
- /// This is the part after "org.mpris.MediaPlayer2.", not including Flatpak name parts and the instance part.
110
+ /// This is the part after "org.mpris.MediaPlayer2.", not including the instance part.
111
+ ///
112
+ /// **Note**: The instance part removal isn't guaranteed to work. It assumes that the player
113
+ /// implements it as mentioned in the MPRIS specification example.
111
114
///
112
115
/// See: [MPRIS2 specification about bus names][bus_names].
113
116
///
114
117
/// [bus_names]: https://specifications.freedesktop.org/mpris-spec/latest/#Bus-Name-Policy
115
118
pub fn bus_name_player_name_part ( & self ) -> & str {
116
- let bus_split: Vec < & str > = self
117
- . bus_name
118
- . trim_start_matches ( MPRIS2_PREFIX )
119
- . rsplit ( '.' )
120
- . collect ( ) ;
121
-
122
- if bus_split. len ( ) == 1 || bus_split. len ( ) == 3 {
123
- // Safety in case a player's name actually starts with "instance"
124
- bus_split[ 0 ]
125
- } else if bus_split[ 0 ] . starts_with ( "instance" ) {
126
- bus_split[ 1 ]
119
+ let bus_trimmed = self . bus_name . trim_start_matches ( MPRIS2_PREFIX ) ;
120
+
121
+ if let Some ( find_index) = bus_trimmed. rfind ( ".instance" ) {
122
+ & bus_trimmed[ 0 ..find_index]
127
123
} else {
128
- bus_split [ 0 ]
124
+ bus_trimmed
129
125
}
130
126
}
131
127
You can’t perform that action at this time.
0 commit comments