Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: create providers for cpu, memory, host, network, and battery #9

Merged
merged 52 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
27fbbaa
simple `sysinfo` test
lars-berger Oct 29, 2023
4f5cffc
add `set_interval`
lars-berger Oct 29, 2023
4cd1e4b
move out simple hash
lars-berger Oct 29, 2023
fe705cc
wip battery provider
lars-berger Oct 29, 2023
27ed76e
wip provider init
lars-berger Oct 29, 2023
2d85e5a
wip
lars-berger Oct 29, 2023
097adf8
separate provider files
lars-berger Oct 29, 2023
72428ba
full example added to main
lars-berger Oct 29, 2023
ed37315
wip creating provider scheduler
lars-berger Oct 29, 2023
affad8a
init provider_scheduler
lars-berger Oct 29, 2023
d0b9bf2
feat: successfully start tokio interval from fe invoke
lars-berger Oct 29, 2023
349b845
some progress
lars-berger Oct 29, 2023
ce36b31
feat: progress with channels
lars-berger Oct 30, 2023
21a50a6
feat: somewhat working but need to emit
lars-berger Oct 30, 2023
8691b83
working!!
lars-berger Oct 30, 2023
0712e9a
feat: progress on creating cpu provider
lars-berger Nov 1, 2023
3722b62
refactor: rename provider scheduler -> manager
lars-berger Nov 1, 2023
4903890
feat: move cpu provider logic
lars-berger Nov 1, 2023
4b7f93f
feat: create network provider
lars-berger Nov 1, 2023
e0c6a73
feat: run both providers at once
lars-berger Nov 1, 2023
34286b9
async traits
lars-berger Nov 2, 2023
d3f28ca
wip
lars-berger Nov 2, 2023
e7f9ad3
feat: change `start` / `stop` to not take a mutable reference
lars-berger Nov 2, 2023
f257e70
feat: move out fns for creating channels
lars-berger Nov 2, 2023
830900c
feat: partially implement unlistening
lars-berger Nov 2, 2023
223cb51
wip active providers
lars-berger Nov 2, 2023
7c6e41b
compiling
lars-berger Nov 2, 2023
b65d2ee
feat: create `ProviderRef` struct
lars-berger Nov 2, 2023
7422353
wip cancelling
lars-berger Nov 2, 2023
65cca12
stopping works
lars-berger Nov 2, 2023
4155df3
feat: move out `sysinfo` to shared arc; partially implement refreshing
lars-berger Nov 4, 2023
a0c33b2
wip `set_interval`
lars-berger Nov 4, 2023
66598f4
feat: pass `emit_output_tx` to `on_refresh`
lars-berger Nov 4, 2023
e161bf6
implement `on_refresh` for network
lars-berger Nov 5, 2023
e005765
wip
lars-berger Nov 5, 2023
416025c
refactor: folder structure
lars-berger Nov 5, 2023
bd92020
create `cpu` and `network` dirs
lars-berger Nov 5, 2023
e1d43e1
move out provider configs within respective dirs
lars-berger Nov 5, 2023
47ddda1
file renames
lars-berger Nov 5, 2023
dc37e39
feat: add improve comments; add `variables.rs`
lars-berger Nov 5, 2023
808f48d
feat: change providers to emit provider variables instead of string
lars-berger Nov 5, 2023
ff11c89
feat: additional cpu variabls
lars-berger Nov 5, 2023
6b5bba5
Add battery + host provider to desktop app
lars-berger Nov 8, 2023
2509e4f
feat: wip `RefreshableProvider`
lars-berger Nov 8, 2023
55925cd
wip
lars-berger Nov 8, 2023
173ea31
add interval provider
lars-berger Nov 10, 2023
a32e7a1
feat: emit options hash from provider manager
lars-berger Nov 10, 2023
2d13298
refactor
lars-berger Nov 10, 2023
25597be
fix: refreshing + stopping fully working
lars-berger Nov 11, 2023
e03f233
working battery provider
lars-berger Nov 11, 2023
98b909e
feat: add host provider
lars-berger Nov 13, 2023
090ae96
feat: add `isLoading` state to tauri providers
lars-berger Nov 13, 2023
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
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"rust-analyzer.linkedProjects": ["packages/desktop/Cargo.toml"],
"cssModules.camelCase": true
"cssModules.camelCase": true,
"rust-analyzer.showUnlinkedFileNotification": false
}
31 changes: 30 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,23 @@ Zebar is a way to create customizable and cross-platform taskbars, desktop widge

