mirror of
https://github.com/KRTirtho/spotube.git
synced 2025-12-09 08:47:31 +00:00
chore: refactor CLI stuff to separate service folder
This commit is contained in:
parent
187bdaf75c
commit
5ac971fea1
@ -4,7 +4,7 @@ import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:spotube/hooks/use_async_effect.dart';
|
||||
|
||||
bool _asked = false;
|
||||
void useDisableBatterOptimizations() {
|
||||
void useDisableBatteryOptimizations() {
|
||||
useAsyncEffect(() async {
|
||||
if (!DesktopTools.platform.isAndroid || _asked) return;
|
||||
final localStorage = await SharedPreferences.getInstance();
|
||||
|
||||
@ -14,7 +14,6 @@ import 'package:hive/hive.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:media_kit/media_kit.dart';
|
||||
import 'package:metadata_god/metadata_god.dart';
|
||||
import 'package:package_info_plus/package_info_plus.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:spotube/collections/routes.dart';
|
||||
import 'package:spotube/collections/intents.dart';
|
||||
@ -26,6 +25,7 @@ import 'package:spotube/models/skip_segment.dart';
|
||||
import 'package:spotube/provider/palette_provider.dart';
|
||||
import 'package:spotube/provider/user_preferences_provider.dart';
|
||||
import 'package:spotube/services/audio_player/audio_player.dart';
|
||||
import 'package:spotube/services/cli/cli.dart';
|
||||
import 'package:spotube/services/connectivity_adapter.dart';
|
||||
import 'package:spotube/themes/theme.dart';
|
||||
import 'package:spotube/utils/persisted_state_notifier.dart';
|
||||
@ -37,41 +37,7 @@ import 'package:flutter_native_splash/flutter_native_splash.dart';
|
||||
import 'package:flutter_displaymode/flutter_displaymode.dart';
|
||||
|
||||
Future<void> main(List<String> rawArgs) async {
|
||||
final parser = ArgParser();
|
||||
|
||||
parser.addFlag(
|
||||
'verbose',
|
||||
abbr: 'v',
|
||||
help: 'Verbose mode',
|
||||
defaultsTo: !kReleaseMode,
|
||||
callback: (verbose) {
|
||||
if (verbose) {
|
||||
logEnv['VERBOSE'] = 'true';
|
||||
logEnv['DEBUG'] = 'true';
|
||||
logEnv['ERROR'] = 'true';
|
||||
}
|
||||
},
|
||||
);
|
||||
parser.addFlag(
|
||||
"version",
|
||||
help: "Print version and exit",
|
||||
negatable: false,
|
||||
);
|
||||
|
||||
parser.addFlag("help", abbr: "h", negatable: false);
|
||||
|
||||
final arguments = parser.parse(rawArgs);
|
||||
|
||||
if (arguments["help"] == true) {
|
||||
print(parser.usage);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
if (arguments["version"] == true) {
|
||||
final package = await PackageInfo.fromPlatform();
|
||||
print("Spotube v${package.version}");
|
||||
exit(0);
|
||||
}
|
||||
final arguments = await startCLI(rawArgs);
|
||||
|
||||
final widgetsBinding = WidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
@ -215,7 +181,7 @@ class SpotubeState extends ConsumerState<Spotube> {
|
||||
};
|
||||
}, []);
|
||||
|
||||
useDisableBatterOptimizations();
|
||||
useDisableBatteryOptimizations();
|
||||
|
||||
final lightTheme = useMemoized(
|
||||
() => theme(paletteColor ?? accentMaterialColor, Brightness.light),
|
||||
|
||||
46
lib/services/cli/cli.dart
Normal file
46
lib/services/cli/cli.dart
Normal file
@ -0,0 +1,46 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:args/args.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:package_info_plus/package_info_plus.dart';
|
||||
import 'package:spotube/models/logger.dart';
|
||||
|
||||
Future<ArgResults> startCLI(List<String> args) async {
|
||||
final parser = ArgParser();
|
||||
|
||||
parser.addFlag(
|
||||
'verbose',
|
||||
abbr: 'v',
|
||||
help: 'Verbose mode',
|
||||
defaultsTo: !kReleaseMode,
|
||||
callback: (verbose) {
|
||||
if (verbose) {
|
||||
logEnv['VERBOSE'] = 'true';
|
||||
logEnv['DEBUG'] = 'true';
|
||||
logEnv['ERROR'] = 'true';
|
||||
}
|
||||
},
|
||||
);
|
||||
parser.addFlag(
|
||||
"version",
|
||||
help: "Print version and exit",
|
||||
negatable: false,
|
||||
);
|
||||
|
||||
parser.addFlag("help", abbr: "h", negatable: false);
|
||||
|
||||
final arguments = parser.parse(args);
|
||||
|
||||
if (arguments["help"] == true) {
|
||||
print(parser.usage);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
if (arguments["version"] == true) {
|
||||
final package = await PackageInfo.fromPlatform();
|
||||
print("Spotube v${package.version}");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
return arguments;
|
||||
}
|
||||
29
pubspec.lock
29
pubspec.lock
@ -517,18 +517,23 @@ packages:
|
||||
fl_query:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: fl_query
|
||||
sha256: "64f482fc09eb1166adca232f68772b2b11c616d88bce3208b2753c940ebc9f71"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
path: "../fl-query/packages/fl_query"
|
||||
relative: true
|
||||
source: path
|
||||
version: "1.0.0-alpha.3"
|
||||
fl_query_devtools:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
path: "../fl-query/packages/fl_query_devtools"
|
||||
relative: true
|
||||
source: path
|
||||
version: "0.1.0-alpha.1"
|
||||
fl_query_hooks:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: fl_query_hooks
|
||||
sha256: b0ffc81fb047cbcedd9766776f9c72b95382730ce173226f0695c3f45774b0bc
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
path: "../fl-query/packages/fl_query_hooks"
|
||||
relative: true
|
||||
source: path
|
||||
version: "1.0.0-alpha.3"
|
||||
fluentui_system_icons:
|
||||
dependency: "direct main"
|
||||
@ -998,6 +1003,14 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "6.6.2"
|
||||
json_view:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: json_view
|
||||
sha256: "905c69f9e69d1eab5406b87ab6c10c3706c04c70c6a4959621bd2b43c2d27374"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.4.2"
|
||||
jwt_decode:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
||||
10
pubspec.yaml
10
pubspec.yaml
@ -34,8 +34,12 @@ dependencies:
|
||||
duration: ^3.0.12
|
||||
envied: ^0.3.0
|
||||
file_picker: ^5.2.2
|
||||
fl_query: ^1.0.0-alpha.3
|
||||
fl_query_hooks: ^1.0.0-alpha.3
|
||||
fl_query:
|
||||
path: ../fl-query/packages/fl_query
|
||||
fl_query_hooks:
|
||||
path: ../fl-query/packages/fl_query_hooks
|
||||
fl_query_devtools:
|
||||
path: ../fl-query/packages/fl_query_devtools
|
||||
fluentui_system_icons: ^1.1.189
|
||||
flutter:
|
||||
sdk: flutter
|
||||
@ -119,6 +123,8 @@ dev_dependencies:
|
||||
dependency_overrides:
|
||||
http: ^1.1.0
|
||||
flutter_hooks: ^0.20.0
|
||||
fl_query:
|
||||
path: ../fl-query/packages/fl_query
|
||||
|
||||
flutter:
|
||||
generate: true
|
||||
|
||||
Loading…
Reference in New Issue
Block a user