@native-sdk/cli 0.9.0 → 0.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. package/build/app.zig +331 -24
  2. package/build.zig +179 -11
  3. package/native-sdk.d.ts +8 -0
  4. package/package.json +10 -10
  5. package/packages/core/compile-surface/core.ts +70 -1
  6. package/packages/core/package-lock.json +11 -11
  7. package/packages/core/package.json +2 -2
  8. package/packages/core/scripts/merge_static_archives.mjs +78 -0
  9. package/packages/core/scripts/run_external_core_compiler.mjs +52 -7
  10. package/packages/core/scripts/run_external_service_compiler.mjs +53 -13
  11. package/packages/core/scripts/stage_external_services.mjs +1 -1
  12. package/packages/core/sdk/core.d.ts +75 -0
  13. package/packages/core/sdk/core.ts +167 -12
  14. package/packages/core/sdk/events.d.ts +53 -0
  15. package/packages/core/sdk/events.ts +78 -7
  16. package/packages/core/src/checker.ts +470 -2
  17. package/packages/core/src/cli.ts +13 -0
  18. package/packages/core/src/contract.ts +3 -1
  19. package/packages/core/src/devhost.ts +30 -1
  20. package/packages/core/src/devhost_journal.mjs +10 -8
  21. package/packages/core/src/diagnostics.ts +99 -8
  22. package/packages/core/src/frontend.ts +6 -0
  23. package/packages/core/src/infer.ts +24 -0
  24. package/skill-data/automation/SKILL.md +1 -1
  25. package/skill-data/native-ui/SKILL.md +11 -5
  26. package/skill-data/ts-core/SKILL.md +53 -20
  27. package/skill-data/ts-services/SKILL.md +4 -4
  28. package/skill-data/ts-services/references/service-surface.md +2 -1
  29. package/skill-data/zig/SKILL.md +1 -1
  30. package/src/app_runner/root.zig +29 -0
  31. package/src/app_runner/ts_core_main.zig +5 -0
  32. package/src/app_runner/ts_core_mobile.zig +241 -0
  33. package/src/automation/protocol.zig +5 -1
  34. package/src/automation/snapshot.zig +8 -6
  35. package/src/embed/app_exports.zig +1 -0
  36. package/src/embed/root.zig +1 -0
  37. package/src/embed/tests.zig +28 -0
  38. package/src/embed/ui_host.zig +68 -2
  39. package/src/platform/linux/cef_host.cpp +7 -1
  40. package/src/platform/linux/gtk_host.c +200 -5
  41. package/src/platform/linux/gtk_host.h +2 -1
  42. package/src/platform/linux/root.zig +69 -4
  43. package/src/platform/macos/appkit_host.h +11 -7
  44. package/src/platform/macos/appkit_host.m +210 -88
  45. package/src/platform/macos/cef_host.mm +210 -88
  46. package/src/platform/macos/root.zig +77 -30
  47. package/src/platform/null_platform.zig +234 -51
  48. package/src/platform/null_platform_tests.zig +39 -0
  49. package/src/platform/root.zig +10 -0
  50. package/src/platform/types.zig +105 -16
  51. package/src/platform/windows/root.zig +20 -6
  52. package/src/platform/windows/webview2_host.cpp +41 -5
  53. package/src/root.zig +7 -0
  54. package/src/runtime/api.zig +8 -0
  55. package/src/runtime/automation_commands.zig +35 -2
  56. package/src/runtime/automation_snapshot.zig +32 -24
  57. package/src/runtime/bridge_permission_tests.zig +35 -1
  58. package/src/runtime/bridge_responses.zig +1 -1
  59. package/src/runtime/builtin_bridge.zig +11 -1
  60. package/src/runtime/core.zig +12 -6
  61. package/src/runtime/effects.zig +1323 -35
  62. package/src/runtime/effects_file_tests.zig +587 -0
  63. package/src/runtime/effects_notification_tests.zig +11 -0
  64. package/src/runtime/file_access.zig +400 -0
  65. package/src/runtime/file_effect_crash_helper.zig +28 -0
  66. package/src/runtime/file_effect_crash_tests.zig +37 -0
  67. package/src/runtime/flow.zig +21 -9
  68. package/src/runtime/native_command_event_tests.zig +44 -2
  69. package/src/runtime/pty.zig +5 -2
  70. package/src/runtime/root.zig +5 -0
  71. package/src/runtime/session_blobs.zig +4 -1
  72. package/src/runtime/session_journal.zig +56 -5
  73. package/src/runtime/session_record.zig +38 -0
  74. package/src/runtime/session_replay.zig +97 -7
  75. package/src/runtime/session_tests.zig +81 -0
  76. package/src/runtime/state.zig +10 -0
  77. package/src/runtime/system_services.zig +129 -36
  78. package/src/runtime/ts_core_host.zig +281 -11
  79. package/src/runtime/ts_core_host_tests.zig +95 -1
  80. package/src/runtime/ts_ui_app.zig +461 -8
  81. package/src/runtime/ui_app.zig +321 -109
  82. package/src/runtime/ui_app_tests.zig +132 -6
  83. package/src/runtime/ui_app_window_tests.zig +61 -7
  84. package/src/runtime/validation.zig +20 -0
  85. package/src/tooling/templates.zig +28 -0
  86. package/src/tooling/ts_core.zig +83 -0
  87. package/tools/corewire/emit.zig +3 -3
  88. package/tools/corewire/emit_facade.zig +65 -5
  89. package/tools/corewire/emit_profile.zig +2 -2
  90. package/tools/corewire/emit_service.zig +2 -2
  91. package/tools/corewire/service_contract.zig +4 -4
  92. package/tools/corewire/sidecar.zig +4 -4
