hivedesk 1.0.1 → 1.1.0

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 (52) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/README.md +306 -303
  3. package/desktop/README.md +0 -3
  4. package/desktop/release-notes/1.0.2.json +12 -0
  5. package/desktop/release-notes/1.1.0.json +12 -0
  6. package/desktop/scripts/package.mjs +134 -134
  7. package/i18n/README.pt-BR.md +307 -304
  8. package/i18n/de.json +7 -31
  9. package/i18n/en.json +7 -31
  10. package/i18n/es.json +7 -31
  11. package/i18n/fr.json +7 -31
  12. package/i18n/it.json +7 -31
  13. package/i18n/ja.json +7 -31
  14. package/i18n/ko.json +7 -31
  15. package/i18n/parts/s2-p2p.de.json +5 -15
  16. package/i18n/parts/s2-p2p.en.json +5 -15
  17. package/i18n/parts/s2-p2p.es.json +5 -15
  18. package/i18n/parts/s2-p2p.fr.json +5 -15
  19. package/i18n/parts/s2-p2p.it.json +5 -15
  20. package/i18n/parts/s2-p2p.ja.json +5 -15
  21. package/i18n/parts/s2-p2p.ko.json +5 -15
  22. package/i18n/parts/s2-p2p.pt-BR.json +5 -15
  23. package/i18n/parts/s2-p2p.ru.json +5 -15
  24. package/i18n/parts/s2-p2p.zh-CN.json +5 -15
  25. package/i18n/pt-BR.json +7 -31
  26. package/i18n/ru.json +7 -31
  27. package/i18n/zh-CN.json +7 -31
  28. package/package.json +1 -1
  29. package/src/city/membership.js +1 -1
  30. package/src/extensions/engine-hook.js +1 -1
  31. package/src/lend/index.js +4 -3
  32. package/src/p2p/city-port.js +2 -2
  33. package/src/p2p/cli.js +31 -38
  34. package/src/p2p/doctor.js +4 -1
  35. package/src/p2p/engine.js +1 -1
  36. package/src/p2p/node.js +25 -8
  37. package/ui/js/widgets/lend.js +2 -2
  38. package/ui/lend/collab/client.js +9 -27
  39. package/ui/lend/collab/frames.js +1 -1
  40. package/ui/lend/collab/panel.js +8 -20
  41. package/ui/lend/collab/session.js +1 -1
  42. package/ui/lend/core/frames.js +1 -1
  43. package/ui/lend/core/session.js +37 -44
  44. package/ui/lend/join-window.js +8 -21
  45. package/ui/lend/lend-screen.js +14 -29
  46. package/ui/lend/lend.css +0 -2
  47. package/ui/lend/p2p-model.js +8 -19
  48. package/ui/lend/p2p-screen.js +21 -43
  49. package/ui/lend/p2p-text.js +4 -14
  50. package/ui/lend/text.js +1 -6
  51. package/ui/lend/view.js +1 -1
  52. package/ui/office/office.js +662 -662
package/desktop/README.md CHANGED
@@ -292,9 +292,6 @@ WebKitGTK 4.1 (see Fallbacks). The tray icon needs an AppIndicator library
292
292
  a setup, "Use the system title bar" in the menu switches to the OS frame.
293
293
  * Windows on ARM runs the x64 runtime through emulation.
294
294
  * On Linux the tray icon depends on an AppIndicator library and the desktop environment.
295
- * `npx hivedesk` uses the desktop window once `src/cli.js` calls `desktop/index.js` (the hooks requested
296
- in NOTES-engine.md) and `desktop` is in the package.json `files`. Until then it opens the browser
297
- window as before; the downloadable packages do not depend on it.
298
295
 
299
296
  ## Credits
300
297
 
