Skip to content

Commit

Permalink
Merge pull request #20 from Muska-Ami/dev
Browse files Browse the repository at this point in the history
Dark theme(beta)
  • Loading branch information
Muska-Ami authored Jan 9, 2024
2 parents 44cedab + 94ef7fc commit 540bf07
Show file tree
Hide file tree
Showing 18 changed files with 413 additions and 81 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,16 @@ An unoffical LoCyanFrp launcher.
- [x] 注册
- [x] 自动登录
- [ ] Frpc管理
- [x] *进程管理器
- [x] 进程管理器
- [x] Token复制
- [x] 隧道信息展示
- [x] 隧道启动
- [x] 高级启动
- [x] *控制台
- [x] 控制台
- [ ] 隧道编辑
- [x] 公告
- [x] 通知
- [ ] 暗色主题

## Repo stats

Expand Down
1 change: 1 addition & 0 deletions lib/controller/dconsole.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class ConsoleController extends GetxController {
onPressed: () {
/// 杀死进程
FrpcProcessManager().kill(element);
load();
},
),
),
Expand Down
22 changes: 6 additions & 16 deletions lib/controller/dsetting.dart → lib/controller/dsettingfrpc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@ import 'package:flutter/material.dart';
import 'package:get/get.dart' hide Response;
import 'package:nyalcf/io/frpcManagerStorage.dart';
import 'package:nyalcf/model/FrpcConfig.dart';
import 'package:nyalcf/prefs/SettingPrefs.dart';
import 'package:nyalcf/prefs/FrpcSettingPrefs.dart';
import 'package:nyalcf/ui/model/FrpcDownloadDialog.dart';
import 'package:nyalcf/ui/model/FrpcDownloadTip.dart';
import 'package:nyalcf/util/CPUArch.dart';
import 'package:nyalcf/util/frpc/Archive.dart';
import 'package:package_info_plus/package_info_plus.dart';

