import UITaskbarItem from './UITaskbarItem.js'
import UIPopover from './UIPopover.js'
async function UITaskbar(options){
global_element_id++;
options = options ?? {};
options.content = options.content ?? '';
// get launch apps
$.ajax({
url: api_origin + "/get-launch-apps",
type: 'GET',
async: true,
contentType: "application/json",
headers: {
"Authorization": "Bearer "+auth_token
},
success: function (apps){
window.launch_apps = apps;
}
});
let h = '';
h += `
`;
$('.desktop').append(h);
//---------------------------------------------
// add `Start` to taskbar
//---------------------------------------------
UITaskbarItem({
icon: window.icons['start.svg'],
name: 'Start',
sortable: false,
keep_in_taskbar: true,
disable_context_menu: true,
onClick: async function(item){
// skip if popover already open
if($(item).hasClass('has-open-popover'))
return;
// show popover
let popover = UIPopover({
content: `
✕
`,
snapToElement: item,
parent_element: item,
width: 500,
height: 500,
center_horizontally: true,
});
// In the rare case that launch_apps is not populated yet, get it from the server
// then populate the popover
if(!launch_apps || !launch_apps.recent || launch_apps.recent.length === 0){
// get launch apps
launch_apps = await $.ajax({
url: api_origin + "/get-launch-apps",
type: 'GET',
async: true,
contentType: "application/json",
headers: {
"Authorization": "Bearer "+auth_token
},
});
}
let apps_str = '';
apps_str += `
`);
$(el).show();
$(ui.item).removeItems();
update_taskbar();
}
// only proceed to update DB if the item sorted was a pinned item otherwise no point in updating the taskbar in DB
else if($(ui.item).attr('data-keep-in-taskbar') === 'true'){
update_taskbar();
}
},
});
}
export default UITaskbar;