Skip to content

[WIP] Refactor InfiniFrame.Native#267

Draft
freakdaniel wants to merge 8 commits intoInfiniLore:corefrom
freakdaniel:refactor
Draft

[WIP] Refactor InfiniFrame.Native#267
freakdaniel wants to merge 8 commits intoInfiniLore:corefrom
freakdaniel:refactor

Conversation

@freakdaniel
Copy link
Copy Markdown
Contributor

Summary

Major refactoring of the InfiniFrame.Native interop layer to address issue #260. PR introduces a status-code-based error propagation model, modularizes platform-specific code into focused components, establishes native CI quality gates, and centralizes memory ownership contracts. The monolithic Exports.cpp and platform window files are split into logical modules with consistent precondition guards

Type of Change

  • Refactor / Code cleanup (no functional change)
  • New feature (adding functionality)
  • Test addition or update

Affected Modules / Scope

  • InfiniFrame.Native
  • InfiniFrame.Shared
  • InfiniFrame
  • InfiniFrameTests

Changes Introduced

Interop Layer Redesign

  • Introduced InfiniFrameNativeStatusCode enum for consistent native call status reporting
  • Added NativeResult.h with EnsureSucceeded() method for error checking and detailed exception messages
  • Added NativeString.h and NativeBuffer.h to centralize string/buffer ownership contracts
  • Added InitParamsReader.h for validated init parameter parsing
  • Added ExportApi.h with shared export declarations

Export Modularization

  • Exports.cpp - main entry/exit with guards
  • Exports.Browser.cpp - browser operations (navigation, web messaging, notifications, custom schemes)
  • Exports.Dialog.cpp - dialog operations
  • Exports.Events.cpp - event callbacks (monitors, closing, focus, moved, resized, invoke)
  • Exports.Lifecycle.cpp - window lifecycle (ctor/dtor/close)
  • Exports.Memory.cpp - memory operations (FreeString, FreeStringArray)
  • Exports.Platform.cpp - platform-specific APIs
  • Exports.WindowCommands.cpp - window commands (center, restore, minimize, maximize, etc.)

Platform Modularization

  • Windows: Split Window.cpp into WindowProc.Win32.cpp/h, WebView2Host.Win32.cpp, WebView2CustomSchemes.Win32.cpp/h, WebView2Messaging.Win32.cpp, WebView2ResourceRequests.Win32.cpp, WebView2Settings.Win32.cpp, WebView2Bridge.Win32.cpp, Monitors.Win32.cpp, Notifications.WinToast.cpp, UiDispatcher.Win32.cpp, WindowImpl.Win32.h
  • Linux: Split Window.cpp into WebKitBridge.Gtk.cpp, WebKitCustomSchemes.Gtk.cpp, WebKitMessaging.Gtk.cpp/h, WebKitSettings.Gtk.cpp, Monitors.Gtk.cpp, Notifications.LibNotify.cpp, UiDispatcher.Gtk.cpp, WindowState.Gtk.cpp, WindowImpl.Gtk.h
  • macOS: Split Window.mm into WKWebViewBridge.Cocoa.mm, WKWebViewSettings.Cocoa.mm, WKCustomSchemes.Cocoa.mm, WKJsInterop.Cocoa.mm, Monitors.Cocoa.mm, Notifications.UserNotifications.Cocoa.mm, UiDispatcher.Cocoa.mm, WindowState.Cocoa.mm, WindowImpl.Cocoa.h

Error Handling Improvements

  • Replaced void-returning exports with status code returns
  • Added C ABI guard layer validating instance, output pointers, and invalid arguments
  • Replaced exit(0) paths in window construction with error propagation via EnsureSucceeded()
  • Updated InvokeUtilities and MonitorsUtility to use status codes in callbacks
  • Updated InfiniFrameWindow to handle status codes and ensure proper error propagation

Test Infrastructure

  • Test-only exports (Exports.Tests.cpp) now behind INFINIFRAME_BUILD_TEST_EXPORTS cmake option
  • Added InfiniFrameNativeExportGuardTests.cs to validate error handling and status codes
  • Updated CI workflows to pass InfiniFrameNativeTestExports=true for test builds

