mirror of
https://github.com/KRTirtho/spotube.git
synced 2025-09-13 07:55:18 +00:00
fix(android): only ask battery optimization once #1252
This commit is contained in:
parent
a248a4b48c
commit
e516afb185
@ -1,47 +1,21 @@
|
|||||||
import 'package:disable_battery_optimization/disable_battery_optimization.dart';
|
import 'package:disable_battery_optimization/disable_battery_optimization.dart';
|
||||||
import 'package:flutter_desktop_tools/flutter_desktop_tools.dart';
|
import 'package:flutter_desktop_tools/flutter_desktop_tools.dart';
|
||||||
import 'package:shared_preferences/shared_preferences.dart';
|
|
||||||
import 'package:spotube/hooks/utils/use_async_effect.dart';
|
import 'package:spotube/hooks/utils/use_async_effect.dart';
|
||||||
|
import 'package:spotube/services/kv_store/kv_store.dart';
|
||||||
|
|
||||||
bool _asked = false;
|
|
||||||
void useDisableBatteryOptimizations() {
|
void useDisableBatteryOptimizations() {
|
||||||
useAsyncEffect(() async {
|
useAsyncEffect(() async {
|
||||||
if (!DesktopTools.platform.isAndroid || _asked) return;
|
if (!DesktopTools.platform.isAndroid ||
|
||||||
final localStorage = await SharedPreferences.getInstance();
|
KVStoreService.askedForBatteryOptimization) return;
|
||||||
|
|
||||||
final rawIsBatteryOptimizationDisabled =
|
await DisableBatteryOptimization.showDisableBatteryOptimizationSettings();
|
||||||
localStorage.getBool("isBatteryOptimizationDisabled");
|
|
||||||
final isBatteryOptimizationDisabled =
|
|
||||||
await DisableBatteryOptimization.isBatteryOptimizationDisabled;
|
|
||||||
if (rawIsBatteryOptimizationDisabled != false &&
|
|
||||||
isBatteryOptimizationDisabled == false) {
|
|
||||||
final hasDisabled = await DisableBatteryOptimization
|
|
||||||
.showDisableBatteryOptimizationSettings();
|
|
||||||
|
|
||||||
localStorage.setBool(
|
await DisableBatteryOptimization
|
||||||
"isBatteryOptimizationDisabled",
|
.showDisableManufacturerBatteryOptimizationSettings(
|
||||||
hasDisabled == true,
|
"Your device has additional battery optimization",
|
||||||
);
|
"Follow the steps and disable the optimizations to allow smooth functioning of this app",
|
||||||
}
|
);
|
||||||
|
|
||||||
final rawIsManBatteryOptimizationDisabled =
|
await KVStoreService.setAskedForBatteryOptimization(true);
|
||||||
localStorage.getBool("isManufacturerBatteryOptimizationDisabled");
|
|
||||||
final isManBatteryOptimizationDisabled = await DisableBatteryOptimization
|
|
||||||
.isManufacturerBatteryOptimizationDisabled;
|
|
||||||
|
|
||||||
if (rawIsManBatteryOptimizationDisabled != false &&
|
|
||||||
isManBatteryOptimizationDisabled == false) {
|
|
||||||
final hasDisabled = await DisableBatteryOptimization
|
|
||||||
.showDisableManufacturerBatteryOptimizationSettings(
|
|
||||||
"Your device has additional battery optimization",
|
|
||||||
"Follow the steps and disable the optimizations to allow smooth functioning of this app",
|
|
||||||
);
|
|
||||||
|
|
||||||
localStorage.setBool(
|
|
||||||
"isManufacturerBatteryOptimizationDisabled",
|
|
||||||
hasDisabled == true,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
_asked = true;
|
|
||||||
}, null, []);
|
}, null, []);
|
||||||
}
|
}
|
||||||
|
@ -12,4 +12,9 @@ abstract class KVStoreService {
|
|||||||
sharedPreferences.getBool('doneGettingStarted') ?? false;
|
sharedPreferences.getBool('doneGettingStarted') ?? false;
|
||||||
static Future<void> setDoneGettingStarted(bool value) async =>
|
static Future<void> setDoneGettingStarted(bool value) async =>
|
||||||
await sharedPreferences.setBool('doneGettingStarted', value);
|
await sharedPreferences.setBool('doneGettingStarted', value);
|
||||||
|
|
||||||
|
static bool get askedForBatteryOptimization =>
|
||||||
|
sharedPreferences.getBool('askedForBatteryOptimization') ?? false;
|
||||||
|
static Future<void> setAskedForBatteryOptimization(bool value) async =>
|
||||||
|
await sharedPreferences.setBool('askedForBatteryOptimization', value);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user