Skip to content

facade: frontend/obs-main.cpp: move 30 platform conditionals behind frontend/utility/platform.hpp #865

Closed

Description

@zackees

Part of #847.

Inventory of platform conditionals in frontend/obs-main.cpp measured on origin/master. Total: 30.

Conditionals

Line Macro What the branch does
21 __APPLE__ include OBSPermissions.hpp
32 _WIN32 include win-version.h
44 _WIN32 include shellapi.h / windows.h
95 _WIN32 localtime_s vs localtime_r in timestamp helper
204 !_WIN32 va_copy of log args for the default handler
211 _WIN32 log handler: IsDebuggerPresent -> OutputDebugString of the line
229 !_WIN32 && _DEBUG echo log to default handler in debug builds
234 !_WIN32 && !_DEBUG echo log to default handler in release builds
242 _WIN32 && OBS_DEBUGBREAK_ON_ERROR __debugbreak() on LOG_ERROR with debugger attached
248 !_WIN32 va_end of args2
407 _WIN32 open log file by wide path (utf8 -> wcs)
505 _WIN32 Qt high-DPI rounding policy PassThrough
511 __APPLE__ InstallNSApplicationSubclass / InstallNSThreadLocks
522 !_WIN32 && !__APPLE__ turn off the incompatible gtk Qt theme (env override) on Linux/BSD
560 _WIN32 keep the RunOnceMutex returned by CheckIfAlreadyRunning
607 !_WIN32 && !__APPLE__ && !__FreeBSD__ detect ChromeOS cros-containers dir
625 _WIN32 && OBS_RUST_VERSION VerifyAppIdentity after logger ready
631 __APPLE__ VerifyMacApplicationIcon
662 __APPLE__ CheckPermission for audio/video/input-monitoring at startup
677 _WIN32 IsRunningOnWine warning dialog
729 _WIN32 crash message / crash-log copy dialog
753 _WIN32 open crash log file by wide path
765 _WIN32 normalise path separators to backslash
836 _WIN32 Outdated VC++ runtime error strings/helper
886 __APPLE__ or __linux__ BASE_PATH ".." vs "../.."
892 ENABLE_PORTABLE_CONFIG or _WIN32 ALLOW_PORTABLE_MODE define
900 !_WIN32 install SIGINT/SIGTERM handlers
934 _WIN32 abort if MSVC runtime outdated; DLL blocklist / rtwq init
1071 _WIN32 --help via MessageBoxA vs stdout
1112 _WIN32 RtwqShutdown at exit

Proposed facade operations

Declared in frontend/utility/platform.hpp; implemented in frontend/utility/platform-windows.cpp, platform-osx.mm, platform-x11.cpp (Linux/BSD). Names are proposals; one facade function per logical operation, moves kept small and mechanical so upstream merges stay manageable.

Facade function Implementation
platform_localtime(const time_t*, tm*) platform-windows.cpp (localtime_s) / platform-x11.cpp + platform-osx.mm (localtime_r); one entry shared with utility/CrashHandler.cpp
platform_log_to_debugger(const char*), platform_debugbreak_on_error(), platform_echo_log_to_console(level,msg,args) windows: debugger output/debugbreak; osx/x11: default handler echo
platform_open_text_stream(path, mode) windows: wide-path open; others: narrow (log file, crash log, path separator normalisation)
platform_early_init() (DPI policy, NS subclass/thread locks, Qt style env override, VC runtime check, DLL blocklist) and platform_late_init() (app identity, mac icon) per platform
platform_check_startup_permissions(), platform_is_wine(), platform_detect_chromeos(), platform_crash_report_prompt() osx / windows / x11
platform_install_signal_handlers() x11 + osx; no-op on windows
platform_show_help(text), platform_shutdown(), constants platform_base_path() / platform_allow_portable_mode() per platform

Likely must stay / caveats

  • Include-only conditionals (21/32/44) move into the platform impl files together with the code using them.
  • ENABLE_PORTABLE_CONFIG, OBS_RUST_VERSION, OBS_DEBUGBREAK_ON_ERROR, _DEBUG are build-feature macros, not platform macros; they stay inside the facade implementation.
  • RunOnceMutex (560) is a Windows-only type; expose an opaque PlatformInstanceGuard from the facade.

Test approach

Characterisation tests for the pure pieces (platform_localtime, path separator normalisation, platform_base_path, portable-mode default) as a small Qt-free unit test run on each OS; the rest is covered by native builds (ci-full) and the startup smoke in test-appimage.sh.

RED first (failing characterisation test or facade stub), then GREEN, per docs/rust-port/testing-policy.md. Add the ci-full label since this touches shared frontend code built natively on all platforms.

Done when the listed files have no platform conditionals other than the documented exceptions, and the ratchet baseline (#848) is lowered accordingly.

Activity

  1. zackees commented on Oct 24, 2026

    @zackees
    MemberAuthor

    Claiming: #865 (frontend/obs-main.cpp.hpp, 26 baseline findings plus 4 in its PCH).

    Plan, one PR per slice, each with a Tier 2/Qt test RED first:

    1. Logging and crash handling (do_log/debugbreak/crash handler, lines ~170-220) behind host functions in frontend/utility/platform.hpp, with platform-{windows,osx,x11} implementations.
    2. Startup: single-instance check, process priority, macOS app setup, Linux session/Wayland checks (~470-650).
    3. Config and portable-mode paths, plus the Windows command-line, crash-sentinel and update bits (~700-1060), and the PCH conditionals.

    First PR expected within a day.

  2. added
    claimed
    on Oct 24, 2026
  3. zackees commented on Oct 24, 2026

    @zackees
    MemberAuthor

    Done in #2167, #2170 and #2176. frontend/obs-main.cpp.hpp and its PCH no longer test platform macros, and both have left the ratchet baseline.

    • frontend/utility/obs-main-{windows,macos,linux,posix}.hpp are self-guarded host headers in the obs-main PCH. They cover:
      • logging hooks
      • startup hooks: DPI and NSApplication setup, the bundle check, qt5ct, the run-once mutex, Wine and ChromeOS refusal, identity and icon checks, the macOS permissions dialog
      • BASE_PATH and ALLOW_PORTABLE_MODE
    • frontend/utility/obs-main-host-windows.cpp.hpp is in a new frontend.windows-obs-main unity group. It holds the crash dialog, the debug privilege, the VC++ runtime check, mitigation policies, early init and RTWorkQ, and the help box.

    test_frontend_obs_main_host checks that the macOS and Windows headers stay off Linux. One behavior change: the ChromeOS check now keys on __linux__.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    claimed

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions