Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into feat/focused-window-p…
Browse files Browse the repository at this point in the history
…rovider
  • Loading branch information
HolbyFPV committed Nov 20, 2024
2 parents 529c5f4 + 315608a commit ed96141
Show file tree
Hide file tree
Showing 59 changed files with 2,804 additions and 341 deletions.
25 changes: 25 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

108 changes: 102 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,46 @@ In some cases, updating to the latest Microsoft Webview2 version is needed ([sta

Through the `zebar` NPM package, Zebar exposes various system information via reactive "providers". Providers are a collection of functions and variables that can change over time.

- [audio](#Audio)
- [battery](#Battery)
- [cpu](#CPU)
- [date](#Date)
- [disk](#Disk)
- [focusedWindow](#focused-window)
- [glazewm](#GlazeWM)
- [host](#Host)
- [ip](#IP)
- [keyboard](#Keyboard)
- [komorebi](#Komorebi)
- [media](#Media)
- [memory](#Memory)
- [network](#Network)
- [weather](#Weather)

### Audio

#### Config

No config options.

#### Outputs

| Variable | Description | Return type | Supported OS |
| ------------------- | ----------- | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `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

#### `AudioDevice`

| Variable | Description | Return type |
| ------------------ | ----------------------------- | ----------------------- |
| `deviceId` | Device ID. | `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 playback device.| `boolean` |

### Battery

#### Config
Expand Down Expand Up @@ -131,6 +158,44 @@ Through the `zebar` NPM package, Zebar exposes various system information via re
| `now` | Current date/time as milliseconds since epoch. Uses `Date.now()` under the hood. | `number` | <img src="https://github.com/glzr-io/zebar/assets/34844898/568e90c8-cd32-49a5-a17f-ab233d41f1aa" alt="microsoft icon" width="24"><img src="https://github.com/glzr-io/zebar/assets/34844898/005a0760-da9d-460e-b533-9b2aba7f5c03" alt="apple icon" width="24"><img src="https://github.com/glzr-io/zebar/assets/34844898/1c5d91b1-879f-42a6-945e-912a11daebb4" alt="linux icon" width="24"> |
| `iso` | Current date/time as an ISO-8601 string (eg. `2017-04-22T20:47:05.335-04:00`). Uses `date.toISOString()` under the hood. | `string` | <img src="https://github.com/glzr-io/zebar/assets/34844898/568e90c8-cd32-49a5-a17f-ab233d41f1aa" alt="microsoft icon" width="24"><img src="https://github.com/glzr-io/zebar/assets/34844898/005a0760-da9d-460e-b533-9b2aba7f5c03" alt="apple icon" width="24"><img src="https://github.com/glzr-io/zebar/assets/34844898/1c5d91b1-879f-42a6-945e-912a11daebb4" alt="linux icon" width="24"> |

### Disk

#### Config

| Option | Description | Option type | Default value |
| ------------------ | -------------------------------------------------- | ----------- | ------------- |
| `refreshInterval` | How often this provider refreshes in milliseconds. | `number` | `60000` |

#### Outputs

| Variable | Description | Return type | Supported OS |
| ------------------- | ----------- | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `disks` | Available disks on the system. | `Disk[]` | <img src="https://github.com/glzr-io/zebar/assets/34844898/568e90c8-cd32-49a5-a17f-ab233d41f1aa" alt="microsoft icon" width="24"><img src="https://github.com/glzr-io/zebar/assets/34844898/005a0760-da9d-460e-b533-9b2aba7f5c03" alt="apple icon" width="24"><img src="https://github.com/glzr-io/zebar/assets/34844898/1c5d91b1-879f-42a6-945e-912a11daebb4" alt="linux icon" width="24"> |

#### Return types

#### `Disk`

| Variable | Description | Return type |
| ------------------ | ----------------------------- | ----------------------- |
| `name` | Disk name. | `string \| null` |
| `fileSystem` | File system used on the disk (e.g. `EXT4`, `NTFS`). | `string` |
| `mountPoint` | Mount point of the disk (e.g. `/`, `C:\\`). | `string` |
| `totalSpace` | Total disk size. | `DataSizeMeasure` |
| `availableSpace` | Available disk size. | `DataSizeMeasure` |
| `isRemovable` | Whether the disk is removable. | `boolean` |
| `driveType` | Type of disk (e.g. `HDD`, `SSD`). | `string` |

#### `DataSizeMeasure`

| Variable | Description | Return type |
| ---------- | --------------------------------------------------------------------------- | ----------- |
| `bytes` | Raw byte value. | `number` |
| `siValue` | Bytes converted in according to the SI standard. 1000 bytes in a kilobyte. | `number` |
| `siUnit` | Unit of the converted bytes in according to the SI standard. KB, MB, ... | `string` |
| `iecValue` | Bytes converted in according to the IEC standard. 1024 bytes in a kibibyte. | `number` |
| `iecUnit` | Unit of the converted bytes in according to the IEC standard. KiB, MiB, ... | `string` |



## Focused Window
Expand Down Expand Up @@ -163,6 +228,7 @@ No config options.
| `currentWorkspaces` | Workspaces on the current monitor. | `Workspace[]` | <img src="https://github.com/glzr-io/zebar/assets/34844898/568e90c8-cd32-49a5-a17f-ab233d41f1aa" alt="microsoft icon" width="24"> |
| `allWorkspaces` | Workspaces across all monitors. | `Workspace[]` | <img src="https://github.com/glzr-io/zebar/assets/34844898/568e90c8-cd32-49a5-a17f-ab233d41f1aa" alt="microsoft icon" width="24"> |
| `allMonitors` | All monitors. | `Monitor[]` | <img src="https://github.com/glzr-io/zebar/assets/34844898/568e90c8-cd32-49a5-a17f-ab233d41f1aa" alt="microsoft icon" width="24"> |
| `allWindows` | All windows. | `Window[]` | <img src="https://github.com/glzr-io/zebar/assets/34844898/568e90c8-cd32-49a5-a17f-ab233d41f1aa" alt="microsoft icon" width="24"> |
| `focusedMonitor` | Monitor that currently has focus. | `Monitor` | <img src="https://github.com/glzr-io/zebar/assets/34844898/568e90c8-cd32-49a5-a17f-ab233d41f1aa" alt="microsoft icon" width="24"> |
| `currentMonitor` | Monitor that is nearest to this Zebar widget. | `Monitor` | <img src="https://github.com/glzr-io/zebar/assets/34844898/568e90c8-cd32-49a5-a17f-ab233d41f1aa" alt="microsoft icon" width="24"> |
| `focusedContainer` | Container that currently has focus (on any monitor). | `Container` | <img src="https://github.com/glzr-io/zebar/assets/34844898/568e90c8-cd32-49a5-a17f-ab233d41f1aa" alt="microsoft icon" width="24"> |
Expand Down Expand Up @@ -249,16 +315,16 @@ No config options.

#### Return types

### NetworkTraffic
#### `NetworkTraffic`

| Variable | Description | Return type |
| ------------------ | ----------------------------- | ----------------------- |
| `received` | Received bytes per second. | `NetworkTrafficMeasure` |
| `transmitted` | Transmitted bytes per second. | `NetworkTrafficMeasure` |
| `totalReceived` | Total received bytes. | `NetworkTrafficMeasure` |
| `totalTransmitted` | Total transmitted bytes. | `NetworkTrafficMeasure` |
| `received` | Received bytes per second. | `DataSizeMeasure` |
| `transmitted` | Transmitted bytes per second. | `DataSizeMeasure` |
| `totalReceived` | Total received bytes. | `DataSizeMeasure` |
| `totalTransmitted` | Total transmitted bytes. | `DataSizeMeasure` |

### NetworkTrafficMeasure
#### `DataSizeMeasure`

| Variable | Description | Return type |
| ---------- | --------------------------------------------------------------------------- | ----------- |
Expand Down Expand Up @@ -300,6 +366,36 @@ No config options.
| `focusedMonitor` | Monitor that currently has focus. | `KomorebiMonitor` | <img src="https://github.com/glzr-io/zebar/assets/34844898/568e90c8-cd32-49a5-a17f-ab233d41f1aa" alt="microsoft icon" width="24"> |
| `currentMonitor` | Monitor that is nearest to this Zebar widget. | `KomorebiMonitor` | <img src="https://github.com/glzr-io/zebar/assets/34844898/568e90c8-cd32-49a5-a17f-ab233d41f1aa" alt="microsoft icon" width="24"> |

### Media

#### Config

No config options.

#### Outputs

| Variable | Description | Return type | Supported OS |
| ------------------- | ----------- | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `session` | Currently playing media session. | `MediaSession \| null` | <img src="https://github.com/glzr-io/zebar/assets/34844898/568e90c8-cd32-49a5-a17f-ab233d41f1aa" alt="microsoft icon" width="24"> |

#### Return types

#### `MediaSession`

| Variable | Description | Return type |
| ------------------ | ----------------------------- | ----------------------- |
| `title` | TODO | `string` |
| `artist` | TODO | `string \| null` |
| `albumTitle` | TODO | `string \| null` |
| `albumArtist` | TODO | `string \| null` |
| `trackNumber` | TODO | `number` |
| `startTime` | TODO | `number` |
| `endTime` | TODO | `number` |
| `position` | TODO | `number` |
| `isPlaying` | TODO | `boolean` |

#### `DataSizeMeasure`


### Weather

Expand Down
5 changes: 5 additions & 0 deletions examples/boilerplate-react-buildless/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
battery: { type: 'battery' },
memory: { type: 'memory' },
weather: { type: 'weather' },
media: { type: 'media' },
});

createRoot(document.getElementById('root')).render(<App />);
Expand All @@ -49,6 +50,10 @@

return (
<div className="app">
<div class="chip">
Media: {output.media?.session?.title} -
{output.media?.session?.artist}
</div>
<div className="chip">CPU usage: {output.cpu?.usage}</div>
<div className="chip">
Battery charge: {output.battery?.chargePercent}
Expand Down
10 changes: 10 additions & 0 deletions examples/boilerplate-solid-ts/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ import * as zebar from 'zebar';
import { createSignal, createEffect } from 'solid-js';

const providers = zebar.createProviderGroup({
audio: { type: 'audio' },
cpu: { type: 'cpu' },
focusedWindow: { type: 'focusedWindow' },
battery: { type: 'battery' },
memory: { type: 'memory' },
weather: { type: 'weather' },
media: { type: 'media' },
});

render(() => <App />, document.getElementById('root')!);
Expand Down Expand Up @@ -55,6 +57,14 @@ function App() {

return (
<div class="app">
<div class="chip">
{output.audio?.defaultPlaybackDevice?.name} -
{output.audio?.defaultPlaybackDevice?.volume}
</div>
<div class="chip">
Media: {output.media?.session?.title} -
{output.media?.session?.artist}
</div>
<div class="chip">CPU usage: {output.cpu?.usage}</div>
{iconUrl() && (
<img height="20" width="20" src={iconUrl()!} alt="icon" />
Expand Down
5 changes: 5 additions & 0 deletions examples/starter/with-glazewm.html
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@
<button
className="binding-mode"
key={bindingMode.name}
onClick={() =>
output.glazewm.runCommand(
`wm-disable-binding-mode --name ${bindingMode.name}`,
)
}
>
{bindingMode.displayName ?? bindingMode.name}
</button>
Expand Down
5 changes: 5 additions & 0 deletions packages/client-api/src/config/dock-config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export type DockConfig = {
enabled: boolean;
edge: 'top' | 'bottom' | 'left' | 'right' | null;
windowMargin: string;
};
1 change: 1 addition & 0 deletions packages/client-api/src/config/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from './monitor-selection';
export * from './dock-config';
export * from './widget-config';
export * from './widget-placement';
export * from './widget-preset';
2 changes: 2 additions & 0 deletions packages/client-api/src/config/widget-placement.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { MonitorSelection } from './monitor-selection';
import type { DockConfig } from './dock-config';

export type WidgetPlacement = {
anchor:
Expand All @@ -14,4 +15,5 @@ export type WidgetPlacement = {
width: string;
height: string;
monitorSelection: MonitorSelection;
dockToEdge: DockConfig;
};
19 changes: 19 additions & 0 deletions packages/client-api/src/providers/audio/audio-provider-types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import type { Provider } from '../create-base-provider';

export interface AudioProviderConfig {
type: 'audio';
}

export type AudioProvider = Provider<AudioProviderConfig, AudioOutput>;

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

export interface AudioDevice {
deviceId: string;
name: string;
volume: number;
isDefault: boolean;
}
29 changes: 29 additions & 0 deletions packages/client-api/src/providers/audio/create-audio-provider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { z } from 'zod';

import { createBaseProvider } from '../create-base-provider';
import { onProviderEmit } from '~/desktop';
import type {
AudioOutput,
AudioProvider,
AudioProviderConfig,
} from './audio-provider-types';

const audioProviderConfigSchema = z.object({
type: z.literal('audio'),
});

export function createAudioProvider(
config: AudioProviderConfig,
): AudioProvider {
const mergedConfig = audioProviderConfigSchema.parse(config);

return createBaseProvider(mergedConfig, async queue => {
return onProviderEmit<AudioOutput>(mergedConfig, ({ result }) => {
if ('error' in result) {
queue.error(result.error);
} else {
queue.output(result.output);
}
});
});
}
Loading

0 comments on commit ed96141

Please sign in to comment.