@@ -3,12 +3,15 @@
3
3
  #include <gtk/gtk.h>
4
4
  #include <glib/gstdio.h>
5
5
  #include <dlfcn.h>
6
+ #include <errno.h>
7
+ #include <fcntl.h>
6
8
  #include <limits.h>
7
9
  #include <math.h>
8
10
  #include <stdint.h>
9
11
  #include <string.h>
10
12
  #include <stdlib.h>
11
13
  #include <stdio.h>
14
+ #include <unistd.h>
12
15
 
13
16
  /* NATIVE_SDK_ALLOW_WEBKITGTK_STUB is the build graph's declaration that
14
17
  * this app uses no web layer, and it wins over header visibility: on a
@@ -383,6 +386,13 @@ typedef struct native_sdk_gtk_window {
383
386
  int native_view_count;
384
387
  } native_sdk_gtk_window_t;
385
388
 
389
+ typedef struct native_sdk_gtk_notification_action {
390
+ char *command;
391
+ char *notification_id;
392
+ } native_sdk_gtk_notification_action_t;
393
+
394
+ static const char native_sdk_notification_action_name[] = "native-sdk-notification-action";
395
+
386
396
  struct native_sdk_gtk_host {
387
397
  GtkApplication *app;
388
398
  /* Display providers are global and the display retains them until
@@ -452,6 +462,14 @@ struct native_sdk_gtk_host {
452
462
  native_sdk_gtk_context_menu_t *context_menu_teardowns;
453
463
  /* Feeds each context menu's per-invocation action-group name. */
454
464
  uint64_t context_menu_serial;
465
+ /* Notification buttons carry only an unguessable, process-scoped
466
+ * token across the exported GApplication action. The command stays
467
+ * private to this host, so another session-bus client cannot supply
468
+ * an arbitrary command name and notifications from an earlier app
469
+ * execution cannot dispatch into this one. The id map invalidates a
470
+ * superseded same-id notification's token before replacement. */
471
+ GHashTable *notification_actions;
472
+ GHashTable *notification_action_tokens_by_id;
455
473
  native_sdk_gtk_audio_t audio;
456
474
  };
457
475
 
@@ -471,6 +489,46 @@ static char *native_sdk_strndup(const char *s, size_t len) {
471
489
  return out;
472
490
  }
473
491
 
