chore: clean up code comments
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
# Project-level configuration.
|
||||
cmake_minimum_required(VERSION 3.14)
|
||||
project(plezy LANGUAGES CXX)
|
||||
|
||||
# Download and extract mpv-dev (architecture-dependent)
|
||||
set(MPV_VERSION "20251228")
|
||||
set(MPV_GIT_HASH "a58dd8a")
|
||||
|
||||
@@ -61,15 +59,12 @@ FetchContent_Declare(
|
||||
)
|
||||
FetchContent_MakeAvailable(simdutf)
|
||||
|
||||
# The name of the executable created for the application. Change this to change
|
||||
# the on-disk name of your application.
|
||||
set(BINARY_NAME "plezy")
|
||||
|
||||
# Explicitly opt in to modern CMake behaviors to avoid warnings with recent
|
||||
# versions of CMake.
|
||||
cmake_policy(VERSION 3.14...3.25)
|
||||
|
||||
# Define build configuration option.
|
||||
get_property(IS_MULTICONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
|
||||
if(IS_MULTICONFIG)
|
||||
set(CMAKE_CONFIGURATION_TYPES "Debug;Profile;Release"
|
||||
@@ -82,13 +77,11 @@ else()
|
||||
"Debug" "Profile" "Release")
|
||||
endif()
|
||||
endif()
|
||||
# Define settings for the Profile build mode.
|
||||
set(CMAKE_EXE_LINKER_FLAGS_PROFILE "${CMAKE_EXE_LINKER_FLAGS_RELEASE}")
|
||||
set(CMAKE_SHARED_LINKER_FLAGS_PROFILE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE}")
|
||||
set(CMAKE_C_FLAGS_PROFILE "${CMAKE_C_FLAGS_RELEASE}")
|
||||
set(CMAKE_CXX_FLAGS_PROFILE "${CMAKE_CXX_FLAGS_RELEASE}")
|
||||
|
||||
# Use Unicode for all projects.
|
||||
add_definitions(-DUNICODE -D_UNICODE)
|
||||
|
||||
# Compilation settings that should be applied to most targets.
|
||||
@@ -104,7 +97,6 @@ function(APPLY_STANDARD_SETTINGS TARGET)
|
||||
target_compile_definitions(${TARGET} PRIVATE "$<$<CONFIG:Debug>:_DEBUG>")
|
||||
endfunction()
|
||||
|
||||
# Flutter library and tool build rules.
|
||||
set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter")
|
||||
add_subdirectory(${FLUTTER_MANAGED_DIR})
|
||||
|
||||
|
||||
@@ -230,14 +230,12 @@ $ErrorActionPreference = "Stop"
|
||||
|
||||
Write-Host "Building Windows installer packages..." -ForegroundColor Cyan
|
||||
|
||||
# Ensure we're in the project root
|
||||
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
|
||||
$ProjectRoot = Split-Path -Parent $ScriptDir
|
||||
Set-Location $ProjectRoot
|
||||
|
||||
$ResolvedOutput = Resolve-Path $OutputDir
|
||||
|
||||
# Auto-detect build dirs from default Flutter output paths if not provided
|
||||
if (-not $X64BuildDir -and (Test-Path "build\windows\x64\runner\Release")) {
|
||||
$X64BuildDir = "build\windows\x64\runner\Release"
|
||||
}
|
||||
@@ -268,7 +266,6 @@ if ($EmitScriptOnly) {
|
||||
exit 0
|
||||
}
|
||||
|
||||
# Check for 7-Zip
|
||||
Write-Host "`nChecking for 7-Zip..." -ForegroundColor Cyan
|
||||
if (-not (Get-Command 7z -ErrorAction SilentlyContinue)) {
|
||||
Write-Host "7-Zip not found in PATH. Installing via Chocolatey..." -ForegroundColor Yellow
|
||||
@@ -287,7 +284,6 @@ if (-not (Get-Command 7z -ErrorAction SilentlyContinue)) {
|
||||
}
|
||||
}
|
||||
|
||||
# Create Portable Archives
|
||||
if ($HasX64) {
|
||||
Write-Host "`nCreating x64 portable archive..." -ForegroundColor Cyan
|
||||
$X64Portable = Join-Path $ResolvedOutput "plezy-windows-x64-portable.7z"
|
||||
@@ -314,7 +310,6 @@ if ($HasArm64) {
|
||||
}
|
||||
}
|
||||
|
||||
# Stage files for Inno Setup
|
||||
Write-Host "`nStaging files for installer..." -ForegroundColor Cyan
|
||||
$StagingDir = "staging"
|
||||
if (Test-Path $StagingDir) { Remove-Item $StagingDir -Recurse -Force }
|
||||
@@ -330,13 +325,11 @@ if ($HasArm64) {
|
||||
Copy-Item -Path "$Arm64BuildDir\*" -Destination $Arm64Staging -Recurse
|
||||
}
|
||||
|
||||
# Generate Inno Setup Script
|
||||
Write-Host "`nGenerating Inno Setup script..." -ForegroundColor Cyan
|
||||
New-InnoSetupScript -Version $Version -HasX64 ([bool]$HasX64) -HasArm64 ([bool]$HasArm64) |
|
||||
Out-File -FilePath $SetupScript -Encoding ASCII
|
||||
Write-Host "Created: $SetupScript" -ForegroundColor Green
|
||||
|
||||
# Check for Inno Setup
|
||||
Write-Host "`nChecking for Inno Setup..." -ForegroundColor Cyan
|
||||
$InnoSetupPath = "C:\Program Files (x86)\Inno Setup 6\ISCC.exe"
|
||||
|
||||
@@ -356,7 +349,6 @@ if (-not (Test-Path $InnoSetupPath)) {
|
||||
}
|
||||
}
|
||||
|
||||
# Build Installer
|
||||
Write-Host "`nBuilding installer with Inno Setup..." -ForegroundColor Cyan
|
||||
& $InnoSetupPath $SetupScript
|
||||
|
||||
@@ -365,10 +357,8 @@ if ($LASTEXITCODE -ne 0) {
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Clean up staging
|
||||
Remove-Item $StagingDir -Recurse -Force -ErrorAction SilentlyContinue
|
||||
|
||||
# Summary
|
||||
Write-Host "`nBuild complete!" -ForegroundColor Green
|
||||
if ($HasX64) { Write-Host "Portable (x64): $X64Portable" -ForegroundColor White }
|
||||
if ($HasArm64) { Write-Host "Portable (arm64): $Arm64Portable" -ForegroundColor White }
|
||||
|
||||
@@ -1,11 +1,6 @@
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
project(runner LANGUAGES CXX)
|
||||
|
||||
# Define the application target. To change its name, change BINARY_NAME in the
|
||||
# top-level CMakeLists.txt, not the value here, or `flutter run` will no longer
|
||||
# work.
|
||||
#
|
||||
# Any new source files that you add to the application should be added here.
|
||||
add_executable(${BINARY_NAME} WIN32
|
||||
"flutter_window.cpp"
|
||||
"main.cpp"
|
||||
@@ -19,32 +14,23 @@ add_executable(${BINARY_NAME} WIN32
|
||||
"runner.exe.manifest"
|
||||
)
|
||||
|
||||
# Apply the standard set of build settings. This can be removed for applications
|
||||
# that need different build settings.
|
||||
apply_standard_settings(${BINARY_NAME})
|
||||
|
||||
# Setup precompiled header
|
||||
target_precompile_headers(${BINARY_NAME} PRIVATE "pch.h")
|
||||
|
||||
# Add preprocessor definitions for the build version.
|
||||
target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION=\"${FLUTTER_VERSION}\"")
|
||||
target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_MAJOR=${FLUTTER_VERSION_MAJOR}")
|
||||
target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_MINOR=${FLUTTER_VERSION_MINOR}")
|
||||
target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_PATCH=${FLUTTER_VERSION_PATCH}")
|
||||
target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_BUILD=${FLUTTER_VERSION_BUILD}")
|
||||
|
||||
# Disable Windows macros that collide with C++ standard library functions.
|
||||
target_compile_definitions(${BINARY_NAME} PRIVATE "NOMINMAX")
|
||||
|
||||
# Build simdutf as a static library from the single-header amalgamation.
|
||||
add_library(simdutf STATIC "${simdutf_SOURCE_DIR}/simdutf.cpp")
|
||||
target_include_directories(simdutf PUBLIC "${simdutf_SOURCE_DIR}")
|
||||
target_compile_features(simdutf PUBLIC cxx_std_17)
|
||||
# Suppress warnings in third-party code
|
||||
target_compile_options(simdutf PRIVATE /W0)
|
||||
|
||||
# Add dependency libraries and include directories. Add any application-specific
|
||||
# dependencies here.
|
||||
target_link_libraries(${BINARY_NAME} PRIVATE flutter flutter_wrapper_app flutter_wrapper_plugin)
|
||||
target_link_libraries(${BINARY_NAME} PRIVATE "dwmapi.lib" "comctl32.lib")
|
||||
target_link_libraries(${BINARY_NAME} PRIVATE "${MPV_LIB_DIR}/libmpv.dll.a")
|
||||
|
||||
@@ -6,11 +6,9 @@
|
||||
#include "mpv/display_mode_manager.h"
|
||||
#include "mpv/mpv_plugin.h"
|
||||
|
||||
// Registry key for window placement persistence
|
||||
static constexpr wchar_t kWindowPlacementKey[] = L"Software\\Plezy";
|
||||
static constexpr wchar_t kWindowPlacementValue[] = L"WindowPlacement";
|
||||
|
||||
// Debounce timer for saving window placement
|
||||
static UINT_PTR g_saveTimerId = 0;
|
||||
static HWND g_mainHwnd = nullptr;
|
||||
// When true, WM_WINDOWPOSCHANGED should not persist placement. Used while a
|
||||
@@ -18,17 +16,14 @@ static HWND g_mainHwnd = nullptr;
|
||||
// as the user's last "normal" placement.
|
||||
static bool g_suppressPlacementSave = false;
|
||||
|
||||
// Forward declaration
|
||||
static void SaveWindowPlacement(HWND hwnd);
|
||||
|
||||
// Timer callback for debounced save
|
||||
static void CALLBACK SaveTimerProc(HWND, UINT, UINT_PTR, DWORD) {
|
||||
if (g_mainHwnd) SaveWindowPlacement(g_mainHwnd);
|
||||
KillTimer(nullptr, g_saveTimerId);
|
||||
g_saveTimerId = 0;
|
||||
}
|
||||
|
||||
// Write a WINDOWPLACEMENT struct directly to the registry.
|
||||
static void WriteWindowPlacement(const WINDOWPLACEMENT& wp) {
|
||||
HKEY hKey;
|
||||
if (RegCreateKeyExW(
|
||||
@@ -39,7 +34,6 @@ static void WriteWindowPlacement(const WINDOWPLACEMENT& wp) {
|
||||
}
|
||||
}
|
||||
|
||||
// Save the window's current WINDOWPLACEMENT to registry.
|
||||
static void SaveWindowPlacement(HWND hwnd) {
|
||||
WINDOWPLACEMENT wp{};
|
||||
wp.length = sizeof(wp);
|
||||
@@ -47,8 +41,6 @@ static void SaveWindowPlacement(HWND hwnd) {
|
||||
WriteWindowPlacement(wp);
|
||||
}
|
||||
|
||||
// Load and apply WINDOWPLACEMENT from registry
|
||||
// Returns whether the window should be maximized
|
||||
static bool LoadWindowPlacement(HWND hwnd) {
|
||||
HKEY hKey;
|
||||
if (RegOpenKeyExW(HKEY_CURRENT_USER, kWindowPlacementKey, 0, KEY_READ, &hKey) != ERROR_SUCCESS) return false;
|
||||
@@ -71,11 +63,10 @@ static bool LoadWindowPlacement(HWND hwnd) {
|
||||
return wasMaximized;
|
||||
}
|
||||
|
||||
// Debounce save to avoid excessive registry writes during resize/move
|
||||
static void DebounceSaveWindowPlacement(HWND hwnd) {
|
||||
g_mainHwnd = hwnd;
|
||||
if (g_saveTimerId) KillTimer(nullptr, g_saveTimerId);
|
||||
g_saveTimerId = SetTimer(nullptr, 0, 500, SaveTimerProc); // 500ms debounce
|
||||
g_saveTimerId = SetTimer(nullptr, 0, 500, SaveTimerProc);
|
||||
}
|
||||
|
||||
FlutterWindow::FlutterWindow(const flutter::DartProject& project) : project_(project) {}
|
||||
@@ -93,13 +84,11 @@ bool FlutterWindow::OnCreate() {
|
||||
// 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());
|
||||
|
||||
// Register mpv player plugins (video + dedicated audio-only music core).
|
||||
OutputDebugStringA("FlutterWindow: About to register MpvPlayerPlugin\n");
|
||||
MpvPlayerPluginRegisterWithRegistrar(flutter_controller_->engine()->GetRegistrarForPlugin("MpvPlayerPlugin"));
|
||||
MpvAudioPlayerPluginRegisterWithRegistrar(
|
||||
@@ -110,7 +99,6 @@ bool FlutterWindow::OnCreate() {
|
||||
|
||||
SetChildContent(flutter_controller_->view()->GetNativeWindow());
|
||||
|
||||
// Load saved window placement before showing
|
||||
HWND hwnd = GetHandle();
|
||||
bool maximized = LoadWindowPlacement(hwnd);
|
||||
|
||||
|
||||
@@ -10,27 +10,21 @@
|
||||
|
||||
#include "win32_window.h"
|
||||
|
||||
// A window that does nothing but host a Flutter view.
|
||||
class FlutterWindow : public Win32Window {
|
||||
public:
|
||||
// Creates a new FlutterWindow hosting a Flutter view running |project|.
|
||||
explicit FlutterWindow(const flutter::DartProject& project);
|
||||
virtual ~FlutterWindow();
|
||||
|
||||
protected:
|
||||
// Win32Window:
|
||||
bool OnCreate() override;
|
||||
void OnDestroy() override;
|
||||
LRESULT MessageHandler(HWND window, UINT const message, WPARAM const wparam, LPARAM const lparam) noexcept override;
|
||||
|
||||
private:
|
||||
// The project to run.
|
||||
flutter::DartProject project_;
|
||||
|
||||
// The Flutter instance hosted by this window.
|
||||
std::unique_ptr<flutter::FlutterViewController> flutter_controller_;
|
||||
|
||||
// Method channel exposing window controls to Dart (plezy/window).
|
||||
std::unique_ptr<flutter::MethodChannel<flutter::EncodableValue>> window_channel_;
|
||||
|
||||
// Fullscreen state tracking for monitor-aware native fullscreen.
|
||||
|
||||
@@ -16,7 +16,6 @@ wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev, _In_ wchar_t* command
|
||||
// created. (On a stock engine the flag is a no-op and compositing breaks.)
|
||||
::SetEnvironmentVariableW(L"FLUTTER_WINDOWS_DCOMP", L"1");
|
||||
|
||||
// Single instance enforcement
|
||||
HANDLE mutex = CreateMutex(nullptr, TRUE, L"com.edde746.Plezy.SingleInstance");
|
||||
if (GetLastError() == ERROR_ALREADY_EXISTS) {
|
||||
HWND existing = FindWindow(L"FLUTTER_RUNNER_WIN32_WINDOW", L"Plezy");
|
||||
@@ -34,8 +33,7 @@ wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev, _In_ wchar_t* command
|
||||
CreateAndAttachConsole();
|
||||
}
|
||||
|
||||
// Initialize COM, so that it is available for use in the library and/or
|
||||
// plugins.
|
||||
// Initialize COM for Win32 libraries and plugins.
|
||||
::CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED);
|
||||
|
||||
flutter::DartProject project(L"data");
|
||||
|
||||
@@ -72,7 +72,6 @@ DisplayModeManager::DisplayModeManager() {}
|
||||
|
||||
DisplayModeManager::~DisplayModeManager() {}
|
||||
|
||||
// --- Monitor identification ---
|
||||
|
||||
std::wstring DisplayModeManager::GetMonitorDeviceName(HWND window) {
|
||||
HMONITOR monitor = MonitorFromWindow(window, MONITOR_DEFAULTTONEAREST);
|
||||
@@ -140,7 +139,6 @@ bool DisplayModeManager::IsWin11_24H2OrNewer() {
|
||||
return VerifyVersionInfoW(&osvi, VER_BUILDNUMBER, condition_mask) != FALSE;
|
||||
}
|
||||
|
||||
// --- Refresh rate / resolution ---
|
||||
|
||||
std::vector<DisplayMode> DisplayModeManager::EnumerateDisplayModes(HWND window) {
|
||||
std::wstring device_name = GetMonitorDeviceName(window);
|
||||
@@ -158,7 +156,6 @@ std::vector<DisplayMode> DisplayModeManager::EnumerateDisplayModes(HWND window)
|
||||
modes.push_back(mode);
|
||||
}
|
||||
|
||||
// Remove duplicates.
|
||||
std::sort(modes.begin(), modes.end(), [](const DisplayMode& a, const DisplayMode& b) {
|
||||
if (a.width != b.width) return a.width < b.width;
|
||||
if (a.height != b.height) return a.height < b.height;
|
||||
|
||||
@@ -38,14 +38,12 @@ MpvPlayerPlugin::MpvPlayerPlugin(
|
||||
platform_thread_id_(::GetCurrentThreadId()),
|
||||
audio_only_(audio_only),
|
||||
platform_task_message_(audio_only ? kAudioPlatformTaskMessage : kPlatformTaskMessage) {
|
||||
// Create method channel.
|
||||
method_channel_ = std::make_unique<flutter::MethodChannel<flutter::EncodableValue>>(
|
||||
registrar->messenger(), channel_name, &flutter::StandardMethodCodec::GetInstance());
|
||||
|
||||
method_channel_->SetMethodCallHandler(
|
||||
[this](const auto& call, auto result) { HandleMethodCall(call, std::move(result)); });
|
||||
|
||||
// Create event channel.
|
||||
event_channel_ = std::make_unique<flutter::EventChannel<flutter::EncodableValue>>(
|
||||
registrar->messenger(), channel_name + "/events", &flutter::StandardMethodCodec::GetInstance());
|
||||
|
||||
@@ -78,7 +76,6 @@ MpvPlayerPlugin::~MpvPlayerPlugin() {
|
||||
|
||||
DrainPlatformTasks();
|
||||
|
||||
// Unregister window proc delegate.
|
||||
if (proc_id_) {
|
||||
registrar_->UnregisterTopLevelWindowProcDelegate(proc_id_.value());
|
||||
proc_id_ = std::nullopt;
|
||||
|
||||
Reference in New Issue
Block a user