feat: new ui (#1455)

This commit is contained in:
Levi authored and GitHub committed 2026-09-05 19:53:41 +08:00
1 parent 3be8db664c
commit 177c225f16
742 files changed
+59951 -5934

No files matched your search

@@ -0,0 +1,44 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:gopeed/core/capabilities/capability_rpc.dart';
import 'package:gopeed/core/window/app_window_appearance.dart';
class _Payload {
const _Payload(this.value);
factory _Payload.fromJson(Map<String, dynamic> json) => _Payload(json['value'] as int);
final int value;
Map<String, dynamic> toJson() => {'value': value};
}
void main() {
test('one method descriptor supports direct and serialized dispatch', () async {
const method = RpcMethod<_Payload, _Payload>('test.increment');
final codecs = RpcCodecRegistry()..register<_Payload>((json) => _Payload.fromJson(json! as Map<String, dynamic>));
final registry = CapabilityRegistry(codecs)..bind(method, (payload) => _Payload(payload.value + 1));
final local = await LocalCapabilityInvoker(registry).invoke(method, const _Payload(1));
final serialized = codecs.decode<_Payload>(await registry.invoke(method.name, codecs.encode(const _Payload(4))));
expect(local.value, 2);
expect(serialized.value, 5);
});
test('appearance snapshots use the shared codec registry', () {
final codecs = RpcCodecRegistry()
..register<AppWindowAppearance>((json) => AppWindowAppearance.fromJson(json! as Map<String, dynamic>));
const appearance = AppWindowAppearance(themeMode: 'dark', themeColor: 'blue', locale: 'zh');
expect(codecs.decode<AppWindowAppearance>(codecs.encode(appearance)), appearance);
});
test('unknown capabilities return a structured error', () async {
final registry = CapabilityRegistry(RpcCodecRegistry());
expect(
() => registry.invoke('missing', null),
throwsA(isA<CapabilityException>().having((error) => error.code, 'code', 'method_not_found')),
);
});
}
@@ -0,0 +1,32 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:gopeed/core/entry/app_startup_options.dart';
void main() {
test('starts hidden for the launch-at-startup flag', () {
expect(AppStartupOptions.fromArgs(const ['--hidden']).hidden, isTrue);
});
test('starts hidden for the browser host silent wake URI', () {
expect(AppStartupOptions.fromArgs(const ['gopeed:?hidden=true']).hidden, isTrue);
expect(AppStartupOptions.fromArgs(const ['gopeed:///?hidden=true']).hidden, isTrue);
});
test('does not hide task and extension deep links', () {
expect(AppStartupOptions.fromArgs(const ['gopeed:///create?hidden=true']).hidden, isFalse);
expect(AppStartupOptions.fromArgs(const ['gopeed:///extension']).hidden, isFalse);
});
test('merges a platform-provided initial URI before the window is shown', () {
final options = AppStartupOptions.fromArgs(const []);
expect(options.withInitialUri(Uri.parse('gopeed:?hidden=true')).hidden, isTrue);
expect(options.withInitialUri(Uri.parse('gopeed:///create')).hidden, isFalse);
});
test('recognizes only the root hidden wake URI', () {
expect(isSilentGopeedWakeUri(Uri.parse('gopeed:?hidden=true')), isTrue);
expect(isSilentGopeedWakeUri(Uri.parse('gopeed:///?hidden=true')), isTrue);
expect(isSilentGopeedWakeUri(Uri.parse('gopeed:///create?hidden=true')), isFalse);
expect(isSilentGopeedWakeUri(Uri.parse('https://example.com/?hidden=true')), isFalse);
});
}
@@ -0,0 +1,13 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:gopeed/core/utils/byte_size_formatter.dart';
void main() {
test('formats scaled byte sizes with up to two decimal places', () {
expect(ByteSizeFormatter.format(-1), '0 B');
expect(ByteSizeFormatter.format(512), '512 B');
expect(ByteSizeFormatter.format(1536), '1.5 KB');
expect(ByteSizeFormatter.format(1280), '1.25 KB');
expect(ByteSizeFormatter.format(32 * 1024 * 1024), '32 MB');
expect(ByteSizeFormatter.format(2 * 1024 * 1024 * 1024), '2 GB');
});
}
@@ -0,0 +1,8 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:gopeed/core/utils/content_uri_resolver.dart';
void main() {
test('rejects non-content URIs', () async {
expect(() => ContentUriResolver.copyToCache(Uri.parse('file:///tmp/example.torrent')), throwsArgumentError);
});
}
@@ -0,0 +1,14 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:gopeed/core/utils/transfer_rate_formatter.dart';
void main() {
test('formats transfer rates with adaptive binary units', () {
expect(TransferRateFormatter.format(-1).text, '0 B/s');
expect(TransferRateFormatter.format(512).text, '512 B/s');
expect(TransferRateFormatter.format(96 * 1024).text, '96 KB/s');
expect(TransferRateFormatter.format(1536).text, '1.5 KB/s');
expect(TransferRateFormatter.format(1280).text, '1.25 KB/s');
expect(TransferRateFormatter.format(10 * 1024 * 1024).text, '10 MB/s');
expect(TransferRateFormatter.format(2 * 1024 * 1024 * 1024).text, '2 GB/s');
});
}
@@ -0,0 +1,61 @@
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:gopeed/api/model/create_task.dart';
import 'package:gopeed/api/model/request.dart';
import 'package:gopeed/core/window/app_window_launcher.dart';
import 'package:gopeed/core/window/window_capability_transport.dart';
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
const multiWindowChannel = MethodChannel('mixin.one/desktop_multi_window');
const windowChannels = MethodChannel('mixin.one/desktop_multi_window/channels');
final messenger = TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger;
setUp(() {
messenger.setMockMethodCallHandler(windowChannels, (call) async => null);
});
tearDown(() async {
await AppWindowCapabilityHost.instance.stop();
messenger.setMockMethodCallHandler(multiWindowChannel, null);
messenger.setMockMethodCallHandler(windowChannels, null);
});
test('create-task window stays hidden until child bootstrap is ready', () async {
final calls = <MethodCall>[];
messenger.setMockMethodCallHandler(multiWindowChannel, (call) async {
calls.add(call);
if (call.method == 'createWindow') return 'create-window-id';
return null;
});
messenger.setMockMethodCallHandler(windowChannels, (call) async {
calls.add(call);
return null;
});
final opened = await AppWindowLauncher.openCreateTaskWindow(
createTask: CreateTask(req: Request(url: 'https://example.com/file.zip')),
);
expect(opened, isTrue);
final createCall = calls.firstWhere((call) => call.method == 'createWindow');
final configuration = Map<String, dynamic>.from(createCall.arguments as Map);
expect(configuration['hiddenAtLaunch'], isTrue);
expect(
calls.where((call) => call.method == 'window_show' && (call.arguments as Map)['windowId'] == 'create-window-id'),
isEmpty,
);
});
test('create-task window failure reports fallback availability', () async {
messenger.setMockMethodCallHandler(multiWindowChannel, (call) async {
if (call.method == 'createWindow') {
throw PlatformException(code: 'create_failed');
}
return null;
});
expect(await AppWindowLauncher.openCreateTaskWindow(), isFalse);
});
}
@@ -0,0 +1,55 @@
import 'dart:convert';
import 'package:flutter_test/flutter_test.dart';
import 'package:gopeed/core/window/app_window_bootstrap.dart';
import 'package:gopeed/core/window/app_window_payload.dart';
import 'package:gopeed/l10n/l10n.dart';
void main() {
test('create-task child window has a localized native title', () {
expect(
AppWindowBootstrap.subWindowTitle(AppWindowType.createTask, appLocalizationsFor('en')),
'Create Task - Gopeed',
);
expect(AppWindowBootstrap.subWindowTitle(AppWindowType.createTask, appLocalizationsFor('zh')), '创建任务 - Gopeed');
});
test('create-task payload only carries initial task data', () {
final raw = AppWindowPayload.createTask(
createTask: {
'urls': ['https://example.com/file.zip'],
},
).toRaw();
final decoded = jsonDecode(raw) as Map<String, dynamic>;
expect(decoded.keys, containsAll(<String>['type', 'createTask']));
expect(decoded.keys, hasLength(2));
expect(decoded, isNot(contains('apiToken')));
expect(decoded, isNot(contains('theme')));
expect(decoded, isNot(contains('createHistory')));
});
test('create-task payload preserves nested browser request parameters', () {
final payload = AppWindowPayload.createTask(
createTask: {
'req': {
'rawUrl': 'https://page.example/download',
'url': 'https://cdn.example/archive.zip',
'extra': {
'method': 'GET',
'header': {'Cookie': 'session=abc', 'Referer': 'https://page.example/', 'Authorization': 'Bearer token'},
'body': '',
},
'labels': {'source': 'browser-extension'},
'skipVerifyCert': true,
},
'opts': {'name': 'archive.zip', 'path': 'D:/Downloads', 'selectFiles': <int>[], 'extra': null},
},
);
final decoded = AppWindowPayload.fromRaw(payload.toRaw()).createTask;
expect(decoded?['req'], payload.createTask?['req']);
expect(decoded?['opts'], payload.createTask?['opts']);
});
}