feat: desktop — connexion compte central + environnement prod/dev (#230)
Liaison d'appareil sur og/og-dev, validation du jeton draco et ouverture de la session de l'admin local. Sélecteur prod/dev (Configuration + premier lancement), admin local par défaut admin/chab30, sans impact sur le web Docker. Inclut BUG-126 (runtime python-embed/_pth + copie de backend/frontend + signature updater opt-in) et BUG-127 (retour /liaison même hôte).
This commit is contained in:
+93
-4
@@ -12,6 +12,8 @@
|
||||
* Usage: import { initDesktopIntegration } from './desktop.js';
|
||||
*/
|
||||
|
||||
import { t } from './i18n.js';
|
||||
|
||||
// ── Detection ──────────────────────────────────────────────────────────────
|
||||
// window.__TAURI__ is injected by Tauri when app.withGlobalTauri === true.
|
||||
// window.__TAURI_INTERNALS__ is a secondary signal used by some Tauri builds.
|
||||
@@ -52,6 +54,54 @@ export async function getSystemTheme() {
|
||||
return 'light';
|
||||
}
|
||||
|
||||
// ── Environnement central (#230) ───────────────────────────────────────────
|
||||
// prod = https://og.dracodev.net, dev = https://og-dev.dracodev.net.
|
||||
// Persisté par le shell Rust (%APPDATA%/ObsiGate/config.json) et injecté au
|
||||
// backend embarqué en DRACO_* ; sans effet sur l'application web.
|
||||
|
||||
export function desktopEnvironmentLabel(env, centralUrl) {
|
||||
const key = env === 'dev' ? 'dev' : 'prod';
|
||||
const host = centralUrl || (key === 'dev'
|
||||
? 'https://og-dev.dracodev.net'
|
||||
: 'https://og.dracodev.net');
|
||||
return t('desktop.env_' + key) + ' — ' + host.replace(/^https?:\/\//, '');
|
||||
}
|
||||
|
||||
export async function getDesktopSettings() {
|
||||
if (!isTauriEnv()) return undefined;
|
||||
return await invoke('get_desktop_settings');
|
||||
}
|
||||
|
||||
export async function setDesktopEnvironment(environment) {
|
||||
if (!isTauriEnv()) return undefined;
|
||||
return await invoke('set_desktop_environment', { environment: environment });
|
||||
}
|
||||
|
||||
// Opens a URL in the user's default browser (Tauri shell plugin). Returns
|
||||
// false when unavailable (web), true otherwise.
|
||||
export async function openExternalUrl(url) {
|
||||
if (!isTauriEnv() || !url) return false;
|
||||
// Commande Rust : valide https://*.dracodev.net puis ouvre le navigateur
|
||||
// système (shell:allow-open). `true` = succès, `undefined` = échec IPC.
|
||||
const res = await invoke('open_external_url', { url: url });
|
||||
if (res === true) return true;
|
||||
try {
|
||||
const shell = window.__TAURI__ && window.__TAURI__.shell;
|
||||
if (shell && typeof shell.open === 'function') {
|
||||
await shell.open(url);
|
||||
return true;
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn('[desktop] shell.open failed:', e);
|
||||
}
|
||||
try {
|
||||
window.open(url, '_blank', 'noopener');
|
||||
return true;
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// ── Theme preference detection ─────────────────────────────────────────────
|
||||
// The real theme engine is themes.js: it persists the *mode* under
|
||||
// 'obsigate-theme-mode' (dark/light/high-contrast/sepia). Absence of that key
|
||||
@@ -235,7 +285,7 @@ export async function initDesktopWizard() {
|
||||
if (!shouldShowWizard({ hasVaultPath: wizardDone })) return;
|
||||
|
||||
// Defer so the app shell is fully rendered before injecting the banner.
|
||||
setTimeout(function () {
|
||||
setTimeout(async function () {
|
||||
if (document.getElementById('obsigate-desktop-wizard')) return;
|
||||
const banner = document.createElement('div');
|
||||
banner.id = 'obsigate-desktop-wizard';
|
||||
@@ -250,10 +300,44 @@ export async function initDesktopWizard() {
|
||||
|
||||
const text = document.createElement('span');
|
||||
text.style.cssText = 'flex:1;min-width:220px;font-size:13px;color:var(--text,#e6edf3);';
|
||||
text.textContent = 'Bienvenue dans ObsiGate Desktop. Choisissez le dossier de vos vaults Obsidian pour commencer.';
|
||||
text.textContent = t('desktop.wizard_text');
|
||||
|
||||
// #230 : choix prod/dev avant la première connexion. Persisté côté Rust ;
|
||||
// le backend redémarre pour recevoir les URL DRACO_* de l'environnement.
|
||||
const settings = await getDesktopSettings();
|
||||
const currentEnv = settings && settings.environment ? settings.environment : 'prod';
|
||||
const envWrap = document.createElement('label');
|
||||
envWrap.style.cssText = 'display:flex;flex-direction:column;gap:4px;font-size:12px;color:var(--text-2,#8b949e);min-width:190px;';
|
||||
const envLabel = document.createElement('span');
|
||||
envLabel.textContent = t('desktop.wizard_env_label');
|
||||
const envSelect = document.createElement('select');
|
||||
envSelect.id = 'desktop-wizard-environment';
|
||||
envSelect.style.cssText = 'padding:6px 8px;border-radius:6px;border:1px solid var(--border,#21262d);background:var(--bg-primary,#0d1117);color:var(--text,#e6edf3);font-size:13px;';
|
||||
[['prod', t('desktop.env_prod')], ['dev', t('desktop.env_dev')]].forEach(function (pair) {
|
||||
const opt = document.createElement('option');
|
||||
opt.value = pair[0];
|
||||
opt.textContent = pair[1];
|
||||
envSelect.appendChild(opt);
|
||||
});
|
||||
envSelect.value = currentEnv === 'dev' ? 'dev' : 'prod';
|
||||
const envStatus = document.createElement('span');
|
||||
envSelect.addEventListener('change', async function () {
|
||||
envSelect.disabled = true;
|
||||
envStatus.textContent = t('desktop.env_restarting');
|
||||
const saved = await setDesktopEnvironment(envSelect.value);
|
||||
if (saved) {
|
||||
await invoke('restart_backend');
|
||||
} else {
|
||||
envSelect.disabled = false;
|
||||
envStatus.textContent = '';
|
||||
}
|
||||
});
|
||||
envWrap.appendChild(envLabel);
|
||||
envWrap.appendChild(envSelect);
|
||||
envWrap.appendChild(envStatus);
|
||||
|
||||
const pickBtn = document.createElement('button');
|
||||
pickBtn.textContent = 'Choisir mon dossier';
|
||||
pickBtn.textContent = t('desktop.wizard_pick');
|
||||
pickBtn.style.cssText = 'background:#7c3aed;color:#fff;border:none;border-radius:6px;padding:8px 14px;cursor:pointer;font-weight:600;font-size:13px;';
|
||||
pickBtn.addEventListener('click', async function () {
|
||||
const p = await pickAndAddVault();
|
||||
@@ -261,7 +345,7 @@ export async function initDesktopWizard() {
|
||||
});
|
||||
|
||||
const laterBtn = document.createElement('button');
|
||||
laterBtn.textContent = 'Plus tard';
|
||||
laterBtn.textContent = t('desktop.wizard_later');
|
||||
laterBtn.style.cssText = 'background:transparent;color:var(--text-2,#8b949e);border:1px solid var(--border,#21262d);border-radius:6px;padding:8px 14px;cursor:pointer;font-size:13px;';
|
||||
laterBtn.addEventListener('click', function () {
|
||||
dismissWizard();
|
||||
@@ -269,6 +353,7 @@ export async function initDesktopWizard() {
|
||||
});
|
||||
|
||||
banner.appendChild(text);
|
||||
banner.appendChild(envWrap);
|
||||
banner.appendChild(pickBtn);
|
||||
banner.appendChild(laterBtn);
|
||||
document.body.appendChild(banner);
|
||||
@@ -307,6 +392,10 @@ export default {
|
||||
getSystemTheme,
|
||||
hasExplicitThemeMode,
|
||||
syncSystemTheme,
|
||||
desktopEnvironmentLabel,
|
||||
getDesktopSettings,
|
||||
setDesktopEnvironment,
|
||||
openExternalUrl,
|
||||
defineBackendCrashBanner,
|
||||
pickVaultFolder,
|
||||
pickAndAddVault,
|
||||
|
||||
Reference in New Issue
Block a user