mirror of
https://github.com/HeyPuter/puter
synced 2024-11-14 22:06:00 +00:00
tweak: automatically update sidebar_items
every 2 seconds
This commit is contained in:
parent
2e122c2cab
commit
05950b0fc3
@ -567,6 +567,12 @@ async function UIDesktop(options){
|
||||
puter.kv.get("sidebar_items").then(async (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
|
||||
puter.kv.get('menubar_style').then(async (val) => {
|
||||
|
@ -2397,7 +2397,6 @@ async function UIWindow(options) {
|
||||
// Sidebar sortable
|
||||
//--------------------------------------------------
|
||||
if(options.is_dir && !isMobile.phone){
|
||||
loadSavedSidebarOrder(el_window);
|
||||
const $sidebar = $(el_window).find('.window-sidebar');
|
||||
|
||||
$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;
|
||||
|
Loading…
Reference in New Issue
Block a user