mirror of
https://github.com/HeyPuter/puter
synced 2024-11-14 22:06:00 +00:00
Integrate ProcessService with task manager
This commit is contained in:
parent
9d9e091a7a
commit
79bfcf226b
@ -2,29 +2,6 @@ import UIWindow from "./UIWindow.js";
|
||||
|
||||
const UIWindowTaskManager = async function UIWindowTaskManager () {
|
||||
const svc_process = globalThis.services.get('process');
|
||||
const sample_data = [
|
||||
{
|
||||
name: 'root',
|
||||
children: [
|
||||
{
|
||||
name: 'terminal',
|
||||
children: [
|
||||
{
|
||||
name: 'phoenix'
|
||||
}
|
||||
],
|
||||
children: [
|
||||
{
|
||||
name: 'ai-plugin'
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: 'editor'
|
||||
}
|
||||
]
|
||||
}
|
||||
];
|
||||
|
||||
const w = await UIWindow({
|
||||
title: i18n('task_manager'),
|
||||
@ -95,7 +72,10 @@ const UIWindowTaskManager = async function UIWindowTaskManager () {
|
||||
};
|
||||
|
||||
const Task = ({ placement, name }) => {
|
||||
const { indent_level, last_item } = placement;
|
||||
const {
|
||||
indent_level, last_item,
|
||||
parent_last_item,
|
||||
} = placement;
|
||||
|
||||
const el = document.createElement('div');
|
||||
el.classList.add('taskmgr-task');
|
||||
@ -106,7 +86,7 @@ const UIWindowTaskManager = async function UIWindowTaskManager () {
|
||||
console.log('last_item', last_item);
|
||||
Indent({
|
||||
has_trunk: (last_cell && ( ! last_item )) ||
|
||||
! last_cell,
|
||||
(!last_cell && !parent_last_item[i]),
|
||||
has_branch: last_cell
|
||||
}).appendTo(el);
|
||||
}
|
||||
@ -178,27 +158,37 @@ const UIWindowTaskManager = async function UIWindowTaskManager () {
|
||||
|
||||
el_taskarea.appendChild(tasktable.el());
|
||||
|
||||
const iter_tasks = (items, { indent_level }) => {
|
||||
const iter_tasks = (items, { indent_level, parent_last_item }) => {
|
||||
console.log('aaah', parent_last_item);
|
||||
for ( let i=0 ; i < items.length; i++ ) {
|
||||
const row = Row();
|
||||
const item = items[i];
|
||||
const last_item = i === items.length - 1;
|
||||
row.add(Task({
|
||||
placement: {
|
||||
parent_last_item,
|
||||
indent_level,
|
||||
last_item: i === items.length - 1,
|
||||
last_item,
|
||||
},
|
||||
name: item.name
|
||||
}));
|
||||
row.add($('<span>open</span>')[0])
|
||||
tasktable.add(row);
|
||||
if ( item.children ) {
|
||||
iter_tasks(item.children, {
|
||||
indent_level: indent_level + 1
|
||||
|
||||
const children = svc_process.get_children_of(item.uuid);
|
||||
if ( children ) {
|
||||
iter_tasks(children, {
|
||||
indent_level: indent_level + 1,
|
||||
parent_last_item:
|
||||
[...parent_last_item, last_item],
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
iter_tasks(sample_data, { indent_level: 0 });
|
||||
|
||||
const processes = [svc_process.get_init()];
|
||||
|
||||
iter_tasks(processes, { indent_level: 0, parent_last_item: [] });
|
||||
w_body.appendChild(el_taskarea);
|
||||
}
|
||||
|
||||
|
@ -21,9 +21,10 @@ export class Service {
|
||||
};
|
||||
|
||||
export class Process {
|
||||
constructor ({ uuid, parent, meta }) {
|
||||
constructor ({ uuid, parent, name, meta }) {
|
||||
this.uuid = uuid;
|
||||
this.parent = parent;
|
||||
this.name = name;
|
||||
this.meta = meta;
|
||||
|
||||
this._construct();
|
||||
@ -44,6 +45,8 @@ export class InitProccess extends Process {
|
||||
static created_ = false;
|
||||
|
||||
_construct () {
|
||||
this.name = 'Puter';
|
||||
|
||||
if (InitProccess.created_) {
|
||||
throw new Error('InitProccess already created');
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ import update_username_in_gui from './helpers/update_username_in_gui.js';
|
||||
import update_title_based_on_uploads from './helpers/update_title_based_on_uploads.js';
|
||||
import content_type_to_icon from './helpers/content_type_to_icon.js';
|
||||
import UIWindowDownloadDirProg from './UI/UIWindowDownloadDirProg.js';
|
||||
import { PortalProcess } from "./definitions.js";
|
||||
import { PortalProcess, PseudoProcess } from "./definitions.js";
|
||||
|
||||
window.is_auth = ()=>{
|
||||
if(localStorage.getItem("auth_token") === null || auth_token === null)
|
||||
@ -1681,16 +1681,6 @@ window.launch_app = async (options)=>{
|
||||
// Create entry to track the "portal"
|
||||
// (portals are processese in Puter's GUI)
|
||||
// -----------------------------------
|
||||
const portal = new PortalProcess({
|
||||
uuid,
|
||||
parent: options.parent_instance_id,
|
||||
meta: {
|
||||
launch_options: options,
|
||||
app_info: app_info,
|
||||
}
|
||||
});
|
||||
const svc_process = globalThis.services.get('process');
|
||||
svc_process.register(portal);
|
||||
|
||||
let el_win;
|
||||
|
||||
@ -1698,6 +1688,17 @@ window.launch_app = async (options)=>{
|
||||
// Explorer
|
||||
//------------------------------------
|
||||
if(options.name === 'explorer'){
|
||||
const process = new PseudoProcess({
|
||||
uuid,
|
||||
name: 'explorer',
|
||||
parent: options.parent_instance_id,
|
||||
meta: {
|
||||
launch_options: options,
|
||||
app_info: app_info,
|
||||
}
|
||||
});
|
||||
const svc_process = globalThis.services.get('process');
|
||||
svc_process.register(process);
|
||||
if(options.path === window.home_path){
|
||||
title = 'Home';
|
||||
icon = window.icons['folder-home.svg'];
|
||||
@ -1727,6 +1728,18 @@ window.launch_app = async (options)=>{
|
||||
// All other apps
|
||||
//------------------------------------
|
||||
else{
|
||||
const portal = new PortalProcess({
|
||||
uuid,
|
||||
name: app_info.name,
|
||||
parent: options.parent_instance_id,
|
||||
meta: {
|
||||
launch_options: options,
|
||||
app_info: app_info,
|
||||
}
|
||||
});
|
||||
const svc_process = globalThis.services.get('process');
|
||||
svc_process.register(portal);
|
||||
|
||||
//-----------------------------------
|
||||
// iframe_url
|
||||
//-----------------------------------
|
||||
|
@ -15,6 +15,18 @@ export class ProcessService extends Service {
|
||||
this.register_(root);
|
||||
}
|
||||
|
||||
get_init () {
|
||||
return this.processes_map.get(NULL_UUID);
|
||||
}
|
||||
|
||||
get_children_of (uuid) {
|
||||
if ( ! uuid ) {
|
||||
uuid = NULL_UUID;
|
||||
}
|
||||
|
||||
return this.uuid_to_treelist.get(uuid);
|
||||
}
|
||||
|
||||
register (process) {
|
||||
this.register_(process);
|
||||
this.attach_to_parent_(process);
|
||||
|
Loading…
Reference in New Issue
Block a user