-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: create providers for
cpu
, memory
, host
, network
, and `b…
…attery` (#9)
- Loading branch information
1 parent
fa436cd
commit 7e0ed55
Showing
61 changed files
with
1,784 additions
and
333 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
74 changes: 70 additions & 4 deletions
74
packages/client-api/src/context/providers/battery/create-battery-provider.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}, | ||
}; | ||
}, | ||
); |
58 changes: 54 additions & 4 deletions
58
packages/client-api/src/context/providers/cpu/create-cpu-provider.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}, | ||
}; | ||
}, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
packages/client-api/src/context/providers/host/create-host-provider.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}, | ||
}; | ||
}, | ||
); |
Oops, something went wrong.