Skip to content
This repository was archived by the owner on Apr 10, 2026. It is now read-only.

Improve multiple platform support#48

Merged
Jack251970 merged 8 commits intomasterfrom
dev
Nov 15, 2025
Merged

Improve multiple platform support#48
Jack251970 merged 8 commits intomasterfrom
dev

Conversation

@Jack251970
Copy link
Copy Markdown
Owner

This pull request introduces several improvements and refactors across the codebase to enhance cross-platform compatibility, especially for clipboard and data directory handling, as well as error handling and exception reporting. The most significant changes are grouped below.

Cross-platform clipboard and data handling:

  • Refactored ClipboardHelper to support both Windows and non-Windows platforms by using platform-specific clipboard APIs (ClipboardAvalonia for Windows, Avalonia's IClipboard for others). The monitoring and paste logic now adapts to the underlying OS, improving reliability and user experience across platforms. ([[1]](https://github.com/Jack251970/Math-Editor/pull/48/files#diff-b1575595a439c78421141a464b06393756e3f9643303351fcf0f11037672c09cR2-R9), [[2]](https://github.com/Jack251970/Math-Editor/pull/48/files#diff-b1575595a439c78421141a464b06393756e3f9643303351fcf0f11037672c09cR22-R30), [[3]](https://github.com/Jack251970/Math-Editor/pull/48/files#diff-b1575595a439c78421141a464b06393756e3f9643303351fcf0f11037672c09cR50-R58), [[4]](https://github.com/Jack251970/Math-Editor/pull/48/files#diff-b1575595a439c78421141a464b06393756e3f9643303351fcf0f11037672c09cL62-R76), [[5]](https://github.com/Jack251970/Math-Editor/pull/48/files#diff-b1575595a439c78421141a464b06393756e3f9643303351fcf0f11037672c09cL76-R139), [[6]](https://github.com/Jack251970/Math-Editor/pull/48/files#diff-b1575595a439c78421141a464b06393756e3f9643303351fcf0f11037672c09cR157-L124), [[7]](https://github.com/Jack251970/Math-Editor/pull/48/files#diff-b1575595a439c78421141a464b06393756e3f9643303351fcf0f11037672c09cR169-R192), [[8]](https://github.com/Jack251970/Math-Editor/pull/48/files#diff-476d31742b86307aa01ea1e3b11f708de0c4316553fc50bddd9f523d1d873de0R119), [[9]](https://github.com/Jack251970/Math-Editor/pull/48/files#diff-476d31742b86307aa01ea1e3b11f708de0c4316553fc50bddd9f523d1d873de0L141-R142))
  • Overhauled DataLocation to robustly determine the application data directory based on the operating system, supporting Windows, macOS, and Linux (using XDG_CONFIG_HOME or .config). Added error handling, caching, and directory writability checks for portable mode. ([Editor/Extensions/DataLocation.csR3-R128](https://github.com/Jack251970/Math-Editor/pull/48/files#diff-aad771c1289d5376c6449731794b067481c5bfbb594076cec17f6f63c6dbe9fdR3-R128))

Exception handling and reporting:

  • Improved exception reporting in ExceptionFormatter to provide detailed OS and .NET runtime information on all platforms, including attempts to enumerate installed .NET runtimes on non-Windows systems. Enhanced error handling to avoid crashes during report generation. ([[1]](https://github.com/Jack251970/Math-Editor/pull/48/files#diff-63e6e9e23642cae8294a0745122bb57454f0fff7077a41526e70e1b3f9352199R3-R18), [[2]](https://github.com/Jack251970/Math-Editor/pull/48/files#diff-63e6e9e23642cae8294a0745122bb57454f0fff7077a41526e70e1b3f9352199L64-R76), [[3]](https://github.com/Jack251970/Math-Editor/pull/48/files#diff-63e6e9e23642cae8294a0745122bb57454f0fff7077a41526e70e1b3f9352199R110-R159))
  • Updated the main application entry point to handle critical exceptions more gracefully by logging and exiting the process, rather than rethrowing. ([Editor.Desktop/Program.csL45-R52](https://github.com/Jack251970/Math-Editor/pull/48/files#diff-92dd97a4ce599f5f0d868a7f0a356b4824731b96c04951958e379a9f161189e0L45-R52))

General robustness and logging:

  • Added error logging to BrowserHelper to capture failures when opening URLs in the default browser, improving diagnostics. ([[1]](https://github.com/Jack251970/Math-Editor/pull/48/files#diff-0d3efe8ec8e2b00df8642f92f5bb044b4533fba00bfc86812c7f4c8d037f43eaR9-R17), [[2]](https://github.com/Jack251970/Math-Editor/pull/48/files#diff-0d3efe8ec8e2b00df8642f92f5bb044b4533fba00bfc86812c7f4c8d037f43eaR44-R48))
  • Minor cleanup, such as removing the unused ApplicationFileName constant. ([Editor/Constants.csL11](https://github.com/Jack251970/Math-Editor/pull/48/files#diff-8bd1b02b9d887f27bb6e1aa3133f52e3d737db89e2369fa9c60f023d8da0ec1aL11))

Resolve #21.

Refactored the `Open` method to improve error handling and
maintainability. Wrapped platform-specific logic in a
`try-catch` block to handle exceptions and added logging
via `EditorLogger.Error` for better debugging. Introduced
a `PlatformNotSupportedException` for unsupported OS cases.
Reorganized code for clarity and removed redundant logic.
Enhanced OS and .NET runtime detection to support non-Windows platforms:
- Added `GetFullVersion()` for cross-platform OS version reporting.
- Replaced `GetFrameworkVersionFromRegistry()` with `GetFrameworkVersion()`.
- Introduced CLI and disk-based runtime enumeration for non-Windows.
- Improved error handling and logging for runtime/OS detection.

Refactored code for readability using regions and helper methods.
Updated exception formatting to use new cross-platform methods.
The `ApplicationFileName` constant, which held the value
`"Editor.exe"`, was removed from the `Constants` class in the
`Editor` namespace. This change was likely made to eliminate
unused or redundant code or to refactor how the application
file name is managed elsewhere in the codebase.
Updated FontFactory to use platform-specific font families:
- Added `System.Runtime.InteropServices` for platform checks.
- macOS: Fallback to "Helvetica, Arial, sans-serif".
- Linux: Fallback to "Noto Sans, DejaVu Sans, sans-serif".
- Windows: Fallback to "Segoe UI, Arial, sans-serif".
Replaced the default fallback ("Segoe UI") with platform-specific logic.
Added a final fallback to `FontFamily.Default`.
Replaced the hardcoded fallback font `"Segoe UI"` with
`FontFamily.Default` in the `FontFactory` class. This change
ensures the use of a predefined default font family, improving
maintainability and consistency across the application.
Replaced hardcoded roaming data path with a platform-specific method (`GetDefaultDataHome`) to dynamically determine the default data directory based on the operating system.

Added caching for `PortableDataLocationInUse` to improve performance and avoid redundant checks. Enhanced error handling and logging for portable data location checks.

Introduced `IsDirectoryWritable` to verify directory writability with robust fallback mechanisms. Updated `SettingsDirectory` to a property for dynamic path resolution.

Improved overall maintainability and platform compatibility.
Refactored `ClipboardHelper` to introduce platform-specific clipboard handling, supporting both Windows (`ClipboardAvalonia`) and non-Windows platforms (`IClipboard`). Updated methods like `CanPasteFromClipboard` and `SetClipboard` to use asynchronous operations for improved responsiveness.

Added `TopLevel` parameter to `StartMonitoring` to tie clipboard operations to the application's top-level window. Enhanced clipboard data handling to support custom XML formats and plain text. Introduced constants for clipboard format consistency.

Improved error handling, logging, and null checks to ensure stability. Removed legacy synchronous clipboard handling code. Updated `App.axaml.cs` to pass `TopLevel` to `ClipboardHelper` for proper initialization.
@Jack251970 Jack251970 requested a review from Copilot November 15, 2025 02:33
@Jack251970 Jack251970 added the enhancement New feature or request label Nov 15, 2025
@Jack251970 Jack251970 merged commit dd340dd into master Nov 15, 2025
13 checks passed
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This pull request introduces comprehensive cross-platform support improvements for Windows, macOS, and Linux. The changes enable the application to run reliably across different operating systems by implementing platform-specific handling for clipboard operations, data directory management, font selection, and exception reporting.

Key changes:

  • Refactored clipboard operations to use platform-specific APIs (ClipboardAvalonia for Windows, Avalonia's IClipboard for other platforms)
  • Implemented OS-aware data directory resolution following platform conventions (AppData on Windows, XDG on Linux, Application Support on macOS)
  • Enhanced exception reporting with cross-platform OS version detection and .NET runtime enumeration

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 19 comments.

Show a summary per file
File Description
Editor/Helper/FontFactory.cs Adds platform-specific default font families for macOS, Linux, and Windows
Editor/Helper/ExceptionFormatter.cs Implements cross-platform OS version detection and .NET runtime discovery for non-Windows systems
Editor/Helper/ClipboardHelper.cs Refactors clipboard handling to support both Windows (ClipboardAvalonia) and non-Windows (Avalonia IClipboard) platforms
Editor/Helper/BrowserHelper.cs Adds error logging for browser opening failures across platforms
Editor/Extensions/DataLocation.cs Implements platform-aware data directory resolution with caching and writability checks
Editor/Constants.cs Removes unused ApplicationFileName constant
Editor/App.axaml.cs Adds TopLevel parameter for clipboard monitoring initialization
Editor.slnx Reorganizes solution file structure
.github/workflows/build.yml Adds multi-platform CI/CD support with matrix strategy for Windows, Ubuntu, and macOS

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread Editor/Helper/ClipboardHelper.cs
Comment thread Editor/Helper/ClipboardHelper.cs
Comment thread Editor/Helper/ClipboardHelper.cs
Comment thread Editor/Helper/ExceptionFormatter.cs
Comment thread Editor/Extensions/DataLocation.cs
Comment thread Editor/Helper/ExceptionFormatter.cs
Comment thread Editor/Helper/ExceptionFormatter.cs
Comment thread Editor/Helper/ExceptionFormatter.cs
Comment thread Editor/Helper/ExceptionFormatter.cs
Comment thread Editor/Helper/ExceptionFormatter.cs
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use Avalonia clipboard API when image type is available

2 participants