Parcourir la source

Integrate ProcessService with task manager

KernelDeimos il y a 1 an
Parent
commit
79bfcf226b
4 fichiers modifiés avec 61 ajouts et 43 suppressions
  1. 21 31
      src/UI/UIWindowTaskManager.js
  2. 4 1
      src/definitions.js
  3. 24 11
      src/helpers.js
  4. 12 0
      src/services/ProcessService.js

+ 21 - 31
src/UI/UIWindowTaskManager.js

@@ -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);
 }
 

+ 4 - 1
src/definitions.js

@@ -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');
         }

+ 24 - 11
src/helpers.js

@@ -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
         //-----------------------------------

+ 12 - 0
src/services/ProcessService.js

@@ -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);