mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-07-29 20:07:55 +00:00
Fallback to cross-platform minimal open when apprt is not available
This commit is contained in:
@@ -625,28 +625,35 @@ pub const ConfigChange = struct {
|
||||
}
|
||||
};
|
||||
|
||||
/// The type of the data at the URL to open. This is used as a hint to
|
||||
/// potentially open the URL in a different way.
|
||||
/// Sync with: ghostty_action_open_url_kind_s
|
||||
pub const OpenUrlKind = enum(c_int) {
|
||||
text,
|
||||
unknown,
|
||||
};
|
||||
|
||||
/// Open a URL
|
||||
pub const OpenUrl = struct {
|
||||
/// The type of data that the URL refers to.
|
||||
kind: OpenUrlKind,
|
||||
kind: Kind,
|
||||
|
||||
/// The URL.
|
||||
url: []const u8,
|
||||
|
||||
/// The type of the data at the URL to open. This is used as a hint to
|
||||
/// potentially open the URL in a different way.
|
||||
///
|
||||
/// Sync with: ghostty_action_open_url_kind_e
|
||||
pub const Kind = enum(c_int) {
|
||||
/// The type is unknown. This is the default and apprts should
|
||||
/// open the URL in the most generic way possible. For example,
|
||||
/// on macOS this would be the equivalent of `open` or on Linux
|
||||
/// this would be `xdg-open`.
|
||||
unknown,
|
||||
|
||||
/// The URL is known to be a text file. In this case, the apprt
|
||||
/// should try to open the URL in a text editor or viewer or
|
||||
/// some equivalent, if possible.
|
||||
text,
|
||||
};
|
||||
|
||||
// Sync with: ghostty_action_open_url_s
|
||||
pub const C = extern struct {
|
||||
/// The type of data that the URL refers to.
|
||||
kind: OpenUrlKind,
|
||||
/// The URL (not zero terminated).
|
||||
kind: Kind,
|
||||
url: [*]const u8,
|
||||
/// The number of bytes in the URL.
|
||||
len: usize,
|
||||
};
|
||||
|
||||
|
||||
@@ -1759,12 +1759,18 @@ fn initActions(self: *App) void {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: use https://flatpak.github.io/xdg-desktop-portal/docs/doc-org.freedesktop.portal.OpenURI.html
|
||||
pub fn openUrl(
|
||||
app: *App,
|
||||
value: apprt.action.OpenUrl,
|
||||
) void {
|
||||
internal_os.open(app.core_app.alloc, value.kind, value.url) catch |err| {
|
||||
log.warn("unable to open url: {}", .{err});
|
||||
};
|
||||
// TODO: use https://flatpak.github.io/xdg-desktop-portal/docs/doc-org.freedesktop.portal.OpenURI.html
|
||||
|
||||
// Fallback to the minimal cross-platform way of opening a URL.
|
||||
// This is always a safe fallback and enables for example Windows
|
||||
// to open URLs (GTK on Windows via WSL is a thing).
|
||||
internal_os.open(
|
||||
app.core_app.alloc,
|
||||
value.kind,
|
||||
value.url,
|
||||
) catch |err| log.warn("unable to open url: {}", .{err});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user