mirror of
https://github.com/KRTirtho/spotube.git
synced 2025-09-13 07:55:18 +00:00
feat(android): disable battery optimization for better playback
This commit is contained in:
parent
4077fac39f
commit
fe5b429dda
47
lib/hooks/use_disable_battery_optimizations.dart
Normal file
47
lib/hooks/use_disable_battery_optimizations.dart
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
import 'package:disable_battery_optimization/disable_battery_optimization.dart';
|
||||||
|
import 'package:flutter_desktop_tools/flutter_desktop_tools.dart';
|
||||||
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
import 'package:spotube/hooks/use_async_effect.dart';
|
||||||
|
|
||||||
|
bool _asked = false;
|
||||||
|
void useDisableBatterOptimizations() {
|
||||||
|
useAsyncEffect(() async {
|
||||||
|
if (!DesktopTools.platform.isAndroid || _asked) return;
|
||||||
|
final localStorage = await SharedPreferences.getInstance();
|
||||||
|
|
||||||
|
final rawIsBatteryOptimizationDisabled =
|
||||||
|
localStorage.getBool("isBatteryOptimizationDisabled");
|
||||||
|
final isBatteryOptimizationDisabled =
|
||||||
|
await DisableBatteryOptimization.isBatteryOptimizationDisabled;
|
||||||
|
if (rawIsBatteryOptimizationDisabled != false &&
|
||||||
|
isBatteryOptimizationDisabled == false) {
|
||||||
|
final hasDisabled = await DisableBatteryOptimization
|
||||||
|
.showDisableBatteryOptimizationSettings();
|
||||||
|
|
||||||
|
localStorage.setBool(
|
||||||
|
"isBatteryOptimizationDisabled",
|
||||||
|
hasDisabled == true,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
final rawIsManBatteryOptimizationDisabled =
|
||||||
|
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, []);
|
||||||
|
}
|
@ -19,6 +19,7 @@ import 'package:shared_preferences/shared_preferences.dart';
|
|||||||
import 'package:spotube/collections/env.dart';
|
import 'package:spotube/collections/env.dart';
|
||||||
import 'package:spotube/collections/routes.dart';
|
import 'package:spotube/collections/routes.dart';
|
||||||
import 'package:spotube/collections/intents.dart';
|
import 'package:spotube/collections/intents.dart';
|
||||||
|
import 'package:spotube/hooks/use_disable_battery_optimizations.dart';
|
||||||
import 'package:spotube/l10n/l10n.dart';
|
import 'package:spotube/l10n/l10n.dart';
|
||||||
import 'package:spotube/models/logger.dart';
|
import 'package:spotube/models/logger.dart';
|
||||||
import 'package:spotube/models/matched_track.dart';
|
import 'package:spotube/models/matched_track.dart';
|
||||||
@ -189,6 +190,8 @@ class SpotubeState extends ConsumerState<Spotube> {
|
|||||||
};
|
};
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
useDisableBatterOptimizations();
|
||||||
|
|
||||||
final lightTheme = useMemoized(
|
final lightTheme = useMemoized(
|
||||||
() => theme(paletteColor ?? accentMaterialColor, Brightness.light),
|
() => theme(paletteColor ?? accentMaterialColor, Brightness.light),
|
||||||
[paletteColor, accentMaterialColor],
|
[paletteColor, accentMaterialColor],
|
||||||
|
32
pubspec.lock
32
pubspec.lock
@ -161,14 +161,6 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "7.4.0"
|
version: "7.4.0"
|
||||||
badges:
|
|
||||||
dependency: "direct main"
|
|
||||||
description:
|
|
||||||
name: badges
|
|
||||||
sha256: "727580d938b7a1ff47ea42df730d581415606b4224cfa708671c10287f8d3fe6"
|
|
||||||
url: "https://pub.dev"
|
|
||||||
source: hosted
|
|
||||||
version: "2.0.3"
|
|
||||||
boolean_selector:
|
boolean_selector:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -466,6 +458,14 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "5.1.2"
|
version: "5.1.2"
|
||||||
|
disable_battery_optimization:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: disable_battery_optimization
|
||||||
|
sha256: b3441975ab2a3ab0c19ed78e909a88d245ce689d43d17f9b23582b1ed41c047b
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "1.1.0+1"
|
||||||
dots_indicator:
|
dots_indicator:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -1439,14 +1439,6 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.22.0"
|
version: "2.22.0"
|
||||||
queue:
|
|
||||||
dependency: "direct main"
|
|
||||||
description:
|
|
||||||
name: queue
|
|
||||||
sha256: "9a41ecadc15db79010108c06eae229a45c56b18db699760f34e8c9ac9b831ff9"
|
|
||||||
url: "https://pub.dev"
|
|
||||||
source: hosted
|
|
||||||
version: "3.1.0+2"
|
|
||||||
quiver:
|
quiver:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -1631,14 +1623,6 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.0.1"
|
version: "1.0.1"
|
||||||
simple_circular_progress_bar:
|
|
||||||
dependency: "direct main"
|
|
||||||
description:
|
|
||||||
name: simple_circular_progress_bar
|
|
||||||
sha256: e661ca942fbc617298e975b41fde19003d995de73ca6c2a1526c54d52f07151b
|
|
||||||
url: "https://pub.dev"
|
|
||||||
source: hosted
|
|
||||||
version: "1.0.2"
|
|
||||||
skeleton_text:
|
skeleton_text:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
|
@ -15,7 +15,6 @@ dependencies:
|
|||||||
audio_service: ^0.18.9
|
audio_service: ^0.18.9
|
||||||
audio_session: ^0.1.13
|
audio_session: ^0.1.13
|
||||||
auto_size_text: ^3.0.0
|
auto_size_text: ^3.0.0
|
||||||
badges: ^2.0.3
|
|
||||||
buttons_tabbar: ^1.3.6
|
buttons_tabbar: ^1.3.6
|
||||||
cached_network_image: ^3.2.2
|
cached_network_image: ^3.2.2
|
||||||
catcher:
|
catcher:
|
||||||
@ -70,11 +69,9 @@ dependencies:
|
|||||||
path_provider: ^2.0.8
|
path_provider: ^2.0.8
|
||||||
permission_handler: ^10.2.0
|
permission_handler: ^10.2.0
|
||||||
popover: ^0.2.6+3
|
popover: ^0.2.6+3
|
||||||
queue: ^3.1.0+1
|
|
||||||
scroll_to_index: ^3.0.1
|
scroll_to_index: ^3.0.1
|
||||||
shared_preferences: ^2.0.11
|
shared_preferences: ^2.0.11
|
||||||
sidebarx: ^0.15.0
|
sidebarx: ^0.15.0
|
||||||
simple_circular_progress_bar: ^1.0.2
|
|
||||||
skeleton_text: ^3.0.0
|
skeleton_text: ^3.0.0
|
||||||
smtc_windows:
|
smtc_windows:
|
||||||
git:
|
git:
|
||||||
@ -104,6 +101,7 @@ dependencies:
|
|||||||
dbus: ^0.7.8
|
dbus: ^0.7.8
|
||||||
background_downloader: ^7.4.0
|
background_downloader: ^7.4.0
|
||||||
duration: ^3.0.12
|
duration: ^3.0.12
|
||||||
|
disable_battery_optimization: ^1.1.0+1
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
build_runner: ^2.3.2
|
build_runner: ^2.3.2
|
||||||
|
Loading…
Reference in New Issue
Block a user