-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
76 lines (63 loc) · 2.28 KB
/
app.js
File metadata and controls
76 lines (63 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/**
* DownloadLib main module
* Initializes the application, registers services, and sets up the UI
* @license MIT
* @author ivanvit
* @version 1.0.0
*/
'use strict';
(function() {
console.log('[App] Initializing...');
const extensionApi = typeof getExtensionApi === 'function'
? getExtensionApi()
: ((typeof browser !== 'undefined' && browser) || (typeof chrome !== 'undefined' && chrome) || null);
if (!extensionApi)
console.warn('[App] Extension API is not available in this context');
const dependencies = [
'EventBus',
'RateLimiter',
'ServiceRegistry',
'DownloadManager',
'BaseService',
'MangaLibService',
'RanobeLibService',
'BaseExporter',
'FB2Exporter',
'EPUBExporter',
'PDFExporter',
'ExporterFactory',
'PopupController'
];
const missing = dependencies.filter(dep => typeof window[dep] === 'undefined');
if (missing.length > 0) {
console.error('[App] Missing dependencies:', missing);
document.body.innerHTML = '<div style="padding: 20px; color: red;">Ошибка загрузки модулей: ' + missing.join(', ') + '</div>';
return;
}
console.log('[App] All dependencies loaded');
try {
window.serviceRegistry.register(window.MangaLibService);
} catch (e) {
console.error('[App] Failed to register MangaLibService:', e);
}
try {
window.serviceRegistry.register(window.RanobeLibService);
} catch (e) {
console.error('[App] Failed to register RanobeLibService:', e);
}
const services = window.serviceRegistry.getAllServices();
function initUI() {
console.log('[App] Initializing UI...');
try {
window.popupController = new window.PopupController();
} catch (e) {
console.error('[App] Failed to initialize PopupController:', e);
document.getElementById('error').textContent = 'Ошибка инициализации: ' + e.message;
document.getElementById('error').classList.remove('hidden');
}
}
if (document.readyState === 'loading')
document.addEventListener('DOMContentLoaded', initUI);
else
setTimeout(initUI, 100);
})();