improve ux, moved functionality for better ui experience on app and extension.
This commit is contained in:
@@ -6,18 +6,41 @@
|
||||
let discordToken = null;
|
||||
let discordTokenCapturedAt = null;
|
||||
|
||||
// Track initialization state
|
||||
let initialized = false;
|
||||
|
||||
/**
|
||||
* Ensure extension is initialized
|
||||
*/
|
||||
async function ensureInitialized() {
|
||||
if (!initialized) {
|
||||
console.log('Initializing extension...');
|
||||
try {
|
||||
await api.init();
|
||||
await loadDiscordToken();
|
||||
initialized = true;
|
||||
console.log('Extension initialized successfully');
|
||||
} catch (error) {
|
||||
console.error('Failed to initialize extension:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize API on startup
|
||||
browser.runtime.onInstalled.addListener(async () => {
|
||||
console.log('GallerySubscriber extension installed');
|
||||
await api.init();
|
||||
await loadDiscordToken();
|
||||
await ensureInitialized();
|
||||
});
|
||||
|
||||
browser.runtime.onStartup.addListener(async () => {
|
||||
await api.init();
|
||||
await loadDiscordToken();
|
||||
console.log('GallerySubscriber extension startup');
|
||||
await ensureInitialized();
|
||||
});
|
||||
|
||||
// Also initialize immediately in case background wakes up from idle
|
||||
ensureInitialized().catch(err => console.error('Initial init failed:', err));
|
||||
|
||||
/**
|
||||
* Load Discord token from storage
|
||||
*/
|
||||
@@ -88,6 +111,13 @@ browser.runtime.onMessage.addListener((message, sender, sendResponse) => {
|
||||
* @returns {Promise<object>} - Response data
|
||||
*/
|
||||
async function handleMessage(message) {
|
||||
console.log('Handling message:', message.type);
|
||||
|
||||
// Ensure initialized for operations that need it
|
||||
if (['EXPORT_COOKIES', 'EXPORT_ALL_COOKIES', 'GET_PLATFORM_STATUS', 'TEST_CONNECTION'].includes(message.type)) {
|
||||
await ensureInitialized();
|
||||
}
|
||||
|
||||
switch (message.type) {
|
||||
case 'EXPORT_COOKIES':
|
||||
return await exportCookies(message.platform);
|
||||
|
||||
Reference in New Issue
Block a user