Integration Guide¶
As a Zig Dependency¶
Add to your build.zig.zon:
.dependencies = .{
.zig_notify = .{
.url = "https://github.com/Jesssullivan/zig-notify/archive/refs/heads/main.tar.gz",
},
},
Then in build.zig:
const notify_dep = b.dependency("zig_notify", .{
.target = target,
.optimize = optimize,
});
exe.root_module.addImport("zig-notify", notify_dep.module("zig-notify"));
For C ABI consumers, build this repository as a static library and link zig-out/lib/libzig-notify.a.
As a C Static Library¶
Build and link against libzig-notify.a:
#include "zig_notify.h"
int main() {
// Initialize (required on Linux, no-op on macOS)
zig_notify_init("myapp", 5);
// Request permission (macOS only, no-op on Linux)
zig_notify_request_permission();
// Send notification
const char *title = "Hello";
const char *body = "World";
zig_notify_send(title, 5, body, 5, ZIG_NOTIFY_URGENCY_NORMAL);
// Clean up (required on Linux, no-op on macOS)
zig_notify_deinit();
return 0;
}
Swift Integration¶
This repository does not yet ship a SwiftPM package or module map. Use a bridging header that includes include/zig_notify.h, add the header search path, and link the static library.
import Foundation
let title = "Download Complete"
let body = "Your file has been saved"
var titleCString = Array(title.utf8CString)
var bodyCString = Array(body.utf8CString)
titleCString.withUnsafeBufferPointer { titleBuffer in
bodyCString.withUnsafeBufferPointer { bodyBuffer in
_ = zig_notify_send(
titleBuffer.baseAddress,
title.utf8.count,
bodyBuffer.baseAddress,
body.utf8.count,
ZIG_NOTIFY_URGENCY_NORMAL
)
}
}
Urgency Levels¶
| Level | Value | Description |
|---|---|---|
ZIG_NOTIFY_URGENCY_LOW |
0 | Low priority, may be silent |
ZIG_NOTIFY_URGENCY_NORMAL |
1 | Standard notification |
ZIG_NOTIFY_URGENCY_CRITICAL |
2 | Critical on Linux/libnotify; ignored by the macOS osascript backend |