Skip to content

Commit

Permalink
fix: share button doesn't response under macos 15
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasXu0 committed Oct 5, 2024
1 parent 8e6f051 commit d35a616
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
13 changes: 10 additions & 3 deletions frontend/appflowy_flutter/lib/core/frameless_window.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'dart:io';

import 'package:appflowy/startup/tasks/device_info_task.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:universal_platform/universal_platform.dart';

class CocoaWindowChannel {
CocoaWindowChannel._();
Expand Down Expand Up @@ -44,7 +44,14 @@ class MoveWindowDetectorState extends State<MoveWindowDetector> {

@override
Widget build(BuildContext context) {
if (!Platform.isMacOS) {
// the frameless window is only supported on macOS
if (!UniversalPlatform.isMacOS) {
return widget.child ?? const SizedBox.shrink();
}

// above macOS 15, we can control the window position by using system APIs
if (ApplicationInfo.macOSMajorVersion != null &&
ApplicationInfo.macOSMajorVersion! >= 15) {
return widget.child ?? const SizedBox.shrink();
}

Expand Down
10 changes: 10 additions & 0 deletions frontend/appflowy_flutter/lib/startup/tasks/device_info_task.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ class ApplicationInfo {
static String applicationVersion = '';
static String buildNumber = '';
static String deviceId = '';

// macOS major version
static int? macOSMajorVersion;
static int? macOSMinorVersion;
}

class ApplicationInfoTask extends LaunchTask {
Expand All @@ -21,6 +25,12 @@ class ApplicationInfoTask extends LaunchTask {
final DeviceInfoPlugin deviceInfoPlugin = DeviceInfoPlugin();
final PackageInfo packageInfo = await PackageInfo.fromPlatform();

if (Platform.isMacOS) {
final macInfo = await deviceInfoPlugin.macOsInfo;
ApplicationInfo.macOSMajorVersion = macInfo.majorVersion;
ApplicationInfo.macOSMinorVersion = macInfo.minorVersion;
}

if (Platform.isAndroid) {
final androidInfo = await deviceInfoPlugin.androidInfo;
ApplicationInfo.androidSDKVersion = androidInfo.version.sdkInt;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ class MainFlutterWindow: NSWindow {
self.styleMask.insert(StyleMask.fullSizeContentView)
self.isMovableByWindowBackground = true

// For the macOS version 15 or higher, set it to true to enable the window tiling
if #available(macOS 15.0, *) {
self.isMovable = true
} else {
self.isMovable = false
}

self.layoutTrafficLights()

RegisterGeneratedPlugins(registry: flutterViewController)
Expand Down

0 comments on commit d35a616

Please sign in to comment.