Files
xianyan/windows/runner/flutter_window.cpp
Developer 49b6323772 release: 发布6.6.18版本,完成多项合规与功能优化
此版本包含以下核心更新:
1. 版本号升级至6.6.18,更新全平台配置文件
2. 实现隐私合规改造:
   - 新增剪贴板隐私守卫,未同意协议前禁止读取剪贴板
   - 所有桌面小部件继承隐私感知基类,未同意协议时显示占位提示
   - 移除自动剪贴板监控,改为用户主动触发
3. 新增Windows平台深色主题同步功能
4. 补全多语言默认句子翻译
5. 优化安卓快捷方式配置与小部件合规性
6. 修复macOS插件注册问题
7. 新增Windows安装脚本
8. 优化触觉反馈服务初始化时机
2026-06-17 04:47:06 +08:00

100 lines
3.2 KiB
C++

#include "flutter_window.h"
#include <optional>
#include <flutter/method_channel.h>
#include <flutter/standard_method_codec.h>
#include "flutter/generated_plugin_registrant.h"
FlutterWindow::FlutterWindow(const flutter::DartProject& project)
: project_(project) {}
FlutterWindow::~FlutterWindow() {}
bool FlutterWindow::OnCreate() {
if (!Win32Window::OnCreate()) {
return false;
}
RECT frame = GetClientArea();
// The size here must match the window dimensions to avoid unnecessary surface
// creation / destruction in the startup path.
flutter_controller_ = std::make_unique<flutter::FlutterViewController>(
frame.right - frame.left, frame.bottom - frame.top, project_);
// Ensure that basic setup of the controller was successful.
if (!flutter_controller_->engine() || !flutter_controller_->view()) {
return false;
}
RegisterPlugins(flutter_controller_->engine());
SetChildContent(flutter_controller_->view()->GetNativeWindow());
flutter_controller_->engine()->SetNextFrameCallback([&]() {
this->Show();
});
// Flutter can complete the first frame before the "show window" callback is
// registered. The following call ensures a frame is pending to ensure the
// window is shown. It is a no-op if the first frame hasn't completed yet.
flutter_controller_->ForceRedraw();
// Register Windows platform MethodChannel for theme control
const static std::string channel_name("com.xianyan.windows");
platform_channel_ = std::make_unique<flutter::MethodChannel<>>(
flutter_controller_->engine()->messenger(), channel_name,
&flutter::StandardMethodCodec::GetInstance());
platform_channel_->SetMethodCallHandler(
[this](const flutter::MethodCall<>& call,
std::unique_ptr<flutter::MethodResult<>> result) {
if (call.method_name() == "setDarkMode") {
bool is_dark = false;
if (const auto* args = std::get_if<flutter::EncodableMap>(call.arguments())) {
auto it = args->find(flutter::EncodableValue("isDark"));
if (it != args->end() && std::holds_alternative<bool>(it->second)) {
is_dark = std::get<bool>(it->second);
}
}
Win32Window::SetDarkMode(GetHandle(), is_dark);
result->Success();
} else {
result->NotImplemented();
}
});
return true;
}
void FlutterWindow::OnDestroy() {
if (flutter_controller_) {
flutter_controller_ = nullptr;
}
Win32Window::OnDestroy();
}
LRESULT
FlutterWindow::MessageHandler(HWND hwnd, UINT const message,
WPARAM const wparam,
LPARAM const lparam) noexcept {
// Give Flutter, including plugins, an opportunity to handle window messages.
if (flutter_controller_) {
std::optional<LRESULT> result =
flutter_controller_->HandleTopLevelWindowProc(hwnd, message, wparam,
lparam);
if (result) {
return *result;
}
}
switch (message) {
case WM_FONTCHANGE:
flutter_controller_->engine()->ReloadSystemFonts();
break;
}
return Win32Window::MessageHandler(hwnd, message, wparam, lparam);
}