Skip to content

Commit

Permalink
Refactor(WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
gvenusleo committed Jun 6, 2024
1 parent d51e944 commit 8c4104d
Show file tree
Hide file tree
Showing 13 changed files with 11 additions and 112 deletions.
Binary file removed assets/sarasa-ui-sc.ttf
Binary file not shown.
14 changes: 3 additions & 11 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ class MyApp extends StatelessWidget {
return DynamicColorBuilder(builder: (lightDynamic, darkDynamic) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: "Lex",
title: "lex",
localizationsDelegates: const [
GlobalWidgetsLocalizations.delegate,
GlobalMaterialLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
supportedLocales: const [
Locale("en"),
Locale("zh"),
Locale("en", "US"),
Locale("zh", "CN"),
],
theme: buildLightTheme(lightDynamic, context),
darkTheme: buildDarkTheme(darkDynamic, context),
Expand All @@ -47,14 +47,6 @@ class MyApp extends StatelessWidget {
ThemeMode.dark
][context.watch<ThemeProvider>().themeMode],
home: const HomePage(),
builder: (context, child) {
return ClipRRect(
borderRadius: BorderRadius.circular(
prefs.getBool("useRoundedWindow") ?? true ? 12 : 0,
),
child: child,
);
},
);
});
}
Expand Down
24 changes: 5 additions & 19 deletions lib/pages/setting_page/app_setting_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ class _AppSettingPageState extends State<AppSettingPage> {
late double _windowOpacity;
// 窗口是非跟随鼠标
late bool _windowFllowCursor;
late bool _useRoundedWindow;
// 是否开机自启动
bool _launchAtStartup = false;
// 启动时隐藏窗口
Expand All @@ -47,7 +46,6 @@ class _AppSettingPageState extends State<AppSettingPage> {
});
_windowOpacity = prefs.getDouble("windowOpacity") ?? 1.0;
_windowFllowCursor = prefs.getBool("windowFollowCursor") ?? false;
_useRoundedWindow = prefs.getBool("useRoundedWindow") ?? true;
_hideWindowAtStartup = prefs.getBool("hideWindowAtStartup") ?? false;
_proxyAddressController.text = _proxyAddress;
super.initState();
Expand Down Expand Up @@ -78,7 +76,7 @@ class _AppSettingPageState extends State<AppSettingPage> {
title: const Text("全局字体"),
subtitle: const Text("设置应用界面字体"),
trailing: Text(
context.watch<ThemeProvider>().fontFamily == "Sarasa-UI-SC"
context.watch<ThemeProvider>().fontFamily == "system"
? "默认字体"
: context.watch<ThemeProvider>().fontFamily.split(".").first,
style: const TextStyle(fontSize: 16),
Expand Down Expand Up @@ -129,18 +127,6 @@ class _AppSettingPageState extends State<AppSettingPage> {
title: const Text("窗口跟随鼠标"),
subtitle: const Text("划词翻译时窗口跟随鼠标"),
),
SwitchListTile(
value: _useRoundedWindow,
onChanged: (value) async {
setState(() {
_useRoundedWindow = value;
});
prefs.setBool("useRoundedWindow", value);
},
secondary: const Icon(Icons.rounded_corner_rounded),
title: const Text("使用圆角窗口"),
subtitle: const Text("重启应用后生效"),
),
SwitchListTile(
value: _launchAtStartup,
onChanged: (value) async {
Expand Down Expand Up @@ -262,7 +248,7 @@ class _AppSettingPageState extends State<AppSettingPage> {
/// 设置全局字体
Future<void> setGlobalFont() async {
List<String> fonts = await readAllFont();
fonts.insert(0, "Sarasa-UI-SC");
fonts.insert(0, "system");
if (!mounted) return;
showDialog(
context: context,
Expand All @@ -277,7 +263,7 @@ class _AppSettingPageState extends State<AppSettingPage> {
crossAxisAlignment: CrossAxisAlignment.center,
children: [
...fonts.map((e) {
if (e == "Sarasa-UI-SC") {
if (e == "system") {
return RadioListTile(
value: e,
groupValue: context.watch<ThemeProvider>().fontFamily,
Expand Down Expand Up @@ -309,7 +295,7 @@ class _AppSettingPageState extends State<AppSettingPage> {
if (context.read<ThemeProvider>().fontFamily == e) {
context
.read<ThemeProvider>()
.changeFontFamily("Sarasa-UI-SC");
.changeFontFamily("system");
}
await deleteFont(e);
setFontState(() {
Expand All @@ -333,7 +319,7 @@ class _AppSettingPageState extends State<AppSettingPage> {
await loadLocalFont();
readAllFont().then((value) {
fonts = value;
fonts.insert(0, "Sarasa-UI-SC");
fonts.insert(0, "system");
setFontState(() {});
});
},
Expand Down
2 changes: 1 addition & 1 deletion lib/providers/theme_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class ThemeProvider extends ChangeNotifier {
// 主题背景
int themeMode = prefs.getInt("themeMode") ?? 0;
// 全局字体
String fontFamily = prefs.getString("fontFamily") ?? "Sarasa-UI-SC";
String fontFamily = prefs.getString("fontFamily") ?? "system";
// 使用系统主题颜色
bool useSystemThemeColor = prefs.getBool("useSystemThemeColor") ?? true;

Expand Down
18 changes: 0 additions & 18 deletions lib/utils/capture.dart

This file was deleted.

4 changes: 2 additions & 2 deletions lib/utils/font_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ Future<List<String>> readAllFont() async {

/// 读取主题字体文件,注册到系统中
Future<void> readThemeFont() async {
final String themeFontName = prefs.getString("fontFamily") ?? "Sarasa-UI-SC";
if (themeFontName != "Sarasa-UI-SC") {
final String themeFontName = prefs.getString("fontFamily") ?? "system";
if (themeFontName != "system") {
final fontFileDir = await getFontDir();
readFont(
"${fontFileDir.path}${getDirSeparator()}$themeFontName", themeFontName);
Expand Down
4 changes: 0 additions & 4 deletions linux/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include "generated_plugin_registrant.h"

#include <audioplayers_linux/audioplayers_linux_plugin.h>
#include <bitsdojo_window_linux/bitsdojo_window_plugin.h>
#include <clipboard_watcher/clipboard_watcher_plugin.h>
#include <dynamic_color/dynamic_color_plugin.h>
#include <hotkey_manager_linux/hotkey_manager_linux_plugin.h>
Expand All @@ -23,9 +22,6 @@ void fl_register_plugins(FlPluginRegistry* registry) {
g_autoptr(FlPluginRegistrar) audioplayers_linux_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "AudioplayersLinuxPlugin");
audioplayers_linux_plugin_register_with_registrar(audioplayers_linux_registrar);
g_autoptr(FlPluginRegistrar) bitsdojo_window_linux_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "BitsdojoWindowPlugin");
bitsdojo_window_plugin_register_with_registrar(bitsdojo_window_linux_registrar);
g_autoptr(FlPluginRegistrar) clipboard_watcher_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "ClipboardWatcherPlugin");
clipboard_watcher_plugin_register_with_registrar(clipboard_watcher_registrar);
Expand Down
1 change: 0 additions & 1 deletion linux/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

list(APPEND FLUTTER_PLUGIN_LIST
audioplayers_linux
bitsdojo_window_linux
clipboard_watcher
dynamic_color
hotkey_manager_linux
Expand Down
2 changes: 0 additions & 2 deletions macos/Flutter/GeneratedPluginRegistrant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import FlutterMacOS
import Foundation

import audioplayers_darwin
import bitsdojo_window_macos
import clipboard_watcher
import dynamic_color
import hotkey_manager_macos
Expand All @@ -23,7 +22,6 @@ import window_manager

func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
AudioplayersDarwinPlugin.register(with: registry.registrar(forPlugin: "AudioplayersDarwinPlugin"))
BitsdojoWindowPlugin.register(with: registry.registrar(forPlugin: "BitsdojoWindowPlugin"))
ClipboardWatcherPlugin.register(with: registry.registrar(forPlugin: "ClipboardWatcherPlugin"))
DynamicColorPlugin.register(with: registry.registrar(forPlugin: "DynamicColorPlugin"))
HotkeyManagerMacosPlugin.register(with: registry.registrar(forPlugin: "HotkeyManagerMacosPlugin"))
Expand Down
40 changes: 0 additions & 40 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -89,46 +89,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "4.0.0"
bitsdojo_window:
dependency: "direct main"
description:
name: bitsdojo_window
sha256: "88ef7765dafe52d97d7a3684960fb5d003e3151e662c18645c1641c22b873195"
url: "https://pub.dev"
source: hosted
version: "0.1.6"
bitsdojo_window_linux:
dependency: transitive
description:
name: bitsdojo_window_linux
sha256: "9519c0614f98be733e0b1b7cb15b827007886f6fe36a4fb62cf3d35b9dd578ab"
url: "https://pub.dev"
source: hosted
version: "0.1.4"
bitsdojo_window_macos:
dependency: transitive
description:
name: bitsdojo_window_macos
sha256: f7c5be82e74568c68c5b8449e2c5d8fd12ec195ecd70745a7b9c0f802bb0268f
url: "https://pub.dev"
source: hosted
version: "0.1.4"
bitsdojo_window_platform_interface:
dependency: transitive
description:
name: bitsdojo_window_platform_interface
sha256: "65daa015a0c6dba749bdd35a0f092e7a8ba8b0766aa0480eb3ef808086f6e27c"
url: "https://pub.dev"
source: hosted
version: "0.1.2"
bitsdojo_window_windows:
dependency: transitive
description:
name: bitsdojo_window_windows
sha256: fa982cf61ede53f483e50b257344a1c250af231a3cdc93a7064dd6dc0d720b68
url: "https://pub.dev"
source: hosted
version: "0.1.6"
boolean_selector:
dependency: transitive
description:
Expand Down
10 changes: 0 additions & 10 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ environment:

dependencies:
audioplayers: ^6.0.0
bitsdojo_window: ^0.1.5
# bitsdojo_window 没有在 lib/ 中使用
# 在 linux/my_application.cc 中使用
# 作用是使窗口圆角处保持透明 (window_manager 无法实现)
# 以及调整窗口大小 (window_manager DragToResizeArea 可实现)
clipboard_watcher: ^0.2.0
crypto: ^3.0.3
dio: ^5.3.2
Expand Down Expand Up @@ -56,8 +51,3 @@ flutter:
- assets/logo.ico
- assets/service/translation/
- assets/service/ocr/

fonts:
- family: Sarasa-UI-SC
fonts:
- asset: assets/sarasa-ui-sc.ttf
3 changes: 0 additions & 3 deletions windows/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include "generated_plugin_registrant.h"

#include <audioplayers_windows/audioplayers_windows_plugin.h>
#include <bitsdojo_window_windows/bitsdojo_window_plugin.h>
#include <clipboard_watcher/clipboard_watcher_plugin.h>
#include <dynamic_color/dynamic_color_plugin_c_api.h>
#include <hotkey_manager_windows/hotkey_manager_windows_plugin_c_api.h>
Expand All @@ -22,8 +21,6 @@
void RegisterPlugins(flutter::PluginRegistry* registry) {
AudioplayersWindowsPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("AudioplayersWindowsPlugin"));
BitsdojoWindowPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("BitsdojoWindowPlugin"));
ClipboardWatcherPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("ClipboardWatcherPlugin"));
DynamicColorPluginCApiRegisterWithRegistrar(
Expand Down
1 change: 0 additions & 1 deletion windows/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

list(APPEND FLUTTER_PLUGIN_LIST
audioplayers_windows
bitsdojo_window_windows
clipboard_watcher
dynamic_color
hotkey_manager_windows
Expand Down

0 comments on commit 8c4104d

Please sign in to comment.