@@ -0,0 +1,12 @@
1
+ {
2
+ "en": "hivedesk 1.0.2. A new website in 10 languages, with a light and a dark theme. The relay check (hivedesk doctor --p2p) no longer prints a warning when a relay is an IP address. A download whose part file turned into a folder now stops with a clear message, and Code together links open the right page.",
3
+ "pt-BR": "hivedesk 1.0.2. Um site novo em 10 idiomas, com tema claro e escuro. A verificação do relay (hivedesk doctor --p2p) não mostra mais um aviso quando o relay é um endereço IP. Um download cujo arquivo parcial virou uma pasta agora para com uma mensagem clara, e os links de Code together abrem a página certa.",
4
+ "es": "hivedesk 1.0.2. Un sitio nuevo en 10 idiomas, con tema claro y oscuro. La comprobación del relay (hivedesk doctor --p2p) ya no muestra un aviso cuando el relay es una dirección IP. Una descarga cuyo archivo parcial se convirtió en carpeta ahora se detiene con un mensaje claro, y los enlaces de Code together abren la página correcta.",
5
+ "fr": "hivedesk 1.0.2. Un nouveau site en 10 langues, avec un thème clair et un thème sombre. La vérification du relais (hivedesk doctor --p2p) n'affiche plus d'avertissement quand le relais est une adresse IP. Un téléchargement dont le fichier partiel est devenu un dossier s'arrête maintenant avec un message clair, et les liens Code together ouvrent la bonne page.",
6
+ "de": "hivedesk 1.0.2. Eine neue Website in 10 Sprachen, mit hellem und dunklem Design. Die Relay-Prüfung (hivedesk doctor --p2p) zeigt keine Warnung mehr, wenn ein Relay eine IP-Adresse ist. Ein Download, dessen Teildatei zu einem Ordner wurde, stoppt jetzt mit einer klaren Meldung, und Code together-Links öffnen die richtige Seite.",
7
+ "it": "hivedesk 1.0.2. Un sito nuovo in 10 lingue, con tema chiaro e scuro. Il controllo del relay (hivedesk doctor --p2p) non mostra più un avviso quando il relay è un indirizzo IP. Un download il cui file parziale è diventato una cartella ora si ferma con un messaggio chiaro, e i link di Code together aprono la pagina giusta.",
8
+ "ja": "hivedesk 1.0.2。10言語に対応し、ライトとダークのテーマを備えた新しいWebサイトになりました。リレーの確認(hivedesk doctor --p2p)は、リレーがIPアドレスのときに警告を出さなくなりました。途中のファイルがフォルダーになってしまったダウンロードは、わかりやすいメッセージとともに止まるようになり、Code together のリンクは正しいページを開きます。",
9
+ "ko": "hivedesk 1.0.2. 10개 언어와 라이트, 다크 테마를 갖춘 새 웹사이트입니다. 릴레이 확인(hivedesk doctor --p2p)은 릴레이가 IP 주소일 때 더 이상 경고를 표시하지 않습니다. 임시 파일이 폴더로 바뀐 다운로드는 이제 분명한 메시지와 함께 멈추고, Code together 링크는 올바른 페이지를 엽니다.",
10
+ "zh-CN": "hivedesk 1.0.2。全新的网站,支持 10 种语言,提供浅色和深色主题。中继检查(hivedesk doctor --p2p)在中继为 IP 地址时不再显示警告。如果下载的临时文件变成了文件夹,下载现在会停止并给出清楚的提示;Code together 链接会打开正确的页面。",
11
+ "ru": "hivedesk 1.0.2. Новый сайт на 10 языках, со светлой и тёмной темой. Проверка ретранслятора (hivedesk doctor --p2p) больше не выводит предупреждение, когда ретранслятор задан IP-адресом. Загрузка, у которой временный файл оказался папкой, теперь останавливается с понятным сообщением, а ссылки Code together открывают нужную страницу."
12
+ }
@@ -0,0 +1,12 @@
1
+ {
2
+ "en": "hivedesk 1.1.0. Pairing is just the words now: paste your friend's six words or link and you are connected. No check words to compare and no Accept. The lender chooses what to lend before making the words, keeps the Lending now list with Revoke and Stop lending, and known peers reconnect without words. The same goes for Code together.",
3
+ "pt-BR": "hivedesk 1.1.0. Parear agora é só usar as palavras: cole as seis palavras ou o link do seu amigo e pronto. Sem palavras para conferir e sem Aceitar. Quem empresta escolhe o que emprestar antes de gerar as palavras, mantém a lista Emprestando agora com Revogar e Parar de emprestar, e amigos conhecidos se reconectam sem palavras. O mesmo vale para o Code together.",
4
+ "es": "hivedesk 1.1.0. Emparejar ahora es solo usar las palabras: pega las seis palabras o el enlace de tu amigo y listo. Sin palabras que comparar y sin Aceptar. Quien presta elige qué prestar antes de generar las palabras, conserva la lista Prestando ahora con Revocar y Dejar de prestar, y los contactos conocidos se reconectan sin palabras. Lo mismo vale para Code together.",
5
+ "fr": "hivedesk 1.1.0. Pour s'appairer, les mots suffisent : colle les six mots ou le lien de ton ami et c'est connecté. Plus de mots à comparer ni de bouton Accepter. Qui prête choisit quoi prêter avant de créer les mots, garde la liste Prêt en cours avec Révoquer et Arrêter de prêter, et les pairs connus se reconnectent sans mots. Pareil pour Code together.",
6
+ "de": "hivedesk 1.1.0. Koppeln geht jetzt nur mit den Wörtern: Füge die sechs Wörter oder den Link deines Freundes ein und ihr seid verbunden. Keine Prüfwörter zum Vergleichen und kein Annehmen. Wer verleiht, wählt vor dem Erzeugen der Wörter, was er verleiht, behält die Liste Gerade verliehen mit Widerrufen und Verleihen beenden, und bekannte Peers verbinden sich ohne Wörter neu. Dasselbe gilt für Code together.",
7
+ "it": "hivedesk 1.1.0. Per abbinarsi bastano le parole: incolla le sei parole o il link del tuo amico e sei connesso. Niente parole da confrontare e niente Accetta. Chi presta sceglie cosa prestare prima di creare le parole, mantiene l'elenco In prestito ora con Revoca e Smetti di prestare, e i peer conosciuti si riconnettono senza parole. Lo stesso vale per Code together.",
8
+ "ja": "hivedesk 1.1.0。ペアリングは言葉だけになりました。友だちの6つの言葉かリンクを貼り付ければ接続できます。確認用の言葉の見比べも承認もありません。貸す側は言葉を作る前に貸す内容を選び、「貸し出し中」の一覧で取り消しや貸し出し停止ができます。既知の相手は言葉なしで再接続します。Code together も同じです。",
9
+ "ko": "hivedesk 1.1.0. 이제 페어링은 단어만으로 끝납니다. 친구의 여섯 단어나 링크를 붙여 넣으면 연결됩니다. 비교할 확인 단어도, 수락도 없습니다. 빌려주는 사람은 단어를 만들기 전에 빌려줄 항목을 고르고, 지금 빌려주는 중 목록에서 취소와 빌려주기 중지를 할 수 있으며, 아는 피어는 단어 없이 다시 연결됩니다. Code together도 마찬가지입니다.",
10
+ "zh-CN": "hivedesk 1.1.0。配对现在只需要词语:粘贴朋友的六个词或链接即可连接。无需比对确认词,也无需接受。借出方在生成词语之前选择要借出的内容,并可在“正在借出”列表中撤销或停止借出;已知的对等方无需词语即可重新连接。Code together 也是如此。",
11
+ "ru": "hivedesk 1.1.0. Теперь для сопряжения достаточно слов: вставьте шесть слов или ссылку друга, и вы подключены. Никаких проверочных слов и никакого «Принять». Тот, кто одалживает, выбирает, что одолжить, ещё до создания слов, видит список «Сейчас одолжено» с кнопками «Отозвать» и «Прекратить», а знакомые узлы переподключаются без слов. То же для Code together."
12
+ }
@@ -1,134 +1,134 @@
1
- // Builds the folder of one downloadable package. Used by .github/workflows/desktop.yml.
2
- // node desktop/scripts/package.mjs --target windows-x64|macos-universal|linux-x64 --node <node binary> --out <dir>
3
- // [--launcher <hivedesk.exe>] (Windows: the compiled launcher)
4
- // [--npm <npm folder>] (the npm package of the same Node.js build; found next to --node when left out)
5
- // The runtime binary comes from the pinned upstream archive and is checked against desktop/platform.js.
6
- import fs from 'node:fs';
7
- import os from 'node:os';
8
- import path from 'node:path';
9
- import { fileURLToPath } from 'node:url';
10
- import { RUNTIME, BINARIES } from '../platform.js';
11
- import { sha256 } from '../runtime.js';
12
- import { extractEntry } from '../zip.js';
13
- import { packagedHelperAllowed } from '../native.js';
14
-
15
- const HERE = path.dirname(fileURLToPath(import.meta.url));
16
- const ROOT = path.resolve(HERE, '..', '..');
17
- const DESKTOP = path.join(ROOT, 'desktop');
18
-
19
- const opts = {};
20
- for (let i = 2; i < process.argv.length; i += 2) opts[process.argv[i].replace(/^--/, '')] = process.argv[i + 1];
21
- const TARGETS = {
22
- 'windows-x64': { bin: 'win_x64', runtimeName: 'hivedesk-runtime.exe' },
23
- 'macos-universal': { bin: 'mac_universal', runtimeName: 'hivedesk-runtime' },
24
- 'linux-x64': { bin: 'linux_x64', runtimeName: 'hivedesk-runtime' }
25
- };
26
- const t = TARGETS[opts.target];
27
- if (!t || !opts.node || !opts.out) {
28
- console.error('usage: package.mjs --target windows-x64|macos-universal|linux-x64 --node <node binary> --out <dir> [--launcher <exe>] [--zip <runtime zip>]');
29
- process.exit(2);
30
- }
31
- const pkg = JSON.parse(fs.readFileSync(path.join(ROOT, 'package.json'), 'utf8'));
32
-
33
- /** Copies what npm would publish (package.json "files"), always with desktop/. */
34
- function copyApp(dest) {
35
- // "!path" entries of package.json files are left out, as npm does.
36
- const slash = (p) => p.split(path.sep).join('/');
37
- const excluded = (pkg.files || []).filter((f) => f.startsWith('!')).map((f) => f.slice(1));
38
- const files = new Set([...(pkg.files || []).filter((f) => !f.startsWith('!')), 'desktop', 'package.json', 'LICENSE']);
39
- // Only the native helpers desktop/native.js lists (with a pinned hash) go into a package.
40
- const helperOk = (rel) => !/^desktop[\\/]helpers([\\/]|$)/.test(rel) || packagedHelperAllowed(rel.replace(/^desktop[\\/]/, ''));
41
- const skip = (rel) => excluded.some((x) => slash(rel) === x || slash(rel).startsWith(`${x}/`)) || !helperOk(rel) || /^desktop[\\/](scripts|launcher|bin)([\\/]|$)/.test(rel) || /^desktop[\\/]icons[\\/].*\.(icns|ico)$/.test(rel) || /(^|[\\/])node_modules([\\/]|$)/.test(rel);
42
- for (const f of files) {
43
- const src = path.join(ROOT, f);
44
- if (!fs.existsSync(src)) continue;
45
- fs.cpSync(src, path.join(dest, f), { recursive: true, filter: (s) => !skip(path.relative(ROOT, s)) });
46
- }
47
- }
48
-
49
- async function runtimeBinary() {
50
- let zip;
51
- if (opts.zip) zip = fs.readFileSync(opts.zip);
52
- else {
53
- const res = await fetch(RUNTIME.zip.url, { redirect: 'follow' });
54
- if (!res.ok) throw new Error(`runtime download: HTTP ${res.status}`);
55
- zip = Buffer.from(await res.arrayBuffer());
56
- }
57
- if (sha256(zip) !== RUNTIME.zip.sha256) throw new Error('runtime archive checksum mismatch');
58
- const b = BINARIES[t.bin];
59
- const bin = extractEntry(zip, b.file);
60
- if (!bin || sha256(bin) !== b.sha256) throw new Error(`${b.file}: checksum mismatch`);
61
- return bin;
62
- }
63
-
64
- const out = path.resolve(opts.out);
65
- fs.rmSync(out, { recursive: true, force: true });
66
- const bin = await runtimeBinary();
67
- let appDir;
68
- let nodeDest;
69
- if (opts.target === 'macos-universal') {
70
- const contents = path.join(out, 'hivedesk.app', 'Contents');
71
- appDir = path.join(contents, 'Resources', 'app');
72
- nodeDest = path.join(contents, 'Resources', 'node', 'bin', 'node');
73
- fs.mkdirSync(path.join(contents, 'MacOS'), { recursive: true });
74
- fs.writeFileSync(path.join(contents, 'Info.plist'), fs.readFileSync(path.join(DESKTOP, 'launcher', 'macos', 'Info.plist'), 'utf8').replaceAll('@VERSION@', pkg.version));
75
- fs.copyFileSync(path.join(DESKTOP, 'launcher', 'macos', 'hivedesk'), path.join(contents, 'MacOS', 'hivedesk'));
76
- fs.chmodSync(path.join(contents, 'MacOS', 'hivedesk'), 0o755);
77
- fs.mkdirSync(path.join(contents, 'Resources'), { recursive: true });
78
- fs.copyFileSync(path.join(DESKTOP, 'icons', 'hivedesk.icns'), path.join(contents, 'Resources', 'hivedesk.icns'));
79
- } else if (opts.target === 'windows-x64') {
80
- if (!opts.launcher) throw new Error('--launcher <hivedesk.exe> is needed for Windows');
81
- appDir = path.join(out, 'hivedesk', 'app');
82
- nodeDest = path.join(out, 'hivedesk', 'node', 'node.exe');
83
- fs.mkdirSync(path.join(out, 'hivedesk'), { recursive: true });
84
- fs.copyFileSync(opts.launcher, path.join(out, 'hivedesk', 'hivedesk.exe'));
85
- } else {
86
- const base = path.join(out, 'hivedesk');
87
- appDir = path.join(base, 'app');
88
- nodeDest = path.join(base, 'node', 'bin', 'node');
89
- fs.mkdirSync(base, { recursive: true });
90
- for (const f of ['hivedesk', 'hivedesk.desktop']) fs.copyFileSync(path.join(DESKTOP, 'launcher', 'linux', f), path.join(base, f));
91
- fs.chmodSync(path.join(base, 'hivedesk'), 0o755);
92
- fs.copyFileSync(path.join(DESKTOP, 'icons', 'icon-512.png'), path.join(base, 'hivedesk.png'));
93
- }
94
- copyApp(appDir);
95
- fs.mkdirSync(path.join(appDir, 'desktop', 'bin'), { recursive: true });
96
- fs.writeFileSync(path.join(appDir, 'desktop', 'bin', t.runtimeName), bin, { mode: 0o755 });
97
- // Licenses of the bundled runtimes.
98
- const lic = await fetch(RUNTIME.license);
99
- if (!lic.ok) throw new Error('runtime license: HTTP ' + lic.status);
100
- fs.writeFileSync(path.join(appDir, 'desktop', 'bin', 'LICENSE-neutralinojs.txt'), Buffer.from(await lic.arrayBuffer()));
101
- fs.mkdirSync(path.dirname(nodeDest), { recursive: true });
102
- const nodeLicense = [path.dirname(opts.node), path.dirname(path.dirname(opts.node))].map((d) => path.join(d, 'LICENSE')).find((f) => fs.existsSync(f));
103
- if (nodeLicense) fs.copyFileSync(nodeLicense, path.join(path.dirname(nodeDest), 'LICENSE'));
104
- else console.warn('package: no Node.js LICENSE found next to the node binary');
105
- fs.copyFileSync(opts.node, nodeDest);
106
- fs.chmodSync(nodeDest, 0o755);
107
- // npm goes with the bundled Node.js: the local model runtime (node-llama-cpp) is installed with it on first use,
108
- // and a PC without Node.js has no other npm. It sits where src/brain/runtime.js looks for it: next to node.exe on
109
- // Windows, in ../lib/node_modules on macOS and Linux, the layout of the official Node.js archives.
110
- const npmSrc = opts.npm || [path.join(path.dirname(opts.node), 'node_modules', 'npm'), path.join(path.dirname(path.dirname(opts.node)), 'lib', 'node_modules', 'npm')]
111
- .find((d) => fs.existsSync(path.join(d, 'bin', 'npm-cli.js')));
112
- if (!npmSrc || !fs.existsSync(path.join(npmSrc, 'bin', 'npm-cli.js'))) throw new Error('package: npm was not found next to the bundled Node.js; pass --npm <folder>');
113
- const npmDest = opts.target === 'windows-x64'
114
- ? path.join(path.dirname(nodeDest), 'node_modules', 'npm')
115
- : path.join(path.dirname(path.dirname(nodeDest)), 'lib', 'node_modules', 'npm');
116
- fs.cpSync(npmSrc, npmDest, { recursive: true });
117
-
118
- const readme = [
119
- `hivedesk ${pkg.version} (${opts.target})`,
120
- '',
121
- 'Start it:',
122
- opts.target === 'windows-x64' ? ' double click hivedesk.exe' : opts.target === 'macos-universal' ? ' open hivedesk.app' : ' ./hivedesk (or install hivedesk.desktop in ~/.local/share/applications)',
123
- '',
124
- 'Inside:',
125
- ' the hivedesk app (the same files as the npm package),',
126
- ` a Node.js runtime (${path.basename(opts.node)}), so nothing else needs to be installed,`,
127
- ` the desktop runtime ${RUNTIME.name} ${RUNTIME.version} (MIT), which shows the app in the system web view.`,
128
- '',
129
- 'The app is not signed. See https://github.com/kwy404/hivedesk/blob/main/desktop/README.md for the first launch prompts.',
130
- 'Logs: ~/.hivedesk/desktop/launcher.log. Projects default to ~/hivedesk.',
131
- ''
132
- ].join(os.EOL);
133
- fs.writeFileSync(path.join(opts.target === 'macos-universal' ? out : path.join(out, 'hivedesk'), 'README.txt'), readme);
134
- console.log(`package: ${opts.target} staged in ${out}`);
1
+ // Builds the folder of one downloadable package. Used by .github/workflows/desktop.yml.
2
+ // node desktop/scripts/package.mjs --target windows-x64|macos-universal|linux-x64 --node <node binary> --out <dir>
3
+ // [--launcher <hivedesk.exe>] (Windows: the compiled launcher)
4
+ // [--npm <npm folder>] (the npm package of the same Node.js build; found next to --node when left out)
5
+ // The runtime binary comes from the pinned upstream archive and is checked against desktop/platform.js.
6
+ import fs from 'node:fs';
7
+ import os from 'node:os';
8
+ import path from 'node:path';
9
+ import { fileURLToPath } from 'node:url';
10
+ import { RUNTIME, BINARIES } from '../platform.js';
11
+ import { sha256 } from '../runtime.js';
12
+ import { extractEntry } from '../zip.js';
13
+ import { packagedHelperAllowed } from '../native.js';
14
+
15
+ const HERE = path.dirname(fileURLToPath(import.meta.url));
16
+ const ROOT = path.resolve(HERE, '..', '..');
17
+ const DESKTOP = path.join(ROOT, 'desktop');
18
+
19
+ const opts = {};
20
+ for (let i = 2; i < process.argv.length; i += 2) opts[process.argv[i].replace(/^--/, '')] = process.argv[i + 1];
21
+ const TARGETS = {
22
+ 'windows-x64': { bin: 'win_x64', runtimeName: 'hivedesk-runtime.exe' },
23
+ 'macos-universal': { bin: 'mac_universal', runtimeName: 'hivedesk-runtime' },
24
+ 'linux-x64': { bin: 'linux_x64', runtimeName: 'hivedesk-runtime' }
25
+ };
26
+ const t = TARGETS[opts.target];
27
+ if (!t || !opts.node || !opts.out) {
28
+ console.error('usage: package.mjs --target windows-x64|macos-universal|linux-x64 --node <node binary> --out <dir> [--launcher <exe>] [--zip <runtime zip>]');
29
+ process.exit(2);
30
+ }
31
+ const pkg = JSON.parse(fs.readFileSync(path.join(ROOT, 'package.json'), 'utf8'));
32
+
33
+ /** Copies what npm would publish (package.json "files"), always with desktop/. */
34
+ function copyApp(dest) {
35
+ // "!path" entries of package.json files are left out, as npm does.
36
+ const slash = (p) => p.split(path.sep).join('/');
37
+ const excluded = (pkg.files || []).filter((f) => f.startsWith('!')).map((f) => f.slice(1));
38
+ const files = new Set([...(pkg.files || []).filter((f) => !f.startsWith('!')), 'desktop', 'package.json', 'LICENSE']);
39
+ // Only the native helpers desktop/native.js lists (with a pinned hash) go into a package.
40
+ const helperOk = (rel) => !/^desktop[\\/]helpers([\\/]|$)/.test(rel) || packagedHelperAllowed(rel.replace(/^desktop[\\/]/, ''));
41
+ const skip = (rel) => excluded.some((x) => slash(rel) === x || slash(rel).startsWith(`${x}/`)) || !helperOk(rel) || /^desktop[\\/](scripts|launcher|bin)([\\/]|$)/.test(rel) || /^desktop[\\/]icons[\\/].*\.(icns|ico)$/.test(rel) || /(^|[\\/])node_modules([\\/]|$)/.test(rel);
42
+ for (const f of files) {
43
+ const src = path.join(ROOT, f);
44
+ if (!fs.existsSync(src)) continue;
45
+ fs.cpSync(src, path.join(dest, f), { recursive: true, filter: (s) => !skip(path.relative(ROOT, s)) });
46
+ }
47
+ }
48
+
49
+ async function runtimeBinary() {
50
+ let zip;
51
+ if (opts.zip) zip = fs.readFileSync(opts.zip);
52
+ else {
53
+ const res = await fetch(RUNTIME.zip.url, { redirect: 'follow' });
54
+ if (!res.ok) throw new Error(`runtime download: HTTP ${res.status}`);
55
+ zip = Buffer.from(await res.arrayBuffer());
56
+ }
57
+ if (sha256(zip) !== RUNTIME.zip.sha256) throw new Error('runtime archive checksum mismatch');
58
+ const b = BINARIES[t.bin];
59
+ const bin = extractEntry(zip, b.file);
60
+ if (!bin || sha256(bin) !== b.sha256) throw new Error(`${b.file}: checksum mismatch`);
61
+ return bin;
62
+ }
63
+
64
+ const out = path.resolve(opts.out);
65
+ fs.rmSync(out, { recursive: true, force: true });
66
+ const bin = await runtimeBinary();
67
+ let appDir;
68
+ let nodeDest;
69
+ if (opts.target === 'macos-universal') {
70
+ const contents = path.join(out, 'hivedesk.app', 'Contents');
71
+ appDir = path.join(contents, 'Resources', 'app');
72
+ nodeDest = path.join(contents, 'Resources', 'node', 'bin', 'node');
73
+ fs.mkdirSync(path.join(contents, 'MacOS'), { recursive: true });
74
+ fs.writeFileSync(path.join(contents, 'Info.plist'), fs.readFileSync(path.join(DESKTOP, 'launcher', 'macos', 'Info.plist'), 'utf8').replaceAll('@VERSION@', pkg.version));
75
+ fs.copyFileSync(path.join(DESKTOP, 'launcher', 'macos', 'hivedesk'), path.join(contents, 'MacOS', 'hivedesk'));
76
+ fs.chmodSync(path.join(contents, 'MacOS', 'hivedesk'), 0o755);
77
+ fs.mkdirSync(path.join(contents, 'Resources'), { recursive: true });
78
+ fs.copyFileSync(path.join(DESKTOP, 'icons', 'hivedesk.icns'), path.join(contents, 'Resources', 'hivedesk.icns'));
79
+ } else if (opts.target === 'windows-x64') {
80
+ if (!opts.launcher) throw new Error('--launcher <hivedesk.exe> is needed for Windows');
81
+ appDir = path.join(out, 'hivedesk', 'app');
82
+ nodeDest = path.join(out, 'hivedesk', 'node', 'node.exe');
83
+ fs.mkdirSync(path.join(out, 'hivedesk'), { recursive: true });
84
+ fs.copyFileSync(opts.launcher, path.join(out, 'hivedesk', 'hivedesk.exe'));
85
+ } else {
86
+ const base = path.join(out, 'hivedesk');
87
+ appDir = path.join(base, 'app');
88
+ nodeDest = path.join(base, 'node', 'bin', 'node');
89
+ fs.mkdirSync(base, { recursive: true });
90
+ for (const f of ['hivedesk', 'hivedesk.desktop']) fs.copyFileSync(path.join(DESKTOP, 'launcher', 'linux', f), path.join(base, f));
91
+ fs.chmodSync(path.join(base, 'hivedesk'), 0o755);
92
+ fs.copyFileSync(path.join(DESKTOP, 'icons', 'icon-512.png'), path.join(base, 'hivedesk.png'));
93
+ }
94
+ copyApp(appDir);
95
+ fs.mkdirSync(path.join(appDir, 'desktop', 'bin'), { recursive: true });
96
+ fs.writeFileSync(path.join(appDir, 'desktop', 'bin', t.runtimeName), bin, { mode: 0o755 });
97
+ // Licenses of the bundled runtimes.
98
+ const lic = await fetch(RUNTIME.license);
99
+ if (!lic.ok) throw new Error('runtime license: HTTP ' + lic.status);
100
+ fs.writeFileSync(path.join(appDir, 'desktop', 'bin', 'LICENSE-neutralinojs.txt'), Buffer.from(await lic.arrayBuffer()));
101
+ fs.mkdirSync(path.dirname(nodeDest), { recursive: true });
102
+ const nodeLicense = [path.dirname(opts.node), path.dirname(path.dirname(opts.node))].map((d) => path.join(d, 'LICENSE')).find((f) => fs.existsSync(f));
103
+ if (nodeLicense) fs.copyFileSync(nodeLicense, path.join(path.dirname(nodeDest), 'LICENSE'));
104
+ else console.warn('package: no Node.js LICENSE found next to the node binary');
105
+ fs.copyFileSync(opts.node, nodeDest);
106
+ fs.chmodSync(nodeDest, 0o755);
107
+ // npm goes with the bundled Node.js: the local model runtime (node-llama-cpp) is installed with it on first use,
108
+ // and a PC without Node.js has no other npm. It sits where src/brain/runtime.js looks for it: next to node.exe on
109
+ // Windows, in ../lib/node_modules on macOS and Linux, the layout of the official Node.js archives.
110
+ const npmSrc = opts.npm || [path.join(path.dirname(opts.node), 'node_modules', 'npm'), path.join(path.dirname(path.dirname(opts.node)), 'lib', 'node_modules', 'npm')]
111
+ .find((d) => fs.existsSync(path.join(d, 'bin', 'npm-cli.js')));
112
+ if (!npmSrc || !fs.existsSync(path.join(npmSrc, 'bin', 'npm-cli.js'))) throw new Error('package: npm was not found next to the bundled Node.js; pass --npm <folder>');
113
+ const npmDest = opts.target === 'windows-x64'
114
+ ? path.join(path.dirname(nodeDest), 'node_modules', 'npm')
115
+ : path.join(path.dirname(path.dirname(nodeDest)), 'lib', 'node_modules', 'npm');
116
+ fs.cpSync(npmSrc, npmDest, { recursive: true });
117
+
118
+ const readme = [
119
+ `hivedesk ${pkg.version} (${opts.target})`,
120
+ '',
121
+ 'Start it:',
122
+ opts.target === 'windows-x64' ? ' double click hivedesk.exe' : opts.target === 'macos-universal' ? ' open hivedesk.app' : ' ./hivedesk (or install hivedesk.desktop in ~/.local/share/applications)',
123
+ '',
124
+ 'Inside:',
125
+ ' the hivedesk app (the same files as the npm package),',
126
+ ` a Node.js runtime (${path.basename(opts.node)}), so nothing else needs to be installed,`,
127
+ ` the desktop runtime ${RUNTIME.name} ${RUNTIME.version} (MIT), which shows the app in the system web view.`,
128
+ '',
129
+ 'The app is not signed. See https://github.com/kwy404/hivedesk/blob/main/desktop/README.md for the first launch prompts.',
130
+ 'Logs: ~/.hivedesk/desktop/launcher.log. Projects default to ~/hivedesk.',
131
+ ''
132
+ ].join(os.EOL);
133
+ fs.writeFileSync(path.join(opts.target === 'macos-universal' ? out : path.join(out, 'hivedesk'), 'README.txt'), readme);
134
+ console.log(`package: ${opts.target} staged in ${out}`);