feat(core): bettery save mode (#12996)

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **New Features**
* Introduced a battery save mode that can pause background sync and
processing to conserve energy.
* Battery save mode is automatically enabled when the app window loses
focus and disabled when the window regains focus or is interacted with.
  * Available in both web and desktop (Electron) versions.

* **Improvements**
* Added user activity detection to optimize background operations for
better battery efficiency.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
EYHN
2025-07-03 11:48:17 +08:00
committed by GitHub
parent 2ae3c3e2cd
commit b2bf591463
6 changed files with 102 additions and 0 deletions
@@ -86,6 +86,21 @@ export class StoreManagerClient {
connection.dispose();
});
}
enableBatterySaveMode() {
this.connections.forEach(connection => {
connection.store.enableBatterySaveMode().catch(err => {
console.error('error enabling battery save mode', err);
});
});
}
disableBatterySaveMode() {
this.connections.forEach(connection => {
connection.store.disableBatterySaveMode().catch(err => {
console.error('error disabling battery save mode', err);
});
});
}
}
export class StoreClient {
@@ -113,6 +128,13 @@ export class StoreClient {
readonly blobFrontend: BlobFrontend;
readonly awarenessFrontend: AwarenessFrontend;
readonly indexerFrontend: IndexerFrontend;
enableBatterySaveMode(): Promise<void> {
return this.client.call('sync.enableBatterySaveMode');
}
disableBatterySaveMode(): Promise<void> {
return this.client.call('sync.disableBatterySaveMode');
}
}
class WorkerDocStorage implements DocStorage {