class DSettingController extends GetxController {
DSettingController({required this.context});
class DSettingFrpcController extends GetxController {
DSettingFrpcController({required this.context});

final context;
List<Map<String, dynamic>> arch = <Map<String, dynamic>>[];
Expand All @@ -32,20 +31,11 @@ class DSettingController extends GetxController {

var frpc_version = ''.obs;

var app_name = ''.obs;
var app_version = ''.obs;
var app_package_name = ''.obs;

var github_proxy = ''.obs;

var cpu_arch = ''.obs;

load() async {
final packageInfo = await PackageInfo.fromPlatform();
app_name.value = packageInfo.appName;
app_version.value = packageInfo.version;
app_package_name.value = packageInfo.packageName;

cpu_arch.value = await CPUArch.getCPUArchitecture();

frpc_version.value = await FrpcManagerStorage.usingVersion;
Expand Down Expand Up @@ -100,11 +90,11 @@ class DSettingController extends GetxController {
version: '0.51.3',
);
if (unarchive) {
SettingPrefs.setFrpcDownloadedVersionsInfo('0.51.3');
FrpcSettingPrefs.setFrpcDownloadedVersionsInfo('0.51.3');
FrpcManagerStorage.save(
FrpcConfig(
settings: (await SettingPrefs.getFrpcInfo()).settings,
lists: (await SettingPrefs.getFrpcInfo()).lists),
settings: (await FrpcSettingPrefs.getFrpcInfo()).settings,
lists: (await FrpcSettingPrefs.getFrpcInfo()).lists),
);
/**if (!Platform.isWindows) {
print('*nix platform, change file permission');
Expand Down
27 changes: 27 additions & 0 deletions lib/controller/dsettinglauncher.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import 'package:get/get.dart';
import 'package:nyalcf/prefs/LauncherSettingPrefs.dart';
import 'package:package_info_plus/package_info_plus.dart';

class DSettingLauncherController extends GetxController {
var app_name = ''.obs;
var app_version = ''.obs;
var app_package_name = ''.obs;

var theme_auto = false.obs;
var theme_dark = false.obs;
var theme_light_seed = ''.obs;
var theme_light_seed_enable = false.obs;

load() async {
final packageInfo = await PackageInfo.fromPlatform();
app_name.value = packageInfo.appName;
app_version.value = packageInfo.version;
app_package_name.value = packageInfo.packageName;

final settings = await LauncherSettingPrefs.getInfo();
theme_auto.value = settings.theme_auto;
theme_dark.value = settings.theme_dark;
theme_light_seed.value = settings.theme_light_seed;
theme_light_seed_enable.value = settings.theme_light_seed_enable;
}
}
4 changes: 2 additions & 2 deletions lib/io/frpcManagerStorage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'dart:convert';
import 'dart:io';

import 'package:nyalcf/model/FrpcConfig.dart';
import 'package:nyalcf/prefs/SettingPrefs.dart';
import 'package:nyalcf/prefs/FrpcSettingPrefs.dart';
import 'package:nyalcf/util/FileIO.dart';

class FrpcManagerStorage {
Expand All @@ -22,7 +22,7 @@ class FrpcManagerStorage {
}
}

static Future<FrpcConfig> get _info async => SettingPrefs.getFrpcInfo();
static Future<FrpcConfig> get _info async => FrpcSettingPrefs.getFrpcInfo();

static void init() {
_path.then((path) {
Expand Down
52 changes: 51 additions & 1 deletion lib/io/settingStorage.dart
Original file line number Diff line number Diff line change
@@ -1 +1,51 @@
class SettingStorage {}
import 'dart:convert';
import 'dart:io';

import 'package:nyalcf/model/Setting.dart';
import 'package:nyalcf/util/FileIO.dart';

class SettingStorage {
static final _path = FileIO.support_path;

static void init() {
_path.then((path) {
if (!Directory(path).existsSync()) Directory(path).createSync();
final infoF = File('${path}/settings.json');
if (!infoF.existsSync()) {
Map<String, dynamic> json = {
'theme': {
'auto': true,
'dark': {
'enable': false,
},
'light': {
'seed': {
'enable': false,
'value': '66ccff',
},
}
},
};
infoF.writeAsStringSync(jsonEncode(json));
}
});
}

/// 保存数据
static Future<void> save(Setting data) async {
final String write_data = jsonEncode(data);
await File('${await _path}/settings.json')
.writeAsString(write_data, encoding: utf8);
}

/// 读取数据
static Future<Setting?> read() async {
try {
final String result =
File('${await _path}/settings.json').readAsStringSync(encoding: utf8);
return Setting.fromJson(jsonDecode(result));
} catch (e) {
return null;
}
}
}
70 changes: 56 additions & 14 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import 'package:bitsdojo_window/bitsdojo_window.dart';
import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';
import 'package:get/get.dart';
import 'package:nyalcf/controller/user.dart';
import 'package:nyalcf/io/frpcManagerStorage.dart';
import 'package:nyalcf/io/settingStorage.dart';
import 'package:nyalcf/model/Setting.dart';
import 'package:nyalcf/prefs/LauncherSettingPrefs.dart';
import 'package:nyalcf/ui/auth/login.dart';
import 'package:nyalcf/ui/auth/register.dart';
import 'package:nyalcf/ui/home.dart';
Expand All @@ -11,7 +15,14 @@ import 'package:nyalcf/ui/panel/home.dart';
import 'package:nyalcf/ui/panel/proxies.dart';
import 'package:nyalcf/ui/setting/injector.dart';

void main() {
Setting? _settings = null;

void main() async {
/// 初始化配置文件
SettingStorage.init();
FrpcManagerStorage.init();
_settings = await SettingStorage.read();

runApp(const App());

doWhenWindowReady(() {
Expand All @@ -29,11 +40,51 @@ class App extends StatelessWidget {

final title = 'Nya LoCyanFrp!';

// This widget is the root of your application.
/// This widget is the root of your application.
@override
Widget build(BuildContext context) {
// 初始化Frpc配置
FrpcManagerStorage.init();
LauncherSettingPrefs.setInfo(_settings ??
Setting(
theme_auto: true,
theme_dark: false,
theme_light_seed_enable: false,
theme_light_seed: '66ccff',
));

ThemeData _theme_data;

final bool isDarkMode = (Theme.of(context).brightness == Brightness.dark ||
Theme.of(context).colorScheme.brightness == Brightness.dark) ||
SchedulerBinding.instance.platformDispatcher.platformBrightness ==
Brightness.dark ||
MediaQuery.of(context).platformBrightness == Brightness.dark;

print('dark mode: ${isDarkMode}');

/// 判定是否需要切换暗色主题
if (((_settings?.theme_auto ?? true) && isDarkMode) ||
(_settings?.theme_dark ?? false)) {
_theme_data = ThemeData.dark(useMaterial3: true);
} else if ((_settings?.theme_light_seed_enable ?? false)) {
_theme_data = ThemeData(
useMaterial3: true,
fontFamily: 'HarmonyOS Sans',
colorScheme: ColorScheme.fromSeed(
seedColor:
Color('0x${_settings?.theme_light_seed ?? '66ccff'}' as int),
));
} else {
_theme_data = ThemeData(
useMaterial3: true,
fontFamily: 'HarmonyOS Sans',
colorScheme: ColorScheme.fromSeed(
seedColor: Colors.pink.shade300,
).copyWith(
primary: Colors.pink.shade500,
secondary: Colors.pink.shade400,
),
);
}

Get.put(UserController());
return GetMaterialApp(
Expand All @@ -47,16 +98,7 @@ class App extends StatelessWidget {
'/panel/console': (context) => PanelConsole(title: title),
'/setting': (context) => SettingInjector(title: title),
},
theme: ThemeData(
useMaterial3: true,
fontFamily: 'HarmonyOS Sans',
colorScheme: ColorScheme.fromSeed(
seedColor: Colors.pink.shade300,
).copyWith(
primary: Colors.pink.shade500,
secondary: Colors.pink.shade400,
),
),
theme: _theme_data,
);
}
}
34 changes: 34 additions & 0 deletions lib/model/Setting.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
class Setting {
Setting({
required this.theme_auto,
required this.theme_dark,
required this.theme_light_seed_enable,
required this.theme_light_seed,
});

final bool theme_auto;
final bool theme_dark;
final bool theme_light_seed_enable;
final String theme_light_seed;

Map<String, dynamic> toJson() => {
'theme': {
'auto': theme_auto,
'dark': {
'enable': theme_dark,
},
'light': {
'seed': {
'enable': theme_light_seed_enable,
'value': theme_light_seed,
},
}
},
};

Setting.fromJson(Map<String, dynamic> json)
: theme_auto = json['theme']['auto'],
theme_dark = json['theme']['dark']['enable'],
theme_light_seed = json['theme']['light']['seed']['value'],
theme_light_seed_enable = json['theme']['light']['seed']['enable'];
}
31 changes: 16 additions & 15 deletions lib/prefs/SettingPrefs.dart → lib/prefs/FrpcSettingPrefs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,32 @@ import 'package:nyalcf/io/frpcManagerStorage.dart';
import 'package:nyalcf/model/FrpcConfig.dart';
import 'package:shared_preferences/shared_preferences.dart';

class SettingPrefs {
class FrpcSettingPrefs {
static Future<void> setFrpcInfo(FrpcConfig frpcinfo) async {
SharedPreferences prefs = await SharedPreferences.getInstance();
prefs.setString('setting@frpc_version', frpcinfo.frpc_version);
prefs.setStringList(
'list@frpc_downloaded_versions', frpcinfo.frpc_downloaded_versions);
prefs.setString('setting@github_proxy', frpcinfo.github_proxy);
prefs.setStringList('list@github_proxies', frpcinfo.github_proxies);
prefs.setString('frpc@setting@frpc_version', frpcinfo.frpc_version);
prefs.setStringList('frpc@list@frpc_downloaded_versions',
frpcinfo.frpc_downloaded_versions);
prefs.setString('frpc@setting@github_proxy', frpcinfo.github_proxy);
prefs.setStringList('frpc@list@github_proxies', frpcinfo.github_proxies);
}

static Future<void> setFrpcDownloadedVersionsInfo(String version) async {
SharedPreferences prefs = await SharedPreferences.getInstance();
final newlist =
(await getFrpcInfo()).lists['frpc_downloaded_versions'] ?? [];
newlist.add(version);
prefs.setStringList('list@frpc_downloaded_versions', newlist);
prefs.setStringList('frpc@list@frpc_downloaded_versions', newlist);
}

static Future<FrpcConfig> getFrpcInfo() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
final s_frpc_version = prefs.getString('setting@frpc_version') ?? '';
final s_frpc_version = prefs.getString('frpc@setting@frpc_version') ?? '';
final l_frpc_downloaded_versions =
prefs.getStringList('list@frpc_downloaded_versions') ?? [];
final s_github_proxy = prefs.getString('setting@github_proxy') ?? '';
final l_github_proxies = prefs.getStringList('list@github_proxies') ?? [];
prefs.getStringList('frpc@list@frpc_downloaded_versions') ?? [];
final s_github_proxy = prefs.getString('frpc@setting@github_proxy') ?? '';
final l_github_proxies =
prefs.getStringList('frpc@list@github_proxies') ?? [];

final Map<String, dynamic> settings = Map();
settings['frpc_version'] = s_frpc_version;
Expand All @@ -39,8 +40,8 @@ class SettingPrefs {
return FrpcConfig(settings: settings, lists: lists);
}

static Future<void> refresh() async => {
if (await FrpcManagerStorage.read() != null)
setFrpcInfo((await FrpcManagerStorage.read())!)
};
static Future<void> refresh() async {
final res = await FrpcManagerStorage.read();
if (res != null) setFrpcInfo(res);
}
}
Loading

0 comments on commit 540bf07

Please sign in to comment.