Skip to content

Commit

Permalink
fix: disabling battery savings takes some extra time in certain phones
Browse files Browse the repository at this point in the history
  • Loading branch information
agonper committed Apr 5, 2022
1 parent 72dac57 commit 3e2265b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
Empty file modified publish/publish.sh
100644 → 100755
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,7 @@ export function waitForActivityResume(): Promise<void> {
);
});
}

export function fireInMs(ms: number): Promise<void> {
return new Promise<void>((resolve) => setTimeout(resolve, ms));
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { Application, Utils } from "@nativescript/core";
import { createSavingsDeactivationIntent } from "../intents.android";
import { Logger, getLogger } from "../../../../../utils/logger";
import { waitForActivityResume } from "./perm-request-common";
import { fireInMs, waitForActivityResume } from "./perm-request-common";

const MS_TO_UPDATE = 1000;

export class PowerSavingsManager {
private logger: Logger;
Expand Down Expand Up @@ -48,6 +50,9 @@ export class PowerSavingsManager {

await activityResume;

// In certain phones the savings update is not immediate
await fireInMs(MS_TO_UPDATE);

if (!this.areDisabled()) {
throw new Error(
"Disabling battery optimizations is required for the app to work as expected!"
Expand Down

0 comments on commit 3e2265b

Please sign in to comment.