tweak: automatically update sidebar_items every 2 seconds

This commit is contained in:
jelveh 2024-11-03 17:13:24 -08:00
parent 2e122c2cab
commit 05950b0fc3
2 changed files with 7 additions and 33 deletions

View File

@ -566,7 +566,13 @@ async function UIDesktop(options){
// load window sidebar items from KV // load window sidebar items from KV
puter.kv.get("sidebar_items").then(async (val) => { puter.kv.get("sidebar_items").then(async (val) => {
window.sidebar_items = val; window.sidebar_items = val;
}) })
// also update every 2 seconds
setInterval(async () => {
puter.kv.get("sidebar_items").then(async (val) => {
window.sidebar_items = val;
})
}, 2000);
// Get menubar style // Get menubar style
puter.kv.get('menubar_style').then(async (val) => { puter.kv.get('menubar_style').then(async (val) => {

View File

@ -2397,7 +2397,6 @@ async function UIWindow(options) {
// Sidebar sortable // Sidebar sortable
//-------------------------------------------------- //--------------------------------------------------
if(options.is_dir && !isMobile.phone){ if(options.is_dir && !isMobile.phone){
loadSavedSidebarOrder(el_window);
const $sidebar = $(el_window).find('.window-sidebar'); const $sidebar = $(el_window).find('.window-sidebar');
$sidebar.sortable({ $sidebar.sortable({
@ -3678,35 +3677,4 @@ async function saveSidebarOrder(order) {
} }
} }
// Function to load and apply saved sidebar order
async function loadSavedSidebarOrder(el_window) {
setTimeout(async () => {
try {
// Load saved sidebar order
let savedOrder = window.sidebar_items
// If not found in window object, try to get from KV
if(!savedOrder){
savedOrder = await puter.kv.get("sidebar_items");
}
// If found, apply the order
if (savedOrder && savedOrder !== 'null' && savedOrder !== 'undefined') {
const order = JSON.parse(savedOrder);
const $sidebar = $(el_window).find('.window-sidebar');
// Reorder items according to saved order
order.forEach(item => {
const $item = $sidebar.find(`.window-sidebar-item[data-path="${item.path}"]`);
if ($item.length) {
$item.appendTo($sidebar);
}
});
}
} catch(err) {
console.error('Error loading sidebar order:', err);
}
}, 1000);
}
export default UIWindow; export default UIWindow;