made BinStore a static class

This commit is contained in:
Djeeberjr 2023-07-27 20:45:37 +02:00
parent 74d0232160
commit 89f209130e
6 changed files with 9 additions and 18 deletions

View File

@ -200,7 +200,7 @@ class Terminal implements Process {
} }
private function getProgByName(name:String):Process { private function getProgByName(name:String):Process {
var bin = BinStore.instance.getBinByAlias(name); var bin = BinStore.getBinByAlias(name);
if (bin == null) { if (bin == null) {
return null; return null;
} }

View File

@ -30,8 +30,6 @@ class Init {
WindowManager.init(); WindowManager.init();
MainTerm.instance = new MainTerm(); MainTerm.instance = new MainTerm();
BinStore.instance = new BinStore();
if (Turtle.isTurtle()){ if (Turtle.isTurtle()){
Turtle.instance = new Turtle(); Turtle.instance = new Turtle();
} }

View File

@ -22,9 +22,7 @@ import bin.Disk;
import haxe.ds.ReadOnlyArray; import haxe.ds.ReadOnlyArray;
class BinStore { class BinStore {
public static var instance: BinStore; private static final store:ReadOnlyArray<Bin> = [
private final store:ReadOnlyArray<Bin> = [
{c: Disk, name: "Disk", aliases: ["disk"]}, {c: Disk, name: "Disk", aliases: ["disk"]},
{c: GPS, name: "GPS", aliases: ["gps"]}, {c: GPS, name: "GPS", aliases: ["gps"]},
{c: HelloWorld, name: "HelloWorld", aliases: ["hello"]}, {c: HelloWorld, name: "HelloWorld", aliases: ["hello"]},
@ -46,12 +44,7 @@ class BinStore {
{c: PFClient, name: "PFClient", aliases: ["pfclient"]} {c: PFClient, name: "PFClient", aliases: ["pfclient"]}
]; ];
@:allow(kernel.Init) public static function getBinByName(name:String):Null<Bin> {
private function new() {
}
public function getBinByName(name:String):Null<Bin> {
for (bin in store) { for (bin in store) {
if (bin.name == name) { if (bin.name == name) {
return bin; return bin;
@ -60,7 +53,7 @@ class BinStore {
return null; return null;
} }
public function getBinByAlias(alias:String):Null<Bin> { public static function getBinByAlias(alias:String):Null<Bin> {
for (bin in store) { for (bin in store) {
for (a in bin.aliases) { for (a in bin.aliases) {
if (a == alias) { if (a == alias) {
@ -71,7 +64,7 @@ class BinStore {
return null; return null;
} }
public function getNameByAlias(alias: String): String { public static function getNameByAlias(alias: String): String {
var bin = getBinByAlias(alias); var bin = getBinByAlias(alias);
if (bin == null) { if (bin == null) {
return null; return null;

View File

@ -21,7 +21,7 @@ class Service {
} }
public function start() { public function start() {
var bin = BinStore.instance.getBinByAlias(this.binName); var bin = BinStore.getBinByAlias(this.binName);
if (bin == null){ if (bin == null){
throw new Error('Bin ${this.binName} not found'); throw new Error('Bin ${this.binName} not found');

View File

@ -67,7 +67,7 @@ class ServiceManager {
} }
public function register(name: String, binName: String,args: Array<String>): Outcome<Noise,String> { public function register(name: String, binName: String,args: Array<String>): Outcome<Noise,String> {
if (BinStore.instance.getBinByAlias(binName) == null){ if (BinStore.getBinByAlias(binName) == null){
return Failure("bin not found"); return Failure("bin not found");
} }

View File

@ -105,7 +105,7 @@ class HomeContext {
} }
private function spawnPs(binName: String) { private function spawnPs(binName: String) {
var bin = BinStore.instance.getBinByAlias(binName); var bin = BinStore.getBinByAlias(binName);
if (bin == null) { if (bin == null) {
Log.error('Could not find bin: ${binName}'); Log.error('Could not find bin: ${binName}');
@ -159,7 +159,7 @@ class HomeContext {
for (i in 0...listedApps.length) { for (i in 0...listedApps.length) {
children.push(new TextElement( children.push(new TextElement(
'Add ${BinStore.instance.getNameByAlias(listedApps[i])}', 'Add ${BinStore.getNameByAlias(listedApps[i])}',
{uiEvents: {onClick: this.spawnPs.bind(listedApps[i])}} {uiEvents: {onClick: this.spawnPs.bind(listedApps[i])}}
)); ));
} }