@legendapp/spark 0.0.1-next.7 → 0.0.1-next.8

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 (127) hide show
  1. package/package.json +8 -8
  2. package/schema.json +9 -0
  3. package/skills/spark/SKILL.md +1 -1
  4. package/skills/spark/UPGRADING.md +21 -0
  5. package/vendor/node_modules/@legendapp/spark-ai/package.json +3 -3
  6. package/vendor/node_modules/@legendapp/spark-audio/package.json +2 -2
  7. package/vendor/node_modules/@legendapp/spark-auth-session/package.json +3 -3
  8. package/vendor/node_modules/@legendapp/spark-cli/dist/add-desktop.js +1 -1
  9. package/vendor/node_modules/@legendapp/spark-cli/dist/build.js +16 -4
  10. package/vendor/node_modules/@legendapp/spark-cli/dist/create.js +16 -4
  11. package/vendor/node_modules/@legendapp/spark-cli/dist/init-template.cjs +2 -1
  12. package/vendor/node_modules/@legendapp/spark-cli/dist/macos-release.js +4 -0
  13. package/vendor/node_modules/@legendapp/spark-cli/dist/project.js +10 -4
  14. package/vendor/node_modules/@legendapp/spark-cli/dist/release-driver.js +35 -0
  15. package/vendor/node_modules/@legendapp/spark-cli/dist/release.json +18 -18
  16. package/vendor/node_modules/@legendapp/spark-cli/dist/updates.js +18 -8
  17. package/vendor/node_modules/@legendapp/spark-cli/dist/windows.js +1 -1
  18. package/vendor/node_modules/@legendapp/spark-cli/package.json +4 -4
  19. package/vendor/node_modules/@legendapp/spark-cli/templates/blank-typescript/app.json +5 -1
  20. package/vendor/node_modules/@legendapp/spark-cli/templates/blank-typescript/gitignore +2 -1
  21. package/vendor/node_modules/@legendapp/spark-cli/templates/blank-typescript/package.json +7 -7
  22. package/vendor/node_modules/@legendapp/spark-cli/templates/universal/app.json +5 -1
  23. package/vendor/node_modules/@legendapp/spark-cli/templates/universal/gitignore +2 -1
  24. package/vendor/node_modules/@legendapp/spark-cli/templates/universal/package.json +8 -8
  25. package/vendor/node_modules/@legendapp/spark-cli/templates/windows/app.json +5 -1
  26. package/vendor/node_modules/@legendapp/spark-cli/templates/windows/gitignore +2 -1
  27. package/vendor/node_modules/@legendapp/spark-cli/templates/windows/package.json +8 -8
  28. package/vendor/node_modules/@legendapp/spark-clipboard/package.json +2 -2
  29. package/vendor/node_modules/@legendapp/spark-codex/cpp/HybridCodexAppServer.mm +88 -76
  30. package/vendor/node_modules/@legendapp/spark-codex/package.json +2 -2
  31. package/vendor/node_modules/@legendapp/spark-commands/package.json +5 -5
  32. package/vendor/node_modules/@legendapp/spark-context-menu/package.json +2 -2
  33. package/vendor/node_modules/@legendapp/spark-desktop-app/RNDesktopApp.podspec +12 -1
  34. package/vendor/node_modules/@legendapp/spark-desktop-app/macos/RNDesktopApp.mm +8 -1
  35. package/vendor/node_modules/@legendapp/spark-desktop-app/macos/SparkDesktop.h +8 -0
  36. package/vendor/node_modules/@legendapp/spark-desktop-app/macos/SparkDesktop.mm +84 -21
  37. package/vendor/node_modules/@legendapp/spark-desktop-app/macos/SparkInstance.h +27 -0
  38. package/vendor/node_modules/@legendapp/spark-desktop-app/macos/SparkInstance.mm +207 -0
  39. package/vendor/node_modules/@legendapp/spark-desktop-app/macos/SparkTestDriver.h +44 -0
  40. package/vendor/node_modules/@legendapp/spark-desktop-app/macos/SparkTestDriver.mm +349 -0
  41. package/vendor/node_modules/@legendapp/spark-desktop-app/macos/SparkWindow.mm +3 -1
  42. package/vendor/node_modules/@legendapp/spark-desktop-app/package.json +1 -1
  43. package/vendor/node_modules/@legendapp/spark-desktop-app/src/api.ts +39 -6
  44. package/vendor/node_modules/@legendapp/spark-desktop-app/src/contracts/menu.ts +21 -7
  45. package/vendor/node_modules/@legendapp/spark-desktop-config/accessibility-state.cjs +50 -0
  46. package/vendor/node_modules/@legendapp/spark-desktop-config/app.plugin.cjs +9 -1
  47. package/vendor/node_modules/@legendapp/spark-desktop-config/autolinking.cjs +8 -1
  48. package/vendor/node_modules/@legendapp/spark-desktop-config/config.cjs +1 -1
  49. package/vendor/node_modules/@legendapp/spark-desktop-config/config.d.cts +7 -1
  50. package/vendor/node_modules/@legendapp/spark-desktop-config/package.json +4 -4
  51. package/vendor/node_modules/@legendapp/spark-desktop-config/rtl-scroll-view.cjs +144 -0
  52. package/vendor/node_modules/@legendapp/spark-desktop-config/rtl-text-alignment.cjs +60 -0
  53. package/vendor/node_modules/@legendapp/spark-desktop-config/rtl-text-input-alignment.cjs +112 -0
  54. package/vendor/node_modules/@legendapp/spark-desktop-config/schema.json +9 -0
  55. package/vendor/node_modules/@legendapp/spark-desktop-config/test-driver.cjs +11 -0
  56. package/vendor/node_modules/@legendapp/spark-desktop-config/test-driver.d.cts +2 -0
  57. package/vendor/node_modules/@legendapp/spark-desktop-config/text-input-accessibility.cjs +47 -0
  58. package/vendor/node_modules/@legendapp/spark-desktop-config/updates.cjs +4 -2
  59. package/vendor/node_modules/@legendapp/spark-desktop-config/validation.cjs +2 -1
  60. package/vendor/node_modules/@legendapp/spark-desktop-config/windows.plugin.cjs +1 -1
  61. package/vendor/node_modules/@legendapp/spark-desktop-host/AppDelegate.mm +18 -6
  62. package/vendor/node_modules/@legendapp/spark-desktop-host/package.json +2 -2
  63. package/vendor/node_modules/@legendapp/spark-desktop-host/windows/application.inc +61 -15
  64. package/vendor/node_modules/@legendapp/spark-desktop-host/windows/launch.inc +67 -0
  65. package/vendor/node_modules/@legendapp/spark-desktop-links/package.json +2 -2
  66. package/vendor/node_modules/@legendapp/spark-desktop-shortcuts/package.json +2 -2
  67. package/vendor/node_modules/@legendapp/spark-desktop-windows/RNDesktopWindows.podspec +3 -0
  68. package/vendor/node_modules/@legendapp/spark-desktop-windows/macos/RNDesktopWindows.mm +5 -2
  69. package/vendor/node_modules/@legendapp/spark-desktop-windows/macos/window-manager/RNWindowManager.mm +22 -3
  70. package/vendor/node_modules/@legendapp/spark-desktop-windows/package.json +3 -3
  71. package/vendor/node_modules/@legendapp/spark-documents/package.json +7 -7
  72. package/vendor/node_modules/@legendapp/spark-drag-drop/package.json +2 -2
  73. package/vendor/node_modules/@legendapp/spark-file-dialog/RNFileDialog.podspec +1 -0
  74. package/vendor/node_modules/@legendapp/spark-file-dialog/ios/RNFileDialog.mm +153 -64
  75. package/vendor/node_modules/@legendapp/spark-file-dialog/package.json +2 -2
  76. package/vendor/node_modules/@legendapp/spark-file-dialog/src/index.ts +19 -7
  77. package/vendor/node_modules/@legendapp/spark-file-dialog/src/native.ts +5 -1
  78. package/vendor/node_modules/@legendapp/spark-file-dialog/src/options.ts +42 -4
  79. package/vendor/node_modules/@legendapp/spark-file-dialog/src/types.ts +18 -2
  80. package/vendor/node_modules/@legendapp/spark-file-system/package.json +2 -2
  81. package/vendor/node_modules/@legendapp/spark-global-shortcuts/package.json +2 -2
  82. package/vendor/node_modules/@legendapp/spark-html/package.json +2 -2
  83. package/vendor/node_modules/@legendapp/spark-markdown/package.json +2 -2
  84. package/vendor/node_modules/@legendapp/spark-markdown/src/Markdown.tsx +2 -1
  85. package/vendor/node_modules/@legendapp/spark-message-dialog/macos/RNDesktopMessageDialog.mm +113 -12
  86. package/vendor/node_modules/@legendapp/spark-message-dialog/package.json +2 -2
  87. package/vendor/node_modules/@legendapp/spark-message-dialog/src/index.ts +110 -14
  88. package/vendor/node_modules/@legendapp/spark-native-menu/ios/RNNativeMenu.mm +116 -8
  89. package/vendor/node_modules/@legendapp/spark-native-menu/package.json +2 -2
  90. package/vendor/node_modules/@legendapp/spark-native-menu/src/api.ts +63 -18
  91. package/vendor/node_modules/@legendapp/spark-native-menu/src/hooks.ts +9 -3
  92. package/vendor/node_modules/@legendapp/spark-notifications/package.json +2 -2
  93. package/vendor/node_modules/@legendapp/spark-processes/package.json +2 -2
  94. package/vendor/node_modules/@legendapp/spark-rich-text/package.json +2 -2
  95. package/vendor/node_modules/@legendapp/spark-secure-storage/package.json +2 -2
  96. package/vendor/node_modules/@legendapp/spark-settings/package.json +3 -3
  97. package/vendor/node_modules/@legendapp/spark-settings-ui/package.json +4 -4
  98. package/vendor/node_modules/@legendapp/spark-settings-ui/src/index.tsx +5 -2
  99. package/vendor/node_modules/@legendapp/spark-sqlite/package.json +3 -3
  100. package/vendor/node_modules/@legendapp/spark-system/macos/RNDesktopSystem.mm +13 -3
  101. package/vendor/node_modules/@legendapp/spark-system/macos/SparkAppearancePreferences.h +9 -0
  102. package/vendor/node_modules/@legendapp/spark-system/macos/SparkAppearancePreferences.mm +31 -0
  103. package/vendor/node_modules/@legendapp/spark-system/macos/SparkDockTile.h +24 -0
  104. package/vendor/node_modules/@legendapp/spark-system/macos/SparkDockTile.mm +101 -0
  105. package/vendor/node_modules/@legendapp/spark-system/package.json +2 -2
  106. package/vendor/node_modules/@legendapp/spark-system/src/index.ts +73 -7
  107. package/vendor/node_modules/@legendapp/spark-tray/package.json +2 -2
  108. package/vendor/node_modules/@legendapp/spark-ui/macos/RNSparkButton.mm +2 -0
  109. package/vendor/node_modules/@legendapp/spark-ui/macos/RNSparkLayoutDirection.h +17 -0
  110. package/vendor/node_modules/@legendapp/spark-ui/macos/RNSparkTextInput.mm +6 -1
  111. package/vendor/node_modules/@legendapp/spark-ui/macos/appkit-split-view/RNSidebarSplitViewComponent.mm +55 -8
  112. package/vendor/node_modules/@legendapp/spark-ui/macos/glass-effect-view/RNGlassEffectView.mm +11 -7
  113. package/vendor/node_modules/@legendapp/spark-ui/macos/native-select/RNNativeSegmentedControl.mm +4 -0
  114. package/vendor/node_modules/@legendapp/spark-ui/macos/native-select/RNNativeSelect.mm +4 -0
  115. package/vendor/node_modules/@legendapp/spark-ui/macos/sf-symbol/RNSFSymbol.mm +4 -0
  116. package/vendor/node_modules/@legendapp/spark-ui/macos/sidebar/RNSidebar.mm +77 -14
  117. package/vendor/node_modules/@legendapp/spark-ui/macos/swipe-actions/RNSwipeActions.mm +31 -7
  118. package/vendor/node_modules/@legendapp/spark-ui/macos/text-input-search/RNTextInputSearch.mm +25 -1
  119. package/vendor/node_modules/@legendapp/spark-ui/package.json +2 -2
  120. package/vendor/node_modules/@legendapp/spark-ui/src/sidebar/SidebarNativeComponent.ts +5 -0
  121. package/vendor/node_modules/@legendapp/spark-ui/src/sidebar/index.tsx +19 -8
  122. package/vendor/node_modules/@legendapp/spark-updates/macos/RNDesktopUpdates.mm +25 -13
  123. package/vendor/node_modules/@legendapp/spark-updates/macos/SparkUpdateState.h +39 -0
  124. package/vendor/node_modules/@legendapp/spark-updates/package.json +2 -2
  125. package/vendor/node_modules/@legendapp/spark-updates/src/index.ts +45 -9
  126. package/vendor/node_modules/@legendapp/spark-webview/package.json +2 -2
  127. package/vendor/node_modules/@legendapp/spark-window-options/package.json +1 -1
