dynamic app selection on home context

This commit is contained in:
Djeeberjr 2023-06-30 19:06:46 +02:00
parent 2937de86d6
commit f68ae00098
2 changed files with 32 additions and 4 deletions

View File

@ -68,4 +68,12 @@ class BinStore {
}
return null;
}
public function getNameByAlias(alias: String): String {
var bin = getBinByAlias(alias);
if (bin == null) {
return null;
}
return bin.name;
}
}

View File

@ -1,5 +1,7 @@
package lib;
import kernel.log.Log;
import kernel.binstore.BinStore;
import kernel.peripherals.Screen;
import kernel.peripherals.Peripherals.Peripheral;
import kernel.ps.Process;
@ -29,6 +31,11 @@ class HomeContext {
private var selectedOutput:String = "main";
private var selectedOutputIndex:Int = -1;
private final listedApps:Array<String> = [
"terminal",
"log"
];
public function new() {}
public function run() {
@ -95,7 +102,15 @@ class HomeContext {
focusContext(contextId);
}
private function spawnPs(ps: Process) {
private function spawnPs(binName: String) {
var bin = BinStore.instance.getBinByAlias(binName);
if (bin == null) {
Log.error('Could not find bin: ${binName}');
return;
}
var ps = Type.createInstance(bin.c,[]);
var pid = ProcessManager.run(ps, {});
var lastContextID = -1;
@ -141,10 +156,15 @@ class HomeContext {
for (i in workspaceIDs) new TextElement('Switch to ${i + 1}', {onClick: this.handleSelectContext.bind(i)})
];
children.push(new TextElement('Add Terminal', {onClick: this.spawnPs.bind(new Terminal())}));
children.push(new TextElement('Add Log', {onClick: this.spawnPs.bind(new KernelLog())}));
children.push(new TextElement('Exit', {onClick: KernelEvents.instance.shutdown}));
for (i in 0...listedApps.length) {
children.push(new TextElement(
'Add ${BinStore.instance.getNameByAlias(listedApps[i])}',
{onClick: this.spawnPs.bind(listedApps[i])}
));
}
children.push(new TextElement('Output :${selectedOutput}', {onClick: this.cycleOutput}));
children.push(new TextElement('Exit', {onClick: KernelEvents.instance.shutdown}));
renderer.setChildren(children);