kingkont 0.7.1 → 0.7.2
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.
- package/main.js +36 -0
- package/package.json +1 -1
- package/preload.js +9 -1
package/main.js
CHANGED
|
@@ -409,6 +409,42 @@ ipcMain.handle('updates:check', async () => {
|
|
|
409
409
|
return { current, latest, isNew: isNewerVersion(current, latest) };
|
|
410
410
|
});
|
|
411
411
|
|
|
412
|
+
// In-place install: запускаем `npm i -g kingkont@<version>` дочерним
|
|
413
|
+
// процессом через login shell (чтобы поймать PATH из ~/.zshrc — на macOS
|
|
414
|
+
// Electron, открытый из Finder, не видит Homebrew-путей).
|
|
415
|
+
//
|
|
416
|
+
// Streamим stdout/stderr в renderer через 'updates:install-output' events.
|
|
417
|
+
// На EACCES (нет прав на global install) renderer покажет команду для
|
|
418
|
+
// ручного запуска с sudo.
|
|
419
|
+
const { spawn } = require('child_process');
|
|
420
|
+
ipcMain.handle('updates:install', async (e, target = 'latest') => {
|
|
421
|
+
return new Promise((resolve, reject) => {
|
|
422
|
+
const shell = process.env.SHELL || '/bin/bash';
|
|
423
|
+
const cmd = `npm i -g kingkont@${target}`;
|
|
424
|
+
const proc = spawn(shell, ['-lc', cmd]);
|
|
425
|
+
let stderr = '';
|
|
426
|
+
proc.stdout.on('data', d => {
|
|
427
|
+
const text = d.toString();
|
|
428
|
+
try { e.sender.send('updates:install-output', { stream: 'stdout', text }); } catch {}
|
|
429
|
+
});
|
|
430
|
+
proc.stderr.on('data', d => {
|
|
431
|
+
const text = d.toString();
|
|
432
|
+
stderr += text;
|
|
433
|
+
try { e.sender.send('updates:install-output', { stream: 'stderr', text }); } catch {}
|
|
434
|
+
});
|
|
435
|
+
proc.on('close', code => {
|
|
436
|
+
if (code === 0) resolve({ ok: true });
|
|
437
|
+
else reject(new Error(`npm exit ${code}. ${stderr.slice(-400) || '(нет деталей)'}`));
|
|
438
|
+
});
|
|
439
|
+
proc.on('error', err => reject(err));
|
|
440
|
+
});
|
|
441
|
+
});
|
|
442
|
+
|
|
443
|
+
ipcMain.handle('app:relaunch', () => {
|
|
444
|
+
app.relaunch();
|
|
445
|
+
app.exit(0);
|
|
446
|
+
});
|
|
447
|
+
|
|
412
448
|
// Фоновая проверка при старте: если есть свежая — открываем окно автоматом.
|
|
413
449
|
// Чтобы не доставать юзера до открытия проекта, ждём 5 сек после createWindow.
|
|
414
450
|
async function backgroundCheckUpdates() {
|
package/package.json
CHANGED
package/preload.js
CHANGED
|
@@ -48,10 +48,18 @@ contextBridge.exposeInMainWorld('appSettings', {
|
|
|
48
48
|
openSettingsWindow: () => ipcRenderer.invoke('settings-window:open'),
|
|
49
49
|
});
|
|
50
50
|
|
|
51
|
-
//
|
|
51
|
+
// Проверка/установка обновлений через npm registry (в main-процессе).
|
|
52
52
|
contextBridge.exposeInMainWorld('appUpdates', {
|
|
53
53
|
check: () => ipcRenderer.invoke('updates:check'),
|
|
54
|
+
install: (version) => ipcRenderer.invoke('updates:install', version),
|
|
55
|
+
relaunch: () => ipcRenderer.invoke('app:relaunch'),
|
|
54
56
|
closeWindow: () => ipcRenderer.invoke('updates-window:close'),
|
|
57
|
+
// Стрим stdout/stderr во время install. Возвращает unsubscribe.
|
|
58
|
+
onInstallOutput: (cb) => {
|
|
59
|
+
const handler = (_e, data) => cb(data);
|
|
60
|
+
ipcRenderer.on('updates:install-output', handler);
|
|
61
|
+
return () => ipcRenderer.removeListener('updates:install-output', handler);
|
|
62
|
+
},
|
|
55
63
|
});
|
|
56
64
|
|
|
57
65
|
// Авторизация в Chatium через loopback OAuth-flow.
|