Initialize vault in main entry point
- Import and export UncloseVault - Load CryptoJS dynamically for vault encryption - Initialize vault on page load (auto-restores session if valid) - Expose vault globally via window.UncloseVault
This commit is contained in:
parent
3d07909854
commit
9944d8f757
1 changed files with 33 additions and 1 deletions
|
|
@ -16,6 +16,30 @@ import * as Storage from "./src/storage.js";
|
|||
import * as Translation from "./src/translation.js";
|
||||
import * as TTS from "./src/tts.js";
|
||||
import * as UI from "./src/ui.js";
|
||||
import { UncloseVault } from "./src/vault.js";
|
||||
|
||||
// -------------------------
|
||||
// Vault Support
|
||||
// -------------------------
|
||||
|
||||
// Load CryptoJS dynamically for vault encryption
|
||||
async function ensureCryptoJS() {
|
||||
if (typeof CryptoJS !== 'undefined') return true;
|
||||
|
||||
return new Promise((resolve) => {
|
||||
const script = document.createElement('script');
|
||||
script.src = 'https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.2.0/crypto-js.min.js';
|
||||
script.onload = () => resolve(true);
|
||||
script.onerror = () => {
|
||||
console.warn('uncloseai.js: Failed to load CryptoJS - vault features disabled');
|
||||
resolve(false);
|
||||
};
|
||||
document.head.appendChild(script);
|
||||
});
|
||||
}
|
||||
|
||||
// Export vault for external use
|
||||
export { UncloseVault };
|
||||
|
||||
// -------------------------
|
||||
// Public API - Main Functions
|
||||
|
|
@ -112,11 +136,19 @@ window.hideProgressIndicator = FileUpload.hideProgressIndicator;
|
|||
window.handleTTSFromElement = UI.handleTTSFromElement;
|
||||
window.handleUploadFromElement = UI.handleUploadFromElement;
|
||||
window.handleSmartTranslate = UI.handleSmartTranslate;
|
||||
window.UncloseVault = UncloseVault;
|
||||
|
||||
// Initialize on page load
|
||||
window.addEventListener("load", () => {
|
||||
window.addEventListener("load", async () => {
|
||||
console.log("uncloseai.js: window.onload event fired.");
|
||||
|
||||
// Load CryptoJS and initialize vault early
|
||||
await ensureCryptoJS();
|
||||
if (UncloseVault.isAvailable()) {
|
||||
const restored = UncloseVault.init();
|
||||
console.log("uncloseai.js: Vault initialized, session restored:", restored);
|
||||
}
|
||||
|
||||
// Check skip init flag first
|
||||
if (window.UNCLOSEAI_SKIP_INIT === true) {
|
||||
console.log(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue