Skip to content
This repository has been archived by the owner on Nov 23, 2023. It is now read-only.

Attempt to fix Blix instantiation order #82

Merged
merged 1 commit into from
Jul 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions src/electron/lib/Blix.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CommandRegistry } from "./registries/CommandRegistry";
import { NodeInstance, ToolboxRegistry } from "./registries/ToolboxRegistry";

Check warning on line 2 in src/electron/lib/Blix.ts

View workflow job for this annotation

GitHub Actions / Lint Electron

'NodeInstance' is defined but never used
import { TileRegistry } from "./registries/TileRegistry";
import { ProjectManager } from "./projects/ProjectManager";
import type { MainWindow } from "./api/apis/WindowApi";
Expand All @@ -9,9 +9,9 @@
import type { UUID } from "../../shared/utils/UniqueEntity";
import type { UIGraph } from "../../shared/ui/UIGraph";
import { blixCommands } from "./BlixCommands";
import logger from "../utils/logger";

Check warning on line 12 in src/electron/lib/Blix.ts

View workflow job for this annotation

GitHub Actions / Lint Electron

'logger' is defined but never used
import { AiManager } from "./ai/AiManager";
import { NodeBuilder, NodeUIBuilder } from "./plugins/builders/NodeBuilder";

Check warning on line 14 in src/electron/lib/Blix.ts

View workflow job for this annotation

GitHub Actions / Lint Electron

'NodeBuilder' is defined but never used

Check warning on line 14 in src/electron/lib/Blix.ts

View workflow job for this annotation

GitHub Actions / Lint Electron

'NodeUIBuilder' is defined but never used

// Encapsulates the backend representation for
// the entire running Blix application
Expand Down Expand Up @@ -60,14 +60,8 @@
// this._aiManager = new AiManager(mainWindow);
this._projectManager = new ProjectManager(mainWindow);

// Add subscribers
const graphSubscriber = new IPCGraphSubscriber();

graphSubscriber.listen = (graphId: UUID, newGraph: UIGraph) => {
mainWindow.apis.graphClientApi.graphChanged(graphId, newGraph);
};

this._graphManager.addAllSubscriber(graphSubscriber);
this.initSubscribers();
Rec1dite marked this conversation as resolved.
Show resolved Hide resolved
mainWindow.apis.utilClientApi.onBlixReady();

// testStuffies(this);

Expand All @@ -84,6 +78,16 @@
// }, 3000);
}

private initSubscribers() {
const graphSubscriber = new IPCGraphSubscriber();

graphSubscriber.listen = (graphId: UUID, newGraph: UIGraph) => {
this.mainWindow?.apis.graphClientApi.graphChanged(graphId, newGraph);
};

this._graphManager.addAllSubscriber(graphSubscriber);
}

