Skip to content

[WIP] Refactor InfiniFrame.Native#267

Draft
freakdaniel wants to merge 1 commit intoInfiniLore:corefrom
freakdaniel:refactor
Draft

[WIP] Refactor InfiniFrame.Native#267
freakdaniel wants to merge 1 commit 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

@AnnaSasDev AnnaSasDev linked an issue May 2, 2026 that may be closed by this pull request
2 tasks
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

1 participant