mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-17 01:06:08 +03:00
cli/gtk: clean ups and better error handling in GTK new-window IPC
This commit is contained in:
@ -41,6 +41,12 @@ pub fn openNewWindow(alloc: Allocator, target: apprt.ipc.Target, value: apprt.ip
|
||||
.ReleaseFast, .ReleaseSmall => .{ "com.mitchellh.ghostty", "/com/mitchellh/ghostty" },
|
||||
},
|
||||
};
|
||||
defer {
|
||||
switch (target) {
|
||||
.class => alloc.free(object_path),
|
||||
.detect => {},
|
||||
}
|
||||
}
|
||||
|
||||
if (gio.Application.idIsValid(bus_name.ptr) == 0) {
|
||||
try stderr.print("D-Bus bus name is not valid: {s}\n", .{bus_name});
|
||||
@ -80,7 +86,7 @@ pub fn openNewWindow(alloc: Allocator, target: apprt.ipc.Target, value: apprt.ip
|
||||
// Initialize our builder to build up our parameters
|
||||
var builder: glib.VariantBuilder = undefined;
|
||||
builder.init(builder_type);
|
||||
errdefer builder.unref();
|
||||
errdefer builder.clear();
|
||||
|
||||
// action
|
||||
if (value.arguments == null) {
|
||||
@ -96,6 +102,7 @@ pub fn openNewWindow(alloc: Allocator, target: apprt.ipc.Target, value: apprt.ip
|
||||
|
||||
var parameters: glib.VariantBuilder = undefined;
|
||||
parameters.init(av);
|
||||
errdefer parameters.clear();
|
||||
|
||||
if (value.arguments) |arguments| {
|
||||
// If `-e` was specified on the command line, the first
|
||||
@ -108,6 +115,7 @@ pub fn openNewWindow(alloc: Allocator, target: apprt.ipc.Target, value: apprt.ip
|
||||
|
||||
var command: glib.VariantBuilder = undefined;
|
||||
command.init(as);
|
||||
errdefer command.clear();
|
||||
|
||||
for (arguments) |argument| {
|
||||
command.add("s", argument.ptr);
|
||||
|
@ -5,6 +5,9 @@ const Allocator = std.mem.Allocator;
|
||||
const assert = std.debug.assert;
|
||||
|
||||
pub const Errors = error{
|
||||
/// The IPC failed. If a function returns this error, it's expected that
|
||||
/// an a more specific error message will have been written to stderr (or
|
||||
/// otherwise shown to the user in an appropriate way).
|
||||
IPCFailed,
|
||||
};
|
||||
|
||||
@ -38,8 +41,6 @@ pub const Target = union(Key) {
|
||||
return .{
|
||||
.key = @as(Key, self),
|
||||
.value = switch (self) {
|
||||
.release => .{ .release = {} },
|
||||
.debug => .{ .debug = {} },
|
||||
.class => |class| .{ .class = class.ptr },
|
||||
.detect => .{ .detect = {} },
|
||||
},
|
||||
@ -68,6 +69,11 @@ pub const Action = union(enum) {
|
||||
new_window: NewWindow,
|
||||
|
||||
pub const NewWindow = struct {
|
||||
/// A list of command arguments to launch in the new window. If this is
|
||||
/// `null` the command configured in the config or the user's default
|
||||
/// shell should be launched.
|
||||
///
|
||||
/// It is an error for this to be non-`null`, but zero length.
|
||||
arguments: ?[][:0]const u8,
|
||||
|
||||
pub const C = extern struct {
|
||||
|
Reference in New Issue
Block a user