Skip to content

Commit

Permalink
feat: window blur effect add
Browse files Browse the repository at this point in the history
  • Loading branch information
KRTirtho committed Dec 9, 2022
1 parent 4dc26af commit b0db5e7
Show file tree
Hide file tree
Showing 11 changed files with 43 additions and 8 deletions.
2 changes: 2 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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();
Expand Down
16 changes: 14 additions & 2 deletions lib/pages/root/root_app.dart
Original file line number Diff line number Diff line change
@@ -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: "/",
Expand All @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions linux/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include <audioplayers_linux/audioplayers_linux_plugin.h>
#include <bitsdojo_window_linux/bitsdojo_window_plugin.h>
#include <flutter_acrylic/flutter_acrylic_plugin.h>
#include <metadata_god/metadata_god_plugin.h>
#include <url_launcher_linux/url_launcher_plugin.h>

Expand All @@ -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);
Expand Down
1 change: 1 addition & 0 deletions linux/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
list(APPEND FLUTTER_PLUGIN_LIST
audioplayers_linux
bitsdojo_window_linux
flutter_acrylic
metadata_god
url_launcher_linux
)
Expand Down
4 changes: 1 addition & 3 deletions linux/my_application.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
2 changes: 2 additions & 0 deletions macos/Flutter/GeneratedPluginRegistrant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"))
Expand Down
10 changes: 7 additions & 3 deletions macos/Runner/MainFlutterWindow.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import flutter_acrylic
import Cocoa
import FlutterMacOS
import bitsdojo_window_macos
Expand All @@ -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()
}
Expand Down
7 changes: 7 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions windows/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <audioplayers_windows/audioplayers_windows_plugin.h>
#include <bitsdojo_window_windows/bitsdojo_window_plugin.h>
#include <connectivity_plus_windows/connectivity_plus_windows_plugin.h>
#include <flutter_acrylic/flutter_acrylic_plugin.h>
#include <metadata_god/metadata_god_plugin_c_api.h>
#include <permission_handler_windows/permission_handler_windows_plugin.h>
#include <url_launcher_windows/url_launcher_windows.h>
Expand All @@ -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(
Expand Down
1 change: 1 addition & 0 deletions windows/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b0db5e7

Please sign in to comment.