Add silent start for desktop
This commit is contained in:
@@ -4,6 +4,7 @@ import 'package:flutter_localizations/flutter_localizations.dart';
|
||||
import 'package:hiddify/core/locale/locale.dart';
|
||||
import 'package:hiddify/core/router/router.dart';
|
||||
import 'package:hiddify/core/theme/theme.dart';
|
||||
import 'package:hiddify/features/common/common_controllers.dart';
|
||||
import 'package:hiddify/utils/utils.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
|
||||
@@ -16,6 +17,8 @@ class AppView extends HookConsumerWidget with PresLogger {
|
||||
final locale = ref.watch(localeControllerProvider).locale;
|
||||
final theme = ref.watch(themeControllerProvider);
|
||||
|
||||
ref.watch(commonControllersProvider);
|
||||
|
||||
return MaterialApp.router(
|
||||
routerConfig: router,
|
||||
locale: locale,
|
||||
|
||||
17
lib/core/prefs/general_prefs.dart
Normal file
17
lib/core/prefs/general_prefs.dart
Normal file
@@ -0,0 +1,17 @@
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
|
||||
part 'general_prefs.freezed.dart';
|
||||
part 'general_prefs.g.dart';
|
||||
|
||||
@freezed
|
||||
class GeneralPrefs with _$GeneralPrefs {
|
||||
const GeneralPrefs._();
|
||||
|
||||
const factory GeneralPrefs({
|
||||
// desktop only
|
||||
@Default(false) bool silentStart,
|
||||
}) = _GeneralPrefs;
|
||||
|
||||
factory GeneralPrefs.fromJson(Map<String, dynamic> json) =>
|
||||
_$GeneralPrefsFromJson(json);
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:hiddify/core/prefs/general_prefs.dart';
|
||||
import 'package:hiddify/core/prefs/prefs_state.dart';
|
||||
import 'package:hiddify/data/data_providers.dart';
|
||||
import 'package:hiddify/domain/clash/clash.dart';
|
||||
@@ -15,6 +16,7 @@ class PrefsController extends _$PrefsController with AppLogger {
|
||||
@override
|
||||
PrefsState build() {
|
||||
return PrefsState(
|
||||
general: _getGeneralPrefs(),
|
||||
clash: _getClashPrefs(),
|
||||
network: _getNetworkPrefs(),
|
||||
);
|
||||
@@ -22,8 +24,15 @@ class PrefsController extends _$PrefsController with AppLogger {
|
||||
|
||||
SharedPreferences get _prefs => ref.read(sharedPreferencesProvider);
|
||||
|
||||
static const _generalKey = "general_prefs";
|
||||
static const _overridesKey = "clash_overrides";
|
||||
static const _networkKey = "clash_overrides";
|
||||
static const _networkKey = "network_prefs";
|
||||
|
||||
GeneralPrefs _getGeneralPrefs() {
|
||||
final persisted = _prefs.getString(_generalKey);
|
||||
if (persisted == null) return const GeneralPrefs();
|
||||
return GeneralPrefs.fromJson(jsonDecode(persisted) as Map<String, dynamic>);
|
||||
}
|
||||
|
||||
ClashConfig _getClashPrefs() {
|
||||
final persisted = _prefs.getString(_overridesKey);
|
||||
@@ -37,6 +46,14 @@ class PrefsController extends _$PrefsController with AppLogger {
|
||||
return NetworkPrefs.fromJson(jsonDecode(persisted) as Map<String, dynamic>);
|
||||
}
|
||||
|
||||
Future<void> patchGeneralPrefs({bool? silentStart}) async {
|
||||
final newPrefs = state.general.copyWith(
|
||||
silentStart: silentStart ?? state.general.silentStart,
|
||||
);
|
||||
await _prefs.setString(_generalKey, jsonEncode(newPrefs.toJson()));
|
||||
state = state.copyWith(general: newPrefs);
|
||||
}
|
||||
|
||||
Future<void> patchClashOverrides(ClashConfigPatch overrides) async {
|
||||
final newPrefs = state.clash.patch(overrides);
|
||||
await _prefs.setString(_overridesKey, jsonEncode(newPrefs.toJson()));
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
import 'package:hiddify/core/prefs/general_prefs.dart';
|
||||
import 'package:hiddify/domain/clash/clash.dart';
|
||||
import 'package:hiddify/domain/connectivity/connectivity.dart';
|
||||
|
||||
@@ -9,6 +10,7 @@ class PrefsState with _$PrefsState {
|
||||
const PrefsState._();
|
||||
|
||||
const factory PrefsState({
|
||||
@Default(GeneralPrefs()) GeneralPrefs general,
|
||||
@Default(ClashConfig()) ClashConfig clash,
|
||||
@Default(NetworkPrefs()) NetworkPrefs network,
|
||||
}) = _PrefsState;
|
||||
|
||||
Reference in New Issue
Block a user