Skip to content

Commit 978d1ee

Browse files
authored
Add CI, update example, dependencies, readme (#228)
* Add CI and update example 1. Add CI build test with GitHub Actions 2. Delete example web target 3. Change example target name to `bitsdojo_window_example` 4. Update example dependencies version * Update dependencies version * Update README.md 1. Add badges 2. Optimize markdown syntax 3. Update code block readability * Add file path to code block * macOS fixes
1 parent 816d217 commit 978d1ee

39 files changed

+476
-349
lines changed

.github/workflows/build_test.yaml

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
name: build-test
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
paths-ignore:
8+
- ".vscode/**"
9+
- "CHANGELOG.md"
10+
- "LICENSE"
11+
- "README.md"
12+
- "resources/**"
13+
- "**/CHANGELOG.md"
14+
- "**/LICENSE"
15+
- "**/README.md"
16+
pull_request:
17+
paths-ignore:
18+
- ".vscode/**"
19+
- "CHANGELOG.md"
20+
- "LICENSE"
21+
- "README.md"
22+
- "resources/**"
23+
- "**/CHANGELOG.md"
24+
- "**/LICENSE"
25+
- "**/README.md"
26+
workflow_dispatch:
27+
28+
concurrency:
29+
group: >
30+
${{ github.workflow }}
31+
${{ github.event.pull_request.number || github.ref }}
32+
cancel-in-progress: true
33+
34+
jobs:
35+
build:
36+
name: ${{ matrix.runner }}
37+
runs-on: ${{ matrix.runner }}-latest
38+
timeout-minutes: 30
39+
strategy:
40+
fail-fast: false # Important
41+
matrix:
42+
runner: [ubuntu, windows, macos]
43+
include:
44+
- runner: ubuntu
45+
target: linux
46+
- runner: windows
47+
target: windows
48+
- runner: macos
49+
target: macos
50+
51+
steps:
52+
- name: Checkout repository
53+
uses: actions/checkout@v3
54+
with:
55+
fetch-depth: 1
56+
submodules: true
57+
58+
- name: Setup Flutter SDK
59+
uses: subosito/flutter-action@v2
60+
with:
61+
channel: "stable"
62+
cache: true
63+
64+
- name: Setup Ninja and GTK3 toolchain (Only Linux)
65+
if: matrix.runner == 'ubuntu'
66+
run: |
67+
sudo apt-get update -y
68+
sudo apt-get install -y ninja-build libgtk-3-dev
69+
70+
- name: Fetch dependencies
71+
working-directory: bitsdojo_window/example
72+
run: flutter pub get
73+
74+
- name: Run flutter build ${{ matrix.target }}
75+
working-directory: bitsdojo_window/example
76+
run: flutter build ${{ matrix.target }} --release -v
77+
78+
- name: Archive artifacts (Linux)
79+
if: matrix.runner == 'ubuntu'
80+
uses: actions/upload-artifact@v3
81+
with:
82+
name: bitsdojo_window_example_${{ matrix.runner }}
83+
path: bitsdojo_window/example/build/linux/x64/release/bundle/
84+
85+
- name: Archive artifacts (Windows)
86+
if: matrix.runner == 'windows'
87+
uses: actions/upload-artifact@v3
88+
with:
89+
name: bitsdojo_window_example_${{ matrix.runner }}
90+
path: bitsdojo_window/example/build/windows/runner/Release/bitsdojo_window_example.exe
91+
92+
- name: Archive artifacts (macOS)
93+
if: matrix.runner == 'macos'
94+
uses: actions/upload-artifact@v3
95+
with:
96+
name: bitsdojo_window_example_${{ matrix.runner }}
97+
path: bitsdojo_window/example/build/macos/Build/Products/Release/bitsdojo_window_example.app

README.md

Lines changed: 111 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,102 @@
1+
[![Pub Version](https://img.shields.io/pub/v/bitsdojo_window)](https://pub.dev/packages/bitsdojo_window)
2+
[![Pub Popularity](https://img.shields.io/pub/popularity/bitsdojo_window)](https://pub.dev/packages/bitsdojo_window)
3+
[![Pub Points](https://img.shields.io/pub/points/bitsdojo_window)](https://pub.dev/packages/bitsdojo_window)
4+
5+
[![GitHub Stars](https://img.shields.io/github/stars/bitsdojo/bitsdojo_window)](https://github.com/bitsdojo/bitsdojo_window/stargazers)
6+
[![Build Test](https://github.com/bitsdojo/bitsdojo_window/actions/workflows/build_test.yaml/badge.svg)](https://github.com/bitsdojo/bitsdojo_window/actions/workflows/build_test.yaml)
7+
[![GitHub License](https://img.shields.io/github/license/bitsdojo/bitsdojo_window)](https://github.com/bitsdojo/bitsdojo_window/blob/main/LICENSE)
8+
19
# bitsdojo_window
210

3-
A [Flutter package](https://pub.dev/packages/bitsdojo_window) that makes it easy to customize and work with your Flutter desktop app window **on Windows, macOS and Linux**.
11+
A [Flutter package](https://pub.dev/packages/bitsdojo_window) that makes it easy to customize and work with your Flutter desktop app window on **Windows**, **macOS** and **Linux**.
412

5-
Watch the tutorial to get started. Click the image below to watch the video:
13+
Watch the tutorial to get started. Click the image below to watch the video:
614

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

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

1119
**Features**:
1220

13-
- Custom window frame - remove standard Windows/macOS/Linux titlebar and buttons
14-
- Hide window on startup
15-
- Show/hide window
16-
- Move window using Flutter widget
17-
- Minimize/Maximize/Restore/Close window
18-
- Set window size, minimum size and maximum size
19-
- Set window position
20-
- Set window alignment on screen (center/topLeft/topRight/bottomLeft/bottomRight)
21-
- Set window title
21+
- Custom window frame - remove standard Windows/macOS/Linux titlebar and buttons
22+
- Hide window on startup
23+
- Show/hide window
24+
- Move window using Flutter widget
25+
- Minimize/Maximize/Restore/Close window
26+
- Set window size, minimum size and maximum size
27+
- Set window position
28+
- Set window alignment on screen (center/topLeft/topRight/bottomLeft/bottomRight)
29+
- Set window title
2230

2331
# Getting Started
2432

25-
Install the package using `pubspec.yaml`
33+
Add the package to your project's `pubspec.yaml` file manually or using the command below:
2634

27-
# For Windows apps
35+
```shell
36+
pub add bitsdojo_window
37+
```
2838

29-
Inside your application folder, go to `windows\runner\main.cpp` and add these two lines at the beginning of the file:
39+
The `pubspec.yaml` file should look like this:
3040

31-
```cpp
32-
#include <bitsdojo_window_windows/bitsdojo_window_plugin.h>
33-
auto bdw = bitsdojo_window_configure(BDW_CUSTOM_FRAME | BDW_HIDE_ON_STARTUP);
34-
```
41+
```diff
42+
// pubspec.yaml
3543

36-
# For macOS apps
44+
...
3745

38-
Inside your application folder, go to `macos\runner\MainFlutterWindow.swift` and add this line after the one saying `import FlutterMacOS` :
46+
dependencies:
47+
flutter:
48+
sdk: flutter
49+
+ bitsdojo_window: ^0.1.6
3950

40-
```swift
41-
import FlutterMacOS
42-
import bitsdojo_window_macos // Add this line
51+
dev_dependencies:
52+
53+
...
4354
```
4455

45-
Then change this line from:
56+
# For Windows apps
4657

47-
```swift
48-
class MainFlutterWindow: NSWindow {
49-
```
58+
Inside your application folder, go to `windows\runner\main.cpp` and change the code look like this:
5059

51-
to this:
60+
```diff
61+
// windows/runner/main.cpp
5262

53-
```swift
54-
class MainFlutterWindow: BitsdojoWindow {
55-
```
63+
...
5664

57-
After changing `NSWindow` to `BitsdojoWindow` add these lines below the line you changed:
65+
#include "flutter_window.h"
66+
#include "utils.h"
5867

59-
```swift
60-
override func bitsdojo_window_configure() -> UInt {
61-
return BDW_CUSTOM_FRAME | BDW_HIDE_ON_STARTUP
62-
}
68+
+ #include <bitsdojo_window_windows/bitsdojo_window_plugin.h>
69+
+ auto bdw = bitsdojo_window_configure(BDW_CUSTOM_FRAME | BDW_HIDE_ON_STARTUP);
70+
71+
int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev,
72+
73+
...
6374
```
6475

65-
Your code should now look like this:
76+
# For macOS apps
77+
78+
Inside your application folder, go to `macos\runner\MainFlutterWindow.swift` and change the code look like this:
79+
80+
```diff
81+
// macos/runner/MainFlutterWindow.swift
6682

67-
```swift
68-
class MainFlutterWindow: BitsdojoWindow {
69-
70-
override func bitsdojo_window_configure() -> UInt {
71-
return BDW_CUSTOM_FRAME | BDW_HIDE_ON_STARTUP
83+
import Cocoa
84+
import FlutterMacOS
85+
+ import bitsdojo_window_macos
86+
87+
- class MainFlutterWindow: NSWindow {
88+
+ class MainFlutterWindow: BitsdojoWindow {
89+
+ override func bitsdojo_window_configure() -> UInt {
90+
+ return BDW_CUSTOM_FRAME | BDW_HIDE_ON_STARTUP
91+
+ }
92+
override func awakeFromNib() {
93+
94+
...
95+
96+
}
7297
}
73-
74-
override func awakeFromNib() {
75-
... //rest of your code
7698
```
99+
77100
#
78101

79102
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.
@@ -82,57 +105,63 @@ If you don't want to hide the window on startup, you can remove the `BDW_HIDE_ON
82105

83106
# For Linux apps
84107

85-
Inside your application folder, go to `linux\my_application.cc` and add this line at the beginning of the file:
108+
Inside your application folder, go to `linux\my_application.cc` and change the code look like this:
86109

87-
```cpp
88-
#include <bitsdojo_window_linux/bitsdojo_window_plugin.h>
89-
```
90-
Then look for these two lines:
110+
```diff
111+
// linux/my_application.cc
91112

92-
```cpp
93-
gtk_window_set_default_size(window, 1280, 720);
94-
gtk_widget_show(GTK_WIDGET(window));
95-
```
96-
and change them to this:
113+
...
114+
#include "flutter/generated_plugin_registrant.h"
115+
+ #include <bitsdojo_window_linux/bitsdojo_window_plugin.h>
97116

98-
```cpp
99-
auto bdw = bitsdojo_window_from(window); // <--- add this line
100-
bdw->setCustomFrame(true); // <-- add this line
101-
//gtk_window_set_default_size(window, 1280, 720); // <-- comment this line
102-
gtk_widget_show(GTK_WIDGET(window));
103-
```
117+
struct _MyApplication {
118+
119+
...
120+
121+
}
104122

105-
As you can see, we commented the line calling `gtk_window_set_default_size` and added these two lines before `gtk_widget_show(GTK_WIDGET(window));`
123+
+ auto bdw = bitsdojo_window_from(window);
124+
+ bdw->setCustomFrame(true);
125+
- gtk_window_set_default_size(window, 1280, 720);
126+
gtk_widget_show(GTK_WIDGET(window));
127+
128+
g_autoptr(FlDartProject) project = fl_dart_project_new();
129+
130+
...
131+
132+
}
106133

107-
```cpp
108-
auto bdw = bitsdojo_window_from(window);
109-
bdw->setCustomFrame(true);
110134
```
111135

112136
# Flutter app integration
113137

114-
Now go to `lib\main.dart` and add this code in the `main` function right after `runApp(MyApp());` :
138+
Now go to `lib\main.dart` and change the code look like this:
115139

116-
```dart
117-
void main() {
118-
runApp(MyApp());
140+
```diff
141+
// lib/main.dart
119142

120-
// Add this code below
143+
import 'package:flutter/material.dart';
144+
+ import 'package:bitsdojo_window/bitsdojo_window.dart';
121145

122-
doWhenWindowReady(() {
123-
const initialSize = Size(600, 450);
124-
appWindow.minSize = initialSize;
125-
appWindow.size = initialSize;
126-
appWindow.alignment = Alignment.center;
127-
appWindow.show();
128-
});
129-
}
146+
void main() {
147+
runApp(MyApp());
148+
149+
+ doWhenWindowReady(() {
150+
+ const initialSize = Size(600, 450);
151+
+ appWindow.minSize = initialSize;
152+
+ appWindow.size = initialSize;
153+
+ appWindow.alignment = Alignment.center;
154+
+ appWindow.show();
155+
+ });
156+
}
130157
```
158+
131159
This will set an initial size and a minimum size for your application window, center it on the screen and show it on the screen.
132160

133-
You can find examples in the `example` folder.
161+
You can find examples in the [example](./bitsdojo_window/example) folder.
134162

135163
Here is an example that displays this window:
164+
136165
<details>
137166
<summary>Click to expand</summary>
138167

@@ -249,9 +278,11 @@ class WindowButtons extends StatelessWidget {
249278
}
250279
}
251280
```
281+
252282
</details>
253283

254284
#
285+
255286
# **Want to help? Become a sponsor**
256287

257288
I am developing this package in my spare time and any help is appreciated.
@@ -262,4 +293,4 @@ If you want to help you can [become a sponsor](https://github.com/sponsors/bitsd
262293

263294
## ☕️ Current sponsors:
264295

265-
No sponsors
296+
No sponsors

bitsdojo_window/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
## 0.1.6
2+
- Various fixes to work with latest Flutter version
13
## 0.1.5
24
- Runs on Windows 7
35
## 0.1.4

0 commit comments

Comments
 (0)