492
+ static void native_sdk_notification_action_free(gpointer data) {
493
+ native_sdk_gtk_notification_action_t *notification_action = data;
494
+ if (!notification_action) return;
495
+ free(notification_action->command);
496
+ free(notification_action->notification_id);
497
+ free(notification_action);
498
+ }
499
+
500
+ static char *native_sdk_random_notification_action_token(void) {
501
+ uint8_t random_bytes[16];
502
+ int random_fd;
503
+ do {
504
+ random_fd = open("/dev/urandom", O_RDONLY | O_CLOEXEC);
505
+ } while (random_fd < 0 && errno == EINTR);
506
+ if (random_fd < 0) return NULL;
507
+
508
+ size_t offset = 0;
509
+ while (offset < sizeof(random_bytes)) {
510
+ const ssize_t count = read(
511
+ random_fd, random_bytes + offset, sizeof(random_bytes) - offset);
512
+ if (count > 0) {
513
+ offset += (size_t)count;
514
+ continue;
515
+ }
516
+ if (count < 0 && errno == EINTR) continue;
517
+ close(random_fd);
518
+ return NULL;
519
+ }
520
+ close(random_fd);
521
+
522
+ static const char hex[] = "0123456789abcdef";
523
+ char *token = g_malloc(sizeof(random_bytes) * 2 + 1);
524
+ for (size_t i = 0; i < sizeof(random_bytes); i++) {
525
+ token[i * 2] = hex[random_bytes[i] >> 4];
526
+ token[i * 2 + 1] = hex[random_bytes[i] & 0x0f];
527
+ }
528
+ token[sizeof(random_bytes) * 2] = '\0';
529
+ return token;
530
+ }
531
+
474
532
  static void native_sdk_free_string_list(char **list, int count) {
475
533
  if (!list) return;
476
534
  for (int i = 0; i < count; i++) free(list[i]);
@@ -2026,7 +2084,7 @@ static const char *native_sdk_bridge_script(void) {
2026
2084
  "});"
2027
2085
  "var os=Object.freeze({"
2028
2086
  "openUrl:function(value){var options=typeof value==='string'?{url:value}:(value||{});return invoke('native-sdk.os.openUrl',{url:ensureString(options.url,'url')});},"
2029
- "showNotification:function(value){var options=typeof value==='string'?{title:value}:(value||{});var payload={title:ensureString(options.title,'title')};if(options.subtitle!=null){payload.subtitle=ensureString(options.subtitle,'subtitle');}if(options.body!=null){payload.body=ensureString(options.body,'body');}return invoke('native-sdk.os.showNotification',payload);},"
2087
+ "showNotification:function(value){var options=typeof value==='string'?{title:value}:(value||{});var payload={title:ensureString(options.title,'title')};if(options.id!=null){payload.id=ensureString(options.id,'id');}if(options.subtitle!=null){payload.subtitle=ensureString(options.subtitle,'subtitle');}if(options.body!=null){payload.body=ensureString(options.body,'body');}if(options.actionLabel!=null){payload.actionLabel=ensureString(options.actionLabel,'actionLabel');}if(options.actionCommand!=null){payload.actionCommand=ensureString(options.actionCommand,'actionCommand');}return invoke('native-sdk.os.showNotification',payload);},"
2030
2088
  "revealPath:function(value){var options=typeof value==='string'?{path:value}:(value||{});return invoke('native-sdk.os.revealPath',{path:ensureString(options.path,'path')});},"
2031
2089
  "addRecentDocument:function(value){var options=typeof value==='string'?{path:value}:(value||{});return invoke('native-sdk.os.addRecentDocument',{path:ensureString(options.path,'path')});},"
2032
2090
  "clearRecentDocuments:function(){return invoke('native-sdk.os.clearRecentDocuments',{});}"
@@ -3253,6 +3311,10 @@ native_sdk_gtk_host_t *native_sdk_gtk_create(
3253
3311
  host->allowed_external_urls_count = 0;
3254
3312
 
3255
3313
  host->app = gtk_application_new(host->bundle_id, G_APPLICATION_DEFAULT_FLAGS);
3314
+ host->notification_actions = g_hash_table_new_full(
3315
+ g_str_hash, g_str_equal, g_free, native_sdk_notification_action_free);
3316
+ host->notification_action_tokens_by_id = g_hash_table_new_full(
3317
+ g_str_hash, g_str_equal, g_free, g_free);
3256
3318
 
3257
3319
  return host;
3258
3320
  }
@@ -3295,6 +3357,15 @@ void native_sdk_gtk_destroy(native_sdk_gtk_host_t *host) {
3295
3357
  g_object_unref(host->transparent_css_provider);
3296
3358
  g_object_unref(host->transparent_css_display);
3297
3359
  }
3360
+ if (host->app && g_action_map_lookup_action(
3361
+ G_ACTION_MAP(host->app), native_sdk_notification_action_name)) {
3362
+ g_action_map_remove_action(
3363
+ G_ACTION_MAP(host->app), native_sdk_notification_action_name);
3364
+ }
3365
+ if (host->notification_action_tokens_by_id) {
3366
+ g_hash_table_destroy(host->notification_action_tokens_by_id);
3367
+ }
3368
+ if (host->notification_actions) g_hash_table_destroy(host->notification_actions);
3298
3369
  g_object_unref(host->app);
3299
3370
  free(host->app_name);
3300
3371
  free(host->window_title);
@@ -4755,9 +4826,80 @@ int native_sdk_gtk_reveal_path(native_sdk_gtk_host_t *host, const char *path, si
4755
4826
  return 1;
4756
4827
  }
4757
4828
 
4758
- int native_sdk_gtk_show_notification(native_sdk_gtk_host_t *host, const char *title, size_t title_len, const char *subtitle, size_t subtitle_len, const char *body, size_t body_len) {
4829
+ static void native_sdk_forget_notification_action_for_id(native_sdk_gtk_host_t *host, const char *notification_id) {
4830
+ if (!host || !host->notification_actions ||
4831
+ !host->notification_action_tokens_by_id || !notification_id) return;
4832
+ const char *token = g_hash_table_lookup(
4833
+ host->notification_action_tokens_by_id, notification_id);
4834
+ if (token) g_hash_table_remove(host->notification_actions, token);
4835
+ g_hash_table_remove(host->notification_action_tokens_by_id, notification_id);
4836
+ }
4837
+
4838
+ static char *native_sdk_take_notification_action_command(
4839
+ native_sdk_gtk_host_t *host, const char *token, size_t token_len)
4840
+ {
4841
+ if (!host || !host->notification_actions || !token || token_len == 0) return NULL;
4842
+ native_sdk_gtk_notification_action_t *notification_action =
4843
+ g_hash_table_lookup(host->notification_actions, token);
4844
+ if (!notification_action || !notification_action->command) return NULL;
4845
+
4846
+ char *command = native_sdk_strndup(
4847
+ notification_action->command, strlen(notification_action->command));
4848
+ if (!command) return NULL;
4849
+ if (notification_action->notification_id &&
4850
+ host->notification_action_tokens_by_id) {
4851
+ const char *current_token = g_hash_table_lookup(
4852
+ host->notification_action_tokens_by_id,
4853
+ notification_action->notification_id);
4854
+ if (current_token && strcmp(current_token, token) == 0) {
4855
+ g_hash_table_remove(
4856
+ host->notification_action_tokens_by_id,
4857
+ notification_action->notification_id);
4858
+ }
4859
+ }
4860
+ /* One click consumes the capability before app code runs. App code
4861
+ * may synchronously show or replace another notification. */
4862
+ g_hash_table_remove(host->notification_actions, token);
4863
+ return command;
4864
+ }
4865
+
4866
+ static void native_sdk_notification_action_activated(GSimpleAction *action, GVariant *parameter, gpointer data) {
4867
+ (void)action;
4868
+ native_sdk_gtk_host_t *host = data;
4869
+ if (!host || !parameter || !g_variant_is_of_type(parameter, G_VARIANT_TYPE_STRING)) return;
4870
+ gsize token_len = 0;
4871
+ const char *token = g_variant_get_string(parameter, &token_len);
4872
+ char *command = native_sdk_take_notification_action_command(host, token, token_len);
4873
+ if (!command) return;
4874
+ const size_t command_len = strlen(command);
4875
+ native_sdk_emit(host, (native_sdk_gtk_event_t){
4876
+ .kind = NATIVE_SDK_GTK_EVENT_NOTIFICATION_COMMAND,
4877
+ .window_id = 1,
4878
+ .command_name = command,
4879
+ .command_name_len = command_len,
4880
+ });
4881
+ free(command);
4882
+ }
4883
+
4884
+ static int native_sdk_ensure_notification_action(native_sdk_gtk_host_t *host) {
4885
+ GActionMap *map = G_ACTION_MAP(host->app);
4886
+ if (g_action_map_lookup_action(map, native_sdk_notification_action_name)) return 1;
4887
+ GSimpleAction *action = g_simple_action_new(
4888
+ native_sdk_notification_action_name, G_VARIANT_TYPE_STRING);
4889
+ if (!action) return 0;
4890
+ g_signal_connect(action, "activate", G_CALLBACK(native_sdk_notification_action_activated), host);
4891
+ g_action_map_add_action(map, G_ACTION(action));
4892
+ g_object_unref(action);
4893
+ return 1;
4894
+ }
4895
+
4896
+ int native_sdk_gtk_show_notification(native_sdk_gtk_host_t *host, const char *title, size_t title_len, const char *subtitle, size_t subtitle_len, const char *body, size_t body_len, const char *notification_id, size_t notification_id_len, const char *action_label, size_t action_label_len, const char *action_command, size_t action_command_len) {
4759
4897
  if (!host || !host->app || !title || title_len == 0) return 0;
4760
- if ((subtitle_len > 0 && !subtitle) || (body_len > 0 && !body)) return 0;
4898
+ if ((subtitle_len > 0 && !subtitle) || (body_len > 0 && !body) ||
4899
+ (notification_id_len > 0 && !notification_id) ||
4900
+ (action_label_len > 0 && !action_label) ||
4901
+ (action_command_len > 0 && !action_command) ||
4902
+ ((action_label_len == 0) != (action_command_len == 0))) return 0;
4761
4903
  char *title_copy = native_sdk_strndup(title, title_len);
4762
4904
  if (!title_copy) return 0;
4763
4905
 
@@ -4787,7 +4929,59 @@ int native_sdk_gtk_show_notification(native_sdk_gtk_host_t *host, const char *ti
4787
4929
  free(message);
4788
4930
  }
4789
4931
 
4790
- g_application_send_notification(G_APPLICATION(host->app), NULL, notification);
4932
+ char *id_copy = notification_id_len > 0 ? native_sdk_strndup(notification_id, notification_id_len) : NULL;
4933
+ if (notification_id_len > 0 && !id_copy) {
4934
+ g_object_unref(notification);
4935
+ return 0;
4936
+ }
4937
+ if (id_copy) native_sdk_forget_notification_action_for_id(host, id_copy);
4938
+
4939
+ if (action_command_len > 0) {
4940
+ if (!native_sdk_ensure_notification_action(host)) {
4941
+ free(id_copy);
4942
+ g_object_unref(notification);
4943
+ return 0;
4944
+ }
4945
+ char *label_copy = native_sdk_strndup(action_label, action_label_len);
4946
+ char *command_copy = native_sdk_strndup(action_command, action_command_len);
4947
+ char *action_token = native_sdk_random_notification_action_token();
4948
+ native_sdk_gtk_notification_action_t *notification_action =
4949
+ calloc(1, sizeof(native_sdk_gtk_notification_action_t));
4950
+ if (!label_copy || !command_copy || !action_token || !notification_action) {
4951
+ free(label_copy);
4952
+ free(command_copy);
4953
+ g_free(action_token);
4954
+ free(notification_action);
4955
+ free(id_copy);
4956
+ g_object_unref(notification);
4957
+ return 0;
4958
+ }
4959
+ notification_action->command = command_copy;
4960
+ notification_action->notification_id = id_copy
4961
+ ? native_sdk_strndup(id_copy, strlen(id_copy))
4962
+ : NULL;
4963
+ if (id_copy && !notification_action->notification_id) {
4964
+ free(label_copy);
4965
+ g_free(action_token);
4966
+ native_sdk_notification_action_free(notification_action);
4967
+ free(id_copy);
4968
+ g_object_unref(notification);
4969
+ return 0;
4970
+ }
4971
+ g_notification_add_button_with_target_value(notification, label_copy,
4972
+ "app.native-sdk-notification-action", g_variant_new_string(action_token));
4973
+ g_hash_table_insert(host->notification_actions, action_token, notification_action);
4974
+ if (id_copy) {
4975
+ g_hash_table_replace(
4976
+ host->notification_action_tokens_by_id,
4977
+ g_strdup(id_copy),
4978
+ g_strdup(action_token));
4979
+ }
4980
+ free(label_copy);
4981
+ }
4982
+
4983
+ g_application_send_notification(G_APPLICATION(host->app), id_copy, notification);
4984
+ free(id_copy);
4791
4985
  g_object_unref(notification);
4792
4986
  return 1;
4793
4987
  }
@@ -6389,7 +6583,8 @@ static void native_sdk_alert_done(GObject *source, GAsyncResult *result, gpointe
6389
6583
  }
6390
6584
 
6391
6585
  int native_sdk_gtk_show_message_dialog(native_sdk_gtk_host_t *host, const native_sdk_gtk_message_dialog_opts_t *opts) {
6392
- GtkAlertDialog *dialog = gtk_alert_dialog_new(NULL);
6586
+ /* The constructor requires a non-NULL printf-style format string. */
6587
+ GtkAlertDialog *dialog = gtk_alert_dialog_new("");
6393
6588
  char *title = native_sdk_bytes_to_string(opts->title, opts->title_len);
6394
6589
  char *message = native_sdk_bytes_to_string(opts->message, opts->message_len);
6395
6590
  char *informative = native_sdk_bytes_to_string(opts->informative_text, opts->informative_text_len);
@@ -31,6 +31,7 @@ typedef enum {
31
31
  NATIVE_SDK_GTK_EVENT_AUDIO = 17,
32
32
  NATIVE_SDK_GTK_EVENT_CONTEXT_MENU_ACTION = 18,
33
33
  NATIVE_SDK_GTK_EVENT_VIEW_FOCUSED = 19,
34
+ NATIVE_SDK_GTK_EVENT_NOTIFICATION_COMMAND = 20,
34
35
  } native_sdk_gtk_event_kind_t;
35
36
 
36
37
  typedef struct {
@@ -248,7 +249,7 @@ int native_sdk_gtk_set_webview_layer(native_sdk_gtk_host_t *host, uint64_t windo
248
249
  int native_sdk_gtk_close_webview(native_sdk_gtk_host_t *host, uint64_t window_id, const char *label, size_t label_len);
249
250
  int native_sdk_gtk_open_external_url(native_sdk_gtk_host_t *host, const char *url, size_t url_len);
250
251
  int native_sdk_gtk_reveal_path(native_sdk_gtk_host_t *host, const char *path, size_t path_len);
251
- int native_sdk_gtk_show_notification(native_sdk_gtk_host_t *host, const char *title, size_t title_len, const char *subtitle, size_t subtitle_len, const char *body, size_t body_len);
252
+ int native_sdk_gtk_show_notification(native_sdk_gtk_host_t *host, const char *title, size_t title_len, const char *subtitle, size_t subtitle_len, const char *body, size_t body_len, const char *notification_id, size_t notification_id_len, const char *action_label, size_t action_label_len, const char *action_command, size_t action_command_len);
252
253
  int native_sdk_gtk_add_recent_document(native_sdk_gtk_host_t *host, const char *path, size_t path_len);
253
254
  int native_sdk_gtk_clear_recent_documents(native_sdk_gtk_host_t *host);
254
255
  int native_sdk_gtk_credentials_available(native_sdk_gtk_host_t *host);
@@ -35,6 +35,7 @@ const GtkEventKind = enum(c_int) {
35
35
  audio = 17,
36
36
  context_menu_action = 18,
37
37
  view_focused = 19,
38
+ notification_command = 20,
38
39
  };
39
40
 
40
41
  const GtkEvent = extern struct {
@@ -156,7 +157,7 @@ extern fn native_sdk_gtk_set_webview_layer(host: *GtkHost, window_id: u64, label
156
157
  extern fn native_sdk_gtk_close_webview(host: *GtkHost, window_id: u64, label: [*]const u8, label_len: usize) c_int;
157
158
  extern fn native_sdk_gtk_open_external_url(host: *GtkHost, url: [*]const u8, url_len: usize) c_int;
158
159
  extern fn native_sdk_gtk_reveal_path(host: *GtkHost, path: [*]const u8, path_len: usize) c_int;
159
- extern fn native_sdk_gtk_show_notification(host: *GtkHost, title: [*]const u8, title_len: usize, subtitle: [*]const u8, subtitle_len: usize, body: [*]const u8, body_len: usize) c_int;
160
+ extern fn native_sdk_gtk_show_notification(host: *GtkHost, title: [*]const u8, title_len: usize, subtitle: [*]const u8, subtitle_len: usize, body: [*]const u8, body_len: usize, notification_id: [*]const u8, notification_id_len: usize, action_label: [*]const u8, action_label_len: usize, action_command: [*]const u8, action_command_len: usize) c_int;
160
161
  extern fn native_sdk_gtk_add_recent_document(host: *GtkHost, path: [*]const u8, path_len: usize) c_int;
161
162
  extern fn native_sdk_gtk_clear_recent_documents(host: *GtkHost) c_int;
162
163
  extern fn native_sdk_gtk_credentials_available(host: *GtkHost) c_int;
@@ -599,6 +600,10 @@ fn gtkCallback(context: ?*anyopaque, event: *const GtkEvent) callconv(.c) void {
599
600
  .name = event.command_name[0..event.command_name_len],
600
601
  .window_id = event.window_id,
601
602
  } }),
603
+ .notification_command => state.emit(.{ .notification_command = .{
604
+ .name = event.command_name[0..event.command_name_len],
605
+ .window_id = event.window_id,
606
+ } }),
602
607
  .files_dropped => {
603
608
  var paths_buffer: [platform_mod.max_drop_paths][]const u8 = undefined;
604
609
  const paths = platform_mod.splitDropPaths(event.drop_paths[0..event.drop_paths_len], paths_buffer[0..]);
@@ -1330,6 +1335,12 @@ fn showNotification(context: ?*anyopaque, options: platform_mod.NotificationOpti
1330
1335
  options.subtitle.len,
1331
1336
  options.body.ptr,
1332
1337
  options.body.len,
1338
+ options.id.ptr,
1339
+ options.id.len,
1340
+ options.action_label.ptr,
1341
+ options.action_label.len,
1342
+ options.action_command.ptr,
1343
+ options.action_command.len,
1333
1344
  ) == 0) return error.UnsupportedService;
1334
1345
  }
1335
1346
 
@@ -1480,20 +1491,23 @@ fn videoLoadUrl(context: ?*anyopaque, url: []const u8, token: u64, sink: platfor
1480
1491
  return videoLoad(context, url, token, sink);
1481
1492
  }
1482
1493
 
1483
- fn createTray(context: ?*anyopaque, options: platform_mod.TrayOptions) anyerror!void {
1494
+ fn createTray(context: ?*anyopaque, status_item_id: platform_mod.StatusItemId, options: platform_mod.TrayOptions) anyerror!void {
1484
1495
  _ = context;
1496
+ _ = status_item_id;
1485
1497
  _ = options;
1486
1498
  return error.UnsupportedService;
1487
1499
  }
1488
1500
 
1489
- fn updateTrayMenu(context: ?*anyopaque, items: []const platform_mod.TrayMenuItem) anyerror!void {
1501
+ fn updateTrayMenu(context: ?*anyopaque, status_item_id: platform_mod.StatusItemId, items: []const platform_mod.TrayMenuItem) anyerror!void {
1490
1502
  _ = context;
1503
+ _ = status_item_id;
1491
1504
  _ = items;
1492
1505
  return error.UnsupportedService;
1493
1506
  }
1494
1507
 
1495
- fn removeTray(context: ?*anyopaque) anyerror!void {
1508
+ fn removeTray(context: ?*anyopaque, status_item_id: platform_mod.StatusItemId) anyerror!void {
1496
1509
  _ = context;
1510
+ _ = status_item_id;
1497
1511
  return error.UnsupportedService;
1498
1512
  }
1499
1513
 
@@ -1878,6 +1892,57 @@ test "linux platform module exports type" {
1878
1892
  _ = LinuxPlatform;
1879
1893
  }
1880
1894
 
1895
+ test "linux message dialogs construct alerts with a non-null format string" {
1896
+ // gtk_alert_dialog_new takes a required printf-style format string.
1897
+ // The host sets the real message below, but NULL still makes GTK
1898
+ // dereference an invalid format pointer during construction.
1899
+ const host_source = @embedFile("gtk_host.c");
1900
+ try std.testing.expect(std.mem.indexOf(
1901
+ u8,
1902
+ host_source,
1903
+ "GtkAlertDialog *dialog = gtk_alert_dialog_new(\"\");",
1904
+ ) != null);
1905
+ try std.testing.expect(std.mem.indexOf(
1906
+ u8,
1907
+ host_source,
1908
+ "gtk_alert_dialog_new(NULL)",
1909
+ ) == null);
1910
+ }
1911
+
1912
+ test "linux notification actions use process-scoped opaque tokens" {
1913
+ const host_source = @embedFile("gtk_host.c");
1914
+ try std.testing.expect(std.mem.indexOf(
1915
+ u8,
1916
+ host_source,
1917
+ "char *action_token = native_sdk_random_notification_action_token();",
1918
+ ) != null);
1919
+ try std.testing.expect(std.mem.indexOf(
1920
+ u8,
1921
+ host_source,
1922
+ "open(\"/dev/urandom\", O_RDONLY | O_CLOEXEC)",
1923
+ ) != null);
1924
+ try std.testing.expect(std.mem.indexOf(
1925
+ u8,
1926
+ host_source,
1927
+ "g_variant_new_string(action_token)",
1928
+ ) != null);
1929
+ try std.testing.expect(std.mem.indexOf(
1930
+ u8,
1931
+ host_source,
1932
+ "native_sdk_take_notification_action_command(host, token, token_len)",
1933
+ ) != null);
1934
+ try std.testing.expect(std.mem.indexOf(
1935
+ u8,
1936
+ host_source,
1937
+ "g_hash_table_remove(host->notification_actions, token);",
1938
+ ) != null);
1939
+ try std.testing.expect(std.mem.indexOf(
1940
+ u8,
1941
+ host_source,
1942
+ "g_variant_new_string(command_copy)",
1943
+ ) == null);
1944
+ }
1945
+
1881
1946
  test "linux transparent windows clear the main webview background" {
1882
1947
  const host_source = @embedFile("gtk_host.c");
1883
1948
  const ensure_at = std.mem.indexOf(
@@ -35,6 +35,7 @@ typedef enum {
35
35
  NATIVE_SDK_APPKIT_EVENT_VIDEO = 21,
36
36
  NATIVE_SDK_APPKIT_EVENT_VIEW_FOCUSED = 22,
37
37
  NATIVE_SDK_APPKIT_EVENT_TRAY_COMMAND = 23,
38
+ NATIVE_SDK_APPKIT_EVENT_NOTIFICATION_COMMAND = 24,
38
39
  } native_sdk_appkit_event_kind_t;
39
40
 
40
41
  /* Audio player reports (EVENT_AUDIO payloads). LOADED acknowledges a
@@ -270,6 +271,8 @@ typedef struct {
270
271
  uint32_t shortcut_modifiers;
271
272
  const char *command_name;
272
273
  size_t command_name_len;
274
+ /* TRAY_COMMAND: stable owner id for the status item that emitted it. */
275
+ uint32_t status_item_id;
273
276
  const char *view_label;
274
277
  size_t view_label_len;
275
278
  const char *key_text;
@@ -644,7 +647,7 @@ int native_sdk_appkit_decode_image(const uint8_t *bytes, size_t bytes_len, uint8
644
647
  void native_sdk_appkit_clipboard_write(native_sdk_appkit_host_t *host, const char *text, size_t text_len);
645
648
  size_t native_sdk_appkit_clipboard_read_data(native_sdk_appkit_host_t *host, const char *mime_type, size_t mime_type_len, char *buffer, size_t buffer_len);
646
649
  int native_sdk_appkit_clipboard_write_data(native_sdk_appkit_host_t *host, const char *mime_type, size_t mime_type_len, const char *bytes, size_t bytes_len);
647
- int native_sdk_appkit_show_notification(native_sdk_appkit_host_t *host, const char *title, size_t title_len, const char *subtitle, size_t subtitle_len, const char *body, size_t body_len);
650
+ int native_sdk_appkit_show_notification(native_sdk_appkit_host_t *host, const char *title, size_t title_len, const char *subtitle, size_t subtitle_len, const char *body, size_t body_len, const char *notification_id, size_t notification_id_len, const char *action_label, size_t action_label_len, const char *action_command, size_t action_command_len);
648
651
  int native_sdk_appkit_open_external_url(native_sdk_appkit_host_t *host, const char *url, size_t url_len);
649
652
  int native_sdk_appkit_reveal_path(native_sdk_appkit_host_t *host, const char *path, size_t path_len);
650
653
  int native_sdk_appkit_add_recent_document(native_sdk_appkit_host_t *host, const char *path, size_t path_len);
@@ -697,7 +700,7 @@ typedef struct {
697
700
  size_t tertiary_button_len;
698
701
  } native_sdk_appkit_message_dialog_opts_t;
699
702
 
700
- typedef void (*native_sdk_appkit_tray_callback_t)(void *context, uint32_t item_id);
703
+ typedef void (*native_sdk_appkit_tray_callback_t)(void *context, uint32_t status_item_id, uint32_t item_id);
701
704
 
702
705
  /* One native scroll driver's desired state (see PlatformServices
703
706
  * set_gpu_surface_scroll_drivers_fn). Frame coordinates are view-local
@@ -766,15 +769,16 @@ int native_sdk_appkit_show_context_menu(native_sdk_appkit_host_t *host, uint64_t
766
769
  native_sdk_appkit_open_dialog_result_t native_sdk_appkit_show_open_dialog(native_sdk_appkit_host_t *host, const native_sdk_appkit_open_dialog_opts_t *opts, char *buffer, size_t buffer_len);
767
770
  size_t native_sdk_appkit_show_save_dialog(native_sdk_appkit_host_t *host, const native_sdk_appkit_save_dialog_opts_t *opts, char *buffer, size_t buffer_len);
768
771
  int native_sdk_appkit_show_message_dialog(native_sdk_appkit_host_t *host, const native_sdk_appkit_message_dialog_opts_t *opts);
769
- void native_sdk_appkit_create_tray(native_sdk_appkit_host_t *host, const char *icon_path, size_t icon_path_len, const char *title, size_t title_len, const char *tooltip, size_t tooltip_len, double width, int tone, double icon_opacity, int monospaced, const char *activation_command, size_t activation_command_len, const char *alternate_activation_command, size_t alternate_activation_command_len, const char *open_command, size_t open_command_len);
770
- void native_sdk_appkit_update_tray_menu(native_sdk_appkit_host_t *host, const uint32_t *item_ids, const char *const *labels, const size_t *label_lens, const int *separators, const int *enabled_flags, const char *const *details, const size_t *detail_lens, const int *roles, const char *const *keys, const size_t *key_lens, const uint32_t *modifiers, size_t count);
772
+ void native_sdk_appkit_create_tray(native_sdk_appkit_host_t *host, uint32_t status_item_id, const char *icon_path, size_t icon_path_len, const char *title, size_t title_len, const char *tooltip, size_t tooltip_len, int visible, double width, int tone, double icon_opacity, int monospaced, const char *activation_command, size_t activation_command_len, const char *alternate_activation_command, size_t alternate_activation_command_len, const char *open_command, size_t open_command_len);
773
+ void native_sdk_appkit_update_tray_shell(native_sdk_appkit_host_t *host, uint32_t status_item_id, const char *icon_path, size_t icon_path_len, const char *tooltip, size_t tooltip_len, int visible, const char *activation_command, size_t activation_command_len, const char *alternate_activation_command, size_t alternate_activation_command_len, const char *open_command, size_t open_command_len);
774
+ void native_sdk_appkit_update_tray_menu(native_sdk_appkit_host_t *host, uint32_t status_item_id, const uint32_t *item_ids, const char *const *labels, const size_t *label_lens, const int *separators, const int *enabled_flags, const char *const *details, const size_t *detail_lens, const int *roles, const char *const *keys, const size_t *key_lens, const uint32_t *modifiers, size_t count);
771
775
  /* Retitle the live status item's button without re-creating it (create
772
776
  * would flicker and reshuffle the menu bar). Empty title falls back to
773
777
  * the icon-only square well, or the app-name initial when there is no
774
778
  * icon either — the same fallbacks as create. */
775
- void native_sdk_appkit_update_tray_title(native_sdk_appkit_host_t *host, const char *title, size_t title_len);
776
- void native_sdk_appkit_update_tray_presentation(native_sdk_appkit_host_t *host, const char *title, size_t title_len, double width, int tone, double icon_opacity, int monospaced);
777
- void native_sdk_appkit_remove_tray(native_sdk_appkit_host_t *host);
779
+ void native_sdk_appkit_update_tray_title(native_sdk_appkit_host_t *host, uint32_t status_item_id, const char *title, size_t title_len);
780
+ void native_sdk_appkit_update_tray_presentation(native_sdk_appkit_host_t *host, uint32_t status_item_id, const char *title, size_t title_len, double width, int tone, double icon_opacity, int monospaced);
781
+ void native_sdk_appkit_remove_tray(native_sdk_appkit_host_t *host, uint32_t status_item_id);
778
782
  void native_sdk_appkit_set_tray_callback(native_sdk_appkit_host_t *host, native_sdk_appkit_tray_callback_t callback, void *context);
779
783
 
780
784
  #ifdef __cplusplus