## Contributing

To set up the project:
Zebar uses the Tauri desktop framework and requires Node.js + Rust.

### Installing Rust

[`rustup`](https://rustup.rs/) is the recommended way to set up the Rust toolchain. It can be installed via:

```shell
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
```

### Installing Node.js

Install Node.js via [NVM](https://github.com/nvm-sh/nvm#installing-and-updating) (recommended for easily switching between Node.js versions) or the [official download](https://nodejs.org/en/download).

### Development

To start the project in development mode:

```shell
# Install pnpm (package manager) if not already installed.
Expand All @@ -16,3 +32,16 @@ pnpm i
# Start in development mode.
pnpm dev
```

## Providers

### Battery

### Host

- `hostname` -
- `os_name` - Name of the operating system. This is 'Darwin' on MacOS, 'Windows' on Windows, or the Linux distro name retrieved from either `/etc/os-release` or `/etc/lsb-release` (eg. 'Debian GNU/Linux' on Debian).
- `os_version` - Operating system version. This is the version number on MacOS (eg. '13.2.1'), the major version + build number on Windows (eg. '11 22000'), or the Linux distro version retrieved from either `/etc/os-release` or `/etc/lsb-release` (eg. '9' on Debian 9).
- `friendly_os_version` - Friendly name of operating system version (eg. 'MacOS 13.2.1', 'Windows 10 Pro', 'Linux Debian GNU/Linux 9').
- `boot_time` - Time when the system booted since UNIX epoch in milliseconds (eg. `1699452379304`).
- `uptime` - Time in milliseconds since boot.
2 changes: 1 addition & 1 deletion packages/client-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"prepublishOnly": "npm run build"
},
"dependencies": {
"@tauri-apps/api": "1.4.0",
"@tauri-apps/api": "1.5.1",
"axios": "1.4.0",
"glazewm": "1.1.1",
"solid-js": "1.8.4",
Expand Down
4 changes: 0 additions & 4 deletions packages/client-api/src/context/create-context-function.ts

This file was deleted.

4 changes: 0 additions & 4 deletions packages/client-api/src/context/create-context-variable.ts

This file was deleted.

2 changes: 0 additions & 2 deletions packages/client-api/src/context/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
export * from './create-context-function';
export * from './create-context-store';
export * from './create-context-variable';
export * from './shared/element-context.model';
export * from './shared/element-type.model';
export * from './providers';
Original file line number Diff line number Diff line change
@@ -1,17 +1,83 @@
import { createEffect } from 'solid-js';
import { createStore } from 'solid-js/store';

import { listenProvider, onProviderEmit, unlistenProvider } from '~/desktop';
import {
BatteryProviderOptions,
BatteryProviderOptionsSchema,
} from '~/user-config';
import { memoize } from '~/utils';
import { memoize, simpleHash } from '~/utils';

const DEFAULT = BatteryProviderOptionsSchema.parse({});

export interface BatteryVariables {
isLoading: boolean;
chargePercent: number;
cycleCount: number;
healthPercent: number;
powerConsumption: number;
state: 'discharging' | 'charging';
timeTillEmpty: number | null;
timeTillFull: number | null;
voltage: number | null;
}

export const createBatteryProvider = memoize(
(options: BatteryProviderOptions = DEFAULT) => {
const [batteryVariables, setBatteryVariables] =
createStore<BatteryVariables>({
isLoading: true,
chargePercent: 0,
cycleCount: 0,
healthPercent: 0,
powerConsumption: 0,
state: 'discharging',
timeTillEmpty: null,
timeTillFull: null,
voltage: null,
});

createEffect(async () => {
const optionsHash = simpleHash(options);

onProviderEmit<BatteryVariables>(optionsHash, payload =>
setBatteryVariables({ ...payload, isLoading: false }),
);

await listenProvider({
optionsHash,
options,
trackedAccess: [],
});

return () => unlistenProvider(optionsHash);
});

return {
percent: '',
is_charging: true,
has_battery: true,
get chargePercent() {
return batteryVariables.chargePercent;
},
get cycleCount() {
return batteryVariables.cycleCount;
},
get healthPercent() {
return batteryVariables.healthPercent;
},
get powerConsumption() {
return batteryVariables.powerConsumption;
},
get state() {
return batteryVariables.state;
},
get timeTillEmpty() {
return batteryVariables.timeTillEmpty;
},
get timeTillFull() {
return batteryVariables.timeTillFull;
},
get voltage() {
return batteryVariables.voltage;
},
};
},
);
Original file line number Diff line number Diff line change
@@ -1,14 +1,64 @@
import { createEffect } from 'solid-js';
import { createStore } from 'solid-js/store';

import { onProviderEmit, listenProvider, unlistenProvider } from '~/desktop';
import { CpuProviderOptions, CpuProviderOptionsSchema } from '~/user-config';
import { memoize } from '~/utils';
import { memoize, simpleHash } from '~/utils';

const DEFAULT = CpuProviderOptionsSchema.parse({});

export interface CpuVariables {
isLoading: boolean;
frequency: number;
usage: number;
logicalCoreCount: number;
physicalCoreCount: number;
vendor: string;
}

export const createCpuProvider = memoize(
(options: CpuProviderOptions = DEFAULT) => {
return {
usage: 0,
temp: 0,
const [cpuVariables, setCpuVariables] = createStore<CpuVariables>({
isLoading: true,
frequency: 0,
usage: 0,
logicalCoreCount: 0,
physicalCoreCount: 0,
vendor: '',
});

createEffect(async () => {
const optionsHash = simpleHash(options);

onProviderEmit<CpuVariables>(optionsHash, payload =>
setCpuVariables({ ...payload, isLoading: false }),
);

await listenProvider({
optionsHash,
options,
trackedAccess: [],
});

return () => unlistenProvider(optionsHash);
});

return {
get frequency() {
return cpuVariables.frequency;
},
get usage() {
return cpuVariables.usage;
},
get logicalCoreCount() {
return cpuVariables.logicalCoreCount;
},
get physicalCoreCount() {
return cpuVariables.physicalCoreCount;
},
get vendor() {
return cpuVariables.vendor;
},
};
},
);
3 changes: 3 additions & 0 deletions packages/client-api/src/context/providers/create-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { createBatteryProvider } from './battery/create-battery-provider';
import { createCpuProvider } from './cpu/create-cpu-provider';
import { createDateTimeProvider } from './date-time/create-date-time-provider';
import { createGlazewmProvider } from './glazewm/create-glazewm-provider';
import { createHostProvider } from './host/create-host-provider';
import { createIpProvider } from './ip/create-ip-provider';
import { createMemoryProvider } from './memory/create-memory-provider';
import { createNetworkProvider } from './network/create-network-provider';
Expand All @@ -23,6 +24,8 @@ export const createProvider = memoize((config: ProviderConfig) => {
return createDateTimeProvider(config);
case 'glazewm':
return createGlazewmProvider(config);
case 'host':
return createHostProvider(config);
case 'ip':
return createIpProvider(config);
case 'memory':
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { createEffect } from 'solid-js';
import { createStore } from 'solid-js/store';

import { onProviderEmit, listenProvider, unlistenProvider } from '~/desktop';
import { HostProviderOptions, HostProviderOptionsSchema } from '~/user-config';
import { memoize, simpleHash } from '~/utils';

const DEFAULT = HostProviderOptionsSchema.parse({});

export interface HostVariables {
isLoading: boolean;
hostname: string | null;
osName: string | null;
osVersion: string | null;
friendlyOsVersion: string | null;
bootTime: number;
uptime: number;
}

export const createHostProvider = memoize(
(options: HostProviderOptions = DEFAULT) => {
const [hostVariables, setHostVariables] = createStore<HostVariables>({
isLoading: true,
hostname: null,
osName: null,
osVersion: null,
friendlyOsVersion: null,
bootTime: 0,
uptime: 0,
});

createEffect(async () => {
const optionsHash = simpleHash(options);

onProviderEmit<HostVariables>(optionsHash, payload =>
setHostVariables({ ...payload, isLoading: false }),
);

await listenProvider({
optionsHash,
options,
trackedAccess: [],
});

return () => unlistenProvider(optionsHash);
});

return {
get hostname() {
return hostVariables.hostname;
},
get osName() {
return hostVariables.osName;
},
get osVersion() {
return hostVariables.osVersion;
},
get friendlyOsVersion() {
return hostVariables.friendlyOsVersion;
},
get bootTime() {
return hostVariables.bootTime;
},
get uptime() {
return hostVariables.uptime;
},
};
},
);
Loading