fix: register menu via Lampa.Controller.add, start only on app:ready

This commit is contained in:
Hermes committed 2026-08-08 03:08:06 +02:00
1 parent 6eb73c2c40
commit e832651e4a
2 files changed
+85 -79

No files matched your search

+23 -18
View File
@@ -106,28 +106,33 @@
.replace(/>/g, '>').replace(/"/g, '"');
}
// ---- Пункт меню ----
function addMenuItem() {
if ($('.menu__item[data-component="' + PLUGIN.name + '"]').length) return;
var item = $('<div class="menu__item selector" data-component="' + PLUGIN.name + '">')
.append($('<span>').text(PLUGIN.title));
$('.menu__list').append(item);
item.on('hover:enter', function () {
Lampa.Activity.push({ url: '', component: PLUGIN.name, title: PLUGIN.title, page: PLUGIN.title });
// ---- Пункт меню (нативный API Lampa) ----
function addMenu() {
Lampa.Controller.add('menu', {
component: PLUGIN.name,
name: PLUGIN.title,
icon: 'archive',
action: function () {
Lampa.Activity.push({
url: '',
component: PLUGIN.name,
title: PLUGIN.title,
page: PLUGIN.title
});
}
});
Lampa.Selector.update();
}
function start() {
addMenuItem();
Lampa.Listener.follow('app', function (e) {
if (e.type === 'ready') addMenuItem();
});
Lampa.Listener.follow('menu', function (e) {
if (e.type === 'open' || e.type === 'update') addMenuItem();
});
addMenu();
}
if (window.Lampa) start();
else document.addEventListener('lampa', start);
// Стартуем ТОЛЬКО когда Lampa готова — иначе Lampa.Selector не проинициализирован
if (window.Lampa && Lampa.Controller) {
Lampa.Listener.follow('app', function (e) {
if (e.type === 'ready') start();
});
} else {
document.addEventListener('lampa', start);
}
})();