From b0db5e7d8246f98835e7ce6656c8aa7620e46bec Mon Sep 17 00:00:00 2001 From: Kingkor Roy Tirtho Date: Fri, 9 Dec 2022 13:42:18 +0600 Subject: [PATCH] feat: window blur effect add --- lib/main.dart | 2 ++ lib/pages/root/root_app.dart | 16 ++++++++++++++-- linux/flutter/generated_plugin_registrant.cc | 4 ++++ linux/flutter/generated_plugins.cmake | 1 + linux/my_application.cc | 4 +--- macos/Flutter/GeneratedPluginRegistrant.swift | 2 ++ macos/Runner/MainFlutterWindow.swift | 10 +++++++--- pubspec.lock | 7 +++++++ pubspec.yaml | 1 + windows/flutter/generated_plugin_registrant.cc | 3 +++ windows/flutter/generated_plugins.cmake | 1 + 11 files changed, 43 insertions(+), 8 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index 8b2c3da7e..e33eb9f1d 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -6,6 +6,7 @@ import 'package:fl_query/fl_query.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; +import 'package:flutter_acrylic/flutter_acrylic.dart'; import 'package:flutter_hooks/flutter_hooks.dart'; import 'package:hive_flutter/hive_flutter.dart'; import 'package:hooks_riverpod/hooks_riverpod.dart'; @@ -34,6 +35,7 @@ void main() async { Hive.registerAdapter(CacheTrackEngagementAdapter()); Hive.registerAdapter(CacheTrackSkipSegmentAdapter()); WidgetsFlutterBinding.ensureInitialized(); + await Window.initialize(); if (kIsDesktop) { doWhenWindowReady(() async { final localStorage = await SharedPreferences.getInstance(); diff --git a/lib/pages/root/root_app.dart b/lib/pages/root/root_app.dart index d601ddad3..d6ec18fc9 100644 --- a/lib/pages/root/root_app.dart +++ b/lib/pages/root/root_app.dart @@ -1,18 +1,18 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; +import 'package:flutter_acrylic/flutter_acrylic.dart'; import 'package:flutter_hooks/flutter_hooks.dart'; import 'package:go_router/go_router.dart'; import 'package:hooks_riverpod/hooks_riverpod.dart'; import 'package:platform_ui/platform_ui.dart'; -import 'package:spotube/collections/side_bar_tiles.dart'; import 'package:spotube/components/shared/dialogs/replace_downloaded_dialog.dart'; import 'package:spotube/components/root/bottom_player.dart'; import 'package:spotube/components/root/sidebar.dart'; import 'package:spotube/components/root/spotube_navigation_bar.dart'; import 'package:spotube/components/shared/page_window_title_bar.dart'; -import 'package:spotube/hooks/use_breakpoints.dart'; import 'package:spotube/hooks/use_update_checker.dart'; import 'package:spotube/provider/downloader_provider.dart'; +import 'package:spotube/utils/platform.dart'; const rootPaths = { 0: "/", @@ -34,6 +34,18 @@ class RootApp extends HookConsumerWidget { final isMounted = useIsMounted(); final downloader = ref.watch(downloaderProvider); + + useEffect(() { + WidgetsBinding.instance.addPostFrameCallback((_) { + Window.setEffect( + effect: kIsLinux ? WindowEffect.transparent : WindowEffect.acrylic, + color: PlatformTheme.of(context).scaffoldBackgroundColor!, + dark: PlatformTheme.of(context).brightness == Brightness.dark, + ); + }); + return null; + }, []); + useEffect(() { downloader.onFileExists = (track) async { if (!isMounted()) return false; diff --git a/linux/flutter/generated_plugin_registrant.cc b/linux/flutter/generated_plugin_registrant.cc index bf0cd78b6..b234ee20d 100644 --- a/linux/flutter/generated_plugin_registrant.cc +++ b/linux/flutter/generated_plugin_registrant.cc @@ -8,6 +8,7 @@ #include #include +#include #include #include @@ -18,6 +19,9 @@ void fl_register_plugins(FlPluginRegistry* registry) { 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) flutter_acrylic_registrar = + fl_plugin_registry_get_registrar_for_plugin(registry, "FlutterAcrylicPlugin"); + flutter_acrylic_plugin_register_with_registrar(flutter_acrylic_registrar); g_autoptr(FlPluginRegistrar) metadata_god_registrar = fl_plugin_registry_get_registrar_for_plugin(registry, "MetadataGodPlugin"); metadata_god_plugin_register_with_registrar(metadata_god_registrar); diff --git a/linux/flutter/generated_plugins.cmake b/linux/flutter/generated_plugins.cmake index 0de3bf803..3a6bc5001 100644 --- a/linux/flutter/generated_plugins.cmake +++ b/linux/flutter/generated_plugins.cmake @@ -5,6 +5,7 @@ list(APPEND FLUTTER_PLUGIN_LIST audioplayers_linux bitsdojo_window_linux + flutter_acrylic metadata_god url_launcher_linux ) diff --git a/linux/my_application.cc b/linux/my_application.cc index e1aa9337c..0961797ac 100644 --- a/linux/my_application.cc +++ b/linux/my_application.cc @@ -51,13 +51,11 @@ static void my_application_activate(GApplication* application) { auto bdw = bitsdojo_window_from(window); bdw->setCustomFrame(true); // gtk_window_set_default_size(window, 1280, 720); - gtk_widget_show(GTK_WIDGET(window)); - g_autoptr(FlDartProject) project = fl_dart_project_new(); fl_dart_project_set_dart_entrypoint_arguments(project, self->dart_entrypoint_arguments); FlView* view = fl_view_new(project); - gtk_widget_show(GTK_WIDGET(view)); + gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(view)); fl_register_plugins(FL_PLUGIN_REGISTRY(view)); diff --git a/macos/Flutter/GeneratedPluginRegistrant.swift b/macos/Flutter/GeneratedPluginRegistrant.swift index 7beb29a87..e0226747c 100644 --- a/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/macos/Flutter/GeneratedPluginRegistrant.swift @@ -10,6 +10,7 @@ import audio_session import audioplayers_darwin import bitsdojo_window_macos import connectivity_plus_macos +import flutter_acrylic import macos_ui import metadata_god import package_info_plus_macos @@ -24,6 +25,7 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { AudioplayersDarwinPlugin.register(with: registry.registrar(forPlugin: "AudioplayersDarwinPlugin")) BitsdojoWindowPlugin.register(with: registry.registrar(forPlugin: "BitsdojoWindowPlugin")) ConnectivityPlugin.register(with: registry.registrar(forPlugin: "ConnectivityPlugin")) + FlutterAcrylicPlugin.register(with: registry.registrar(forPlugin: "FlutterAcrylicPlugin")) MacOSUiPlugin.register(with: registry.registrar(forPlugin: "MacOSUiPlugin")) MetadataGodPlugin.register(with: registry.registrar(forPlugin: "MetadataGodPlugin")) FLTPackageInfoPlusPlugin.register(with: registry.registrar(forPlugin: "FLTPackageInfoPlusPlugin")) diff --git a/macos/Runner/MainFlutterWindow.swift b/macos/Runner/MainFlutterWindow.swift index a5e040aae..ffde4f98c 100644 --- a/macos/Runner/MainFlutterWindow.swift +++ b/macos/Runner/MainFlutterWindow.swift @@ -1,3 +1,4 @@ +import flutter_acrylic import Cocoa import FlutterMacOS import bitsdojo_window_macos @@ -8,12 +9,15 @@ class MainFlutterWindow: BitsdojoWindow { } override func awakeFromNib() { - let flutterViewController = FlutterViewController.init() let windowFrame = self.frame - self.contentViewController = flutterViewController + let blurryContainerViewController = BlurryContainerViewController() + self.contentViewController = blurryContainerViewController self.setFrame(windowFrame, display: true) - RegisterGeneratedPlugins(registry: flutterViewController) + /* Initialize the flutter_acrylic plugin */ + MainFlutterWindowManipulator.start(mainFlutterWindow: self) + + RegisterGeneratedPlugins(registry: blurryContainerViewController.flutterViewController) super.awakeFromNib() } diff --git a/pubspec.lock b/pubspec.lock index 8170dfeb2..63009c504 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -512,6 +512,13 @@ packages: description: flutter source: sdk version: "0.0.0" + flutter_acrylic: + dependency: "direct main" + description: + name: flutter_acrylic + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.0+2" flutter_app_builder: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 9db31b792..d39d56ffb 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -70,6 +70,7 @@ dependencies: macos_ui: ^1.7.5 libadwaita: ^1.2.5 adwaita: ^0.5.2 + flutter_acrylic: 1.0.0+2 dev_dependencies: flutter_test: diff --git a/windows/flutter/generated_plugin_registrant.cc b/windows/flutter/generated_plugin_registrant.cc index c40e4841a..802eee4f5 100644 --- a/windows/flutter/generated_plugin_registrant.cc +++ b/windows/flutter/generated_plugin_registrant.cc @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -20,6 +21,8 @@ void RegisterPlugins(flutter::PluginRegistry* registry) { registry->GetRegistrarForPlugin("BitsdojoWindowPlugin")); ConnectivityPlusWindowsPluginRegisterWithRegistrar( registry->GetRegistrarForPlugin("ConnectivityPlusWindowsPlugin")); + FlutterAcrylicPluginRegisterWithRegistrar( + registry->GetRegistrarForPlugin("FlutterAcrylicPlugin")); MetadataGodPluginCApiRegisterWithRegistrar( registry->GetRegistrarForPlugin("MetadataGodPluginCApi")); PermissionHandlerWindowsPluginRegisterWithRegistrar( diff --git a/windows/flutter/generated_plugins.cmake b/windows/flutter/generated_plugins.cmake index 5dca4667d..8c87de867 100644 --- a/windows/flutter/generated_plugins.cmake +++ b/windows/flutter/generated_plugins.cmake @@ -6,6 +6,7 @@ list(APPEND FLUTTER_PLUGIN_LIST audioplayers_windows bitsdojo_window_windows connectivity_plus_windows + flutter_acrylic metadata_god permission_handler_windows url_launcher_windows