Problem: language preference stored only in localStorage, lost on 'clear site data'. French users with browser lang=fr always got French UI even when profile was English. Solution: - Backend: add 'language' field to user profile (default 'fr') - Backend: PATCH /api/auth/me to update language preference - Frontend: initI18n() priority: server > localStorage > navigator > 'fr' - Frontend: initAuth() runs before initI18n() so server check works - Frontend: profile Save persists language to server via PATCH Verified: tabs show English after server profile set to 'en'
104 lines
3.3 KiB
JavaScript
104 lines
3.3 KiB
JavaScript
/* ObsiGate — Module orchestrator (ES modules).
|
|
Replaces the monolithic frontend/app.js IIFE.
|
|
All code lives in frontend/js/*.js modules. */
|
|
|
|
import * as UI from './ui.js';
|
|
import * as Utils from './utils.js';
|
|
import { initI18n, t } from './i18n.js';
|
|
|
|
// Wire up AI toolbar toast (avoids circular import in utils.js)
|
|
window._obsigateShowToast = UI.showToast;
|
|
import * as Sidebar from './sidebar.js';
|
|
import * as Auth from './auth.js';
|
|
import * as Viewer from './viewer.js';
|
|
import * as Sync from './sync.js';
|
|
import { initGraphView } from './graph.js';
|
|
import * as Legacy from './legacy.js';
|
|
import { initCommandPalette } from './palette.js';
|
|
import { initMobileToolbar } from './mobile-toolbar.js';
|
|
import { initDragDrop } from './dragdrop.js';
|
|
import { initMermaid, setupFocusMode } from './mermaid-viewer.js';
|
|
|
|
// =========================================================================
|
|
// Initialization — mirrors the original app.js init() ordering
|
|
// =========================================================================
|
|
async function init() {
|
|
// 1. Init auth first — needed for server-side language preference
|
|
const authOk = await Auth.AuthManager.initAuth();
|
|
|
|
// 2. Init i18n after auth so server language preference is available
|
|
await initI18n();
|
|
|
|
UI.initTheme();
|
|
UI.initHeaderMenu();
|
|
UI.initCustomDropdowns();
|
|
|
|
document.getElementById("theme-toggle").addEventListener("click", UI.toggleTheme);
|
|
document.getElementById("header-logo").addEventListener("click", Legacy.goHome);
|
|
const refreshBtn = document.getElementById("header-refresh-btn");
|
|
if (refreshBtn) refreshBtn.addEventListener("click", Legacy.goHome);
|
|
|
|
Legacy.initSearch();
|
|
UI.initSidebarToggle();
|
|
UI.initMobile();
|
|
Sidebar.initVaultContext();
|
|
Legacy.initSidebarTabs();
|
|
Legacy.initHelpModal();
|
|
Legacy.initConfigModal();
|
|
Legacy.initAboutModal();
|
|
Sidebar.initSidebarFilter();
|
|
UI.initSidebarResize();
|
|
Utils.initEditor();
|
|
Auth.initLoginForm();
|
|
Legacy.initRecentTab();
|
|
|
|
UI.RightSidebarManager.init();
|
|
UI.FindInPageManager.init();
|
|
UI.ContextMenuManager.init();
|
|
UI.TabManager.init();
|
|
initCommandPalette();
|
|
initMobileToolbar();
|
|
|
|
if (authOk) {
|
|
Legacy.initSyncStatus();
|
|
|
|
try {
|
|
await Promise.all([Legacy.loadVaultSettings(), Sidebar.loadVaults(), Sidebar.loadTags()]);
|
|
|
|
initDragDrop();
|
|
|
|
Legacy.DashboardRecentWidget.init();
|
|
|
|
const urlParams = new URLSearchParams(window.location.search);
|
|
if (urlParams.get("popup") === "true") {
|
|
document.body.classList.add("popup-mode");
|
|
}
|
|
|
|
if (window.location.hash && window.location.hash.startsWith("#file=")) {
|
|
const hashVal = window.location.hash.substring(6);
|
|
const sepIndex = hashVal.indexOf(":");
|
|
if (sepIndex > -1) {
|
|
const vault = decodeURIComponent(hashVal.substring(0, sepIndex));
|
|
const path = decodeURIComponent(hashVal.substring(sepIndex + 1));
|
|
Viewer.openFile(vault, path);
|
|
}
|
|
} else if (urlParams.get("popup") !== "true") {
|
|
Legacy.showWelcome();
|
|
}
|
|
} catch (err) {
|
|
console.error("Failed to initialize ObsiGate:", err);
|
|
UI.showToast(t("error.initialization"), "error");
|
|
}
|
|
}
|
|
|
|
initGraphView();
|
|
initMermaid();
|
|
setupFocusMode();
|
|
Utils.safeCreateIcons();
|
|
}
|
|
|
|
document.addEventListener("DOMContentLoaded", () => {
|
|
init();
|
|
Sync.init();
|
|
});
|