Skip to content

Commit 554a94f

Browse files
authored
Merge pull request #17 from unDefFtr/master
添加 macOS 构建支持并为 macOS 平台启用系统标题栏
2 parents 7fa823d + b4de671 commit 554a94f

12 files changed

Lines changed: 354 additions & 19 deletions

File tree

.github/workflows/build.yml

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,98 @@ jobs:
6060
cd namepicker
6161
flutter build linux
6262
63+
- name: Package linux deb
64+
run: |
65+
cd namepicker
66+
APP_VERSION=$(grep -E '^version:' pubspec.yaml | awk '{print $2}')
67+
DEB_VERSION=${APP_VERSION//+/-}
68+
PKG_DIR=../deb_build
69+
mkdir -p "$PKG_DIR/DEBIAN"
70+
mkdir -p "$PKG_DIR/opt/namepicker"
71+
mkdir -p "$PKG_DIR/usr/bin"
72+
cp -r build/linux/x64/release/bundle/* "$PKG_DIR/opt/namepicker/"
73+
printf "Package: namepicker\nVersion: %s\nSection: utils\nPriority: optional\nArchitecture: amd64\nMaintainer: NamePicker Maintainers <noreply@example.com>\nDepends: libgtk-3-0\nDescription: NamePicker Flutter application\n" "$DEB_VERSION" > "$PKG_DIR/DEBIAN/control"
74+
printf '#!/bin/sh\nexec /opt/namepicker/namepicker "$@"\n' > "$PKG_DIR/usr/bin/namepicker"
75+
chmod 755 "$PKG_DIR/usr/bin/namepicker"
76+
dpkg-deb --build "$PKG_DIR" "../namepicker_${DEB_VERSION}_amd64.deb"
77+
6378
- name: Upload linux artifact
6479
uses: actions/upload-artifact@v4
6580
with:
6681
name: NamePicker-Linux-x64
6782
path: |
6883
namepicker/build/linux/x64/release/bundle
84+
85+
- name: Upload linux deb
86+
uses: actions/upload-artifact@v4
87+
with:
88+
name: NamePicker-Linux-deb
89+
path: |
90+
namepicker_*_amd64.deb
91+
build_macos_intel:
92+
runs-on: macos-13
93+
steps:
94+
- name: Clone repository
95+
uses: actions/checkout@v4
96+
97+
- name: Set up Flutter
98+
uses: subosito/flutter-action@v2
99+
with:
100+
channel: stable
101+
102+
- name: Init flutter env
103+
run: |
104+
cd namepicker
105+
flutter pub get
106+
107+
- name: Build macOS x64 app
108+
run: |
109+
cd namepicker
110+
flutter build macos --release
111+
112+
- name: Package macOS x64 zip
113+
run: |
114+
cd namepicker/build/macos/Build/Products/Release
115+
APP_DIR=$(ls -d *.app | head -n 1)
116+
ditto -c -k --sequesterRsrc --keepParent "$APP_DIR" "./${APP_DIR%.app}-macOS-x64.zip"
117+
118+
- name: Upload macOS x64 artifact
119+
uses: actions/upload-artifact@v4
120+
with:
121+
name: NamePicker-macOS-x64
122+
path: |
123+
namepicker/build/macos/Build/Products/Release/*-macOS-x64.zip
124+
125+
build_macos_arm:
126+
runs-on: macos-14
127+
steps:
128+
- name: Clone repository
129+
uses: actions/checkout@v4
130+
131+
- name: Set up Flutter
132+
uses: subosito/flutter-action@v2
133+
with:
134+
channel: stable
135+
136+
- name: Init flutter env
137+
run: |
138+
cd namepicker
139+
flutter pub get
140+
141+
- name: Build macOS arm64 app
142+
run: |
143+
cd namepicker
144+
flutter build macos --release
145+
146+
- name: Package macOS arm64 zip
147+
run: |
148+
cd namepicker/build/macos/Build/Products/Release
149+
APP_DIR=$(ls -d *.app | head -n 1)
150+
ditto -c -k --sequesterRsrc --keepParent "$APP_DIR" "./${APP_DIR%.app}-macOS-arm64.zip"
151+
152+
- name: Upload macOS arm64 artifact
153+
uses: actions/upload-artifact@v4
154+
with:
155+
name: NamePicker-macOS-arm64
156+
path: |
157+
namepicker/build/macos/Build/Products/Release/*-macOS-arm64.zip
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"
12
#include "Generated.xcconfig"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"
12
#include "Generated.xcconfig"

namepicker/ios/Podfile

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Uncomment this line to define a global platform for your project
2+
# platform :ios, '13.0'
3+
4+
# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
5+
ENV['COCOAPODS_DISABLE_STATS'] = 'true'
6+
7+
project 'Runner', {
8+
'Debug' => :debug,
9+
'Profile' => :release,
10+
'Release' => :release,
11+
}
12+
13+
def flutter_root
14+
generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__)
15+
unless File.exist?(generated_xcode_build_settings_path)
16+
raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first"
17+
end
18+
19+
File.foreach(generated_xcode_build_settings_path) do |line|
20+
matches = line.match(/FLUTTER_ROOT\=(.*)/)
21+
return matches[1].strip if matches
22+
end
23+
raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get"
24+
end
25+
26+
require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root)
27+
28+
flutter_ios_podfile_setup
29+
30+
target 'Runner' do
31+
use_frameworks!
32+
33+
flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
34+
target 'RunnerTests' do
35+
inherit! :search_paths
36+
end
37+
end
38+
39+
post_install do |installer|
40+
installer.pods_project.targets.each do |target|
41+
flutter_additional_ios_build_settings(target)
42+
end
43+
end

namepicker/lib/main.dart

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ Future<void> main() async {
2525
databaseFactory = databaseFactoryFfi;
2626
await windowManager.ensureInitialized();
2727
await windowManager.waitUntilReadyToShow();
28-
await windowManager.setTitleBarStyle(TitleBarStyle.hidden);
28+
if (Platform.isMacOS) {
29+
await windowManager.setTitleBarStyle(TitleBarStyle.normal);
30+
} else {
31+
await windowManager.setTitleBarStyle(TitleBarStyle.hidden);
32+
}
2933
await windowManager.setSize(const Size(900, 600));
3034
await windowManager.setMinimumSize(const Size(600, 400));
3135
await windowManager.center();
@@ -245,7 +249,7 @@ class _MyHomePageState extends State<MyHomePage> {
245249
return Scaffold(
246250
body: Column(
247251
children: [
248-
CustomTitleBar(),
252+
if (!Platform.isMacOS) CustomTitleBar(),
249253
Expanded(
250254
child: LayoutBuilder(
251255
builder: (context, constraints) {
@@ -905,4 +909,4 @@ class HistoryCard extends StatelessWidget {
905909
);
906910
}
907911
}
908-
// 成为英雄吧,救世主。
912+
// 成为英雄吧,救世主。
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"
12
#include "ephemeral/Flutter-Generated.xcconfig"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"
12
#include "ephemeral/Flutter-Generated.xcconfig"

namepicker/macos/Podfile

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
platform :osx, '10.15'
2+
3+
# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
4+
ENV['COCOAPODS_DISABLE_STATS'] = 'true'
5+
6+
project 'Runner', {
7+
'Debug' => :debug,
8+
'Profile' => :release,
9+
'Release' => :release,
10+
}
11+
12+
def flutter_root
13+
generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'ephemeral', 'Flutter-Generated.xcconfig'), __FILE__)
14+
unless File.exist?(generated_xcode_build_settings_path)
15+
raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure \"flutter pub get\" is executed first"
16+
end
17+
18+
File.foreach(generated_xcode_build_settings_path) do |line|
19+
matches = line.match(/FLUTTER_ROOT\=(.*)/)
20+
return matches[1].strip if matches
21+
end
22+
raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Flutter-Generated.xcconfig, then run \"flutter pub get\""
23+
end
24+
25+
require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root)
26+
27+
flutter_macos_podfile_setup
28+
29+
target 'Runner' do
30+
use_frameworks!
31+
32+
flutter_install_all_macos_pods File.dirname(File.realpath(__FILE__))
33+
target 'RunnerTests' do
34+
inherit! :search_paths
35+
end
36+
end
37+
38+
post_install do |installer|
39+
installer.pods_project.targets.each do |target|
40+
flutter_additional_macos_build_settings(target)
41+
end
42+
end

namepicker/macos/Podfile.lock

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
PODS:
2+
- file_picker (0.0.1):
3+
- FlutterMacOS
4+
- FlutterMacOS (1.0.0)
5+
- screen_retriever (0.0.1):
6+
- FlutterMacOS
7+
- shared_preferences_foundation (0.0.1):
8+
- Flutter
9+
- FlutterMacOS
10+
- sqflite_darwin (0.0.4):
11+
- Flutter
12+
- FlutterMacOS
13+
- url_launcher_macos (0.0.1):
14+
- FlutterMacOS
15+
- window_manager (0.2.0):
16+
- FlutterMacOS
17+
18+
DEPENDENCIES:
19+
- file_picker (from `Flutter/ephemeral/.symlinks/plugins/file_picker/macos`)
20+
- FlutterMacOS (from `Flutter/ephemeral`)
21+
- screen_retriever (from `Flutter/ephemeral/.symlinks/plugins/screen_retriever/macos`)
22+
- shared_preferences_foundation (from `Flutter/ephemeral/.symlinks/plugins/shared_preferences_foundation/darwin`)
23+
- sqflite_darwin (from `Flutter/ephemeral/.symlinks/plugins/sqflite_darwin/darwin`)
24+
- url_launcher_macos (from `Flutter/ephemeral/.symlinks/plugins/url_launcher_macos/macos`)
25+
- window_manager (from `Flutter/ephemeral/.symlinks/plugins/window_manager/macos`)
26+
27+
EXTERNAL SOURCES:
28+
file_picker:
29+
:path: Flutter/ephemeral/.symlinks/plugins/file_picker/macos
30+
FlutterMacOS:
31+
:path: Flutter/ephemeral
32+
screen_retriever:
33+
:path: Flutter/ephemeral/.symlinks/plugins/screen_retriever/macos
34+
shared_preferences_foundation:
35+
:path: Flutter/ephemeral/.symlinks/plugins/shared_preferences_foundation/darwin
36+
sqflite_darwin:
37+
:path: Flutter/ephemeral/.symlinks/plugins/sqflite_darwin/darwin
38+
url_launcher_macos:
39+
:path: Flutter/ephemeral/.symlinks/plugins/url_launcher_macos/macos
40+
window_manager:
41+
:path: Flutter/ephemeral/.symlinks/plugins/window_manager/macos
42+
43+
SPEC CHECKSUMS:
44+
file_picker: 7584aae6fa07a041af2b36a2655122d42f578c1a
45+
FlutterMacOS: d0db08ddef1a9af05a5ec4b724367152bb0500b1
46+
screen_retriever: 4f97c103641aab8ce183fa5af3b87029df167936
47+
shared_preferences_foundation: 9e1978ff2562383bd5676f64ec4e9aa8fa06a6f7
48+
sqflite_darwin: 20b2a3a3b70e43edae938624ce550a3cbf66a3d0
49+
url_launcher_macos: 0fba8ddabfc33ce0a9afe7c5fef5aab3d8d2d673
50+
window_manager: 1d01fa7ac65a6e6f83b965471b1a7fdd3f06166c
51+
52+
PODFILE CHECKSUM: 54d867c82ac51cbd61b565781b9fada492027009
53+
54+
COCOAPODS: 1.16.2

0 commit comments

Comments
 (0)