Skip to content

Commit

Permalink
0.0.8 - macOS support
Browse files Browse the repository at this point in the history
  • Loading branch information
bitsdojo committed Mar 2, 2021
1 parent 4098294 commit 51081d7
Show file tree
Hide file tree
Showing 34 changed files with 824 additions and 261 deletions.
59 changes: 53 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# bitsdojo_window

A Flutter package that makes it easy to customize and work with your Flutter desktop app window.
A Flutter package that makes it easy to customize and work with your Flutter desktop app window **on both Windows and macOS** .

Watch the tutorial to get started. Click the image below to watch the video:

[![IMAGE ALT TEXT](https://img.youtube.com/vi/bee2AHQpGK4/0.jpg)](http://www.youtube.com/watch?v=bee2AHQpGK4 "Click to open")
[![IMAGE ALT TEXT](https://img.youtube.com/vi/bee2AHQpGK4/0.jpg)](https://www.youtube.com/watch?v=bee2AHQpGK4 "Click to open")

<img src="https://raw.githubusercontent.com/bitsdojo/bitsdojo_window/master/resources/screenshot.png">

**Features**:

- Custom window frame - remove standard Windows titlebar and buttons
- Custom window frame - remove standard Windows/macOS titlebar and buttons
- Hide window on startup
- Show/hide window
- Move window using Flutter widget
Expand All @@ -21,23 +21,70 @@ Watch the tutorial to get started. Click the image below to watch the video:
- Set window title


Currently working with Flutter desktop apps for **Windows**. macOS support is also planned in the future.
Currently working with Flutter desktop apps for **Windows** and **macOS**. Linux support is also planned in the future.

## Getting Started
# Getting Started

Install the package using `pubspec.yaml`

# For Windows apps

Inside your application folder, go to `windows\runner\main.cpp` and add these two lines at the beginning of the file:

```cpp
#include <bitsdojo_window_windows/bitsdojo_window_plugin.h>
auto bdw = bitsdojo_window_configure(BDW_CUSTOM_FRAME | BDW_HIDE_ON_STARTUP);
```

If you don't want to use a custom frame and prefer the standard Windows titlebar and buttons, you can remove the `BDW_CUSTOM_FRAME` flag from the code above.
# For macOS apps

Inside your application folder, go to `macos\runner\MainFlutterWindow.swift` and add this line after the one saying `import FlutterMacOS` :

```swift
import FlutterMacOS
import bitsdojo_window_macos // Add this line
```

Then change this line from:

```swift
class MainFlutterWindow: NSWindow {
```

to this:

```swift
class MainFlutterWindow: BitsdojoWindow {
```

After changing `NSWindow` to `BitsdojoWindow` add these lines below the line you changed:

```swift
override func bitsdojo_window_configure() -> UInt {
return BDW_CUSTOM_FRAME | BDW_HIDE_ON_STARTUP
}
```

Your code should now look like this:

```swift
class MainFlutterWindow: BitsdojoWindow {

override func bitsdojo_window_configure() -> UInt {
return BDW_CUSTOM_FRAME | BDW_HIDE_ON_STARTUP
}

override func awakeFromNib() {
... //rest of your code
```
#

If you don't want to use a custom frame and prefer the standard window titlebar and buttons, you can remove the `BDW_CUSTOM_FRAME` flag from the code above.

If you don't want to hide the window on startup, you can remove the `BDW_HIDE_ON_STARTUP` flag from the code above.

# Flutter app integration

Now go to `lib\main.dart` and add this code in the `main` function right after `runApp(MyApp());` :

```dart
Expand Down
4 changes: 4 additions & 0 deletions bitsdojo_window/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.0.8
- Added macOS readme instructions
## 0.0.7
- macOS support added
## 0.0.6
- Works with latest Flutter version (master channel)
## 0.0.5
Expand Down
65 changes: 56 additions & 9 deletions bitsdojo_window/README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# bitsdojo_window

A Flutter package that makes it easy to customize and work with your Flutter desktop app window.
A Flutter package that makes it easy to customize and work with your Flutter desktop app window **on both Windows and macOS** .

Watch the tutorial to get started. Click the image below to watch the video:

[![IMAGE ALT TEXT](https://img.youtube.com/vi/bee2AHQpGK4/0.jpg)](http://www.youtube.com/watch?v=bee2AHQpGK4 "Click to open")
[![IMAGE ALT TEXT](https://img.youtube.com/vi/bee2AHQpGK4/0.jpg)](https://www.youtube.com/watch?v=bee2AHQpGK4 "Click to open")

<img src="https://raw.githubusercontent.com/bitsdojo/bitsdojo_window/master/resources/screenshot.png">

**Features**:

- Custom window frame - remove standard Windows titlebar and buttons
- Custom window frame - remove standard Windows/macOS titlebar and buttons
- Hide window on startup
- Show/hide window
- Move window using Flutter widget
Expand All @@ -21,26 +21,73 @@ Watch the tutorial to get started. Click the image below to watch the video:
- Set window title


Currently working with Flutter desktop apps for **Windows**. macOS support is also planned in the future.
Currently working with Flutter desktop apps for **Windows** and **macOS**. Linux support is also planned in the future.

## Getting Started
# Getting Started

Install the package using `pubspec.yaml`

# For Windows apps

Inside your application folder, go to `windows\runner\main.cpp` and add these two lines at the beginning of the file:

```
```cpp
#include <bitsdojo_window_windows/bitsdojo_window_plugin.h>
auto bdw = bitsdojo_window_configure(BDW_CUSTOM_FRAME | BDW_HIDE_ON_STARTUP);
```

If you don't want to use a custom frame and prefer the standard Windows titlebar and buttons, you can remove the `BDW_CUSTOM_FRAME` flag from the code above.
# For macOS apps

Inside your application folder, go to `macos\runner\MainFlutterWindow.swift` and add this line after the one saying `import FlutterMacOS` :

```swift
import FlutterMacOS
import bitsdojo_window_macos // Add this line
```

Then change this line from:

```swift
class MainFlutterWindow: NSWindow {
```

to this:

```swift
class MainFlutterWindow: BitsdojoWindow {
```

After changing `NSWindow` to `BitsdojoWindow` add these lines below the line you changed:

```swift
override func bitsdojo_window_configure() -> UInt {
return BDW_CUSTOM_FRAME | BDW_HIDE_ON_STARTUP
}
```

Your code should now look like this:

```swift
class MainFlutterWindow: BitsdojoWindow {

override func bitsdojo_window_configure() -> UInt {
return BDW_CUSTOM_FRAME | BDW_HIDE_ON_STARTUP
}

override func awakeFromNib() {
... //rest of your code
```
#

If you don't want to use a custom frame and prefer the standard window titlebar and buttons, you can remove the `BDW_CUSTOM_FRAME` flag from the code above.

If you don't want to hide the window on startup, you can remove the `BDW_HIDE_ON_STARTUP` flag from the code above.

# Flutter app integration

Now go to `lib\main.dart` and add this code in the `main` function right after `runApp(MyApp());` :

```
```dart
void main() {
runApp(MyApp());

Expand All @@ -62,7 +109,7 @@ You can find examples in the `example` folder.
Here is an example that displays this window:


```
```dart
import 'package:flutter/material.dart';
import 'package:bitsdojo_window/bitsdojo_window.dart';

Expand Down
4 changes: 3 additions & 1 deletion bitsdojo_window/example/macos/Runner/MainFlutterWindow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ import FlutterMacOS
import bitsdojo_window_macos

class MainFlutterWindow: BitsdojoWindow {
override func bitsdojo_window_configure() -> UInt {

override func bitsdojo_window_configure() -> UInt {
return BDW_CUSTOM_FRAME | BDW_HIDE_ON_STARTUP
}

override func awakeFromNib() {
let flutterViewController = FlutterViewController.init()
let windowFrame = self.frame
Expand Down
4 changes: 1 addition & 3 deletions bitsdojo_window/lib/src/app_window.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import 'dart:ui';
import 'package:bitsdojo_window/src/other_platform.dart';
import 'package:bitsdojo_window_platform_interface/bitsdojo_window_platform_interface.dart';
import 'package:bitsdojo_window_platform_interface/method_channel_bitsdojo_window.dart';
import 'package:bitsdojo_window_windows/bitsdojo_window_windows.dart';
import 'package:bitsdojo_window_macos/bitsdojo_window_macos.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter/foundation.dart' show kIsWeb;

import 'dart:io' show Platform;
import './other_platform.dart';

bool _platformInstanceNeedsInit = true;

Expand Down
10 changes: 10 additions & 0 deletions bitsdojo_window/lib/src/other_platform.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,16 @@ class OtherWindow extends DesktopWindow {
throw UnimplementedError('hide() has not been implemented.');
}

@Deprecated("use isVisible instead")
bool get visible {
return isVisible;
}

bool get isVisible {
throw UnimplementedError('isVisible has not been implemented.');
}

@Deprecated("use show()/hide() instead")
set visible(bool isVisible) {
throw UnimplementedError('visible setter has not been implemented.');
}
Expand Down
8 changes: 7 additions & 1 deletion bitsdojo_window/lib/src/widgets/window_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import './mouse_state_builder.dart';
import '../icons/icons.dart';
import '../app_window.dart';
import 'package:flutter/foundation.dart' show kIsWeb;
import 'dart:io' show Platform;

typedef WindowButtonIconBuilder = Widget Function(
WindowButtonContext buttonContext);
Expand Down Expand Up @@ -81,6 +82,11 @@ class WindowButton extends StatelessWidget {
Widget build(BuildContext context) {
if (kIsWeb) {
return Container();
} else {
// Don't show button on macOS
if (Platform.isMacOS) {
return Container();
}
}
final buttonSize = appWindow.titleBarButtonSize;
return MouseStateBuilder(
Expand All @@ -96,7 +102,7 @@ class WindowButton extends StatelessWidget {
double borderSize = appWindow.borderSize;
double defaultPadding =
(appWindow.titleBarHeight - borderSize) / 3 - (borderSize / 2);
// Used when buttonContext.backgroundColor is null, allowing the AnimatedContainer to fade-out smoothly.
// Used when buttonContext.backgroundColor is null, allowing the AnimatedContainer to fade-out smoothly.
var fadeOutColor =
getBackgroundColor(MouseState()..isMouseOver = true).withOpacity(0);
var padding = this.padding ?? EdgeInsets.all(defaultPadding);
Expand Down
10 changes: 5 additions & 5 deletions bitsdojo_window/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: bitsdojo_window
description: A package to help with creating custom windows (custom border, titlebar and minimize/maximize/close buttons) and common window operations (show/hide/position on screen)
version: 0.0.6
description: A package to help with creating custom windows with Flutter desktop (custom border, titlebar and minimize/maximize/close buttons) and common desktop window operations (show/hide/position on screen) for Windows and macOS
version: 0.0.8
homepage: https://www.bitsdojo.com
repository: https://github.com/bitsdojo/bitsdojo_window

Expand All @@ -19,9 +19,9 @@ flutter:
dependencies:
flutter:
sdk: flutter
bitsdojo_window_platform_interface: ^0.0.1
bitsdojo_window_platform_interface: ^0.0.2
#path: ../bitsdojo_window_platform_interface
bitsdojo_window_windows: ^0.0.2
bitsdojo_window_windows: ^0.0.3
#path: ../bitsdojo_window_windows
bitsdojo_window_macos: ^0.0.2
bitsdojo_window_macos: ^0.0.3
#path: ../bitsdojo_window_macos
3 changes: 3 additions & 0 deletions bitsdojo_window_macos/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 0.0.3

* macOS support on pair with Windows support
## 0.0.2

* Upgraded to ffi 1.0.0
Expand Down
3 changes: 1 addition & 2 deletions bitsdojo_window_macos/lib/src/app_window.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
library bitsdojo_window_macos;

import 'package:bitsdojo_window_macos/src/window.dart';
import './window.dart';
import './native_api.dart';

class MacAppWindow extends MacOSWindow {
MacAppWindow._() {
super.handle = getAppWindow();
print("getAppWindow returned $handle");
if (handle == null) {
print("Could not get Flutter window");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ class BitsdojoWindowMacOS extends BitsdojoWindowPlatform {
@override
void doWhenWindowReady(VoidCallback callback) {
WidgetsBinding.instance.waitUntilFirstFrameRasterized.then((value) {
setIsWindowReady(true);
setWindowCanBeShown(true);
setInsideDoWhenWindowReady(true);
callback();
setInsideDoWhenWindowReady(false);
});
}

Expand Down
Loading

0 comments on commit 51081d7

Please sign in to comment.