Skip to content

Commit

Permalink
refactor: rename defaultDevice -> defaultPlaybackDevice; rename `…
Browse files Browse the repository at this point in the history
…devices` -> `playbackDevices`
  • Loading branch information
lars-berger committed Nov 20, 2024
1 parent 9f71683 commit 2b6655e
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 17 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ No config options.

| Variable | Description | Return type | Supported OS |
| ------------------- | ----------- | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `defaultDevice` | Default audio output device. | `AudioDevice \| null` | <img src="https://github.com/glzr-io/zebar/assets/34844898/568e90c8-cd32-49a5-a17f-ab233d41f1aa" alt="microsoft icon" width="24"> |
| `devices` | All devices. | `AudioDevice[]` | <img src="https://github.com/glzr-io/zebar/assets/34844898/568e90c8-cd32-49a5-a17f-ab233d41f1aa" alt="microsoft icon" width="24"> |
| `defaultPlaybackDevice` | Default audio playback device. | `AudioDevice \| null` | <img src="https://github.com/glzr-io/zebar/assets/34844898/568e90c8-cd32-49a5-a17f-ab233d41f1aa" alt="microsoft icon" width="24"> |
| `playbackDevices` | All audio playback devices. | `AudioDevice[]` | <img src="https://github.com/glzr-io/zebar/assets/34844898/568e90c8-cd32-49a5-a17f-ab233d41f1aa" alt="microsoft icon" width="24"> |

#### Return types

Expand All @@ -93,9 +93,9 @@ No config options.
| Variable | Description | Return type |
| ------------------ | ----------------------------- | ----------------------- |
| `deviceId` | Device ID. | `string` |
| `name` | Friendly display name. | `string` |
| `name` | Friendly display name of device. | `string` |
| `volume` | Volume as a % of maximum volume. Returned value is between `0` and `100`. | `number` |
| `isDefault` | `true` if the device is selected as the default output device.| `boolean` |
| `isDefault` | `true` if the device is selected as the default playback device.| `boolean` |

### Battery

Expand Down
4 changes: 2 additions & 2 deletions examples/boilerplate-solid-ts/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ function App() {
return (
<div class="app">
<div class="chip">
{output.audio?.defaultDevice?.name} -
{output.audio?.defaultDevice?.volume}
{output.audio?.defaultPlaybackDevice?.name} -
{output.audio?.defaultPlaybackDevice?.volume}
</div>
<div class="chip">
Media: {output.media?.session?.title} -
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ export interface AudioProviderConfig {
export type AudioProvider = Provider<AudioProviderConfig, AudioOutput>;

export interface AudioOutput {
defaultDevice: AudioDevice;
devices: AudioDevice[];
defaultPlaybackDevice: AudioDevice;
playbackDevices: AudioDevice[];
}

export interface AudioDevice {
Expand Down
22 changes: 13 additions & 9 deletions packages/desktop/src/providers/audio/audio_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@ pub struct AudioDevice {
#[derive(Debug, Clone, PartialEq, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct AudioOutput {
pub devices: Vec<AudioDevice>,
pub default_device: Option<AudioDevice>,
pub playback_devices: Vec<AudioDevice>,
pub default_playback_device: Option<AudioDevice>,
}

impl AudioOutput {
fn new() -> Self {
Self {
devices: Vec::new(),
default_device: None,
playback_devices: Vec::new(),
default_playback_device: None,
}
}
}
Expand Down Expand Up @@ -196,8 +196,8 @@ impl MediaDeviceEventHandler {

if let Some(state) = AUDIO_STATE.get() {
let mut audio_state = state.lock().unwrap();
audio_state.devices = devices;
audio_state.default_device = default_device;
audio_state.playback_devices = devices;
audio_state.default_playback_device = default_device;
}

AudioProvider::emit_volume();
Expand Down Expand Up @@ -320,14 +320,18 @@ impl AudioProvider {
);

// Update device in the devices list.
if let Some(device) =
output.devices.iter_mut().find(|d| d.device_id == device_id)
if let Some(device) = output
.playback_devices
.iter_mut()
.find(|d| d.device_id == device_id)
{
device.volume = volume;
}

// Update default device if it matches.
if let Some(default_device) = &mut output.default_device {
if let Some(default_device) =
&mut output.default_playback_device
{
if default_device.device_id == device_id {
default_device.volume = volume;
}
Expand Down

0 comments on commit 2b6655e

Please sign in to comment.