Skip to content
Draft
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
6 changes: 3 additions & 3 deletions .metadata
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# This file should be version controlled and should not be manually edited.

version:
revision: "17025dd88227cd9532c33fa78f5250d548d87e9a"
revision: "66dd93f9a27ffe2a9bfc8297506ce066ff51265f"
channel: "stable"

project_type: app
Expand All @@ -25,8 +25,8 @@ migration:
create_revision: 17025dd88227cd9532c33fa78f5250d548d87e9a
base_revision: 17025dd88227cd9532c33fa78f5250d548d87e9a
- platform: windows
create_revision: 17025dd88227cd9532c33fa78f5250d548d87e9a
base_revision: 17025dd88227cd9532c33fa78f5250d548d87e9a
create_revision: 66dd93f9a27ffe2a9bfc8297506ce066ff51265f
base_revision: 66dd93f9a27ffe2a9bfc8297506ce066ff51265f

# User provided section

Expand Down
1 change: 0 additions & 1 deletion lib/component/illust_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import 'package:pixez/er/prefer.dart';
import 'package:pixez/i18n.dart';
import 'package:pixez/lighting/lighting_store.dart';
import 'package:pixez/main.dart';
import 'package:pixez/models/illust.dart';
import 'package:pixez/page/picture/illust_lighting_page.dart';
import 'package:pixez/page/picture/illust_store.dart';
import 'package:pixez/page/picture/picture_list_page.dart';
Expand Down
1 change: 0 additions & 1 deletion lib/er/illust_cacher.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'package:mmkv/mmkv.dart';
import 'package:pixez/models/illust.dart';

enum IllustQuality { medium, large, original }

Expand Down
22 changes: 19 additions & 3 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ packages:
source: hosted
version: "1.1.2"
code_assets:
dependency: transitive
dependency: "direct main"
description:
name: code_assets
sha256: "83ccdaa064c980b5596c35dd64a8d3ecc68620174ab9b90b6343b753aa721687"
Expand Down Expand Up @@ -466,6 +466,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.1.4"
ffigen:
dependency: "direct dev"
description:
name: ffigen
sha256: b7803707faeec4ce3c1b0c2274906504b796e3b70ad573577e72333bd1c9b3ba
url: "https://pub.dev"
source: hosted
version: "20.1.1"
file:
dependency: transitive
description:
Expand Down Expand Up @@ -815,7 +823,7 @@ packages:
source: hosted
version: "2.3.2"
hooks:
dependency: transitive
dependency: "direct main"
description:
name: hooks
sha256: "5d309c86e7ce34cd8e37aa71cb30cb652d3829b900ab145e4d9da564b31d59f7"
Expand Down Expand Up @@ -1223,7 +1231,7 @@ packages:
source: hosted
version: "3.16.12"
native_toolchain_c:
dependency: transitive
dependency: "direct main"
description:
name: native_toolchain_c
sha256: "932ba84084915969879a044ab24342dde5f687a5c24208590c487f1af2317d21"
Expand Down Expand Up @@ -2196,6 +2204,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "3.1.3"
yaml_edit:
dependency: transitive
description:
name: yaml_edit
sha256: ec709065bb2c911b336853b67f3732dd13e0336bd065cc2f1061d7610ddf45e3
url: "https://pub.dev"
source: hosted
version: "2.2.3"
sdks:
dart: ">=3.10.0 <4.0.0"
flutter: ">=3.35.0"
4 changes: 4 additions & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ dependencies:
hooks_riverpod: ^3.0.3
flutter_hooks: ^0.21.3+1
mmkv: ^2.3.0
code_assets: any
hooks: any
native_toolchain_c: any

dev_dependencies:
flutter_test:
Expand All @@ -93,6 +96,7 @@ dev_dependencies:
custom_lint: 0.8.0
riverpod_lint: 3.0.3
freezed: 3.2.3
ffigen: ^20.0.0

# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec
Expand Down
30 changes: 8 additions & 22 deletions windows/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,7 @@ message("Pixez for Windows Desktop Application (WinRT)")

# Explicitly opt in to modern CMake behaviors to avoid warnings with recent
# versions of CMake.
cmake_policy(SET CMP0063 NEW)
if(POLICY CMP0175)
# flutter_inappwebview_windows
cmake_policy(SET CMP0175 OLD)
endif()
cmake_policy(VERSION 3.14...3.25)

# Define build configuration option.
get_property(IS_MULTICONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
Expand Down Expand Up @@ -68,6 +64,7 @@ add_subdirectory(${FLUTTER_MANAGED_DIR})
# Application build; see runner/CMakeLists.txt.
add_subdirectory("runner")


# Generated plugin build rules, which manage building the plugins and adding
# them to the application.
include(flutter/generated_plugins.cmake)
Expand Down Expand Up @@ -102,6 +99,12 @@ if(PLUGIN_BUNDLED_LIBRARIES)
COMPONENT Runtime)
endif()