CI Quality Gates

  • Added native_quality.sh script with clang-format, clang-tidy, and sanitizer build modes
  • Added clang-format and clang-tidy to Linux native dependencies
  • Wired native format check, clang-tidy, and sanitizer build into Linux CI workflow (x64 only)

Shared Components

  • Added CustomSchemeResponse.h for cross-platform custom scheme response handling
  • Updated InfiniWindowExtensions.cs Fluent API with status code support
  • Updated InfiniFrameNative.cs to return status codes
  • Updated InfiniFrameNativeStatusCode.cs enum

Related Issues

Checklist

  • My code follows InfiniFrame's coding conventions
  • I added comments for complex or non-obvious code
  • Documentation updated (if applicable)
  • All tests pass locally
  • Added new tests for any new functionality
  • Existing tests pass
  • No new warnings or errors introduced
  • PR only includes changes relevant to the issue / feature

- Introduced InfiniFrameNativeStatusCode enum to represent native call status
- Updated InfiniFrameNative methods to return status codes instead of void
- Added EnsureSucceeded method to handle error checking and throw exceptions with detailed messages
- Modified InvokeUtilities to use status codes in callbacks
- Updated MonitorsUtility and InfiniFrameWindow to handle status codes and ensure proper error handling
- Added tests for native export guards to validate error handling and status codes
- Divide Exports to logical code-zones
- Update clang and testing utilities
- Add native_quality.sh for QA CI
- Update CMakeLists for new native structure
- Create & Update Interop layer
@freakdaniel
Copy link
Copy Markdown
Contributor Author

It will be a big headache

@freakdaniel
Copy link
Copy Markdown
Contributor Author

@AnnaSasDev sorry i am busy at these days. I'll continue my work as soon as I have a day-off

@AnnaSasDev
Copy link
Copy Markdown
Member

@AnnaSasDev sorry i am busy at these days. I'll continue my work as soon as I have a day-off

@freakdaniel no worries, I will continue work on other items then, but that will most likely mean I will have to touch the native layer a bit more when trying to resolve some of the Photino Backlog. Meaning it will cause some merge issues that will need to be resolved.
Will try to focus on .NET / JS issues first though.

AnnaSasDev added 7 commits May 6, 2026 13:19
Set InfiniFrameNativeTestExports to true by default when Configuration is Debug and the property is not explicitly provided, so CMakeBuildTestExports becomes ON for Debug builds. Added a comment and preserved the existing fallback to false for non-Debug or explicitly unset cases.
…dows

- Implemented retry logic with delays in `FocusedTests` to handle cases where the window focus isn't acquired immediately.
- Added fallback activation paths in `InfiniFrameWindow::SetFocused` for restricted foreground activation scenarios.
- Updated `GetFocused` to include additional checks for active, foreground, and child windows.
…ss-thread invoke readiness

- Consolidated branching in `CreateUtility` to reduce complexity in thread creation logic.
- Ensured `messageLoopReady` signaling to improve stability and reliability of cross-thread window operations.
- Updated `TemporaryFilesPath` to include unique subdirectories using `Guid.NewGuid`.
…ecific notifications and tests

- Added checks for Windows OS in relevant tests and methods to ensure platform compatibility.
- Improved thread safety with `RunOnStaThread` for Windows-only test logic in `InfiniFrameBlazorAppBuilderTests`.
- Fixed missing initialization checks for `_toastHandler` in `Notifications.WinToast`.
- Removed redundant `InitializeNotifications` call from `Window.cpp`.
…ehavior

- Updated window functionality tests (`SizeTests`, `WidthTests`, `HeightTests`, `LocationTests`, `TopTests`, `LeftTests`) to set `TemporaryFilesPath` to `null`.
- Prevents test failures caused by inconsistent GUID behavior during parameter setup.
@AnnaSasDev
Copy link
Copy Markdown
Member

AnnaSasDev commented May 6, 2026

@freakdaniel Merged core into the PR and tried to resolve testing issues I found on Windows
This way I hope there is a little bit less pressure on you, and will try to keep this PR up to date with corew

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature | Harden and modularize the native interop layer

2 participants