Skip to content

Commit 670d886

Browse files
committed
fix formatting
1 parent 6e8d381 commit 670d886

File tree

5 files changed

+33
-40
lines changed

5 files changed

+33
-40
lines changed

build.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
use std::process::Command;
21
use std::env;
2+
use std::process::Command;
33

44
#[cfg(target_os = "macos")]
55
fn main() {
6-
7-
// Path to your Swift source file
86
let swift_file = "src/macos/nowplaying.swift";
97

108
// Output directory for compiled library
@@ -22,15 +20,15 @@ fn main() {
2220
"AVFoundation",
2321
"-o",
2422
&lib_path,
25-
swift_file])
23+
swift_file,
24+
])
2625
.status()
2726
.expect("Failed to compile Swift code");
2827

2928
if !status.success() {
3029
panic!("Swift compilation failed");
3130
}
32-
31+
3332
println!("cargo:rustc-link-search=native={}", out_dir);
3433
println!("cargo:rustc-link-lib=static=swiftlib");
35-
3634
}

examples/basic.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
2-
31
use system_media::MediaSession;
42

53
fn main() {
@@ -8,4 +6,4 @@ fn main() {
86
let mut session = MediaSession::new();
97
session.set_title("Hello!");
108
session.start();
11-
}
9+
}

src/lib.rs

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
#[cfg(target_os = "macos")]
22
mod macos;
3-
#[cfg(not(any(
4-
target_os = "macos"
5-
)))]
3+
#[cfg(not(any(target_os = "macos")))]
64
mod null;
75

86
pub trait MediaBackend {
@@ -22,7 +20,7 @@ pub trait MediaBackend {
2220
#[derive(Clone, Copy, PartialEq)]
2321
pub enum MediaType {
2422
Audio,
25-
Video
23+
Video,
2624
}
2725

2826
pub struct Metadata {
@@ -41,14 +39,11 @@ pub struct MediaSession {
4139
}
4240

4341
impl MediaSession {
44-
4542
pub fn new() -> Self {
4643
#[cfg(target_os = "macos")]
4744
let backend = Box::new(macos::NowPlayingBackend::new());
4845

49-
#[cfg(not(any(
50-
target_os = "macos"
51-
)))]
46+
#[cfg(not(any(target_os = "macos")))]
5247
let backend = Box::new(null::NullBackend::new());
5348

5449
Self {
@@ -78,71 +73,69 @@ impl MediaSession {
7873
self.metadata.artist = artist.to_string();
7974
self.backend.set_artist(artist);
8075
}
81-
76+
8277
pub fn artist(&self) -> &str {
8378
&self.metadata.artist
8479
}
85-
80+
8681
pub fn set_album(&mut self, album: &str) {
8782
self.metadata.album = album.to_string();
8883
self.backend.set_album(album);
8984
}
90-
85+
9186
pub fn album(&self) -> &str {
9287
&self.metadata.album
9388
}
94-
89+
9590
pub fn set_genre(&mut self, genre: &str) {
9691
self.metadata.genre = genre.to_string();
9792
self.backend.set_album(genre);
9893
}
99-
94+
10095
pub fn genre(&self) -> &str {
10196
&self.metadata.genre
10297
}
103-
98+
10499
pub fn set_media_type(&mut self, media_type: MediaType) {
105100
self.metadata.media_type = media_type;
106101
self.backend.set_media_type(media_type);
107102
}
108-
103+
109104
pub fn media_type(&self) -> MediaType {
110105
self.metadata.media_type
111106
}
112-
107+
113108
pub fn set_playback_duration(&mut self, duration: f64) {
114109
self.metadata.duration = duration;
115110
self.backend.set_playback_duration(duration);
116111
}
117-
112+
118113
pub fn duration(&self) -> f64 {
119114
self.metadata.duration
120115
}
121-
116+
122117
pub fn set_elapsed_duration(&self, duration: f64) {
123118
self.backend.set_elapsed_duration(duration);
124119
}
125-
120+
126121
pub fn set_playback_rate(&mut self, rate: f64) {
127122
self.metadata.playback_rate = rate;
128123
self.backend.set_playback_rate(rate);
129124
}
130-
125+
131126
pub fn playback_rate(&self) -> f64 {
132127
self.metadata.playback_rate
133128
}
134129

135130
pub fn start(&self) {
136131
self.backend.start_session();
137132
}
138-
133+
139134
pub fn stop(&self) {
140135
self.backend.stop_session();
141136
}
142-
143137
}
144138

145-
146139
#[cfg(test)]
147140
mod tests {
148141
use super::*;

src/macos/mod.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
use std::ffi::CString;
21
use crate::{MediaBackend, MediaType};
2+
use std::ffi::CString;
3+
34
// Swift functions called by Rust
45
unsafe extern "C" {
56
fn swift_set_metadata_title(title: *mut i8);
@@ -16,13 +17,13 @@ unsafe extern "C" {
1617
// Rust functions called by Swift
1718
// TODO: Add hooks for SystemMedia events.
1819
#[unsafe(no_mangle)]
19-
pub unsafe extern "C" fn rust_resume_playback_command() { }
20+
pub unsafe extern "C" fn rust_resume_playback_command() {}
2021
#[unsafe(no_mangle)]
21-
pub unsafe extern "C" fn rust_pause_playback_command() { }
22+
pub unsafe extern "C" fn rust_pause_playback_command() {}
2223
#[unsafe(no_mangle)]
23-
pub unsafe extern "C" fn rust_next_track_playback_command() { }
24+
pub unsafe extern "C" fn rust_next_track_playback_command() {}
2425
#[unsafe(no_mangle)]
25-
pub unsafe extern "C" fn rust_previous_track_playback_command() { }
26+
pub unsafe extern "C" fn rust_previous_track_playback_command() {}
2627

2728
fn str_to_raw(s: &str) -> *mut i8 {
2829
let c_string = CString::new(s).expect("CString::new() failed. ");
@@ -32,7 +33,9 @@ fn str_to_raw(s: &str) -> *mut i8 {
3233
pub struct NowPlayingBackend;
3334

3435
impl NowPlayingBackend {
35-
pub fn new() -> Self { Self }
36+
pub fn new() -> Self {
37+
Self
38+
}
3639
}
3740

3841
impl MediaBackend for NowPlayingBackend {
@@ -81,7 +84,7 @@ impl MediaBackend for NowPlayingBackend {
8184
swift_set_elapsed_duration(duration);
8285
}
8386
}
84-
87+
8588
fn set_playback_rate(&self, rate: f64) {
8689
unsafe {
8790
swift_set_playback_rate(rate);
@@ -97,4 +100,4 @@ impl MediaBackend for NowPlayingBackend {
97100
fn stop_session(&self) {
98101
println!("How do we stop a session?");
99102
}
100-
}
103+
}

src/null/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

0 commit comments

Comments
 (0)