// TODO: Move these to a Utils.ts or something like that
sendInformationMessage(message: string) {
this._mainWindow.apis.utilClientApi.showToast({ message, type: "info" });
Expand Down
10 changes: 1 addition & 9 deletions src/electron/lib/api/MainApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,7 @@ export function exposeMainApis(blix: Blix) {

// @ts-ignore: no-var-requires
global.mainApis = apis as any;

// Return callback to initialize APIs
// once everything else is ready
return async () => {
// apis.projectApi.init();
// apis.pluginApi.init();
apis.graphApi.init();
// apis.toolboxApi.init();
};
return apis;
}

export type MainApis = ReturnType<typeof exposeMainApis>;
Expand Down
11 changes: 0 additions & 11 deletions src/electron/lib/api/apis/GraphApi.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,17 @@
import type { ElectronMainApi } from "electron-affinity/main";
import type { Blix } from "../../Blix";
import { type UUID } from "../../../../shared/utils/UniqueEntity";
import { IPCGraphSubscriber } from "../../core-graph/CoreGraphInteractors";

Check warning on line 4 in src/electron/lib/api/apis/GraphApi.ts

View workflow job for this annotation

GitHub Actions / Lint Electron

'IPCGraphSubscriber' is defined but never used
import { UIGraph } from "@shared/ui/UIGraph";

Check warning on line 5 in src/electron/lib/api/apis/GraphApi.ts

View workflow job for this annotation

GitHub Actions / Lint Electron

'UIGraph' is defined but never used
import { NodeInstance } from "../../registries/ToolboxRegistry";

Check warning on line 6 in src/electron/lib/api/apis/GraphApi.ts

View workflow job for this annotation

GitHub Actions / Lint Electron

'NodeInstance' is defined but never used
import { type NodeSignature } from "@shared/ui/ToolboxTypes";

// Graphs across projects are stored homogeneously and referenced by UUID
export class GraphApi implements ElectronMainApi<GraphApi> {
private readonly _blix: Blix;
private readonly graphSubscriber: IPCGraphSubscriber;
Rec1dite marked this conversation as resolved.
Show resolved Hide resolved

constructor(blix: Blix) {
this._blix = blix;
this.graphSubscriber = new IPCGraphSubscriber();
}

// Called in index.ts after Blix has been initialized
async init() {
// Add IPC subscriber to listen for graph changes and alert the frontend
this._blix.graphManager.addAllSubscriber(this.graphSubscriber);
this.graphSubscriber.listen = (graphId: UUID, newGraph: UIGraph) => {
this._blix.mainWindow?.apis.graphClientApi.graphChanged(graphId, newGraph);
};
}

// TODO: Implement these properly
Expand Down
56 changes: 0 additions & 56 deletions src/frontend/lib/Blix.ts

This file was deleted.

7 changes: 1 addition & 6 deletions src/frontend/lib/api/apiInitializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,16 @@ import type { ToolboxApi } from "@electron/lib/api/apis/ToolboxApi";

// Window APIs
import { CommandClientApi } from "./apis/CommandClientApi";

// stores
import { blixStore } from "../stores/BlixStore";
import { commandStore } from "../stores/CommandStore";
import { GraphClientApi } from "./apis/GraphClientApi";
import { ProjectClientApi } from "./apis/ProjectClientApi";
import { UtilClientApi } from "./apis/UtilClientApi";
import { toolboxStore } from "../stores/ToolboxStore";
import { ToolboxClientApi } from "./apis/ToolboxClientApi";

/**
* Initializes the application by exposing the window IPC APIs to the main
* process and binding the main process IPC APIs to the window.
*/
export async function initializeAPIs() {
export async function initAPIs() {
exposeWindowApis();
window.apis = await bindMainApis();
}
Expand Down
6 changes: 6 additions & 0 deletions src/frontend/lib/api/apis/UtilClientApi.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import type { ElectronWindowApi } from "electron-affinity/window";
import { toastStore, type ToastOptions } from "../../stores/ToastStore";
import { blixStore, setInitialStores } from "../../../lib/stores/BlixStore";

export class UtilClientApi implements ElectronWindowApi<UtilClientApi> {
showToast(options: Partial<ToastOptions>) {
toastStore.trigger(options);
}

async onBlixReady() {
await setInitialStores();
blixStore.update((state) => ({ ...state, blixReady: true }));
}
}
41 changes: 41 additions & 0 deletions src/frontend/lib/stores/BlixStore.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { writable } from "svelte/store";
import { commandStore } from "./CommandStore";
import { toolboxStore } from "./ToolboxStore";

interface BlixStore {
blixReady: boolean;
systemInfo: {
nodeVersion: string;
systemPlatform: string;
Expand All @@ -12,10 +15,48 @@ interface BlixStore {
// Currently used to store some startup config. Can potentially be used to store
// some other global state in the future.
export const blixStore = writable<BlixStore>({
blixReady: false,
systemInfo: {
nodeVersion: "",
systemPlatform: "",
systemType: "",
systemVersion: "",
},
});

export async function setInitialStores() {
// BLix store
const res = await window.apis.utilApi.getSystemInfo();
blixStore.update((state) => ({ ...state, systemInfo: res }));

// Command store
const command = await window.apis.commandApi.getCommands();
commandStore.refreshStore(command);

// Toolbox store
const node = await window.apis.toolboxApi.getNodes();
toolboxStore.refreshStore(node);

// Graph store
// const allGraphIds = await window.apis.graphApi.getAllGraphUUIDs();
// console.log("ALL GRAPHS", allGraphIds);

// for (const graphId of allGraphIds) {
// const graph = await window.apis.graphApi.getGraph(graphId);
// console.log("BACKEND GRAPH", graph.getNodes);

// TODO: REMOVE; This is just for testing
// const uiGraph = new UIGraph(graphId);
// const node1 = new GraphNode("1");
// const node2 = new GraphNode("2");
// const node3 = new GraphNode("a");
// uiGraph.nodes[node1.uuid] = node1;
// uiGraph.nodes[node2.uuid] = node2;
// uiGraph.nodes[node3.uuid] = node3;
// node1.pos.x = 100;
// node1.pos.y = 100;

// graphMall.refreshGraph(uiGraph.uuid, uiGraph);
// }
// exportLayout()
}
23 changes: 10 additions & 13 deletions src/frontend/ui/base/App.svelte
Original file line number Diff line number Diff line change
@@ -1,46 +1,43 @@
<script lang="ts">
import { onMount } from "svelte";
import { init } from "../../lib/Blix";
import { blixStore } from "../../lib/stores/BlixStore";
import Navbar from "./Navbar.svelte";
import Layout from "./layout/Layout.svelte";
import Palette from "./palette/Palette.svelte";
import Toasts from "../../ui/utils/toasts/Toasts.svelte";
import { initAPIs } from "lib/api/apiInitializer";

import Test from "./Test.svelte";

let isLoading = false;
const testing = false;

onMount(async () => {
isLoading = true;
await init();
isLoading = false;
await initAPIs();
});
</script>

<Toasts />

{#if testing}
{#if isLoading}
{#if $blixStore.blixReady}
<Test />
{:else}
<div class="flex h-screen w-screen items-center justify-center bg-zinc-800 p-0">
<span class="text-5xl text-purple-400">Loading</span>
</div>
{:else}
<Test />
{/if}
{:else if isLoading}
<div class="flex h-screen w-screen items-center justify-center bg-zinc-800 p-0">
<span class="text-5xl text-purple-400">Loading</span>
</div>
{:else}
{:else if $blixStore.blixReady}
<div class="h-screen w-screen bg-zinc-800 p-0">
<div class="navbar {$blixStore.systemInfo.systemPlatform === 'darwin' ? 'pl-20' : ''}">
<Navbar />
</div>
<div class="layout"><Layout /></div>
<Palette />
</div>
{:else}
<div class="flex h-screen w-screen items-center justify-center bg-zinc-800 p-0">
<span class="text-5xl text-purple-400">Loading</span>
</div>
{/if}

<style lang="postcss" global>
Expand Down
3 changes: 1 addition & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,11 @@ app.on("ready", async () => {
// coreGraphInterpreter.run();

blix = new Blix();
const initMainApis = exposeMainApis(blix);
Rec1dite marked this conversation as resolved.
Show resolved Hide resolved
exposeMainApis(blix);

createMainWindow().then(async () => {
if (mainWindow) {
await blix.init(mainWindow);
initMainApis();
} else {
app.quit();
}
Expand Down
Loading