From f68ae00098ca26d02bab00de0f4aa5dc64f8dd76 Mon Sep 17 00:00:00 2001 From: Djeeberjr Date: Fri, 30 Jun 2023 19:06:46 +0200 Subject: [PATCH] dynamic app selection on home context --- src/kernel/binstore/BinStore.hx | 8 ++++++++ src/lib/HomeContext.hx | 28 ++++++++++++++++++++++++---- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/src/kernel/binstore/BinStore.hx b/src/kernel/binstore/BinStore.hx index 06a19bc..8e6c3b5 100644 --- a/src/kernel/binstore/BinStore.hx +++ b/src/kernel/binstore/BinStore.hx @@ -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; + } } diff --git a/src/lib/HomeContext.hx b/src/lib/HomeContext.hx index ea34488..3a9f847 100644 --- a/src/lib/HomeContext.hx +++ b/src/lib/HomeContext.hx @@ -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 = [ + "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);