From c988dd88d707efa81fb55839bc24e5bd5b28fae9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?lollipopkit=F0=9F=8F=B3=EF=B8=8F=E2=80=8D=E2=9A=A7?= =?UTF-8?q?=EF=B8=8F?= <10864310+lollipopkit@users.noreply.github.com> Date: Mon, 15 Jul 2024 17:38:30 +0800 Subject: [PATCH] fix: linux duplicated title bar (#462) Fixes #459 --- .metadata | 30 ++++++++++---------- lib/data/model/app/backup.dart | 2 +- lib/data/res/build_data.dart | 2 +- lib/intro.dart | 2 +- lib/main.dart | 1 + lib/view/page/setting/entry.dart | 16 +++++------ lib/view/page/ssh/tab.dart | 7 +++-- linux/CMakeLists.txt | 43 ++++++++++++++++++++++++----- linux/flutter/CMakeLists.txt | 1 + linux/my_application.cc | 47 ++++++++++++++++++++++++++++++++ pubspec.lock | 8 +++--- pubspec.yaml | 6 ++-- 12 files changed, 122 insertions(+), 43 deletions(-) diff --git a/.metadata b/.metadata index 24a13c133..6eb54a17b 100644 --- a/.metadata +++ b/.metadata @@ -4,7 +4,7 @@ # This file should be version controlled and should not be manually edited. version: - revision: "bae5e49bc2a867403c43b2aae2de8f8c33b037e4" + revision: "761747bfc538b5af34aa0d3fac380f1bc331ec49" channel: "stable" project_type: app @@ -13,26 +13,26 @@ project_type: app migration: platforms: - platform: root - create_revision: bae5e49bc2a867403c43b2aae2de8f8c33b037e4 - base_revision: bae5e49bc2a867403c43b2aae2de8f8c33b037e4 + create_revision: 761747bfc538b5af34aa0d3fac380f1bc331ec49 + base_revision: 761747bfc538b5af34aa0d3fac380f1bc331ec49 - platform: android - create_revision: bae5e49bc2a867403c43b2aae2de8f8c33b037e4 - base_revision: bae5e49bc2a867403c43b2aae2de8f8c33b037e4 + create_revision: 761747bfc538b5af34aa0d3fac380f1bc331ec49 + base_revision: 761747bfc538b5af34aa0d3fac380f1bc331ec49 - platform: ios - create_revision: bae5e49bc2a867403c43b2aae2de8f8c33b037e4 - base_revision: bae5e49bc2a867403c43b2aae2de8f8c33b037e4 + create_revision: 761747bfc538b5af34aa0d3fac380f1bc331ec49 + base_revision: 761747bfc538b5af34aa0d3fac380f1bc331ec49 - platform: linux - create_revision: bae5e49bc2a867403c43b2aae2de8f8c33b037e4 - base_revision: bae5e49bc2a867403c43b2aae2de8f8c33b037e4 + create_revision: 761747bfc538b5af34aa0d3fac380f1bc331ec49 + base_revision: 761747bfc538b5af34aa0d3fac380f1bc331ec49 - platform: macos - create_revision: bae5e49bc2a867403c43b2aae2de8f8c33b037e4 - base_revision: bae5e49bc2a867403c43b2aae2de8f8c33b037e4 + create_revision: 761747bfc538b5af34aa0d3fac380f1bc331ec49 + base_revision: 761747bfc538b5af34aa0d3fac380f1bc331ec49 - platform: web - create_revision: bae5e49bc2a867403c43b2aae2de8f8c33b037e4 - base_revision: bae5e49bc2a867403c43b2aae2de8f8c33b037e4 + create_revision: 761747bfc538b5af34aa0d3fac380f1bc331ec49 + base_revision: 761747bfc538b5af34aa0d3fac380f1bc331ec49 - platform: windows - create_revision: bae5e49bc2a867403c43b2aae2de8f8c33b037e4 - base_revision: bae5e49bc2a867403c43b2aae2de8f8c33b037e4 + create_revision: 761747bfc538b5af34aa0d3fac380f1bc331ec49 + base_revision: 761747bfc538b5af34aa0d3fac380f1bc331ec49 # User provided section diff --git a/lib/data/model/app/backup.dart b/lib/data/model/app/backup.dart index 00f3f0634..c1fa56322 100644 --- a/lib/data/model/app/backup.dart +++ b/lib/data/model/app/backup.dart @@ -170,7 +170,7 @@ class Backup { } Pros.reload(); - RNodes.app.build(); + RNodes.app.notify(); _logger.info('Restore success'); } diff --git a/lib/data/res/build_data.dart b/lib/data/res/build_data.dart index 473af4a11..2d84ad230 100644 --- a/lib/data/res/build_data.dart +++ b/lib/data/res/build_data.dart @@ -2,6 +2,6 @@ class BuildData { static const String name = "ServerBox"; - static const int build = 1011; + static const int build = 1014; static const int script = 50; } diff --git a/lib/intro.dart b/lib/intro.dart index 08d8b3fe2..ae377744f 100644 --- a/lib/intro.dart +++ b/lib/intro.dart @@ -95,7 +95,7 @@ final class _IntroPage extends StatelessWidget { ); if (selected != null) { _setting.locale.put(selected.code); - RNodes.app.build(); + RNodes.app.notify(); } }, trailing: Text( diff --git a/lib/main.dart b/lib/main.dart index 8f06bceaf..5830fa444 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -75,6 +75,7 @@ Future _initApp() async { size: windowSize.fetch().toSize(), listener: WindowSizeListener(windowSize), ); + FontUtils.loadFrom(Stores.setting.fontPath.fetch()); _doPlatformRelated(); diff --git a/lib/view/page/setting/entry.dart b/lib/view/page/setting/entry.dart index 41a6be7b2..9474cd4a7 100644 --- a/lib/view/page/setting/entry.dart +++ b/lib/view/page/setting/entry.dart @@ -305,7 +305,7 @@ class _SettingPageState extends State { _setting.primaryColor.put(color.value); context.pop(); context.pop(); - RNodes.app.build(); + RNodes.app.notify(); } // Widget _buildLaunchPage() { @@ -393,7 +393,7 @@ class _SettingPageState extends State { ); if (selected != null) { _setting.themeMode.put(selected); - RNodes.app.build(); + RNodes.app.notify(); } }, trailing: ValBuilder( @@ -442,7 +442,7 @@ class _SettingPageState extends State { onPressed: () { _setting.fontPath.delete(); context.pop(); - RNodes.app.build(); + RNodes.app.notify(); }, child: Text(l10n.clear), ) @@ -466,7 +466,7 @@ class _SettingPageState extends State { } context.pop(); - RNodes.app.build(); + RNodes.app.notify(); } Widget _buildTermFontSize() { @@ -536,7 +536,7 @@ class _SettingPageState extends State { if (selected != null) { _setting.locale.put(selected.code); context.pop(); - RNodes.app.build(); + RNodes.app.notify(); } }, trailing: ListenBuilder( @@ -609,7 +609,7 @@ class _SettingPageState extends State { subtitle: Text(l10n.fullScreenTip, style: UIs.textGrey), trailing: StoreSwitch( prop: _setting.fullScreen, - callback: (_) => RNodes.app.build(), + callback: (_) => RNodes.app.notify(), ), ); } @@ -802,7 +802,7 @@ class _SettingPageState extends State { return; } _setting.textFactor.put(val); - RNodes.app.build(); + RNodes.app.notify(); context.pop(); } @@ -1049,7 +1049,7 @@ class _SettingPageState extends State { title: Text(l10n.more), children: [ _buildBeta(), - _buildWakeLock(), + if (isMobile) _buildWakeLock(), _buildCollapseUI(), _buildCupertinoRoute(), if (isDesktop) _buildHideTitleBar(), diff --git a/lib/view/page/ssh/tab.dart b/lib/view/page/ssh/tab.dart index 21a6cb330..61bb1bd05 100644 --- a/lib/view/page/ssh/tab.dart +++ b/lib/view/page/ssh/tab.dart @@ -1,4 +1,5 @@ import 'package:fl_lib/fl_lib.dart'; +import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:icons_plus/icons_plus.dart'; import 'package:provider/provider.dart'; @@ -89,7 +90,7 @@ class _SSHTabPageState extends State if (confirm != true) return; _tabMap.remove(name); - _tabRN.build(); + _tabRN.notify(); _pageCtrl.previousPage( duration: Durations.medium1, curve: Curves.fastEaseInToSlowEaseOut); } @@ -191,7 +192,7 @@ class _SSHTabPageState extends State ), key: key, ); - _tabRN.build(); + _tabRN.notify(); // Wait for the page to be built await Future.delayed(Durations.short3); final idx = _tabMap.keys.toList().indexOf(name); @@ -213,7 +214,7 @@ final class _TabBar extends StatelessWidget implements PreferredSizeWidget { required this.onClose, }); - final ValueNotifier idxVN; + final ValueListenable idxVN; final _TabMap map; final void Function(int idx) onTap; final void Function(String name) onClose; diff --git a/linux/CMakeLists.txt b/linux/CMakeLists.txt index 621aaed11..5ec7fc684 100644 --- a/linux/CMakeLists.txt +++ b/linux/CMakeLists.txt @@ -1,11 +1,19 @@ +# Project-level configuration. cmake_minimum_required(VERSION 3.10) project(runner LANGUAGES CXX) +# The name of the executable created for the application. Change this to change +# the on-disk name of your application. set(BINARY_NAME "ServerBox") +# The unique GTK application identifier for this application. See: +# https://wiki.gnome.org/HowDoI/ChooseApplicationID set(APPLICATION_ID "tech.lolli.toolbox") +# Explicitly opt in to modern CMake behaviors to avoid warnings with recent +# versions of CMake. cmake_policy(SET CMP0063 NEW) +# Load bundled libraries from the lib/ directory relative to the binary. set(CMAKE_INSTALL_RPATH "$ORIGIN/lib") # Root filesystem for cross-building. @@ -18,7 +26,7 @@ if(FLUTTER_TARGET_PLATFORM_SYSROOT) set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) endif() -# Configure build options. +# Define build configuration options. if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Flutter build mode" FORCE) @@ -27,6 +35,10 @@ if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) endif() # Compilation settings that should be applied to most targets. +# +# Be cautious about adding new options here, as plugins use this function by +# default. In most cases, you should add new options to specific targets instead +# of modifying this function. function(APPLY_STANDARD_SETTINGS TARGET) target_compile_features(${TARGET} PUBLIC cxx_std_14) target_compile_options(${TARGET} PRIVATE -Wall -Werror) @@ -34,9 +46,8 @@ function(APPLY_STANDARD_SETTINGS TARGET) target_compile_definitions(${TARGET} PRIVATE "$<$>:NDEBUG>") endfunction() -set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") - # Flutter library and tool build rules. +set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") add_subdirectory(${FLUTTER_MANAGED_DIR}) # System-level dependencies. @@ -45,16 +56,27 @@ pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) add_definitions(-DAPPLICATION_ID="${APPLICATION_ID}") -# Application build +# Define the application target. To change its name, change BINARY_NAME above, +# not the value here, or `flutter run` will no longer work. +# +# Any new source files that you add to the application should be added here. add_executable(${BINARY_NAME} "main.cc" "my_application.cc" "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" ) + +# Apply the standard set of build settings. This can be removed for applications +# that need different build settings. apply_standard_settings(${BINARY_NAME}) + +# Add dependency libraries. Add any application-specific dependencies here. target_link_libraries(${BINARY_NAME} PRIVATE flutter) target_link_libraries(${BINARY_NAME} PRIVATE PkgConfig::GTK) + +# Run the Flutter tool portions of the build. This must not be removed. add_dependencies(${BINARY_NAME} flutter_assemble) + # Only the install-generated bundle's copy of the executable will launch # correctly, since the resources must in the right relative locations. To avoid # people trying to run the unbundled copy, put it in a subdirectory instead of @@ -64,6 +86,7 @@ set_target_properties(${BINARY_NAME} RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/intermediates_do_not_run" ) + # Generated plugin build rules, which manage building the plugins and adding # them to the application. include(flutter/generated_plugins.cmake) @@ -94,11 +117,17 @@ install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR} install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) -if(PLUGIN_BUNDLED_LIBRARIES) - install(FILES "${PLUGIN_BUNDLED_LIBRARIES}" +foreach(bundled_library ${PLUGIN_BUNDLED_LIBRARIES}) + install(FILES "${bundled_library}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) -endif() +endforeach(bundled_library) + +# Copy the native assets provided by the build.dart from all packages. +set(NATIVE_ASSETS_DIR "${PROJECT_BUILD_DIR}native_assets/linux/") +install(DIRECTORY "${NATIVE_ASSETS_DIR}" + DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" + COMPONENT Runtime) # Fully re-copy the assets directory on each build to avoid having stale files # from a previous install. diff --git a/linux/flutter/CMakeLists.txt b/linux/flutter/CMakeLists.txt index 33fd5801e..d5bd01648 100644 --- a/linux/flutter/CMakeLists.txt +++ b/linux/flutter/CMakeLists.txt @@ -1,3 +1,4 @@ +# This file controls Flutter-level build steps. It should not be edited. cmake_minimum_required(VERSION 3.10) set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral") diff --git a/linux/my_application.cc b/linux/my_application.cc index 6370004fe..8bf67faf6 100644 --- a/linux/my_application.cc +++ b/linux/my_application.cc @@ -20,6 +20,33 @@ static void my_application_activate(GApplication* application) { GtkWindow* window = GTK_WINDOW(gtk_application_window_new(GTK_APPLICATION(application))); + // Use a header bar when running in GNOME as this is the common style used + // by applications and is the setup most users will be using (e.g. Ubuntu + // desktop). + // If running on X and not using GNOME then just use a traditional title bar + // in case the window manager does more exotic layout, e.g. tiling. + // If running on Wayland assume the header bar will work (may need changing + // if future cases occur). + gboolean use_header_bar = TRUE; +#ifdef GDK_WINDOWING_X11 + GdkScreen* screen = gtk_window_get_screen(window); + if (GDK_IS_X11_SCREEN(screen)) { + const gchar* wm_name = gdk_x11_screen_get_window_manager_name(screen); + if (g_strcmp0(wm_name, "GNOME Shell") != 0) { + use_header_bar = FALSE; + } + } +#endif + if (use_header_bar) { + GtkHeaderBar* header_bar = GTK_HEADER_BAR(gtk_header_bar_new()); + gtk_widget_show(GTK_WIDGET(header_bar)); + gtk_header_bar_set_title(header_bar, "ServerBox"); + gtk_header_bar_set_show_close_button(header_bar, TRUE); + gtk_window_set_titlebar(window, GTK_WIDGET(header_bar)); + } else { + gtk_window_set_title(window, "ServerBox"); + } + gtk_window_set_default_size(window, 400, 777); gtk_widget_show(GTK_WIDGET(window)); @@ -54,6 +81,24 @@ static gboolean my_application_local_command_line(GApplication* application, gch return TRUE; } +// Implements GApplication::startup. +static void my_application_startup(GApplication* application) { + //MyApplication* self = MY_APPLICATION(object); + + // Perform any actions required at application startup. + + G_APPLICATION_CLASS(my_application_parent_class)->startup(application); +} + +// Implements GApplication::shutdown. +static void my_application_shutdown(GApplication* application) { + //MyApplication* self = MY_APPLICATION(object); + + // Perform any actions required at application shutdown. + + G_APPLICATION_CLASS(my_application_parent_class)->shutdown(application); +} + // Implements GObject::dispose. static void my_application_dispose(GObject* object) { MyApplication* self = MY_APPLICATION(object); @@ -64,6 +109,8 @@ static void my_application_dispose(GObject* object) { static void my_application_class_init(MyApplicationClass* klass) { G_APPLICATION_CLASS(klass)->activate = my_application_activate; G_APPLICATION_CLASS(klass)->local_command_line = my_application_local_command_line; + G_APPLICATION_CLASS(klass)->startup = my_application_startup; + G_APPLICATION_CLASS(klass)->shutdown = my_application_shutdown; G_OBJECT_CLASS(klass)->dispose = my_application_dispose; } diff --git a/pubspec.lock b/pubspec.lock index 30d534056..89599364e 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -368,8 +368,8 @@ packages: dependency: "direct dev" description: path: "." - ref: "v1.0.32" - resolved-ref: "66b36278a2f9f60da3dba804e81148afc60e342e" + ref: "v1.0.33" + resolved-ref: "885c3479db8867f1c4078b97f65578ee2cbc9466" url: "https://github.com/lppcg/fl_build.git" source: git version: "1.0.0" @@ -385,8 +385,8 @@ packages: dependency: "direct main" description: path: "." - ref: "v1.0.60" - resolved-ref: "5a88f7c6901e8f2c556a1d79ceaf7be9fb518233" + ref: "v1.0.67" + resolved-ref: e91886e49ccede77ba7fed14325963ac260f999e url: "https://github.com/lppcg/fl_lib" source: git version: "0.0.1" diff --git a/pubspec.yaml b/pubspec.yaml index 3eb80cad9..513d23100 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,7 +1,7 @@ name: server_box description: server status & toolbox app. publish_to: 'none' -version: 1.0.1011+1011 +version: 1.0.1014+1014 environment: sdk: ">=3.0.0" @@ -58,7 +58,7 @@ dependencies: fl_lib: git: url: https://github.com/lppcg/fl_lib - ref: v1.0.60 + ref: v1.0.67 dependency_overrides: # dartssh2: @@ -79,7 +79,7 @@ dev_dependencies: # path: ../fl_build git: url: https://github.com/lppcg/fl_build.git - ref: v1.0.32 + ref: v1.0.33 flutter: generate: true