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

fix: Optimized macos platform support #249

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
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
59 changes: 40 additions & 19 deletions lib/data/services/extension_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -443,19 +443,31 @@ class ExtensionService {
}

Future<List<ExtensionListItem>> latest(int page) async {
return runExtension(() async {
final jsResult = await runtime.handlePromise(
await runtime.evaluateAsync('stringify(()=>extension.latest($page))'),
);
List<ExtensionListItem> result =
jsonDecode(jsResult.stringResult).map<ExtensionListItem>((e) {
return ExtensionListItem.fromJson(e);
}).toList();
for (var element in result) {
element.headers ??= await _defaultHeaders;
}
return result;
});
return runExtension(
() async {
final jsPromise = await runtime.evaluateAsync(
Platform.isMacOS
? 'extension.latest($page)'
: 'stringify(()=>extension.latest($page))',
);
final jsResult = await runtime.handlePromise(
jsPromise,
timeout: const Duration(seconds: 15),
);

final data = jsonDecode(jsResult.stringResult);
if (data is! List) throw 'result is not list';

final result = data
.map<ExtensionListItem>((e) => ExtensionListItem.fromJson(e))
.toList();
for (var element in result) {
element.headers ??= await _defaultHeaders;
}

return result;
},
);
}

Future<List<ExtensionListItem>> search(
Expand All @@ -464,17 +476,26 @@ class ExtensionService {
Map<String, List<String>>? filter,
}) async {
return runExtension(() async {
final jsPromise = await runtime.evaluateAsync(
Platform.isMacOS
? 'extension.search("$kw",$page,${filter == null ? null : jsonEncode(filter)})'
: 'stringify(()=>extension.search("$kw",$page,${filter == null ? null : jsonEncode(filter)}))',
);
final jsResult = await runtime.handlePromise(
await runtime.evaluateAsync(
'stringify(()=>extension.search("$kw",$page,${filter == null ? null : jsonEncode(filter)}))'),
jsPromise,
timeout: const Duration(seconds: 15),
);
List<ExtensionListItem> result =
jsonDecode(jsResult.stringResult).map<ExtensionListItem>((e) {
return ExtensionListItem.fromJson(e);
}).toList();

final data = jsonDecode(jsResult.stringResult);
if (data is! List) throw 'result is not list';

final result = data
.map<ExtensionListItem>((e) => ExtensionListItem.fromJson(e))
.toList();
for (var element in result) {
element.headers ??= await _defaultHeaders;
}

return result;
});
}
Expand Down
9 changes: 4 additions & 5 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,12 @@ void main(List<String> args) async {
await windowManager.ensureInitialized();
final sizeArr = MiruStorage.getSetting(SettingKey.windowSize).split(",");
final size = Size(double.parse(sizeArr[0]), double.parse(sizeArr[1]));
WindowOptions windowOptions = WindowOptions(
final windowOptions = WindowOptions(
size: size,
center: true,
skipTaskbar: false,
titleBarStyle: TitleBarStyle.hidden,
titleBarStyle:
Platform.isMacOS ? TitleBarStyle.normal : TitleBarStyle.hidden,
);
windowManager.waitUntilReadyToShow(windowOptions, () async {
final position = MiruStorage.getSetting(SettingKey.windowPosition);
Expand All @@ -72,9 +73,7 @@ void main(List<String> args) async {
double.parse(offsetArr[0]),
double.parse(offsetArr[1]),
);
await windowManager.setPosition(
offset,
);
await windowManager.setPosition(offset);
}
await windowManager.show();
await windowManager.focus();
Expand Down
64 changes: 34 additions & 30 deletions lib/views/pages/main_page.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:io';

import 'package:fluent_ui/fluent_ui.dart' as fluent;
import 'package:flutter/material.dart';
import 'package:get/get.dart';
Expand Down Expand Up @@ -67,37 +69,39 @@ class _DesktopMainPageState extends State<DesktopMainPage> with WindowListener {
@override
Widget build(BuildContext context) {
return fluent.NavigationView(
appBar: fluent.NavigationAppBar(
leading: () {
return fluent.IconButton(
icon: const Icon(fluent.FluentIcons.back, size: 12.0),
onPressed: () {
if (router.canPop()) {
context.pop();
setState(() {});
}
},
);
}(),
title: _title(),
actions: Obx(
() => Row(
children: [
const Spacer(),
...c.actions,
SizedBox(
width: 138,
height: 50,
child: WindowCaption(
backgroundColor: Colors.transparent,
brightness: fluent.FluentTheme.of(context).brightness,
appBar: Platform.isMacOS
? null
: fluent.NavigationAppBar(
leading: () {
return fluent.IconButton(
icon: const Icon(fluent.FluentIcons.back, size: 12.0),
onPressed: () {
if (router.canPop()) {
context.pop();
setState(() {});
}
},
);
}(),
title: _title(),
actions: Obx(
() => Row(
children: [
const Spacer(),
...c.actions,
SizedBox(
width: 138,
height: 50,
child: WindowCaption(
backgroundColor: Colors.transparent,
brightness: fluent.FluentTheme.of(context).brightness,
),
)
],
),
)
],
),
),
automaticallyImplyLeading: false,
),
),
automaticallyImplyLeading: false,
),
paneBodyBuilder: (item, body) {
return widget.child;
},
Expand Down
67 changes: 35 additions & 32 deletions lib/views/pages/search/extension_searcher_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -254,18 +254,21 @@ class _ExtensionSearcherPageState extends fluent.State<ExtensionSearcherPage> {
}

Widget _buildDesktop(BuildContext context) {
final suffix = Row(mainAxisSize: MainAxisSize.min, children: [
Padding(
padding: const EdgeInsetsDirectional.only(start: 2.0),
child: fluent.IconButton(
icon: const Icon(fluent.FluentIcons.chrome_close, size: 9.0),
onPressed: () {
_textEditingController.clear();
_onSearch("");
},
final suffix = Row(
mainAxisSize: MainAxisSize.min,
children: [
Padding(
padding: const EdgeInsetsDirectional.only(start: 2.0),
child: fluent.IconButton(
icon: const Icon(fluent.FluentIcons.chrome_close, size: 9.0),
onPressed: () {
_textEditingController.clear();
_onSearch("");
},
),
),
),
]);
],
);
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expand Down Expand Up @@ -321,27 +324,27 @@ class _ExtensionSearcherPageState extends fluent.State<ExtensionSearcherPage> {
onRefresh: _onRefresh,
onLoad: _onLoad,
child: LayoutBuilder(
builder: ((context, constraints) => GridView.builder(
padding: const EdgeInsets.all(16),
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: constraints.maxWidth ~/ 160,
childAspectRatio: 0.6,
crossAxisSpacing: 16,
mainAxisSpacing: 16,
),
itemCount: _data.length,
itemBuilder: (context, index) {
final item = _data[index];
return ExtensionItemCard(
title: item.title,
url: item.url,
package: widget.package,
cover: item.cover,
update: item.update,
headers: item.headers,
);
},
)),
builder: (context, constraints) => GridView.builder(
padding: const EdgeInsets.all(16),
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: constraints.maxWidth ~/ 160,
childAspectRatio: 0.6,
crossAxisSpacing: 16,
mainAxisSpacing: 16,
),
itemCount: _data.length,
itemBuilder: (context, index) {
final item = _data[index];
return ExtensionItemCard(
title: item.title,
url: item.url,
package: widget.package,
cover: item.cover,
update: item.update,
headers: item.headers,
);
},
),
),
),
)
Expand Down
1 change: 1 addition & 0 deletions macos/Flutter/Flutter-Debug.xcconfig
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"
#include "ephemeral/Flutter-Generated.xcconfig"
1 change: 1 addition & 0 deletions macos/Flutter/Flutter-Release.xcconfig
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"
#include "ephemeral/Flutter-Generated.xcconfig"
43 changes: 43 additions & 0 deletions macos/Podfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
platform :osx, '10.14'

# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'

project 'Runner', {
'Debug' => :debug,
'Profile' => :release,
'Release' => :release,
}

def flutter_root
generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'ephemeral', 'Flutter-Generated.xcconfig'), __FILE__)
unless File.exist?(generated_xcode_build_settings_path)
raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure \"flutter pub get\" is executed first"
end

File.foreach(generated_xcode_build_settings_path) do |line|
matches = line.match(/FLUTTER_ROOT\=(.*)/)
return matches[1].strip if matches
end
raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Flutter-Generated.xcconfig, then run \"flutter pub get\""
end

require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root)

flutter_macos_podfile_setup

target 'Runner' do
use_frameworks!
use_modular_headers!

flutter_install_all_macos_pods File.dirname(File.realpath(__FILE__))
target 'RunnerTests' do
inherit! :search_paths
end
end

post_install do |installer|
installer.pods_project.targets.each do |target|
flutter_additional_macos_build_settings(target)
end
end
Loading
Loading