Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(macOS): Hide traffic lights in band and dock sizes #182

Merged
merged 2 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Justfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
set dotenv-load

lint:
cargo fmt -- $(find native/hub/src/messages -name "*.rs")
cargo fmt -- --check
cargo clippy -- -D warnings
flutter analyze .
Expand Down
2 changes: 1 addition & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ void main(List<String> arguments) async {

doWhenWindowReady(() {
if (Platform.isMacOS) {
MacOSWindowControlButtonManager.setVertical();
MacOSWindowControlButtonManager.shared.setVertical();
}

appWindow.size = windowSize;
Expand Down
16 changes: 14 additions & 2 deletions lib/utils/macos_window_control_button_manager.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
import 'package:flutter/services.dart';

class MacOSWindowControlButtonManager {
static const platform = MethodChannel('not.ci.rune/window_control_button');
static var shared = MacOSWindowControlButtonManager._();

static Future<void> setVertical() async {
MacOSWindowControlButtonManager._();

var platform = MethodChannel('not.ci.rune/window_control_button');
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Consider making the platform channel final to prevent accidental modification

Instance variables that represent system resources like platform channels should generally be immutable to prevent potential issues.

Suggested change
var platform = MethodChannel('not.ci.rune/window_control_button');
final platform = MethodChannel('not.ci.rune/window_control_button');


Future<void> setVertical() async {
await platform.invokeMethod('set_vertical');
}

Future<void> setHide() async {
await platform.invokeMethod('set_hide');
}

Future<void> setShow() async {
await platform.invokeMethod('set_show');
}
}
7 changes: 7 additions & 0 deletions lib/widgets/title_bar/window_frame_for_macos.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ class _WindowFrameForMacOSState extends State<WindowFrameForMacOS> {
DeviceType.tv
],
builder: (context, activeBreakpoint) {
if (activeBreakpoint == DeviceType.band ||
activeBreakpoint == DeviceType.dock) {
MacOSWindowControlButtonManager.shared.setHide();
} else {
MacOSWindowControlButtonManager.shared.setShow();
}

if (activeBreakpoint == DeviceType.band ||
activeBreakpoint == DeviceType.dock ||
path == '/' ||
Expand Down
16 changes: 16 additions & 0 deletions macos/Runner/MainFlutterWindow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ class MainFlutterWindow: BitsdojoWindow {
switch call.method {
case "set_vertical":
WindowButtonPositioner.shared.setVertical()
case "set_hide":
WindowButtonPositioner.shared.setHide()
case "set_show":
WindowButtonPositioner.shared.setShow()
default:
result(FlutterMethodNotImplemented)
}
Expand Down Expand Up @@ -87,6 +91,18 @@ class WindowButtonPositioner {
self.mainFlutterWindow = mainFlutterWindow
}

func setHide() {
mainFlutterWindow?.standardWindowButton(.closeButton)?.isHidden = true
mainFlutterWindow?.standardWindowButton(.miniaturizeButton)?.isHidden = true
mainFlutterWindow?.standardWindowButton(.zoomButton)?.isHidden = true
}

func setShow() {
mainFlutterWindow?.standardWindowButton(.closeButton)?.isHidden = false
mainFlutterWindow?.standardWindowButton(.miniaturizeButton)?.isHidden = false
mainFlutterWindow?.standardWindowButton(.zoomButton)?.isHidden = false
}

func setVertical() {
overrideStandardWindowButtonPosition(buttonType: .closeButton, offset: .init(x: 8, y: 8))
overrideStandardWindowButtonPosition(buttonType: .miniaturizeButton, offset: .init(x: 8, y: 28))
Expand Down
8 changes: 3 additions & 5 deletions native/hub/src/license.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,13 @@ pub async fn check_store_license() -> Result<Option<(String, bool, bool)>> {
pub async fn check_store_license() -> Result<Option<(String, bool, bool)>, &'static str> {
use crate::apple_bridge::apple_bridge::bundle_id;
let bundle_id = bundle_id();
let mut is_active = false;
let mut is_trial = false;

if bundle_id == "ci.not.rune.appstore" {
is_active = true;
is_trial = false;
let is_active = true;
let is_trial = false;
Ok(Some((bundle_id, is_active, is_trial)))
} else {
return Ok(None)
Ok(None)
}
}

Expand Down
Loading