Skip to content

Commit

Permalink
Reduce idle cpu workload of ahqstore_service to mere 3% at max and 0.…
Browse files Browse the repository at this point in the history
…7% at min
  • Loading branch information
ahqsoftwares committed Dec 15, 2024
1 parent f95ae18 commit 19d1233
Show file tree
Hide file tree
Showing 11 changed files with 79 additions and 38 deletions.
18 changes: 12 additions & 6 deletions src-service/src/handlers/service/windows/exe/pipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ pub fn launch() -> impl Future<Output = ()> {
async move {
start_exe_daemon().await;
loop {
write_log("[EXE]: Loop");
println!("[EXE]: Loop");

if let Ok(()) = pipe.connect().await {
unsafe { CONNECTED = true };
Expand Down Expand Up @@ -124,10 +124,17 @@ pub fn launch() -> impl Future<Output = ()> {
continue;
}

let mut count: u8 = 0;

'a: loop {
if !is_current_logged_in_user(process_id as usize) {
let _ = pipe.disconnect();
break 'a;
count += 1;

if count >= 30 {
if !is_current_logged_in_user(process_id as usize) {
let _ = pipe.disconnect();
break 'a;
}
count = 0;
}

match read_msg(pipe).await {
Expand All @@ -140,7 +147,7 @@ pub fn launch() -> impl Future<Output = ()> {
}
_ => {}
}
tokio::time::sleep(Duration::from_nanos(10)).await;
tokio::time::sleep(Duration::from_millis(10)).await;
}
}
unsafe {
Expand Down Expand Up @@ -189,7 +196,6 @@ pub async fn read_msg(pipe: &mut NamedPipeServer) -> ReadResponse {
e => {
let err = format!("{e:?}");

write_log(&err);
if &err != "Uncategorized" {
let _ = pipe.disconnect();
return ReadResponse::Disconnect;
Expand Down
2 changes: 1 addition & 1 deletion src-service/src/ipc/win32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ pub async fn launch() {
//let mut buf: Box<[u8]>;

ext += 1;
if ext >= 10 {
if ext >= 200 {
ext = 0;
let (auth, _, _) = authenticate_process(process_id as usize, false);

Expand Down
2 changes: 1 addition & 1 deletion src/app/apps/components/app_card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export default function AppCard(props: {
getResource(props.id, "0")
.then(setIcon)
.catch((e) => {
console.log(e);
console.warn(e);
setIcon("/package.png");
});
})();
Expand Down
3 changes: 0 additions & 3 deletions src/app/apps/components/app_modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,8 @@ export default function ShowModal(props: AppDataPropsModal) {

useEffect(() => {
const id = worker.listen((lib, update) => {
console.log("Get");
setUpdating(update != "UpToDate" && update != "Disabled");

console.log(installData);
const entry = lib.find((d) => d.app_id == installData);

try {
Expand Down Expand Up @@ -161,7 +159,6 @@ export default function ShowModal(props: AppDataPropsModal) {
});

return () => {
console.log("Unlistening");
worker.unlisten(id)
};
}, [installData]);
Expand Down
4 changes: 0 additions & 4 deletions src/app/developer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,11 @@ export default function Developers(props: DevProps) {
if (uid) {
const hash = await generateGHUserHash(uid).catch(() => "");

console.log("Hash ", hash);

const apps = await get_devs_apps(
hash,
);

console.log(apps);
fetchApps(apps).then((apps) => {
console.log(apps);
setPublishedApps(apps as appData[]);
});
}
Expand Down
43 changes: 29 additions & 14 deletions src/app/library/components/AppsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,37 +21,52 @@ export default function AppsList(props: Props) {
const [rawApps, setRawApps] = useState(0);

async function parseAppsData() {
const apps = await listAllApps();
if (Object.keys(apps).length === 0) {
setRawApps(1);
}
const resolvedApps = await fetchApps(Object.keys(apps));
const icons = await Promise.all(
(resolvedApps as appData[]).map((x) => getResource(x.appId, "0")),
);
try {
const apps = await listAllApps();

const appsKeys: string[] = Object.keys(apps);

const resolvedApps = await fetchApps(appsKeys) as appData[];

setIcons(icons);
setApps(resolvedApps as appData[]);
const icons = await Promise.all(
resolvedApps.map((x) => {
if (x.appId.includes("winget_app_super_unknown_")) {
return "/package.png";
} else {
return getResource(x.appId, "0");
}
}),
);

setIcons(icons);

if (Object.keys(apps).length === 0) {
setRawApps(1);
}
setApps(resolvedApps);
} catch (e) {
console.error(e);
setRawApps(2);
}
}

useEffect(() => {
parseAppsData();
const timeout = setInterval(() => parseAppsData(), 5000);
const timeout = setInterval(() => parseAppsData(), 10_000);

return () => clearInterval(timeout);
}, []);

return (
<div className="flex flex-col w-[98%] h-[100%] mx-auto">
<div className="min-h-[auto] h-[100%] min-w-[100%] pb-[1rem] text-center">
{rawApps === 1 ? (
{(rawApps === 1 || rawApps === 2) ? (
<h1
className={`my-2 w-[100%] flex flex-row text-center items-center justify-center ${
dark ? "text-slate-400" : "text-slate-700"
}`}
>
Install some apps to get the fun started{" "}
<GiPartyPopper size="1.5em" />
{rawApps === 1 ? <> Install some apps to get the fun started{" "} <GiPartyPopper size="1.5em" /></> : <>Something went wrong! ⚠️</>}
</h1>
) : apps.length === 0 ? (
<h1
Expand Down
34 changes: 31 additions & 3 deletions src/app/resources/api/fetchApps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default async function fetchApps(
if (typeof apps === "string") {
return (await resolveApps([apps]))[0];
} else if (Array.isArray(apps)) {
return await resolveApps([...apps]);
return await resolveApps(apps);
} else {
return [];
}
Expand Down Expand Up @@ -65,7 +65,10 @@ export async function fetchAuthor(uid: string) {
async function resolveApps(apps: string[]): Promise<appData[]> {
let promises: Promise<appData>[] = [];

console.log(apps.find((s) => s == undefined));
if (apps == undefined) {
return [];
}

apps.forEach((appId) => {
if (appId != undefined) {
if (cache[appId]) {
Expand All @@ -77,7 +80,32 @@ async function resolveApps(apps: string[]): Promise<appData[]> {
} else {
promises.push(
(async () => {
const app = await get_app(appId);
const app = await get_app(appId).catch((e) => {
console.warn("Failed to get app", appId, e);
return {
appDisplayName: "Unknown",
appId: `winget_app_super_unknown_${Math.random() * 2054568120}`,
authorId: "",
description: "This application has been removed or app id changed",
downloadUrls: [],
license_or_tos: "",
releaseTagName: "",
site: "",
source: "",
appShortcutName: "Unknown",
displayImages: [],
install: {
free: () => { },
},
repo: {
author: "", repo: "",
free: () => { },
},
verified: false,
resources: {},
version: "none"
} as ApplicationData;
});

const appData = {
...app,
Expand Down
5 changes: 2 additions & 3 deletions src/app/resources/core/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ appWindow.listen<string[]>("ws_resp", async ({ payload: pload }) => {
resolve(toObj);
}
if (toObj.method == "TerminateBlock" && ref_id != 0) {
console.log("Removing ", ref_id);
return false;
}

Expand All @@ -126,8 +125,8 @@ appWindow.listen<string[]>("ws_resp", async ({ payload: pload }) => {
}

} catch (e) {
console.log(pload);
console.log(e);
console.warn(pload);
console.warn(e);
}
}
});
2 changes: 1 addition & 1 deletion src/app/resources/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export function get_sha() {
sendWsRequest(WebSocketMessage.GetSha(), (val) => {
if (val.method == "SHAId") {
const sha = val.data as string;
console.log(sha);

invoke("set_commit", {
commit: sha
});
Expand Down
2 changes: 1 addition & 1 deletion src/app/resources/utilities/preferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default async function fetchPrefs(): Promise<appData> {
mkdir("database", { baseDir: BaseDirectory.AppData }).catch((e) => e);

const is_admin = await invoke<boolean>("is_an_admin").catch((e) => {
console.log(e);
console.warn(e);

return true;
});
Expand Down
2 changes: 1 addition & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ if ((window as { __TAURI_INTERNALS__?: string }).__TAURI_INTERNALS__ == null) {
document.querySelector("html")?.setAttribute("data-os", "win32");
}
setTimeout(async () => {
appWindow.setDecorations(true).catch(console.log);
appWindow.setDecorations(true).catch(console.warn);

appWindow.show();
if (!(await appWindow.isMaximized())) {
Expand Down

0 comments on commit 19d1233

Please sign in to comment.