mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-14 15:56:13 +03:00
macOS: zig build run disables window saved state
This commit is contained in:
@ -256,9 +256,8 @@ class AppDelegate: NSObject,
|
|||||||
// Setup signal handlers
|
// Setup signal handlers
|
||||||
setupSignals()
|
setupSignals()
|
||||||
|
|
||||||
// This is a hack used by our build scripts, specifically `zig build run`,
|
// If we launched via zig run then we need to force foreground.
|
||||||
// to force our app to the foreground.
|
if Ghostty.launchSource == .zig_run {
|
||||||
if ProcessInfo.processInfo.environment["GHOSTTY_MAC_ACTIVATE"] == "1" {
|
|
||||||
// This never gets called until we click the dock icon. This forces it
|
// This never gets called until we click the dock icon. This forces it
|
||||||
// activate immediately.
|
// activate immediately.
|
||||||
applicationDidBecomeActive(.init(name: NSApplication.didBecomeActiveNotification))
|
applicationDidBecomeActive(.init(name: NSApplication.didBecomeActiveNotification))
|
||||||
|
@ -48,6 +48,26 @@ extension Ghostty {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MARK: General Helpers
|
||||||
|
|
||||||
|
extension Ghostty {
|
||||||
|
enum LaunchSource: String {
|
||||||
|
case cli
|
||||||
|
case app
|
||||||
|
case zig_run
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns the mechanism that launched the app. This is based on an env var so
|
||||||
|
/// its up to the env var being set in the correct circumstance.
|
||||||
|
static var launchSource: LaunchSource {
|
||||||
|
guard let envValue = ProcessInfo.processInfo.environment["GHOSTTY_MAC_LAUNCH_SOURCE"] else {
|
||||||
|
return .app
|
||||||
|
}
|
||||||
|
|
||||||
|
return LaunchSource(rawValue: envValue) ?? .app
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: Swift Types for C Types
|
// MARK: Swift Types for C Types
|
||||||
|
|
||||||
extension Ghostty {
|
extension Ghostty {
|
||||||
|
@ -88,6 +88,19 @@ pub fn init(
|
|||||||
|
|
||||||
// Our step to open the resulting Ghostty app.
|
// Our step to open the resulting Ghostty app.
|
||||||
const open = open: {
|
const open = open: {
|
||||||
|
const disable_save_state = RunStep.create(b, "disable save state");
|
||||||
|
disable_save_state.has_side_effects = true;
|
||||||
|
disable_save_state.addArgs(&.{
|
||||||
|
"/usr/libexec/PlistBuddy",
|
||||||
|
"-c",
|
||||||
|
// We'll have to change this to `Set` if we ever put this
|
||||||
|
// into our Info.plist.
|
||||||
|
"Add :NSQuitAlwaysKeepsWindows bool false",
|
||||||
|
b.fmt("{s}/Contents/Info.plist", .{app_path}),
|
||||||
|
});
|
||||||
|
disable_save_state.expectExitCode(0);
|
||||||
|
disable_save_state.step.dependOn(&build.step);
|
||||||
|
|
||||||
const open = RunStep.create(b, "run Ghostty app");
|
const open = RunStep.create(b, "run Ghostty app");
|
||||||
open.has_side_effects = true;
|
open.has_side_effects = true;
|
||||||
open.cwd = b.path("");
|
open.cwd = b.path("");
|
||||||
@ -98,15 +111,14 @@ pub fn init(
|
|||||||
|
|
||||||
// Open depends on the app
|
// Open depends on the app
|
||||||
open.step.dependOn(&build.step);
|
open.step.dependOn(&build.step);
|
||||||
|
open.step.dependOn(&disable_save_state.step);
|
||||||
|
|
||||||
// This overrides our default behavior and forces logs to show
|
// This overrides our default behavior and forces logs to show
|
||||||
// up on stderr (in addition to the centralized macOS log).
|
// up on stderr (in addition to the centralized macOS log).
|
||||||
open.setEnvironmentVariable("GHOSTTY_LOG", "1");
|
open.setEnvironmentVariable("GHOSTTY_LOG", "1");
|
||||||
|
|
||||||
// This is hack so that we can activate the app and bring it to
|
// Configure how we're launching
|
||||||
// the front forcibly even though we're executing directly
|
open.setEnvironmentVariable("GHOSTTY_MAC_LAUNCH_SOURCE", "zig_run");
|
||||||
// via the binary and not launch services.
|
|
||||||
open.setEnvironmentVariable("GHOSTTY_MAC_ACTIVATE", "1");
|
|
||||||
|
|
||||||
if (b.args) |args| {
|
if (b.args) |args| {
|
||||||
open.addArgs(args);
|
open.addArgs(args);
|
||||||
|
Reference in New Issue
Block a user