# Copy the native assets provided by the build.dart from all packages.
set(NATIVE_ASSETS_DIR "${PROJECT_BUILD_DIR}native_assets/windows/")
install(DIRECTORY "${NATIVE_ASSETS_DIR}"
DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
COMPONENT Runtime)

# Fully re-copy the assets directory on each build to avoid having stale files
# from a previous install.
set(FLUTTER_ASSET_DIR_NAME "flutter_assets")
Expand All @@ -116,21 +119,4 @@ install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}"
CONFIGURATIONS Profile;Release
COMPONENT Runtime)

# Sqlite
include(FetchContent)

FetchContent_Declare(sqlite3
URL "https://www.sqlite.org/2023/sqlite-dll-win64-x64-3420000.zip"
URL_HASH SHA3_256=2425efa95556793a20761dfdab0d3b56a52e61716e8bb65e6a0a3590d41c97c0
DOWNLOAD_EXTRACT_TIMESTAMP true
)
find_file(SQLITE3 sqlite3)
if(NOT SQLITE3)
message("sqlite3.dll not found, trying to download or use cached version.")
FetchContent_MakeAvailable(sqlite3)
set(SQLITE3 ${sqlite3_SOURCE_DIR}/sqlite3.dll)
endif()

install(FILES "${SQLITE3}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime)

target_link_libraries(pixez PRIVATE windowsapp.lib)
1 change: 1 addition & 0 deletions windows/runner/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ add_executable(${BINARY_NAME} WIN32
"utils.cpp"
"win32_window.cpp"
"settings.cpp"
"plugins_manager.cpp"
"plugins/clipboard_plugin.cpp"
"plugins/document_plugin.cpp"
"plugins/paths_plugin.cpp"
Expand Down
75 changes: 22 additions & 53 deletions windows/runner/flutter_window.cpp
Original file line number Diff line number Diff line change
@@ -1,38 +1,17 @@
#include "flutter_window.h"
#include "plugins_manager.h"

#include <optional>

#include "flutter/generated_plugin_registrant.h"

#include <windows.h>
#include <ShlObj.h>
#include <iostream>
#include <flutter/binary_messenger.h>
#include <flutter/standard_method_codec.h>
#include <flutter/method_channel.h>
#include <flutter/method_result_functions.h>
#include <flutter/encodable_value.h>
#include <fstream>
#include <stdexcept>
#include <stdlib.h>
#include <stdio.h>

#include "plugins/clipboard_plugin.h"
#include "plugins/document_plugin.h"
#include "plugins/paths_plugin.h"
#include "plugins/single_instance_plugin.h"
#include "plugins/weiss_plugin.h"
#include "plugins/win32_plugin.h"

FlutterWindow::FlutterWindow(const flutter::DartProject &project)
FlutterWindow::FlutterWindow(const flutter::DartProject& project)
: project_(project) {}

FlutterWindow::~FlutterWindow() {}

bool FlutterWindow::OnCreate()
{
if (!Win32Window::OnCreate())
{
bool FlutterWindow::OnCreate() {
if (!Win32Window::OnCreate()) {
return false;
}

Expand All @@ -43,32 +22,26 @@ bool FlutterWindow::OnCreate()
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())
{
if (!flutter_controller_->engine() || !flutter_controller_->view()) {
return false;
}
RegisterPlugins(flutter_controller_->engine());
RegisterPixEzPlugins(flutter_controller_->engine(), GetHandle());
SetChildContent(flutter_controller_->view()->GetNativeWindow());
flutter_controller_->engine()->SetNextFrameCallback([&]() {
this->Show();
});

const auto &codec = flutter::StandardMethodCodec::GetInstance();
auto messenger = flutter_controller_->engine()->messenger();
Clipboard::Initialize(messenger, &codec);
Document::Initialize(messenger, &codec, GetHandle());
Paths::Initialize(messenger, &codec);
SingleInstance::Initialize(messenger, &codec);
Weiss::Initialize(messenger, &codec);
Win32::Initialize(messenger, &codec);

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();

return true;
}

void FlutterWindow::OnDestroy()
{
if (flutter_controller_)
{
void FlutterWindow::OnDestroy() {
if (flutter_controller_) {
flutter_controller_ = nullptr;
}

Expand All @@ -78,25 +51,21 @@ void FlutterWindow::OnDestroy()
LRESULT
FlutterWindow::MessageHandler(HWND hwnd, UINT const message,
WPARAM const wparam,
LPARAM const lparam) noexcept
{
LPARAM const lparam) noexcept {
// Give Flutter, including plugins, an opportunity to handle window messages.
if (flutter_controller_)
{
if (flutter_controller_) {
std::optional<LRESULT> result =
flutter_controller_->HandleTopLevelWindowProc(hwnd, message, wparam,
lparam);
if (result)
{
if (result) {
return *result;
}
}

switch (message)
{
case WM_FONTCHANGE:
flutter_controller_->engine()->ReloadSystemFonts();
break;
switch (message) {
case WM_FONTCHANGE:
flutter_controller_->engine()->ReloadSystemFonts();
break;
}

return Win32Window::MessageHandler(hwnd, message, wparam, lparam);
Expand Down
1 change: 1 addition & 0 deletions windows/runner/flutter_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <flutter/dart_project.h>
#include <flutter/flutter_view_controller.h>

#include <memory>

#include "win32_window.h"
Expand Down
19 changes: 19 additions & 0 deletions windows/runner/plugins_manager.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include "plugins_manager.h"
#include "win32_window.h"
#include "plugins/clipboard_plugin.h"
#include "plugins/document_plugin.h"
#include "plugins/paths_plugin.h"
#include "plugins/single_instance_plugin.h"
#include "plugins/weiss_plugin.h"
#include "plugins/win32_plugin.h"

void RegisterPixEzPlugins(flutter::FlutterEngine* engine, HWND hWnd) {
const auto &codec = flutter::StandardMethodCodec::GetInstance();
auto messenger = engine->messenger();
Clipboard::Initialize(messenger, &codec);
Document::Initialize(messenger, &codec, hWnd);
Paths::Initialize(messenger, &codec);
SingleInstance::Initialize(messenger, &codec);
Weiss::Initialize(messenger, &codec);
Win32::Initialize(messenger, &codec);
}
9 changes: 9 additions & 0 deletions windows/runner/plugins_manager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#ifndef PIXEZ_PLUGIN_REGISTRANT_
#define PIXEZ_PLUGIN_REGISTRANT_

#include <flutter/flutter_engine.h>

// Registers Flutter plugins.
void RegisterPixEzPlugins(flutter::FlutterEngine* engine, HWND hWnd);

#endif // PIXEZ_PLUGIN_REGISTRANT_
9 changes: 5 additions & 4 deletions windows/runner/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,19 @@ std::string Utf8FromUtf16(const wchar_t* utf16_string) {
if (utf16_string == nullptr) {
return std::string();
}
int target_length = ::WideCharToMultiByte(
unsigned int target_length = ::WideCharToMultiByte(
CP_UTF8, WC_ERR_INVALID_CHARS, utf16_string,
-1, nullptr, 0, nullptr, nullptr);
-1, nullptr, 0, nullptr, nullptr)
-1; // remove the trailing null character
int input_length = (int)wcslen(utf16_string);
std::string utf8_string;
if (target_length == 0 || target_length > utf8_string.max_size()) {
return utf8_string;
}
utf8_string.resize(target_length);
int converted_length = ::WideCharToMultiByte(
CP_UTF8, WC_ERR_INVALID_CHARS, utf16_string,
-1, utf8_string.data(),
target_length, nullptr, nullptr);
input_length, utf8_string.data(), target_length, nullptr, nullptr);
if (converted_length == 0) {
return std::string();
}
Expand Down
6 changes: 3 additions & 3 deletions windows/runner/win32_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ int Scale(int source, double scale_factor) {
// Dynamically loads the |EnableNonClientDpiScaling| from the User32 module.
// This API is only needed for PerMonitor V1 awareness mode.
void EnableFullDpiSupportIfAvailable(HWND hwnd) {
HMODULE user32_module = LoadLibrary(TEXT("User32.dll"));
HMODULE user32_module = LoadLibraryA("User32.dll");
if (!user32_module) {
return;
}
Expand All @@ -60,7 +60,7 @@ class WindowClassRegistrar {
public:
~WindowClassRegistrar() = default;

// Returns the singleton registar instance.
// Returns the singleton registrar instance.
static WindowClassRegistrar* GetInstance() {
if (!instance_) {
instance_ = new WindowClassRegistrar();
Expand Down Expand Up @@ -135,7 +135,7 @@ bool Win32Window::Create(const std::wstring& title,
double scale_factor = dpi / 96.0;

HWND window = CreateWindow(
window_class, title.c_str(), WS_OVERLAPPEDWINDOW & ~(WS_CAPTION | WS_SYSMENU),
window_class, title.c_str(), WS_OVERLAPPEDWINDOW,
Scale(origin.x, scale_factor), Scale(origin.y, scale_factor),
Scale(size.width, scale_factor), Scale(size.height, scale_factor),
nullptr, nullptr, GetModuleHandle(nullptr), this);
Expand Down
2 changes: 1 addition & 1 deletion windows/runner/win32_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class Win32Window {
// OS callback called by message pump. Handles the WM_NCCREATE message which
// is passed when the non-client area is being created and enables automatic
// non-client DPI scaling so that the non-client area automatically
// responsponds to changes in DPI. All other messages are handled by
// responds to changes in DPI. All other messages are handled by
// MessageHandler.
static LRESULT CALLBACK WndProc(HWND const window,
UINT const message,
Expand Down