@@ -57,6 +57,11 @@ static uint64_t generation = 0, quitRequest = 0;
57
57
  static Json::JsonArray pendingURLs{nullptr};
58
58
  static std::string initialURL;
59
59
  static Json::JsonArray launchArguments{nullptr};
60
+ // Latched in ForwardLaunch, before any window exists: "flag", "modifier" or empty.
61
+ static std::wstring safeModeTrigger;
62
+ static bool relaunched = false;
63
+ // A relaunch started before the quit decision; killed if that decision is a veto.
64
+ static HANDLE relaunchChild = nullptr;
60
65
  static bool appActive = false;
61
66
  static std::set<std::string> hiddenByApp;
62
67
  static std::string hiddenFocus;
@@ -233,7 +238,8 @@ static std::filesystem::path SparkFile(std::string const &id) {
233
238
  return dataDirectory / (id == "main" ? L"window.json" : L"window-" + std::wstring(to_hstring(id)) + L".json");
234
239
  }
235
240
  static void RestoreFrame(std::string const &id) {
236
- auto &window = windows.at(id); if (!window.restoreFrame) return;
241
+ // Safe mode neither reads nor saves frames, so saved ones survive for the next normal launch.
242
+ auto &window = windows.at(id); if (!window.restoreFrame || !safeModeTrigger.empty()) return;
237
243
  try {
238
244
  std::ifstream stream(SparkFile(id)); std::string text((std::istreambuf_iterator<char>(stream)), std::istreambuf_iterator<char>());
239
245
  auto saved = Json::JsonObject::Parse(to_hstring(text)); if (saved.GetNamedNumber(L"version", 0) != 1) return;
@@ -303,14 +309,12 @@ static void ApplyOptions(Window &window, Json::JsonObject const &options) {
303
309
  }
304
310
  if (window.app.Presenter().Kind() != UI::AppWindowPresenterKind::FullScreen) window.app.Resize({static_cast<int32_t>(std::round(width * scale)), static_cast<int32_t>(std::round(height * scale))});
305
311
  }
306
- static void QueueLaunch(std::wstring const &commandLine, bool initial) {
312
+ static void QueueLaunch(std::wstring const &commandLine, bool initial, std::wstring const &directory = {}) {
307
313
  int count = 0; auto argv = CommandLineToArgvW(commandLine.c_str(), &count);
308
314
  if (!argv) return;
309
315
  if (initial) for (int i = 0; i < count; ++i) launchArguments.Append(Json::JsonValue::CreateStringValue(argv[i]));
310
- else {
311
- RNW::JSValueArray arguments; for (int i = 0; i < count; ++i) arguments.push_back(to_string(argv[i]));
312
- Emit({{"type", "secondInstance"}, {"arguments", std::move(arguments)}});
313
- }
316
+ RNW::JSValueArray arguments, files, urls; std::vector<RNW::JSValueObject> opens;
317
+ for (int i = 0; i < count; ++i) arguments.push_back(to_string(argv[i]));
314
318
  for (int i = 1; i < count; ++i) {
315
319
  std::wstring candidate(argv[i]);
316
320
  if (candidate.rfind(L"--spark-dock-action=", 0) == 0) {
@@ -318,16 +322,19 @@ static void QueueLaunch(std::wstring const &commandLine, bool initial) {
318
322
  if (separator != std::wstring::npos) try { Emit({{"type", "dockAction"}, {"owner", to_string(winrt::Windows::Foundation::Uri::UnescapeComponent(payload.substr(0, separator)))}, {"id", to_string(winrt::Windows::Foundation::Uri::UnescapeComponent(payload.substr(separator + 1)))}}); } catch (...) {}
319
323
  continue;
320
324
  }
321
- if (candidate.empty() || candidate[0] == L'-') continue;
322
- bool file = std::filesystem::path(candidate).is_absolute();
323
- if (file) { wchar_t uri[32768]; DWORD length = 32768; if (FAILED(UrlCreateFromPathW(candidate.c_str(), uri, &length, 0))) continue; candidate = uri; }
324
- else { auto colon = candidate.find(L':'); if (colon == std::wstring::npos || colon < 2) continue; }
325
+ auto target = SparkLaunch::Classify(candidate);
326
+ if (target == SparkLaunch::Target::None) continue;
327
+ bool file = target == SparkLaunch::Target::File;
328
+ if (file) { files.push_back(to_string(candidate)); wchar_t uri[32768]; DWORD length = 32768; if (FAILED(UrlCreateFromPathW(candidate.c_str(), uri, &length, 0))) continue; candidate = uri; }
329
+ else urls.push_back(to_string(candidate));
325
330
  auto url = to_string(candidate); auto eventId = std::to_string(++generation);
326
331
  Json::JsonObject item; item.SetNamedValue(L"type", Json::JsonValue::CreateStringValue(file ? L"openFile" : L"openURL")); item.SetNamedValue(L"url", Json::JsonValue::CreateStringValue(candidate)); item.SetNamedValue(L"id", Json::JsonValue::CreateStringValue(to_hstring(eventId)));
327
332
  pendingURLs.Append(item); if (pendingURLs.Size() > 200) pendingURLs.RemoveAt(0); if (initial && initialURL.empty()) initialURL = url;
328
- Emit({{"type", file ? "openFile" : "openURL"}, {"id", eventId}, {"url", url}, {"initial", initial}});
333
+ opens.push_back({{"type", file ? "openFile" : "openURL"}, {"id", eventId}, {"url", url}, {"initial", initial}});
329
334
  }
330
335
  LocalFree(argv);
336
+ if (!initial) Emit({{"type", "secondInstance"}, {"arguments", std::move(arguments)}, {"workingDirectory", to_string(directory)}, {"files", std::move(files)}, {"urls", std::move(urls)}});
337
+ for (auto &event : opens) Emit(std::move(event));
331
338
  }
332
339
  // Retained for the process lifetime. An abandoned owner can be replaced after a
333
340
  // crash; a slow/hung owner must never cause us to start a second notebook writer.
@@ -340,9 +347,22 @@ static std::wstring ProjectKey() {
340
347
  return std::wstring(winrt::Windows::Security::Cryptography::CryptographicBuffer::EncodeToHexString(algorithm.HashData(bytes)));
341
348
  }
342
349
  static bool ForwardLaunch() {
350
+ {
351
+ int count = 0; auto argv = CommandLineToArgvW(GetCommandLineW(), &count); if (!argv) winrt::throw_last_error();
352
+ std::vector<std::wstring> arguments(argv, argv + count); LocalFree(argv);
353
+ safeModeTrigger = SparkLaunch::SafeModeTrigger(arguments, (GetAsyncKeyState(VK_SHIFT) & 0x8000) != 0);
354
+ }
343
355
  auto key = L"Spark.Project." + ProjectKey();
344
356
  instanceMutex.attach(CreateMutexW(nullptr, FALSE, (L"Local\\" + key).c_str()));
345
357
  if (!instanceMutex) winrt::throw_last_error();
358
+ auto parent = SparkWindowsEnv(SparkLaunch::RelaunchParent);
359
+ if (!parent.empty()) {
360
+ // The previous instance owns the mutex until it exits; it terminates this process if its quit is vetoed.
361
+ SetEnvironmentVariableW(SparkLaunch::RelaunchParent, nullptr); relaunched = true;
362
+ const auto wait = WaitForSingleObject(instanceMutex.get(), INFINITE);
363
+ if (wait == WAIT_OBJECT_0 || wait == WAIT_ABANDONED) return false;
364
+ winrt::throw_last_error();
365
+ }
346
366
  const auto deadline = GetTickCount64() + 60000;
347
367
  for (;;) {
348
368
  const auto wait = WaitForSingleObject(instanceMutex.get(), 0);
@@ -352,7 +372,8 @@ static bool ForwardLaunch() {
352
372
  EnumWindows([](HWND hwnd, LPARAM param) -> BOOL { auto data = reinterpret_cast<Search *>(param); if (GetPropW(hwnd, data->key.c_str())) { data->target = hwnd; return FALSE; } return TRUE; }, reinterpret_cast<LPARAM>(&search));
353
373
  if (search.target) {
354
374
  DWORD process = 0; GetWindowThreadProcessId(search.target, &process); AllowSetForegroundWindow(process);
355
- auto text = GetCommandLineW(); COPYDATASTRUCT data{0x4C47, static_cast<DWORD>((wcslen(text) + 1) * sizeof(wchar_t)), text}; DWORD_PTR result = 0;
375
+ auto payload = SparkLaunch::EncodeForward(std::filesystem::current_path().wstring(), GetCommandLineW());
376
+ COPYDATASTRUCT data{0x4C47, static_cast<DWORD>(payload.size() * sizeof(wchar_t)), payload.data()}; DWORD_PTR result = 0;
356
377
  if (!SendMessageTimeoutW(search.target, WM_COPYDATA, 0, reinterpret_cast<LPARAM>(&data), SMTO_ABORTIFHUNG | SMTO_BLOCK, 5000, &result) || !result)
357
378
  throw winrt::hresult_error(HRESULT_FROM_WIN32(ERROR_TIMEOUT), L"The existing Spark app did not accept this launch. Close it before retrying.");
358
379
  return true;
@@ -364,7 +385,7 @@ static bool ForwardLaunch() {
364
385
  }
365
386
  }
366
387
  static void SaveFrame(std::string const &id, HWND hwnd) {
367
- if (dataDirectory.empty() || !windows.at(id).restoreFrame || IsIconic(hwnd) || IsZoomed(hwnd) || windows.at(id).fullscreen) return;
388
+ if (dataDirectory.empty() || !safeModeTrigger.empty() || !windows.at(id).restoreFrame || IsIconic(hwnd) || IsZoomed(hwnd) || windows.at(id).fullscreen) return;
368
389
  auto file = SparkFile(id), temporary = file; temporary += L".pending";
369
390
  RECT frame{}; if (!GetWindowRect(hwnd, &frame)) return;
370
391
  Json::JsonObject saved; saved.SetNamedValue(L"version", Json::JsonValue::CreateNumberValue(1)); saved.SetNamedValue(L"bounds", Info(id).GetNamedObject(L"bounds")); saved.SetNamedValue(L"persistentId", Json::JsonValue::CreateStringValue(OwningDisplay(frame).persistentId));
@@ -374,6 +395,7 @@ static void SaveFrame(std::string const &id, HWND hwnd) {
374
395
  static void FinishQuit(bool allow) {
375
396
  if (!quitPending) return;
376
397
  quitPending = false; pendingQuitGuards.clear(); if (!allow) FinishClose("main", false);
398
+ if (relaunchChild) { if (!allow) TerminateProcess(relaunchChild, 1); CloseHandle(relaunchChild); relaunchChild = nullptr; }
377
399
  if (windows.count("main")) KillTimer(Hwnd(windows.at("main")), 0x4C48);
378
400
  auto waiters = std::move(quitWaiters); quitWaiters.clear();
379
401
  const auto result = allow ? "{\"quitRequested\":true}" : "{\"quitRequested\":false,\"reason\":\"vetoed\"}";
@@ -404,7 +426,7 @@ static LRESULT CALLBACK WindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARA
404
426
  auto text = static_cast<wchar_t const *>(notification->lpData); if (text[notification->cbData / sizeof(wchar_t) - 1]) return FALSE;
405
427
  try { QueueNotificationResponse(to_string(text)); return TRUE; } catch (...) { return FALSE; }
406
428
  }
407
- auto data = reinterpret_cast<COPYDATASTRUCT *>(lParam); if (data && data->dwData == 0x4C47 && data->cbData >= sizeof(wchar_t) && data->cbData <= 65536 && data->cbData % sizeof(wchar_t) == 0) { auto text = static_cast<wchar_t *>(data->lpData); if (text && text[data->cbData / sizeof(wchar_t) - 1] == 0) { QueueLaunch(text, false);
429
+ auto data = reinterpret_cast<COPYDATASTRUCT *>(lParam); std::wstring directory, commandLine; if (data && data->dwData == 0x4C47 && data->cbData <= 65536 && data->cbData % sizeof(wchar_t) == 0) { if (SparkLaunch::DecodeForward(static_cast<wchar_t const *>(data->lpData), data->cbData / sizeof(wchar_t), directory, commandLine)) { QueueLaunch(commandLine, false, directory);
408
430
  bool visible = false; for (auto const &[key, window] : windows) if (IsWindowVisible(Hwnd(window)) && !window.overlay) visible = true;
409
431
  Emit({{"type", "reopen"}, {"hasVisibleWindows", visible}, {"mainWindowWasVisible", !!IsWindowVisible(Hwnd(windows.at("main")))}}); ActivateApplication(); return TRUE; } } return FALSE; }
410
432
  if (message == WM_GETMINMAXINFO) {
@@ -621,6 +643,28 @@ struct SparkDesktopApp {
621
643
  if (args.GetNamedBoolean(L"enabled")) quitGuards.insert(id); else quitGuards.erase(id);
622
644
  FinishQuit(false);
623
645
  } else if (method == "quit") { quitWaiters.push_back(promise); RequestQuit(); return; }
646
+ else if (method == "relaunch") {
647
+ if (!relaunchChild) {
648
+ std::vector<std::wstring> arguments;
649
+ if (args.HasKey(L"arguments")) for (auto const &item : args.GetNamedArray(L"arguments")) arguments.push_back(std::wstring(item.GetString()));
650
+ else {
651
+ std::vector<std::wstring> process;
652
+ for (auto const &item : launchArguments) process.push_back(std::wstring(item.GetString()));
653
+ arguments = SparkLaunch::RelaunchArguments(process);
654
+ }
655
+ wchar_t executable[32768]; const auto length = GetModuleFileNameW(nullptr, executable, 32768);
656
+ if (!length || length >= 32768) winrt::throw_last_error();
657
+ auto commandLine = SparkLaunch::CommandLine(executable, arguments);
658
+ STARTUPINFOW startup{sizeof(startup)}; PROCESS_INFORMATION process{};
659
+ SetEnvironmentVariableW(SparkLaunch::RelaunchParent, std::to_wstring(GetCurrentProcessId()).c_str());
660
+ const auto started = CreateProcessW(executable, commandLine.data(), nullptr, nullptr, FALSE, 0, nullptr, nullptr, &startup, &process);
661
+ const auto error = GetLastError();
662
+ SetEnvironmentVariableW(SparkLaunch::RelaunchParent, nullptr);
663
+ if (!started) winrt::throw_hresult(HRESULT_FROM_WIN32(error));
664
+ CloseHandle(process.hThread); relaunchChild = process.hProcess;
665
+ }
666
+ quitWaiters.push_back(promise); RequestQuit(); return;
667
+ }
624
668
  else if (method == "replyQuit") {
625
669
  auto id = to_string(args.GetNamedString(L"id"));
626
670
  if (quitPending && args.GetNamedNumber(L"requestId") == quitRequest && pendingQuitGuards.erase(id)) {
@@ -630,7 +674,9 @@ struct SparkDesktopApp {
630
674
  } else if (method == "hide") HideApplication();
631
675
  else if (method == "activate") ActivateApplication();
632
676
  else if (method == "context") {
633
- Json::JsonObject result; result.SetNamedValue(L"projectId", Json::JsonValue::CreateStringValue(SparkWindowsEnv(L"SPARK_PROJECT_ID"))); result.SetNamedValue(L"name", Json::JsonValue::CreateStringValue(SparkWindowsEnv(L"SPARK_PROJECT_NAME"))); result.SetNamedValue(L"version", Json::JsonValue::CreateStringValue(SparkWindowsEnv(L"SPARK_PROJECT_VERSION"))); result.SetNamedValue(L"runtime", Json::JsonObject::Parse(to_hstring(NativeSparkRuntime{}.describe()))); result.SetNamedValue(L"launchArguments", launchArguments); promise.Resolve(to_string(result.Stringify())); return;
677
+ Json::JsonObject result; result.SetNamedValue(L"projectId", Json::JsonValue::CreateStringValue(SparkWindowsEnv(L"SPARK_PROJECT_ID"))); result.SetNamedValue(L"name", Json::JsonValue::CreateStringValue(SparkWindowsEnv(L"SPARK_PROJECT_NAME"))); result.SetNamedValue(L"version", Json::JsonValue::CreateStringValue(SparkWindowsEnv(L"SPARK_PROJECT_VERSION"))); result.SetNamedValue(L"runtime", Json::JsonObject::Parse(to_hstring(NativeSparkRuntime{}.describe()))); result.SetNamedValue(L"launchArguments", launchArguments);
678
+ Json::JsonObject launch; launch.SetNamedValue(L"safeMode", safeModeTrigger.empty() ? Json::JsonValue::CreateNullValue() : Json::JsonValue::CreateStringValue(safeModeTrigger)); launch.SetNamedValue(L"relaunched", Json::JsonValue::CreateBooleanValue(relaunched)); launch.SetNamedValue(L"instance", Json::JsonValue::CreateStringValue(L"primary")); result.SetNamedValue(L"launch", launch);
679
+ promise.Resolve(to_string(result.Stringify())); return;
634
680
  } else if (method == "pendingURLs") { promise.Resolve(to_string(pendingURLs.Stringify())); return; }
635
681
  else if (method == "initialURL") { promise.Resolve(initialURL.empty() ? "null" : to_string(Json::JsonValue::CreateStringValue(to_hstring(initialURL)).Stringify())); return; }
636
682
  else throw winrt::hresult_invalid_argument(L"Unsupported application operation");
@@ -0,0 +1,67 @@
1
+ // Spark launch forwarding and relaunch helpers for the Win32 host. Standard C++ only:
2
+ // tests/windows-launch.native.cpp compiles this file on any host.
3
+ #include <string>
4
+ #include <vector>
5
+ namespace SparkLaunch {
6
+ constexpr wchar_t SafeModeFlag[] = L"--spark-safe-mode";
7
+ constexpr wchar_t RelaunchParent[] = L"SPARK_RELAUNCH_PARENT";
8
+
9
+ // WM_COPYDATA payload: working directory, NUL, command line, NUL.
10
+ inline std::wstring EncodeForward(std::wstring const &directory, std::wstring const &commandLine) {
11
+ std::wstring payload = directory; payload.push_back(L'\0'); payload += commandLine; payload.push_back(L'\0');
12
+ return payload;
13
+ }
14
+ inline bool DecodeForward(wchar_t const *data, size_t count, std::wstring &directory, std::wstring &commandLine) {
15
+ if (!data || count < 2 || data[count - 1] != L'\0') return false;
16
+ std::wstring payload(data, count - 1);
17
+ auto separator = payload.find(L'\0');
18
+ if (separator == std::wstring::npos || payload.find(L'\0', separator + 1) != std::wstring::npos) return false;
19
+ directory = payload.substr(0, separator); commandLine = payload.substr(separator + 1);
20
+ return !directory.empty() && !commandLine.empty();
21
+ }
22
+
23
+ enum class Target { None, File, Url };
24
+ // Shell associations pass absolute paths and protocol activations pass URLs; flags and
25
+ // relative arguments stay in `arguments` for the app to interpret.
26
+ inline Target Classify(std::wstring const &argument) {
27
+ if (argument.empty() || argument[0] == L'-') return Target::None;
28
+ auto letter = [](wchar_t c) { return (c >= L'a' && c <= L'z') || (c >= L'A' && c <= L'Z'); };
29
+ if (argument.size() >= 3 && letter(argument[0]) && argument[1] == L':' && (argument[2] == L'\\' || argument[2] == L'/')) return Target::File;
30
+ if (argument.rfind(L"\\\\", 0) == 0) return Target::File;
31
+ auto colon = argument.find(L':');
32
+ if (colon == std::wstring::npos || colon < 2 || !letter(argument[0])) return Target::None;
33
+ for (size_t i = 1; i < colon; ++i) if (!letter(argument[i]) && !(argument[i] >= L'0' && argument[i] <= L'9') && argument[i] != L'+' && argument[i] != L'-' && argument[i] != L'.') return Target::None;
34
+ return Target::Url;
35
+ }
36
+
37
+ // Quotes one argument so CommandLineToArgvW and the CRT parse it back unchanged.
38
+ inline std::wstring QuoteArgument(std::wstring const &argument) {
39
+ if (!argument.empty() && argument.find_first_of(L" \t\n\v\"") == std::wstring::npos) return argument;
40
+ std::wstring quoted = L"\"";
41
+ for (auto it = argument.begin();; ++it) {
42
+ size_t slashes = 0;
43
+ while (it != argument.end() && *it == L'\\') { ++it; ++slashes; }
44
+ if (it == argument.end()) { quoted.append(slashes * 2, L'\\'); break; }
45
+ if (*it == L'"') { quoted.append(slashes * 2 + 1, L'\\'); quoted.push_back(L'"'); }
46
+ else { quoted.append(slashes, L'\\'); quoted.push_back(*it); }
47
+ }
48
+ quoted.push_back(L'"');
49
+ return quoted;
50
+ }
51
+ inline std::wstring CommandLine(std::wstring const &executable, std::vector<std::wstring> const &arguments) {
52
+ std::wstring line = QuoteArgument(executable);
53
+ for (auto const &argument : arguments) { line.push_back(L' '); line += QuoteArgument(argument); }
54
+ return line;
55
+ }
56
+ // Reuses arguments after the executable, excluding the safe-mode launch flag.
57
+ inline std::vector<std::wstring> RelaunchArguments(std::vector<std::wstring> const &process) {
58
+ std::vector<std::wstring> arguments;
59
+ for (size_t i = 1; i < process.size(); ++i) if (process[i] != SafeModeFlag) arguments.push_back(process[i]);
60
+ return arguments;
61
+ }
62
+ // `flag`, `modifier` or empty for a normal launch.
63
+ inline std::wstring SafeModeTrigger(std::vector<std::wstring> const &arguments, bool shiftHeld) {
64
+ for (size_t i = 1; i < arguments.size(); ++i) if (arguments[i] == SafeModeFlag) return L"flag";
65
+ return shiftHeld ? L"modifier" : L"";
66
+ }
67
+ }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@legendapp/spark-desktop-links",
3
- "version": "0.0.1-next.7",
3
+ "version": "0.0.1-next.8",
4
4
  "license": "MIT",
5
5
  "main": "src/index",
6
6
  "react-native": "src/index",
@@ -42,7 +42,7 @@
42
42
  ]
43
43
  },
44
44
  "dependencies": {
45
- "@legendapp/spark-desktop-app": "0.0.1-next.7"
45
+ "@legendapp/spark-desktop-app": "0.0.1-next.8"
46
46
  },
47
47
  "peerDependenciesMeta": {
48
48
  "expo-linking": {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@legendapp/spark-desktop-shortcuts",
3
- "version": "0.0.1-next.7",
3
+ "version": "0.0.1-next.8",
4
4
  "license": "MIT",
5
5
  "main": "src/index",
6
6
  "react-native": "src/index",
@@ -40,7 +40,7 @@
40
40
  ]
41
41
  },
42
42
  "dependencies": {
43
- "@legendapp/spark-desktop-app": "0.0.1-next.7"
43
+ "@legendapp/spark-desktop-app": "0.0.1-next.8"
44
44
  },
45
45
  "private": true
46
46
  }
@@ -10,6 +10,9 @@ Pod::Spec.new do |s|
10
10
  s.source = { :path => "." }
11
11
  s.platforms = { :osx => "14.0" }
12
12
  s.source_files = "macos/**/*.{h,m,mm}"
13
+ # The in-app test driver compiles in Debug builds, and in other builds only for apps that set macos.testDriverInRelease
14
+ # (the Spark config plugin exports SPARK_TEST_DRIVER_RELEASE to the Podfile; docs/test-driver.md#builds).
15
+ s.pod_target_xcconfig = { "SPARK_TEST_DRIVER" => ENV["SPARK_TEST_DRIVER_RELEASE"] == "1" ? "1" : "0", "SPARK_TEST_DRIVER[config=Debug]" => "1", "GCC_PREPROCESSOR_DEFINITIONS" => "$(inherited) SPARK_TEST_DRIVER=$(SPARK_TEST_DRIVER)" }
13
16
  s.dependency "React-Core"
14
17
  s.dependency "ReactCodegen"
15
18
  s.dependency "RNDesktopApp"
@@ -3,6 +3,7 @@
3
3
  #import "SparkWindowGeometry.h"
4
4
  #import <objc/runtime.h>
5
5
  #import <RNDesktopApp/SparkDesktop.h>
6
+ #import <RNDesktopApp/SparkTestDriver.h>
6
7
  #import <React-RCTAppDelegate/RCTRootViewFactory.h>
7
8
  #import <React/RCTSurfaceHostingView.h>
8
9
 
@@ -247,7 +248,9 @@ RCT_EXPORT_MODULE(NativeDesktopWindowManager)
247
248
  if ([args[@"modal"] boolValue] && parent.attachedSheet) { reject(@"E_BUSY", @"Parent already has a sheet", nil); return; }
248
249
  window.minSize = NSMakeSize(100, 100); window.maxSize = NSMakeSize(20000, 20000);
249
250
  if (!ApplyCommon(window, args, reject)) return;
250
- NSDictionary *saved = [args[@"restoreBounds"] boolValue] ? [NSUserDefaults.standardUserDefaults dictionaryForKey:[NSString stringWithFormat:@"%@.bounds.%@", SparkNamespace(), key]] : nil;
251
+ // Safe and driver modes neither read nor save bounds.
252
+ BOOL restoreBounds = [args[@"restoreBounds"] boolValue] && !SparkSafeMode() && !SparkTestDriverActive();
253
+ NSDictionary *saved = restoreBounds ? [NSUserDefaults.standardUserDefaults dictionaryForKey:[NSString stringWithFormat:@"%@.bounds.%@", SparkNamespace(), key]] : nil;
251
254
  if (![saved[@"version"] isEqual:@1]) saved = nil;
252
255
  BOOL restoredShell = [objc_getAssociatedObject(window, NSSelectorFromString(@"sparkRestoredShell")) boolValue];
253
256
  if (!saved && restoredShell) {
@@ -267,7 +270,7 @@ RCT_EXPORT_MODULE(NativeDesktopWindowManager)
267
270
  frame = SparkAppKitFrame(bounds, screen.frame);
268
271
  if (!args[@"position"]) frame = [window constrainFrameRect:frame toScreen:screen];
269
272
  }
270
- [window setFrame:frame display:NO]; delegate.restoreBounds = [args[@"restoreBounds"] boolValue];
273
+ [window setFrame:frame display:NO]; delegate.restoreBounds = restoreBounds;
271
274
  if (parent && ![args[@"modal"] boolValue]) [parent addChildWindow:window ordered:NSWindowAbove];
272
275
  objc_setAssociatedObject(window, @selector(call:args:resolve:reject:), [args copy], OBJC_ASSOCIATION_RETAIN_NONATOMIC);
273
276
  if (![args[@"show"] isEqual:@NO]) {
@@ -25,6 +25,13 @@ extern double LegendMainWindowReactRootAttachedTimeMs;
25
25
  #import <AppKit/AppKit.h>
26
26
  #if __has_include(<RNDesktopApp/SparkDesktop.h>)
27
27
  #import <RNDesktopApp/SparkDesktop.h>
28
+ #import <RNDesktopApp/SparkTestDriver.h>
29
+ // Safe-mode (docs/app.md) and driver-mode (docs/test-driver.md) launches neither restore nor save window state.
30
+ static BOOL LegendSafeMode(void) { return SparkSafeMode(); }
31
+ static BOOL LegendTestDriverActive(void) { return SparkTestDriverActive(); }
32
+ #else
33
+ static BOOL LegendSafeMode(void) { return NO; }
34
+ static BOOL LegendTestDriverActive(void) { return NO; }
28
35
  #endif
29
36
  #import <CoreImage/CoreImage.h>
30
37
  #import <CoreGraphics/CoreGraphics.h>
@@ -50,6 +57,7 @@ static NSString * const LegendMainWindowStartupSplitViewKey = @"LegendMainWindow
50
57
 
51
58
  extern "C" NSDictionary *LegendMainWindowStartupSplitViewConfiguration(void)
52
59
  {
60
+ if (LegendSafeMode() || LegendTestDriverActive()) return nil;
53
61
  NSDictionary *configuration = [NSUserDefaults.standardUserDefaults dictionaryForKey:LegendMainWindowStartupSplitViewKey];
54
62
  return [configuration[@"restoreOnLaunch"] isEqual:@NO] ? nil : configuration;
55
63
  }
@@ -66,6 +74,7 @@ static NSString *LegendManagedWindowFrameAutosaveName(NSString *identifier)
66
74
 
67
75
  static NSArray<NSDictionary *> *LegendReadRestorableWindowOptions(void)
68
76
  {
77
+ if (LegendSafeMode() || LegendTestDriverActive()) return @[];
69
78
  NSArray *records = [NSUserDefaults.standardUserDefaults arrayForKey:LegendRestorableWindowOptionsDefaultsKey];
70
79
  if (![records isKindOfClass:NSArray.class]) {
71
80
  return @[];
@@ -117,6 +126,9 @@ static NSDictionary *LegendRestorableWindowOptions(NSDictionary *options)
117
126
 
118
127
  static void LegendWriteRestorableWindowOptions(NSArray<NSDictionary *> *options)
119
128
  {
129
+ if (LegendSafeMode() || LegendTestDriverActive()) {
130
+ return;
131
+ }
120
132
  NSMutableArray<NSString *> *records = [NSMutableArray new];
121
133
  for (NSDictionary *record in options) {
122
134
  NSData *data = [NSJSONSerialization dataWithJSONObject:record options:0 error:nil];
@@ -715,6 +727,10 @@ extern "C" void LegendPrecreateRestorableWindows(void)
715
727
  }
716
728
 
717
729
  LegendPrecreatedWindows = [NSMutableDictionary new];
730
+ // Safe and driver mode open no saved windows; their records stay for the next normal launch.
731
+ if (LegendSafeMode() || LegendTestDriverActive()) {
732
+ return;
733
+ }
718
734
  for (NSDictionary *options in LegendReadRestorableWindowOptions()) {
719
735
  NSString *identifier = [options[@"identifier"] isKindOfClass:NSString.class] ? options[@"identifier"] : nil;
720
736
  if (identifier.length == 0 || ![options[@"restoreOnLaunch"] boolValue]) {
@@ -2258,7 +2274,7 @@ willBeInsertedIntoToolbar:(BOOL)flag
2258
2274
  LegendApplyBackgroundColorToView(window.contentView, startupBackgroundColor);
2259
2275
  }
2260
2276
 
2261
- if (!precreatedWindow && [options[@"restoreOnLaunch"] boolValue]) {
2277
+ if (!precreatedWindow && [options[@"restoreOnLaunch"] boolValue] && !LegendSafeMode() && !LegendTestDriverActive()) {
2262
2278
  [window setFrameAutosaveName:LegendManagedWindowFrameAutosaveName(identifier)];
2263
2279
  }
2264
2280
  if (!precreatedWindow && LegendPrepareSidebarSplitViewStartup) {
@@ -2615,7 +2631,9 @@ willBeInsertedIntoToolbar:(BOOL)flag
2615
2631
  return;
2616
2632
  }
2617
2633
  [mainWindow orderOut:nil];
2618
- [NSUserDefaults.standardUserDefaults removeObjectForKey:LegendMainWindowStartupSplitViewKey];
2634
+ if (!LegendSafeMode() && !LegendTestDriverActive()) {
2635
+ [NSUserDefaults.standardUserDefaults removeObjectForKey:LegendMainWindowStartupSplitViewKey];
2636
+ }
2619
2637
  [self sendWindowEventWithName:@"onWindowClosed"
2620
2638
  body:@{@"identifier": @"main", @"moduleName": @"main"}];
2621
2639
  resolve([self successJson]);
@@ -2656,7 +2674,8 @@ willBeInsertedIntoToolbar:(BOOL)flag
2656
2674
  }
2657
2675
 
2658
2676
  NSDictionary *options = [self parseObjectJSON:optionsJson];
2659
- id startupSplitView = options[@"windowStyle"][@"startupSplitView"];
2677
+ // Safe and driver modes save no window chrome.
2678
+ id startupSplitView = (LegendSafeMode() || LegendTestDriverActive()) ? nil : options[@"windowStyle"][@"startupSplitView"];
2660
2679
  if ([startupSplitView isKindOfClass:NSDictionary.class]) {
2661
2680
  // Persist window chrome only, just like AppKit's saved frame. No document data.
2662
2681
  if (![startupSplitView isEqual:[NSUserDefaults.standardUserDefaults dictionaryForKey:LegendMainWindowStartupSplitViewKey]]) {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@legendapp/spark-desktop-windows",
3
- "version": "0.0.1-next.7",
3
+ "version": "0.0.1-next.8",
4
4
  "license": "MIT",
5
5
  "main": "src/index",
6
6
  "react-native": "src/index",
@@ -40,8 +40,8 @@
40
40
  ]
41
41
  },
42
42
  "dependencies": {
43
- "@legendapp/spark-desktop-app": "0.0.1-next.7",
44
- "@legendapp/spark-window-options": "0.0.1-next.7",
43
+ "@legendapp/spark-desktop-app": "0.0.1-next.8",
44
+ "@legendapp/spark-window-options": "0.0.1-next.8",
45
45
  "@legendapp/state": "^3.0.0-beta.42"
46
46
  },
47
47
  "private": true
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@legendapp/spark-documents",
3
- "version": "0.0.1-next.7",
3
+ "version": "0.0.1-next.8",
4
4
  "private": true,
5
5
  "license": "MIT",
6
6
  "main": "src/index.tsx",
@@ -8,12 +8,12 @@
8
8
  "src"
9
9
  ],
10
10
  "dependencies": {
11
- "@legendapp/spark-file-dialog": "0.0.1-next.7",
12
- "@legendapp/spark-file-system": "0.0.1-next.7",
13
- "@legendapp/spark-native-menu": "0.0.1-next.7",
14
- "@legendapp/spark-desktop-app": "0.0.1-next.7",
15
- "@legendapp/spark-desktop-windows": "0.0.1-next.7",
16
- "@legendapp/spark-desktop-links": "0.0.1-next.7"
11
+ "@legendapp/spark-file-dialog": "0.0.1-next.8",
12
+ "@legendapp/spark-file-system": "0.0.1-next.8",
13
+ "@legendapp/spark-native-menu": "0.0.1-next.8",
14
+ "@legendapp/spark-desktop-app": "0.0.1-next.8",
15
+ "@legendapp/spark-desktop-windows": "0.0.1-next.8",
16
+ "@legendapp/spark-desktop-links": "0.0.1-next.8"
17
17
  },
18
18
  "peerDependencies": {
19
19
  "react": "^19.1.0",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@legendapp/spark-drag-drop",
3
- "version": "0.0.1-next.7",
3
+ "version": "0.0.1-next.8",
4
4
  "license": "MIT",
5
5
  "main": "src/index.tsx",
6
6
  "react-native": "src/index.tsx",
@@ -39,7 +39,7 @@
39
39
  ]
40
40
  },
41
41
  "dependencies": {
42
- "@legendapp/spark-desktop-app": "0.0.1-next.7"
42
+ "@legendapp/spark-desktop-app": "0.0.1-next.8"
43
43
  },
44
44
  "private": true
45
45
  }
@@ -11,6 +11,7 @@ Pod::Spec.new do |s|
11
11
  s.homepage = "https://legendapp.com"
12
12
  s.source = { :path => "." }
13
13
  s.platforms = { :ios => "15.0", :osx => "14.0" }
14
+ s.osx.frameworks = "UniformTypeIdentifiers"
14
15
  s.source_files = "ios/**/*.{h,m,mm}"
15
16
  s.dependency "React-Core"
16
17
  s.dependency "ReactCodegen"