feat: dark theme

Signed-off-by: Kingtous <kingtous@qq.com>
This commit is contained in:
Kingtous 2022-07-29 16:47:24 +08:00
parent 6b99d4d82e
commit 608f02ea21
7 changed files with 97 additions and 49 deletions

View File

@ -4,6 +4,7 @@ import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/instance_manager.dart'; import 'package:get/instance_manager.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'models/model.dart'; import 'models/model.dart';
@ -38,6 +39,24 @@ class MyTheme {
static const Color idColor = Color(0xFF00B6F0); static const Color idColor = Color(0xFF00B6F0);
static const Color darkGray = Color(0xFFB9BABC); static const Color darkGray = Color(0xFFB9BABC);
static const Color dark = Colors.black87; static const Color dark = Colors.black87;
static ThemeData lightTheme = ThemeData(
brightness: Brightness.light,
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
tabBarTheme: TabBarTheme(labelColor: Colors.black87),
);
static ThemeData darkTheme = ThemeData(
brightness: Brightness.dark,
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
tabBarTheme: TabBarTheme(labelColor: Colors.white70));
}
bool isDarkTheme() {
final isDark = "Y" == Get.find<SharedPreferences>().getString("darkTheme");
debugPrint("current is dark theme: $isDark");
return isDark;
} }
final ButtonStyle flatButtonStyle = TextButton.styleFrom( final ButtonStyle flatButtonStyle = TextButton.styleFrom(
@ -327,4 +346,6 @@ Future<void> initGlobalFFI() async {
await _globalFFI.ffiModel.init(); await _globalFFI.ffiModel.init();
// trigger connection status updater // trigger connection status updater
await _globalFFI.bind.mainCheckConnectStatus(); await _globalFFI.bind.mainCheckConnectStatus();
// global shared preference
await Get.putAsync(() => SharedPreferences.getInstance());
} }

View File

@ -16,7 +16,6 @@ import '../../mobile/pages/home_page.dart';
import '../../mobile/pages/scan_page.dart'; import '../../mobile/pages/scan_page.dart';
import '../../mobile/pages/settings_page.dart'; import '../../mobile/pages/settings_page.dart';
import '../../models/model.dart'; import '../../models/model.dart';
import '../../models/peer_model.dart';
enum RemoteType { recently, favorite, discovered, addressBook } enum RemoteType { recently, favorite, discovered, addressBook }
@ -60,7 +59,7 @@ class _ConnectionPageState extends State<ConnectionPage> {
Widget build(BuildContext context) { Widget build(BuildContext context) {
if (_idController.text.isEmpty) _idController.text = gFFI.getId(); if (_idController.text.isEmpty) _idController.text = gFFI.getId();
return Container( return Container(
decoration: BoxDecoration(color: MyTheme.grayBg), decoration: BoxDecoration(color: isDarkTheme() ? null : MyTheme.grayBg),
child: Column( child: Column(
mainAxisAlignment: MainAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.start,
mainAxisSize: MainAxisSize.max, mainAxisSize: MainAxisSize.max,
@ -83,7 +82,6 @@ class _ConnectionPageState extends State<ConnectionPage> {
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
TabBar( TabBar(
labelColor: Colors.black87,
isScrollable: true, isScrollable: true,
indicatorSize: TabBarIndicatorSize.label, indicatorSize: TabBarIndicatorSize.label,
tabs: [ tabs: [
@ -205,7 +203,7 @@ class _ConnectionPageState extends State<ConnectionPage> {
width: 500, width: 500,
padding: EdgeInsets.symmetric(horizontal: 16, vertical: 24), padding: EdgeInsets.symmetric(horizontal: 16, vertical: 24),
decoration: BoxDecoration( decoration: BoxDecoration(
color: MyTheme.white, color: isDarkTheme() ? null : MyTheme.white,
borderRadius: const BorderRadius.all(Radius.circular(13)), borderRadius: const BorderRadius.all(Radius.circular(13)),
), ),
child: Ink( child: Ink(
@ -235,13 +233,11 @@ class _ConnectionPageState extends State<ConnectionPage> {
helperStyle: TextStyle( helperStyle: TextStyle(
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
fontSize: 16, fontSize: 16,
color: MyTheme.dark,
), ),
labelStyle: TextStyle( labelStyle: TextStyle(
fontWeight: FontWeight.w600, fontWeight: FontWeight.w600,
fontSize: 26, fontSize: 26,
letterSpacing: 0.2, letterSpacing: 0.2,
color: MyTheme.dark,
), ),
), ),
controller: _idController, controller: _idController,
@ -269,7 +265,6 @@ class _ConnectionPageState extends State<ConnectionPage> {
translate( translate(
"Transfer File", "Transfer File",
), ),
style: TextStyle(color: MyTheme.dark),
), ),
), ),
), ),
@ -528,7 +523,6 @@ class _ConnectionPageState extends State<ConnectionPage> {
shape: RoundedRectangleBorder( shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20), borderRadius: BorderRadius.circular(20),
side: BorderSide(color: MyTheme.grayBg)), side: BorderSide(color: MyTheme.grayBg)),
color: Colors.white,
child: Container( child: Container(
width: 200, width: 200,
height: double.infinity, height: double.infinity,

View File

@ -10,6 +10,7 @@ import 'package:flutter_hbb/desktop/widgets/titlebar_widget.dart';
import 'package:flutter_hbb/models/model.dart'; import 'package:flutter_hbb/models/model.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:tray_manager/tray_manager.dart'; import 'package:tray_manager/tray_manager.dart';
import 'package:url_launcher/url_launcher_string.dart'; import 'package:url_launcher/url_launcher_string.dart';
@ -64,7 +65,6 @@ class _DesktopHomePageState extends State<DesktopHomePage> with TrayListener {
return ChangeNotifierProvider.value( return ChangeNotifierProvider.value(
value: gFFI.serverModel, value: gFFI.serverModel,
child: Container( child: Container(
decoration: BoxDecoration(color: MyTheme.white),
child: Column( child: Column(
children: [ children: [
buildTip(context), buildTip(context),
@ -339,13 +339,24 @@ class _DesktopHomePageState extends State<DesktopHomePage> with TrayListener {
super.dispose(); super.dispose();
} }
void changeTheme(String choice) async {
if (choice == "Y") {
Get.changeTheme(MyTheme.darkTheme);
} else {
Get.changeTheme(MyTheme.lightTheme);
}
Get.find<SharedPreferences>().setString("darkTheme", choice);
}
void onSelectMenu(String value) { void onSelectMenu(String value) {
if (value.startsWith('enable-')) { if (value.startsWith('enable-')) {
final option = gFFI.getOption(value); final option = gFFI.getOption(value);
gFFI.setOption(value, option == "N" ? "" : "N"); gFFI.setOption(value, option == "N" ? "" : "N");
} else if (value.startsWith('allow-')) { } else if (value.startsWith('allow-')) {
final option = gFFI.getOption(value); final option = gFFI.getOption(value);
gFFI.setOption(value, option == "Y" ? "" : "Y"); final choice = option == "Y" ? "" : "Y";
gFFI.setOption(value, choice);
changeTheme(choice);
} else if (value == "stop-service") { } else if (value == "stop-service") {
final option = gFFI.getOption(value); final option = gFFI.getOption(value);
gFFI.setOption(value, option == "Y" ? "" : "Y"); gFFI.setOption(value, option == "Y" ? "" : "Y");
@ -367,9 +378,8 @@ class _DesktopHomePageState extends State<DesktopHomePage> with TrayListener {
} }
PopupMenuItem<String> genEnablePopupMenuItem(String label, String value) { PopupMenuItem<String> genEnablePopupMenuItem(String label, String value) {
final isEnable = label.startsWith('enable-') final v = gFFI.getOption(value);
? gFFI.getOption(value) != "N" final isEnable = value.startsWith('enable-') ? v != "N" : v == "Y";
: gFFI.getOption(value) != "Y";
return PopupMenuItem( return PopupMenuItem(
child: Row( child: Row(
children: [ children: [

View File

@ -72,7 +72,7 @@ class _FileManagerPageState extends State<FileManagerPage>
return false; return false;
}, },
child: Scaffold( child: Scaffold(
backgroundColor: MyTheme.grayBg, backgroundColor: isDarkTheme() ? MyTheme.dark : MyTheme.grayBg,
body: Row( body: Row(
children: [ children: [
Flexible(flex: 3, child: body(isLocal: true)), Flexible(flex: 3, child: body(isLocal: true)),

View File

@ -1,8 +1,7 @@
import 'package:contextmenu/contextmenu.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_hbb/desktop/pages/desktop_home_page.dart';
import 'package:flutter_hbb/utils/multi_window_manager.dart'; import 'package:flutter_hbb/utils/multi_window_manager.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:contextmenu/contextmenu.dart';
import '../../common.dart'; import '../../common.dart';
import '../../models/model.dart'; import '../../models/model.dart';
@ -16,11 +15,10 @@ class _PeerCard extends StatefulWidget {
final PopupMenuItemsFunc popupMenuItemsFunc; final PopupMenuItemsFunc popupMenuItemsFunc;
final PeerType type; final PeerType type;
_PeerCard( _PeerCard({required this.peer,
{required this.peer, required this.popupMenuItemsFunc,
required this.popupMenuItemsFunc, Key? key,
Key? key, required this.type})
required this.type})
: super(key: key); : super(key: key);
@override @override
@ -28,11 +26,13 @@ class _PeerCard extends StatefulWidget {
} }
/// State for the connection page. /// State for the connection page.
class _PeerCardState extends State<_PeerCard> { class _PeerCardState extends State<_PeerCard>
with AutomaticKeepAliveClientMixin {
var _menuPos; var _menuPos;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
super.build(context);
final peer = super.widget.peer; final peer = super.widget.peer;
var deco = Rx<BoxDecoration?>(BoxDecoration( var deco = Rx<BoxDecoration?>(BoxDecoration(
border: Border.all(color: Colors.transparent, width: 1.0), border: Border.all(color: Colors.transparent, width: 1.0),
@ -54,10 +54,9 @@ class _PeerCardState extends State<_PeerCard> {
)); ));
} }
Widget _buildPeerTile( Widget _buildPeerTile(BuildContext context, Peer peer, Rx<BoxDecoration?> deco) {
BuildContext context, Peer peer, Rx<BoxDecoration?> deco) {
return Obx( return Obx(
() => Container( () => Container(
decoration: deco.value, decoration: deco.value,
child: Column( child: Column(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
@ -104,7 +103,16 @@ class _PeerCardState extends State<_PeerCard> {
), ),
); );
} else { } else {
return Text(translate("Loading")); // alias has not arrived
return Center(
child: Text(
'${peer.username}@${peer.hostname}',
style: TextStyle(
color: Colors.white70,
fontSize: 12),
textAlign: TextAlign.center,
overflow: TextOverflow.ellipsis,
));
} }
}, },
), ),
@ -127,7 +135,7 @@ class _PeerCardState extends State<_PeerCard> {
child: CircleAvatar( child: CircleAvatar(
radius: 5, radius: 5,
backgroundColor: backgroundColor:
peer.online ? Colors.green : Colors.yellow)), peer.online ? Colors.green : Colors.yellow)),
Text('${peer.id}') Text('${peer.id}')
]), ]),
InkWell( InkWell(
@ -175,13 +183,12 @@ class _PeerCardState extends State<_PeerCard> {
); );
if (value == 'remove') { if (value == 'remove') {
setState(() => gFFI.setByName('remove', '$id')); setState(() => gFFI.setByName('remove', '$id'));
() async { () async {
removePreference(id); removePreference(id);
}(); }();
} else if (value == 'file') { } else if (value == 'file') {
_connect(id, isFileTransfer: true); _connect(id, isFileTransfer: true);
} else if (value == 'add-fav') { } else if (value == 'add-fav') {} else if (value == 'connect') {
} else if (value == 'connect') {
_connect(id, isFileTransfer: false); _connect(id, isFileTransfer: false);
} else if (value == 'ab-delete') { } else if (value == 'ab-delete') {
gFFI.abModel.deletePeer(id); gFFI.abModel.deletePeer(id);
@ -191,6 +198,8 @@ class _PeerCardState extends State<_PeerCard> {
_abEditTag(id); _abEditTag(id);
} else if (value == 'rename') { } else if (value == 'rename') {
_rename(id); _rename(id);
} else if (value == 'unremember-password') {
await gFFI.bind.mainForgetPassword(id: id);
} }
} }
@ -211,7 +220,7 @@ class _PeerCardState extends State<_PeerCard> {
child: GestureDetector( child: GestureDetector(
onTap: onTap, onTap: onTap,
child: Obx( child: Obx(
() => Container( () => Container(
decoration: BoxDecoration( decoration: BoxDecoration(
color: rxTags.contains(tagName) ? Colors.blue : null, color: rxTags.contains(tagName) ? Colors.blue : null,
border: Border.all(color: MyTheme.darkGray), border: Border.all(color: MyTheme.darkGray),
@ -255,12 +264,12 @@ class _PeerCardState extends State<_PeerCard> {
child: Wrap( child: Wrap(
children: tags children: tags
.map((e) => _buildTag(e, selectedTag, onTap: () { .map((e) => _buildTag(e, selectedTag, onTap: () {
if (selectedTag.contains(e)) { if (selectedTag.contains(e)) {
selectedTag.remove(e); selectedTag.remove(e);
} else { } else {
selectedTag.add(e); selectedTag.add(e);
} }
})) }))
.toList(growable: false), .toList(growable: false),
), ),
), ),
@ -366,6 +375,9 @@ class _PeerCardState extends State<_PeerCard> {
); );
}); });
} }
@override
bool get wantKeepAlive => true;
} }
abstract class BasePeerCard extends StatelessWidget { abstract class BasePeerCard extends StatelessWidget {

View File

@ -6,6 +6,7 @@ import 'package:flutter_hbb/desktop/screen/desktop_file_transfer_screen.dart';
import 'package:flutter_hbb/desktop/screen/desktop_remote_screen.dart'; import 'package:flutter_hbb/desktop/screen/desktop_remote_screen.dart';
import 'package:flutter_hbb/utils/multi_window_manager.dart'; import 'package:flutter_hbb/utils/multi_window_manager.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart';
import 'package:get/route_manager.dart'; import 'package:get/route_manager.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
@ -32,6 +33,10 @@ Future<Null> main(List<String> args) async {
runRustDeskApp(args); runRustDeskApp(args);
} }
ThemeData getCurrentTheme() {
return isDarkTheme() ? MyTheme.darkTheme : MyTheme.darkTheme;
}
void runRustDeskApp(List<String> args) async { void runRustDeskApp(List<String> args) async {
if (!isDesktop) { if (!isDesktop) {
runApp(App()); runApp(App());
@ -47,12 +52,17 @@ void runRustDeskApp(List<String> args) async {
WindowType wType = type.windowType; WindowType wType = type.windowType;
switch (wType) { switch (wType) {
case WindowType.RemoteDesktop: case WindowType.RemoteDesktop:
runApp(DesktopRemoteScreen( runApp(GetMaterialApp(
params: argument, theme: getCurrentTheme(),
home: DesktopRemoteScreen(
params: argument,
),
)); ));
break; break;
case WindowType.FileTransfer: case WindowType.FileTransfer:
runApp(DesktopFileTransferScreen(params: argument)); runApp(GetMaterialApp(
theme: getCurrentTheme(),
home: DesktopFileTransferScreen(params: argument)));
break; break;
default: default:
break; break;
@ -85,10 +95,7 @@ class App extends StatelessWidget {
navigatorKey: globalKey, navigatorKey: globalKey,
debugShowCheckedModeBanner: false, debugShowCheckedModeBanner: false,
title: 'RustDesk', title: 'RustDesk',
theme: ThemeData( theme: getCurrentTheme(),
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: isDesktop home: isDesktop
? DesktopHomePage() ? DesktopHomePage()
: !isAndroid : !isAndroid

View File

@ -20,11 +20,11 @@ use crate::flutter::{self, Session, SESSIONS};
use crate::start_server; use crate::start_server;
use crate::ui_interface; use crate::ui_interface;
use crate::ui_interface::{ use crate::ui_interface::{
change_id, check_connect_status, get_api_server, get_app_name, get_async_job_status, change_id, check_connect_status, forget_password, get_api_server, get_app_name,
get_connect_status, get_fav, get_id, get_lan_peers, get_license, get_local_option, get_options, get_async_job_status, get_connect_status, get_fav, get_id, get_lan_peers, get_license,
get_peer, get_peer_option, get_socks, get_sound_inputs, get_uuid, get_version, get_local_option, get_options, get_peer, get_peer_option, get_socks, get_sound_inputs,
has_rendezvous_service, is_ok_change_id, post_request, set_local_option, set_options, get_uuid, get_version, has_rendezvous_service, is_ok_change_id, post_request, set_local_option,
set_peer_option, set_socks, store_fav, test_if_valid_server, using_public_server, set_options, set_peer_option, set_socks, store_fav, test_if_valid_server, using_public_server,
}; };
fn initialize(app_dir: &str) { fn initialize(app_dir: &str) {
@ -504,6 +504,10 @@ pub fn main_set_peer_option(id: String, key: String, value: String) {
set_peer_option(id, key, value) set_peer_option(id, key, value)
} }
pub fn main_forget_password(id: String) {
forget_password(id)
}
/// FFI for **get** commands which are idempotent. /// FFI for **get** commands which are idempotent.
/// Return result in c string. /// Return result in c string.
/// ///