2023-01-11 01:54:33 +00:00
|
|
|
import {init_usdpl, target_usdpl, init_embedded, call_backend, init_tr} from "usdpl-front";
|
2022-08-23 22:50:46 +01:00
|
|
|
|
|
|
|
const USDPL_PORT: number = 44443;
|
|
|
|
|
|
|
|
// Utility
|
|
|
|
|
2022-11-13 17:41:45 +00:00
|
|
|
export function resolve<T>(promise: Promise<T>, setter: (t: T) => void) {
|
2022-08-23 22:50:46 +01:00
|
|
|
(async function () {
|
|
|
|
let data = await promise;
|
|
|
|
if (data != null) {
|
|
|
|
console.debug("Got resolved", data);
|
|
|
|
setter(data);
|
|
|
|
} else {
|
2023-01-21 23:15:26 +00:00
|
|
|
console.warn("Resolve failed:", data, promise);
|
|
|
|
log(LogLevel.Warn, "A resolve failed");
|
2022-08-23 22:50:46 +01:00
|
|
|
}
|
|
|
|
})();
|
|
|
|
}
|
|
|
|
|
2023-01-21 23:15:26 +00:00
|
|
|
export function resolve_nullable<T>(promise: Promise<T | null>, setter: (t: T | null) => void) {
|
|
|
|
(async function () {
|
|
|
|
let data = await promise;
|
|
|
|
console.debug("Got resolved", data);
|
|
|
|
setter(data);
|
|
|
|
})();
|
|
|
|
}
|
|
|
|
|
2022-08-23 22:50:46 +01:00
|
|
|
export async function initBackend() {
|
|
|
|
// init usdpl
|
|
|
|
await init_embedded();
|
|
|
|
init_usdpl(USDPL_PORT);
|
2023-02-24 01:55:12 +00:00
|
|
|
console.log("POWERTOOLS: USDPL started for framework: " + target_usdpl());
|
2023-01-11 01:54:33 +00:00
|
|
|
const user_locale =
|
|
|
|
navigator.languages && navigator.languages.length
|
|
|
|
? navigator.languages[0]
|
|
|
|
: navigator.language;
|
|
|
|
console.log("POWERTOOLS: locale", user_locale);
|
2023-02-22 02:28:59 +00:00
|
|
|
//let mo_path = "../plugins/PowerTools/translations/" + user_locale.toString() + ".mo";
|
|
|
|
await init_tr(user_locale);
|
2023-01-11 01:54:33 +00:00
|
|
|
//await init_tr("../plugins/PowerTools/translations/test.mo");
|
2022-08-23 22:50:46 +01:00
|
|
|
//setReady(true);
|
|
|
|
}
|
|
|
|
|
2023-02-04 21:19:00 +00:00
|
|
|
export type IdcProps = {
|
|
|
|
idc: any;
|
|
|
|
}
|
|
|
|
|
2022-11-19 20:21:09 +00:00
|
|
|
// API limit types
|
|
|
|
|
|
|
|
export type RangeLimit = {
|
|
|
|
min: number;
|
|
|
|
max: number;
|
|
|
|
};
|
|
|
|
|
|
|
|
export type SettingsLimits = {
|
|
|
|
battery: BatteryLimits;
|
|
|
|
cpu: CpusLimits;
|
|
|
|
gpu: GpuLimits;
|
|
|
|
general: GeneralLimits;
|
|
|
|
};
|
|
|
|
|
|
|
|
export type BatteryLimits = {
|
2022-11-21 22:00:43 +00:00
|
|
|
charge_current: RangeLimit | null;
|
|
|
|
charge_current_step: number;
|
2022-11-22 01:58:35 +00:00
|
|
|
charge_modes: string[];
|
2023-03-26 15:49:17 +01:00
|
|
|
charge_limit: RangeLimit | null;
|
|
|
|
charge_limit_step: number;
|
2022-11-19 20:21:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export type CpuLimits = {
|
|
|
|
clock_min_limits: RangeLimit | null;
|
|
|
|
clock_max_limits: RangeLimit | null;
|
|
|
|
clock_step: number;
|
|
|
|
governors: string[];
|
|
|
|
};
|
|
|
|
|
|
|
|
export type CpusLimits = {
|
|
|
|
cpus: CpuLimits[];
|
|
|
|
count: number;
|
|
|
|
smt_capable: boolean;
|
2023-02-03 01:20:16 +00:00
|
|
|
governors: string[];
|
2022-11-19 20:21:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export type GeneralLimits = {};
|
|
|
|
|
|
|
|
export type GpuLimits = {
|
|
|
|
fast_ppt_limits: RangeLimit | null;
|
2024-02-17 14:37:10 +00:00
|
|
|
fast_ppt_default: number;
|
2022-11-19 20:21:09 +00:00
|
|
|
slow_ppt_limits: RangeLimit | null;
|
2024-02-17 14:37:10 +00:00
|
|
|
slow_ppt_default: number;
|
2022-11-19 20:21:09 +00:00
|
|
|
ppt_step: number;
|
|
|
|
clock_min_limits: RangeLimit | null;
|
|
|
|
clock_max_limits: RangeLimit | null;
|
|
|
|
clock_step: number;
|
2024-01-27 23:44:43 +00:00
|
|
|
memory_control: RangeLimit | null,
|
|
|
|
memory_step: number,
|
2022-11-19 20:21:09 +00:00
|
|
|
};
|
|
|
|
|
2022-08-23 22:50:46 +01:00
|
|
|
// API
|
|
|
|
|
2022-09-01 01:18:15 +01:00
|
|
|
export async function getInfo(): Promise<string> {
|
|
|
|
return (await call_backend("V_INFO", []))[0];
|
|
|
|
}
|
|
|
|
|
2022-08-23 22:50:46 +01:00
|
|
|
// Battery
|
|
|
|
|
|
|
|
export async function getBatteryCurrent(): Promise<number> {
|
|
|
|
return (await call_backend("BATTERY_current_now", []))[0];
|
|
|
|
}
|
|
|
|
|
2022-09-05 22:02:02 +01:00
|
|
|
export async function getBatteryChargeNow(): Promise<number> {
|
|
|
|
return (await call_backend("BATTERY_charge_now", []))[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function getBatteryChargeFull(): Promise<number> {
|
|
|
|
return (await call_backend("BATTERY_charge_full", []))[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function getBatteryChargeDesign(): Promise<number> {
|
|
|
|
return (await call_backend("BATTERY_charge_design", []))[0];
|
|
|
|
}
|
|
|
|
|
2023-06-17 03:00:57 +01:00
|
|
|
export async function getBatteryChargePower(): Promise<number> {
|
|
|
|
return (await call_backend("BATTERY_charge_power", []))[0];
|
|
|
|
}
|
|
|
|
|
2023-01-21 23:15:26 +00:00
|
|
|
export async function getBatteryChargeRate(): Promise<number | null> {
|
2022-08-23 22:50:46 +01:00
|
|
|
return (await call_backend("BATTERY_get_charge_rate", []))[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function setBatteryChargeRate(val: number): Promise<number> {
|
|
|
|
return (await call_backend("BATTERY_set_charge_rate", [val]))[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function unsetBatteryChargeRate(): Promise<any[]> {
|
|
|
|
return await call_backend("BATTERY_unset_charge_rate", []);
|
|
|
|
}
|
|
|
|
|
2023-01-21 23:15:26 +00:00
|
|
|
export async function getBatteryChargeMode(): Promise<string | null> {
|
2022-11-21 22:00:43 +00:00
|
|
|
return (await call_backend("BATTERY_get_charge_mode", []))[0];
|
|
|
|
}
|
|
|
|
|
2022-11-22 01:58:35 +00:00
|
|
|
export async function setBatteryChargeMode(val: string): Promise<string> {
|
2022-11-21 22:00:43 +00:00
|
|
|
return (await call_backend("BATTERY_set_charge_mode", [val]))[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function unsetBatteryChargeMode(): Promise<any[]> {
|
|
|
|
return await call_backend("BATTERY_unset_charge_mode", []);
|
|
|
|
}
|
|
|
|
|
2023-03-26 15:49:17 +01:00
|
|
|
export async function getBatteryChargeLimit(): Promise<number | null> {
|
|
|
|
return (await call_backend("BATTERY_get_charge_limit", []))[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function setBatteryChargeLimit(val: number): Promise<number> {
|
|
|
|
return (await call_backend("BATTERY_set_charge_limit", [val]))[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function unsetBatteryChargeLimit(): Promise<any[]> {
|
|
|
|
return await call_backend("BATTERY_unset_charge_limit", []);
|
|
|
|
}
|
|
|
|
|
2022-08-23 22:50:46 +01:00
|
|
|
// CPU
|
|
|
|
|
2023-01-06 02:16:37 +00:00
|
|
|
export async function setCpuSmt(status: boolean): Promise<boolean[]> {
|
|
|
|
return await call_backend("CPU_set_smt", [status]);
|
2022-11-13 04:17:13 +00:00
|
|
|
}
|
|
|
|
|
2023-01-19 02:05:04 +00:00
|
|
|
export async function getCpuSmt(): Promise<boolean> {
|
2023-02-15 02:59:05 +00:00
|
|
|
return (await call_backend("CPU_get_smt", []))[0];
|
2023-01-19 02:05:04 +00:00
|
|
|
}
|
|
|
|
|
2022-11-19 20:21:09 +00:00
|
|
|
/*export async function getCpuCount(): Promise<number> {
|
2022-08-23 22:50:46 +01:00
|
|
|
return (await call_backend("CPU_count", []))[0];
|
2022-11-19 20:21:09 +00:00
|
|
|
}*/
|
2022-08-23 22:50:46 +01:00
|
|
|
|
|
|
|
export async function setCpuOnline(index: number, online: boolean): Promise<boolean> {
|
|
|
|
return (await call_backend("CPU_set_online", [index, online]))[0];
|
|
|
|
}
|
|
|
|
|
2022-09-06 02:36:01 +01:00
|
|
|
export async function setCpuOnlines(onlines: boolean[]): Promise<boolean[]> {
|
|
|
|
return await call_backend("CPU_set_onlines", onlines);
|
|
|
|
}
|
|
|
|
|
2022-08-23 22:50:46 +01:00
|
|
|
export async function getCpusOnline(): Promise<boolean[]> {
|
|
|
|
return (await call_backend("CPU_get_onlines", [])); // -> online status for all CPUs
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function setCpuClockLimits(index: number, min: number, max: number): Promise<number[]> {
|
|
|
|
return (await call_backend("CPU_set_clock_limits", [index, min, max])); // -> [min, max]
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function getCpuClockLimits(index: number): Promise<number[]> {
|
|
|
|
return (await call_backend("CPU_get_clock_limits", [index])); // -> [min, max]
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function unsetCpuClockLimits(index: number): Promise<any[]> {
|
|
|
|
return (await call_backend("CPU_unset_clock_limits", [index]));
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function setCpuGovernor(index: number, val: string): Promise<string> {
|
|
|
|
return (await call_backend("CPU_set_governor", [index, val]))[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function getCpusGovernor(): Promise<string[]> {
|
|
|
|
return (await call_backend("CPU_get_governors", [])); // -> governors for all CPUs
|
|
|
|
}
|
|
|
|
|
|
|
|
// GPU
|
|
|
|
|
|
|
|
export async function setGpuPpt(fast: number, slow: number): Promise<number[]> {
|
|
|
|
return (await call_backend("GPU_set_ppt", [fast, slow])); // -> [fastPPT, slowPPT]
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function getGpuPpt(): Promise<number[]> {
|
|
|
|
return (await call_backend("GPU_get_ppt", [])); // -> [fastPPT, slowPPT]
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function unsetGpuPpt(): Promise<any[]> {
|
|
|
|
return (await call_backend("GPU_unset_ppt", []));
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function setGpuClockLimits(min: number, max: number): Promise<number[]> {
|
|
|
|
return (await call_backend("GPU_set_clock_limits", [min, max])); // -> [min, max]
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function getGpuClockLimits(): Promise<number[]> {
|
|
|
|
return (await call_backend("GPU_get_clock_limits", [])); // -> [min, max]
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function unsetGpuClockLimits(): Promise<any[]> {
|
|
|
|
return (await call_backend("GPU_unset_clock_limits", []));
|
|
|
|
}
|
|
|
|
|
2024-01-27 23:44:43 +00:00
|
|
|
export async function setGpuSlowMemory(clock: number): Promise<number> {
|
|
|
|
return (await call_backend("GPU_set_slow_memory", [clock]))[0];
|
2022-08-23 22:50:46 +01:00
|
|
|
}
|
|
|
|
|
2024-03-17 20:16:04 +00:00
|
|
|
export async function getGpuSlowMemory(): Promise<number | null> {
|
2022-08-23 22:50:46 +01:00
|
|
|
return (await call_backend("GPU_get_slow_memory", []))[0];
|
|
|
|
}
|
2022-08-26 22:00:43 +01:00
|
|
|
|
2024-01-27 23:44:43 +00:00
|
|
|
export async function unsetGpuSlowMemory(): Promise<any[]> {
|
|
|
|
return (await call_backend("GPU_unset_slow_memory", []));
|
|
|
|
}
|
|
|
|
|
2022-08-26 22:00:43 +01:00
|
|
|
// general
|
|
|
|
|
|
|
|
export async function setGeneralPersistent(val: boolean): Promise<boolean> {
|
|
|
|
return (await call_backend("GENERAL_set_persistent", [val]))[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function getGeneralPersistent(): Promise<boolean> {
|
|
|
|
return (await call_backend("GENERAL_get_persistent", []))[0];
|
|
|
|
}
|
|
|
|
|
2024-01-22 01:03:04 +00:00
|
|
|
export async function loadGeneralSettings(id: string, name: string, variant_id: string, variant_name: string | undefined): Promise<boolean> {
|
2023-11-18 20:17:56 +00:00
|
|
|
if (variant_name) {
|
|
|
|
return (await call_backend("GENERAL_load_settings", [id, name, variant_id, variant_name]))[0];
|
|
|
|
} else {
|
|
|
|
return (await call_backend("GENERAL_load_settings", [id, name, variant_id]))[0];
|
|
|
|
}
|
|
|
|
|
2022-08-26 22:00:43 +01:00
|
|
|
}
|
|
|
|
|
2024-01-22 01:03:04 +00:00
|
|
|
export async function loadGeneralSettingsVariant(variant_id: string, variant_name: string | undefined): Promise<boolean> {
|
|
|
|
console.log("GENERAL_load_variant");
|
|
|
|
if (variant_name) {
|
|
|
|
return (await call_backend("GENERAL_load_variant", [variant_id, variant_name]))[0];
|
|
|
|
} else {
|
|
|
|
return (await call_backend("GENERAL_load_variant", [variant_id]))[0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-01 01:18:15 +01:00
|
|
|
export async function loadGeneralDefaultSettings(): Promise<boolean> {
|
|
|
|
return (await call_backend("GENERAL_load_default_settings", []))[0];
|
|
|
|
}
|
|
|
|
|
2022-11-13 04:17:13 +00:00
|
|
|
export async function loadGeneralSystemSettings(): Promise<boolean> {
|
|
|
|
return (await call_backend("GENERAL_load_system_settings", []))[0];
|
|
|
|
}
|
|
|
|
|
2022-11-13 17:41:45 +00:00
|
|
|
export async function getGeneralSettingsName(): Promise<string> {
|
2022-08-26 22:00:43 +01:00
|
|
|
return (await call_backend("GENERAL_get_name", []))[0];
|
|
|
|
}
|
2022-09-01 01:18:15 +01:00
|
|
|
|
2023-03-25 17:46:58 +00:00
|
|
|
export async function getGeneralSettingsPath(): Promise<string> {
|
|
|
|
return (await call_backend("GENERAL_get_path", []))[0];
|
|
|
|
}
|
|
|
|
|
2022-09-01 01:18:15 +01:00
|
|
|
export async function waitForComplete(): Promise<boolean> {
|
|
|
|
return (await call_backend("GENERAL_wait_for_unlocks", []))[0];
|
|
|
|
}
|
2022-11-19 20:21:09 +00:00
|
|
|
|
|
|
|
export async function getLimits(): Promise<SettingsLimits> {
|
|
|
|
return (await call_backend("GENERAL_get_limits", []))[0];
|
|
|
|
}
|
2022-11-21 22:00:43 +00:00
|
|
|
|
2023-01-03 02:22:53 +00:00
|
|
|
export async function getDriverProviderName(name: string): Promise<string> {
|
|
|
|
return (await call_backend("GENERAL_get_provider", [name]))[0];
|
|
|
|
}
|
|
|
|
|
2023-01-05 00:42:59 +00:00
|
|
|
export enum LogLevel {
|
|
|
|
Trace = 1,
|
|
|
|
Debug = 2,
|
|
|
|
Info = 3,
|
|
|
|
Warn = 4,
|
|
|
|
Error = 5,
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function log(level: LogLevel, msg: string): Promise<boolean> {
|
|
|
|
return (await call_backend("LOG", [level, msg]))[0];
|
|
|
|
}
|
|
|
|
|
2022-11-21 22:00:43 +00:00
|
|
|
export async function idk(): Promise<boolean> {
|
|
|
|
return (await call_backend("GENERAL_idk", []))[0];
|
|
|
|
}
|
2023-03-23 02:15:36 +00:00
|
|
|
|
|
|
|
export async function forceApplySettings(): Promise<boolean> {
|
|
|
|
return (await call_backend("GENERAL_apply_now", []))[0];
|
|
|
|
}
|
2023-03-26 15:49:17 +01:00
|
|
|
|
|
|
|
export async function onPluggedIn(): Promise<boolean> {
|
|
|
|
return (await call_backend("GENERAL_on_pluggedin", []))[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function onUnplugged(): Promise<boolean> {
|
|
|
|
return (await call_backend("GENERAL_on_unplugged", []))[0];
|
|
|
|
}
|
2023-07-04 03:00:18 +01:00
|
|
|
|
|
|
|
export type Message = {
|
|
|
|
/// Message identifier
|
|
|
|
id: number | null,
|
|
|
|
/// Message title
|
|
|
|
title: string,
|
|
|
|
/// Message content
|
|
|
|
body: string,
|
|
|
|
/// Link for further information
|
|
|
|
url: string | null,
|
|
|
|
};
|
|
|
|
|
|
|
|
export async function getMessages(since: number | null): Promise<Message[]> {
|
|
|
|
return (await call_backend("MESSAGE_get", [since]));
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function dismissMessage(id: number): Promise<boolean> {
|
|
|
|
return (await call_backend("MESSAGE_dismiss", [id]))[0];
|
|
|
|
}
|
2023-08-07 22:08:24 +01:00
|
|
|
|
|
|
|
export type Periodicals = {
|
|
|
|
battery_current: number | null,
|
|
|
|
battery_charge_now: number | null,
|
|
|
|
battery_charge_full: number | null,
|
|
|
|
battery_charge_power: number | null,
|
|
|
|
settings_path: string | null,
|
|
|
|
};
|
|
|
|
|
|
|
|
export async function getPeriodicals(): Promise<Periodicals> {
|
|
|
|
const result: any[] = await call_backend("GENERAL_get_periodicals", []);
|
|
|
|
return {
|
|
|
|
battery_current: result[0],
|
|
|
|
battery_charge_now: result[1],
|
|
|
|
battery_charge_full: result[2],
|
|
|
|
battery_charge_power: result[3],
|
|
|
|
settings_path: result[4],
|
|
|
|
};
|
|
|
|
}
|
2024-01-06 18:26:35 +00:00
|
|
|
|
|
|
|
export type StoreMetadata = {
|
|
|
|
name: string,
|
|
|
|
steam_app_id: number,
|
|
|
|
steam_user_id: number,
|
|
|
|
steam_username: string,
|
|
|
|
tags: string[],
|
|
|
|
id: string,
|
|
|
|
//config: any,
|
|
|
|
}
|
|
|
|
|
2024-03-17 21:14:44 +00:00
|
|
|
export async function searchStoreByAppId(id: string): Promise<StoreMetadata[]> {
|
|
|
|
//console.log("WEB_search_by_app");
|
2024-01-06 18:26:35 +00:00
|
|
|
return (await call_backend("WEB_search_by_app", [id]))[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
export type VariantInfo = {
|
|
|
|
id: string,
|
|
|
|
name: string,
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function storeDownloadById(id: string): Promise<VariantInfo[]> {
|
|
|
|
return (await call_backend("WEB_download_new", [id]));
|
|
|
|
}
|
|
|
|
|
2024-01-27 20:05:41 +00:00
|
|
|
export async function storeUpload(steam_id: string, steam_username: string): Promise<VariantInfo[]> {
|
|
|
|
return (await call_backend("WEB_upload_new", [steam_id, steam_username]));
|
|
|
|
}
|
|
|
|
|
2024-01-06 18:26:35 +00:00
|
|
|
export async function getAllSettingVariants(): Promise<VariantInfo[]> {
|
2024-03-17 21:14:44 +00:00
|
|
|
//console.log("GENERAL_get_all_variants");
|
2024-01-06 18:26:35 +00:00
|
|
|
return (await call_backend("GENERAL_get_all_variants", []));
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function getCurrentSettingVariant(): Promise<VariantInfo> {
|
2024-03-17 21:14:44 +00:00
|
|
|
//console.log("GENERAL_get_current_variant");
|
2024-01-06 18:26:35 +00:00
|
|
|
return (await call_backend("GENERAL_get_current_variant", []))[0];
|
|
|
|
}
|