opt: win32 api (#2246)

* tweaks

* opt: win32 api
This commit is contained in:
My-Responsitories
2026-05-31 03:03:15 +00:00
committed by GitHub
parent d4d9fc3405
commit b3e2dcf2c5
7 changed files with 18 additions and 45 deletions

View File

@@ -1,6 +1,5 @@
import 'dart:async' show FutureOr; import 'dart:async' show FutureOr;
import 'dart:convert' show utf8, jsonDecode; import 'dart:convert' show utf8, jsonDecode;
import 'dart:io' show File;
import 'package:PiliPlus/common/style.dart'; import 'package:PiliPlus/common/style.dart';
import 'package:PiliPlus/utils/extension/theme_ext.dart'; import 'package:PiliPlus/utils/extension/theme_ext.dart';
@@ -122,8 +121,7 @@ Future<void> importFromLocalFile<T>({
allowedExtensions: const ['json', 'txt'], allowedExtensions: const ['json', 'txt'],
); );
if (result != null) { if (result != null) {
final path = result.xFile.path; final data = await result.xFile.readAsString();
final data = await File(path).readAsString();
final T json; final T json;
try { try {
json = jsonDecode(data); json = jsonDecode(data);
@@ -179,7 +177,7 @@ void importFromInput<T>(
child: Text( child: Text(
'取消', '取消',
style: TextStyle( style: TextStyle(
color: Theme.of(context).colorScheme.outline, color: ColorScheme.of(context).outline,
), ),
), ),
), ),

View File

@@ -10,9 +10,9 @@ import 'package:flutter_svg/flutter_svg.dart';
class CachedNetworkSVGImage extends StatefulWidget { class CachedNetworkSVGImage extends StatefulWidget {
CachedNetworkSVGImage( CachedNetworkSVGImage(
String url, { this._url, {
Key? key, Key? key,
String? cacheKey, this._cacheKey,
this._placeholder, this._placeholder,
this._errorBuilder, this._errorBuilder,
this._width, this._width,
@@ -28,10 +28,8 @@ class CachedNetworkSVGImage extends StatefulWidget {
this._colorFilter, this._colorFilter,
this._placeholderBuilder, this._placeholderBuilder,
BaseCacheManager? cacheManager, BaseCacheManager? cacheManager,
}) : _url = url, }) : _cacheManager = cacheManager ?? DefaultCacheManager(),
_cacheKey = cacheKey, super(key: key ?? ValueKey(_cacheKey ?? _url));
_cacheManager = cacheManager ?? DefaultCacheManager(),
super(key: key ?? ValueKey(cacheKey ?? url));
final String _url; final String _url;
final String? _cacheKey; final String? _cacheKey;

View File

@@ -87,9 +87,7 @@ Widget videoSeasonWidget(
Colors.black54, Colors.black54,
], ],
), ),
borderRadius: BorderRadius.vertical( borderRadius: .vertical(bottom: Style.imgRadius),
bottom: Style.imgRadius,
),
), ),
child: DefaultTextStyle.merge( child: DefaultTextStyle.merge(
style: TextStyle( style: TextStyle(
@@ -103,22 +101,16 @@ Widget videoSeasonWidget(
DecoratedBox( DecoratedBox(
decoration: const BoxDecoration( decoration: const BoxDecoration(
color: Colors.black45, color: Colors.black45,
borderRadius: BorderRadius.all( borderRadius: .all(.circular(4)),
Radius.circular(4),
),
), ),
child: Text(' $durationText '), child: Text(' $durationText '),
), ),
const SizedBox(width: 6), const SizedBox(width: 6),
], ],
if (video.stat case final stat?) ...[ if (video.stat case final stat?) ...[
Text( Text('${NumUtils.numFormat(stat.play)}播放'),
'${NumUtils.numFormat(stat.play)}播放',
),
const SizedBox(width: 6), const SizedBox(width: 6),
Text( Text('${NumUtils.numFormat(stat.danmu)}弹幕'),
'${NumUtils.numFormat(stat.danmu)}弹幕',
),
], ],
const Spacer(), const Spacer(),
Image.asset( Image.asset(

View File

@@ -26,6 +26,7 @@ import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:tray_manager/tray_manager.dart'; import 'package:tray_manager/tray_manager.dart';
import 'package:win32/win32.dart' as kernel32;
import 'package:window_manager/window_manager.dart'; import 'package:window_manager/window_manager.dart';
class MainApp extends StatefulWidget { class MainApp extends StatefulWidget {
@@ -168,7 +169,11 @@ class _MainAppState extends PopScopeState<MainApp>
await GStorage.close(); await GStorage.close();
await trayManager.destroy(); await trayManager.destroy();
if (Platform.isWindows) { if (Platform.isWindows) {
const MethodChannel('window_control').invokeMethod('closeWindow'); // flutter_inappwebview
// 6.2.0-beta.2+ https://github.com/pichillilorenzo/flutter_inappwebview/issues/2482
// 6.1.5 https://github.com/pichillilorenzo/flutter_inappwebview/issues/2512#issuecomment-3031039587
final hProcess = kernel32.GetCurrentProcess();
kernel32.TerminateProcess(hProcess, 0);
} else { } else {
exit(0); exit(0);
} }

View File

@@ -2003,7 +2003,7 @@ packages:
source: git source: git
version: "1.2.2" version: "1.2.2"
win32: win32:
dependency: transitive dependency: "direct main"
description: description:
name: win32 name: win32
sha256: ba6f4bba816c8d7e3c1580e170f3786d216951cc6b94babc3b814c08d2cb2738 sha256: ba6f4bba816c8d7e3c1580e170f3786d216951cc6b94babc3b814c08d2cb2738

View File

@@ -164,6 +164,7 @@ dependencies:
git: git:
url: https://github.com/wgh136/webdav_client.git url: https://github.com/wgh136/webdav_client.git
ref: main ref: main
win32: ^6.3.0
window_manager: window_manager:
git: git:
url: https://github.com/bggRGjQaUbCoE/window_manager.git url: https://github.com/bggRGjQaUbCoE/window_manager.git

View File

@@ -4,9 +4,6 @@
#include "flutter/generated_plugin_registrant.h" #include "flutter/generated_plugin_registrant.h"
#include <flutter/method_channel.h>
#include <flutter/standard_method_codec.h>
FlutterWindow::FlutterWindow(const flutter::DartProject& project) FlutterWindow::FlutterWindow(const flutter::DartProject& project)
: project_(project) {} : project_(project) {}
@@ -29,24 +26,6 @@ bool FlutterWindow::OnCreate() {
} }
RegisterPlugins(flutter_controller_->engine()); RegisterPlugins(flutter_controller_->engine());
// flutter_inappwebview
// 6.2.0-beta.2+ https://github.com/pichillilorenzo/flutter_inappwebview/issues/2482
// 6.1.5 https://github.com/pichillilorenzo/flutter_inappwebview/issues/2512#issuecomment-3031039587
flutter::MethodChannel<> channel(
flutter_controller_->engine()->messenger(), "window_control",
&flutter::StandardMethodCodec::GetInstance());
channel.SetMethodCallHandler(
[](const flutter::MethodCall<>& call,
std::unique_ptr<flutter::MethodResult<>> result) {
if (call.method_name().compare("closeWindow") == 0) {
HANDLE hProcess = GetCurrentProcess();
TerminateProcess(hProcess, 0);
result->Success();
} else {
result->NotImplemented();
}
});
SetChildContent(flutter_controller_->view()->GetNativeWindow()); SetChildContent(flutter_controller_->view()->GetNativeWindow());
// flutter_controller_->engine()->SetNextFrameCallback([&]() { // flutter_controller_->engine()->SetNextFrameCallback([&]() {