forked from Blendman974/faceclaw
Optimize phone CPU usage
This commit is contained in:
1 parent
449cb0bf73
commit
45d2ece0d2
19 files changed
+485
-103
No files matched your search
@@ -14,8 +14,9 @@ export type PersistedOpenApps = {
|
||||
|
||||
const STATE_VERSION = 1;
|
||||
const FILE_NAME = "open-apps.json";
|
||||
// Coalesces bursts (restore, sidebar scrolling) into one write; short enough
|
||||
// that a build-reinstall kill right after a change rarely loses it.
|
||||
// Coalesces bursts (restore, sidebar scrolling) into one write once they
|
||||
// settle; short enough that a build-reinstall kill right after a change
|
||||
// rarely loses it.
|
||||
const WRITE_DELAY_MS = 1000;
|
||||
|
||||
function openAppsFilePath(): string {
|
||||
@@ -50,7 +51,10 @@ let pendingState: PersistedOpenApps | null = null;
|
||||
/** Save the open-app state (debounced; the latest state wins). */
|
||||
export function savePersistedOpenApps(state: PersistedOpenApps): void {
|
||||
pendingState = state;
|
||||
if (writeTimer !== null) return;
|
||||
// Restarted on every change: scrolling through the switcher changes the
|
||||
// foreground app a few times a second, and each synchronous write costs
|
||||
// several milliseconds of main thread.
|
||||
if (writeTimer !== null) clearTimeout(writeTimer);
|
||||
writeTimer = setTimeout(() => {
|
||||
writeTimer = null;
|
||||
const state = pendingState;
|
||||
|
||||
Reference in new issue
Block a user