Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2,263 changes: 1,095 additions & 1,168 deletions Cargo.lock

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ Through the `zebar` NPM package, Zebar exposes various system information via re
- [cpu](#CPU)
- [date](#Date)
- [disk](#Disk)
- [focusedWindow](#focused-window)
- [glazewm](#GlazeWM)
- [host](#Host)
- [ip](#IP)
Expand Down Expand Up @@ -210,6 +211,23 @@ No config options.
| `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

#### Config

No config options.

#### Outputs

| Variable | Description | Return type | Supported OS |
| --------------------- | ----------- | ------------- | --------------------------------------------------------------------------------------------------------------------------------- |
| `title` | Title of the current focused window. | `string` | <img src="https://github.com/glzr-io/zebar/assets/34844898/568e90c8-cd32-49a5-a17f-ab233d41f1aa" alt="microsoft icon" width="24"> |
| `icon` | Icon of the current focused window, encoded as base64 | `string` | <img src="https://github.com/glzr-io/zebar/assets/34844898/568e90c8-cd32-49a5-a17f-ab233d41f1aa" alt="microsoft icon" width="24"> |



### GlazeWM

#### Config
Expand Down
10 changes: 5 additions & 5 deletions examples/boilerplate-solid-ts/dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<title>Zebar</title>
<script type="module" crossorigin src="./assets/index-BrT0S-9W.js"></script>
<link rel="stylesheet" crossorigin href="./assets/index-krRKcsR-.css">
</head>
<body>
<p>
Boilerplate for SolidJS with TypeScript. Run <code>npm i</code> and
<code>npm run dev</code> in the <code>solid-ts</code> directory to
run this example.
</p>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
</body>
</html>
17 changes: 15 additions & 2 deletions examples/boilerplate-solid-ts/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
/* @refresh reload */
import './index.css';
import { render } from 'solid-js/web';
import { createStore } from 'solid-js/store';
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' },
Expand All @@ -18,7 +19,9 @@ render(() => <App />, document.getElementById('root')!);
function App() {
const [output, setOutput] = createStore(providers.outputMap);

providers.onOutput(outputMap => setOutput(outputMap));
providers.onOutput(outputMap => {
setOutput(outputMap);
});

return (
<div class="app">
Expand All @@ -42,6 +45,16 @@ function App() {
<button onClick={() => output.media?.togglePlayPause()}>⏯</button>
</div>
<div class="chip">CPU usage: {output.cpu?.usage}</div>
<div class="chip">
Focused window:
<img
height="20"
width="20"
src={output.focusedWindow?.iconURL}
alt="icon"
/>
{output.focusedWindow?.title}
</div>
<div class="chip">
Battery charge: {output.battery?.chargePercent}
</div>
Expand Down
9 changes: 9 additions & 0 deletions packages/client-api/src/providers/create-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ import type {
DateProviderConfig,
DateProvider,
} from './date/date-provider-types';
import { createFocusedWindowProvider } from './focused-window/create-focused-window-provider';
import type {
FocusedWindowProviderConfig,
FocusedWindowProvider,
} from './focused-window/focused-window-provider-types';
import { createGlazeWmProvider } from './glazewm/create-glazewm-provider';
import type {
GlazeWmProviderConfig,
Expand Down Expand Up @@ -71,6 +76,7 @@ export interface ProviderConfigMap {
battery: BatteryProviderConfig;
cpu: CpuProviderConfig;
date: DateProviderConfig;
focusedWindow: FocusedWindowProviderConfig;
glazewm: GlazeWmProviderConfig;
host: HostProviderConfig;
ip: IpProviderConfig;
Expand All @@ -88,6 +94,7 @@ export interface ProviderMap {
battery: BatteryProvider;
cpu: CpuProvider;
date: DateProvider;
focusedWindow: FocusedWindowProvider;
glazewm: GlazeWmProvider;
host: HostProvider;
ip: IpProvider;
Expand Down Expand Up @@ -129,6 +136,8 @@ export function createProvider<T extends ProviderConfig>(
return createCpuProvider(config) as any;
case 'date':
return createDateProvider(config) as any;
case 'focusedWindow':
return createFocusedWindowProvider(config) as any;
case 'glazewm':
return createGlazeWmProvider(config) as any;
case 'host':
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { z } from 'zod';
import { createBaseProvider } from '../create-base-provider';
import { onProviderEmit } from '~/desktop';
import type {
FocusedWindowOutput,
FocusedWindowProvider,
FocusedWindowProviderConfig,
} from './focused-window-provider-types';

const focusedWindowProviderConfigSchema = z.object({
type: z.literal('focusedWindow'),
});

export function createFocusedWindowProvider(
config: FocusedWindowProviderConfig,
): FocusedWindowProvider {
const mergedConfig = focusedWindowProviderConfigSchema.parse(config);

return createBaseProvider(mergedConfig, async queue => {
return onProviderEmit<FocusedWindowOutput>(
mergedConfig,
({ result }) => {
if ('error' in result) {
queue.error(result.error);
} else {
const iconBlob = new Blob(
[new Uint8Array(result.output.iconBytes)],
{
type: 'image/png',
},
);
queue.output({
...result.output,
iconBlob,
iconURL: URL.createObjectURL(iconBlob),
});
}
},
);
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import type { Provider } from '../create-base-provider';

export interface FocusedWindowProviderConfig {
type: 'focusedWindow';
}

export interface FocusedWindowOutput {
title: string;
iconBytes: number[];
iconBlob: Blob;
iconURL: string;
}

export type FocusedWindowProvider = Provider<
FocusedWindowProviderConfig,
FocusedWindowOutput
>;
1 change: 1 addition & 0 deletions packages/client-api/src/providers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export * from './audio/audio-provider-types';
export * from './battery/battery-provider-types';
export * from './cpu/cpu-provider-types';
export * from './date/date-provider-types';
export * from './focused-window/focused-window-provider-types';
export * from './glazewm/glazewm-provider-types';
export * from './host/host-provider-types';
export * from './ip/ip-provider-types';
Expand Down
4 changes: 4 additions & 0 deletions packages/desktop/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ async-trait = "0.1"
base64 = "0.22"
clap = { version = "4", features = ["derive"] }
crossbeam = "0.8"
image = "0.25.5"
netdev = "0.24"
regex = "1"
reqwest = { version = "0.11", features = ["json"] }
Expand Down Expand Up @@ -53,6 +54,9 @@ windows = { version = "0.58", features = [
"Win32_Media",
"Win32_Media_Audio",
"Win32_Media_Audio_Endpoints",
"Win32_Storage",
"Win32_Storage_Packaging",
"Win32_Storage_Packaging_Appx",
"Win32_System_Console",
"Win32_System_SystemServices",
"Win32_UI_Input_KeyboardAndMouse",
Expand Down
Loading
Loading