Bien sûr ! Je vais intégrer le style esthétique donné dans votre nouveau code JavaScript original (celui qui charge dynamiquement les apps via Root), en remplaçant le style injecté dans ce code par celui que vous fournissez, en veillant à garder toutes les fonctionnalités (recherche, catégories, sous-menus, état apps, interactions accessibles).
Modifications apportées :
- Remplacement complet du bloc CSS injecté dans le code par celui donné dans votre
<style> (adapté en injection JS).
- Le conteneur principal possède désormais l’id
plutoMenuBar (au lieu d’une classe menu-bar).
- Les noms de variables/classes CSS dans le JS sont changés pour correspondre au style (ex:
.menu-search, menu-items restent identiques, pour cohérence).
- Amélioration mineure pour correspondre exactement au style (par exemple la taille de la pastille d’état est passée à 16px, selon votre style).
- Conserve le mécanisme d’affichage des applications, catégories, boutons avec indicateur d’état, gestion des événements.
Voici la version modifiée et intégrée de votre code complet (la fonction exec) :
export default {
name: "Menu Bar",
description: "Composant complet barre de menu Core, avec recherche, catégories, sous-menus, état apps",
ver: "v1.6.2",
type: "process",
privileges: [
{ privilege: "knownPackageList", description: "Accéder aux packages connus" },
{ privilege: "processList", description: "Accéder aux processus pour état apps ouvertes" },
],
exec: async function (Root) {
const Win = (await Root.Lib.loadLibrary("WindowSystem")).win;
const Html = Root.Lib.html;
const vfs = await Root.Lib.loadLibrary("VirtualFS");
const FileMappings = await Root.Lib.loadLibrary("FileMappings");
const win = new Win({
title: "Menu Bar",
pid: Root.PID,
width: "100%",
height: 96,
left: 0,
top: 0,
resizable: false,
onclose: () => Root.Lib.onEnd(),
draggable: false,
});
Root.Lib.setOnEnd(() => win.close());
const wrapper = Html.from(win.window.querySelector(".win-content"));
// Modifie pour correspondre au style donné : id à la place de la classe
wrapper.elm.id = "plutoMenuBar";
// Nettoie les classes héritées et applique pas mal de choses via CSS global, donc on évite redondance ici
wrapper.style({
userSelect: "none",
gap: "2ch",
overflow: "hidden",
});
// Injecter les styles esthétiques du design donné, via élément <style id="pluto-menu-bar-styles">
(function injectStyles() {
if (document.getElementById("pluto-menu-bar-styles")) return;
const style = document.createElement("style");
style.id = "pluto-menu-bar-styles";
style.textContent = `
:root {
--color-bg: #1f2937;
--color-primary: #3b82f6;
--color-text: #f9fafb;
--color-text-muted: #9ca3af;
--color-hover-bg: #374151;
--color-active-bg: #2563eb;
--transition-speed: 0.2s;
--font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
#plutoMenuBar {
position: sticky;
top: 0; left: 0; right: 0;
display: flex;
align-items: center;
height: 96px;
padding: 0 1.5rem;
box-shadow: 0 2px 8px rgba(0,0,0,0.4);
background-color: var(--color-bg);
z-index: 9999;
gap: 2ch;
user-select: none;
font-family: var(--font-family);
color: var(--color-text);
}
#plutoMenuBar .menu-search {
position: relative;
flex-shrink: 0;
width: 250px;
margin-right: 1.5rem;
}
#plutoMenuBar .menu-search input {
width: 100%;
padding: 8px 12px 8px 40px;
border-radius: 6px;
border: none;
outline: none;
font-size: 1.2rem;
color: #111827;
box-shadow: inset 0 0 5px rgba(0,0,0,0.1);
}
#plutoMenuBar .menu-search input::placeholder {
color: var(--color-text-muted);
}
#plutoMenuBar .menu-search svg {
position: absolute;
top: 50%;
left: 10px;
transform: translateY(-50%);
width: 20px;
height: 20px;
fill: var(--color-text-muted);
pointer-events: none;
}
#plutoMenuBar nav.menu-items {
display: flex;
gap: 2rem;
flex-grow: 1;
overflow-x: auto;
scrollbar-width: thin;
scrollbar-color: var(--color-primary) transparent;
}
#plutoMenuBar nav.menu-items::-webkit-scrollbar {
height: 6px;
}
#plutoMenuBar nav.menu-items::-webkit-scrollbar-thumb {
background-color: var(--color-primary);
border-radius: 3px;
}
.menu-category {
position: relative;
min-width: 160px;
}
.menu-category > button {
background: none;
border: none;
color: var(--color-text);
font-weight: 700;
font-size: 1.1rem;
cursor: pointer;
padding: 0.5rem 0.8rem;
display: flex;
align-items: center;
gap: .3rem;
border-radius: 6px;
transition: background-color var(--transition-speed);
user-select: none;
}
.menu-category > button:hover,
.menu-category > button:focus {
background-color: var(--color-hover-bg);
outline: none;
}
.menu-category > button:after {
content: '▼';
font-size: 0.7rem;
margin-left: 6px;
transition: transform var(--transition-speed);
color: var(--color-text-muted);
}
.menu-category.open > button:after {
transform: rotate(180deg);
color: var(--color-primary);
}
.sub-menu {
position: absolute;
top: calc(100% + 0.25rem);
left: 0;
background-color: var(--color-bg);
border: 1.5px solid var(--color-primary);
border-radius: 6px;
box-shadow: 0 6px 12px rgba(0,0,0,0.25);
min-width: 240px;
max-height: 360px;
overflow-y: auto;
padding: 0.4rem 0;
display: none;
flex-direction: column;
font-size: 1rem;
z-index: 1100;
animation: fadeInMenu 250ms ease forwards;
}
.menu-category.open > .sub-menu {
display: flex;
}
@keyframes fadeInMenu {
from {opacity: 0; transform: translateY(-10px);}
to {opacity: 1; transform: translateY(0);}
}
.sub-menu button {
all: unset;
padding: 10px 18px;
cursor: pointer;
display: flex;
align-items: center;
gap: 0.8rem;
border-radius: 6px;
font-weight: 600;
color: var(--color-text);
white-space: nowrap;
user-select: none;
transition: background-color var(--transition-speed);
width: 100%;
}
.sub-menu button:hover,
.sub-menu button:focus {
background-color: var(--color-active-bg);
outline: none;
}
.sub-menu button svg.icon-box {
width: 28px;
height: 28px;
fill: var(--color-primary);
flex-shrink: 0;
}
.app-status {
width: 16px;
height: 16px;
border-radius: 50%;
flex-shrink: 0;
box-shadow: 0 0 5px rgba(0,0,0,0.3);
background-color: #bbb;
margin-left: auto;
margin-right: 4px;
}
.app-status.open {
background-color: #22c55e;
box-shadow: 0 0 8px #22c55e;
}
`;
document.head.appendChild(style);
})();
// Création search input & container
const searchContainer = new Html("div").class("menu-search").appendTo(wrapper);
const searchInput = new Html("input")
.attr({ type: "search", placeholder: "Rechercher...", "aria-label": "Rechercher une application" })
.appendTo(searchContainer);
searchContainer.append(new Html("svg").attr({
"aria-hidden": "true",
"focusable": "false",
"viewBox": "0 0 24 24",
"fill": "none",
"stroke": "currentColor",
"stroke-width": "2",
"stroke-linecap": "round",
"stroke-linejoin": "round",
"style": "position: absolute; top: 50%; left: 10px; transform: translateY(-50%); width: 20px; height: 20px; pointer-events:none;"
}).html(`
<circle cx="11" cy="11" r="7"/>
<line x1="17" y1="17" x2="22" y2="22"/>
`));
// Création nav container
const nav = new Html("nav").class("menu-items").attr({ role: "menubar" }).appendTo(wrapper);
// Données apps (initialement vides)
let menuAppsData = [];
// Récupère list des apps et icônes dynamiquement
async function refreshAppsData() {
const installedApps = (await vfs.list("Root/Pluto/apps")) || [];
const knownApps = Root.Core.knownPackageList.filter(p => p.url.startsWith("apps:"));
const apps = [];
for (const appPkg of knownApps) {
const urlName = appPkg.url.split(":")[1];
const parts = urlName.split("/");
const category = parts.length > 1 ? parts[0] : "Général";
const appName = parts.length > 1 ? parts.slice(1).join("/") : parts[0];
const foundLocal = installedApps.find(a =>
a.item.toLowerCase().startsWith(appName.toLowerCase()) && a.item.endsWith(".app")
);
if (!foundLocal) continue;
let mapping = null;
try {
mapping = await FileMappings.retrieveAllMIMEdata(`Root/Pluto/apps/${foundLocal.item}`);
} catch { }
const icon = (mapping && mapping.icon && Root.Lib.icons[mapping.icon])
? Root.Lib.icons[mapping.icon]
: `<svg class="icon-box" viewBox="0 0 20 20"><rect width="20" height="20" fill="gray"/></svg>`;
apps.push({ id: appPkg.url.toLowerCase(), name: appPkg.pkg.name || appName, category, icon, description: appPkg.pkg.description || "" });
}
menuAppsData = apps;
}
// Trie et groupe par catégorie avec filtre texte
function groupAppsByCategory(filter = "") {
const filtered = filter
? menuAppsData.filter(app => app.name.toLowerCase().includes(filter.toLowerCase()))
: menuAppsData;
const categories = [...new Set(filtered.map(a => a.category))].sort();
return categories.reduce((acc, cat) => {
acc[cat] = filtered.filter(app => app.category === cat).sort((a, b) => a.name.localeCompare(b.name));
return acc;
}, {});
}
// Liste des applications ouvertes par nom
function getOpenAppsUrls() {
if (!Root.Core || !Root.Core.processList) return [];
return Root.Core.processList.filter(p => p && p.proc && typeof p.proc.name === "string").map(p => p.proc.name.toLowerCase());
}
// Créé le bouton application d'après l'objet app
function createAppButton(app, openApps) {
const btn = new Html("button")
.attr({ tabindex: "0", role: "menuitem", "aria-label": `Ouvrir ${app.name}` })
.class("app-item", "row", "ac", "gap")
.style({ width: "100%" });
const isOpen = openApps.some(n => n.includes(app.id));
btn.html(`
<span class="icon-box">${app.icon}</span>
<span class="app-label">${app.name}</span>
<span class="app-status ${isOpen ? "open" : "closed"}" title="${isOpen ? 'Ouvert' : 'Fermé'}"></span>
`);
btn.elm.addEventListener("click", async () => {
try {
await Root.Core.startPkg(app.id);
} catch (e) {
Root.Modal.alert("Erreur", `Impossible de lancer ${app.name} : ${e.message || e}`);
}
});
return btn;
}
// Crée une catégorie (colonne) avec sous-menu contenant apps
function createCategory(catName, apps, openApps) {
const divCat = new Html("div").class("menu-category").attr({ role: "presentation" });
const btnCat = new Html("button")
.text(catName)
.attr({ tabindex: "0", role: "menuitem", "aria-haspopup": "true", "aria-expanded": "false" })
.class("category-btn", "row", "ac", "gap");
divCat.appendChild(btnCat);
const submenu = new Html("div").class("sub-menu").attr({ role: "menu", "aria-label": `Catégorie ${catName}` });
divCat.appendChild(submenu);
apps.forEach(app => submenu.appendChild(createAppButton(app, openApps)));
btnCat.elm.addEventListener("click", () => {
const open = divCat.elm.classList.toggle("open");
btnCat.elm.setAttribute("aria-expanded", open.toString());
});
// Fermeture clic hors
document.addEventListener("click", e => {
if (!divCat.elm.contains(e.target)) {
divCat.elm.classList.remove("open");
btnCat.elm.setAttribute("aria-expanded", "false");
}
});
return divCat;
}
// Rendu complet selon filtre
async function renderMenu(filter = "") {
nav.html("");
await refreshAppsData();
const openApps = getOpenAppsUrls();
const grouped = groupAppsByCategory(filter);
for (const cat of Object.keys(grouped)) {
if (grouped[cat].length === 0) continue;
nav.appendChild(createCategory(cat, grouped[cat], openApps));
}
}
// Debounce recherche
let debounceTimer;
searchInput.elm.addEventListener("input", e => {
clearTimeout(debounceTimer);
debounceTimer = setTimeout(() => renderMenu(e.target.value), 250);
});
await renderMenu();
return Root.Lib.setupReturns(m => {
if (m?.type === "refresh") {
renderMenu();
}
});
},
};
Résultat attendu :
- La barre de menu aura visuellement les couleurs, polices, effets hover/focus et layout de votre style CSS fourni.
- Fonctionnellement la recherche filtre correctement.
- Les catégories s’affichent horizontalement, déroulent leur sous-menu au clic.
- Chaque app affiche son icône SVG, son nom, et une pastille verte si elle est ouverte.
- Cliquez sur app lance la commande (mode Root.Core.startPkg).
- Gestion accessible ARIA et focus.
Si vous souhaitez, je peux vous générer un package complet avec HTML/CSS/JS embarqué (exemple standalone) ou vous expliquer cette intégration plus en détail.