From c9c13e895c060b572257c16bd5a58f258bc45cf8 Mon Sep 17 00:00:00 2001 From: srgooglo Date: Mon, 30 May 2022 22:27:50 +0200 Subject: [PATCH 1/4] fix constructor --- packages/app/src/cores/api/index.js | 43 +++++++++++++++-------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/packages/app/src/cores/api/index.js b/packages/app/src/cores/api/index.js index b7c4cdf4..126b0b83 100644 --- a/packages/app/src/cores/api/index.js +++ b/packages/app/src/cores/api/index.js @@ -4,45 +4,46 @@ import { Bridge } from "linebridge/dist/client" import { Session } from "models" export default class ApiCore extends Core { - apiBridge = this.createBridge() + constructor(props) { + super(props) - WSInterface = { - ...this.apiBridge.wsInterface, - request: this.WSRequest, - listen: this.handleWSListener, - mainSocketConnected: false + this.apiBridge = this.createBridge() + + this.WSInterface = { + ...this.apiBridge.wsInterface, + request: this.WSRequest, + listen: this.handleWSListener, + mainSocketConnected: false + } + + this.ctx.registerPublicMethod("api", this.apiBridge) + this.ctx.registerPublicMethod("ws", this.WSInterface) + this.ctx.registerPublicMethod("request", this.apiBridge.endpoints) + this.ctx.registerPublicMethod("WSRequest", this.WSInterface.wsEndpoints) } - WSSockets = this.WSInterface.sockets - - publicMethods = { - api: this.apiBridge, - ws: this.WSInterface, - request: this.apiBridge.endpoints, - WSRequest: this.WSInterface.wsEndpoints, - } - - async initialize() { - this.WSSockets.main.on("authenticated", () => { + async intialize() { + console.log(this.apiBridge) + this.WSInterface.sockets.main.on("authenticated", () => { console.debug("[WS] Authenticated") }) - this.WSSockets.main.on("authenticateFailed", (error) => { + this.WSInterface.sockets.main.on("authenticateFailed", (error) => { console.error("[WS] Authenticate Failed", error) }) - this.WSSockets.main.on("connect", () => { + this.WSInterface.sockets.main.on("connect", () => { this.ctx.eventBus.emit("websocket_connected") this.WSInterface.mainSocketConnected = true }) - this.WSSockets.main.on("disconnect", (...context) => { + this.WSInterface.sockets.main.on("disconnect", (...context) => { this.ctx.eventBus.emit("websocket_disconnected", ...context) this.WSInterface.mainSocketConnected = false }) - this.WSSockets.main.on("connect_error", (...context) => { + this.WSInterface.sockets.main.on("connect_error", (...context) => { this.ctx.eventBus.emit("websocket_connection_error", ...context) this.WSInterface.mainSocketConnected = false From b020f4018b044767529e5b1e4ed551bb6811ee45 Mon Sep 17 00:00:00 2001 From: srgooglo Date: Mon, 30 May 2022 22:28:00 +0200 Subject: [PATCH 2/4] fix bindContext --- packages/app/src/cores/render/index.jsx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/app/src/cores/render/index.jsx b/packages/app/src/cores/render/index.jsx index ff6e49dc..72205d88 100644 --- a/packages/app/src/cores/render/index.jsx +++ b/packages/app/src/cores/render/index.jsx @@ -8,7 +8,7 @@ import NotFoundRender from "./staticsRenders/404" import CrashRender from "./staticsRenders/crash" export const ConnectWithApp = (component) => { - return window.app.bindContexts(component) + return RenderCore.bindContexts(component) } export function GetRoutesComponentMap() { @@ -108,7 +108,7 @@ export class RenderCore extends Core { progressBar = progressBar.configure({ parent: "html", showSpinner: false }) publicMethods = { - setLocation: this.ctx.history.setLocation, + bindContexts: RenderCore.bindContexts, } initialize = () => { @@ -138,6 +138,8 @@ export class RenderCore extends Core { this.ctx.history.lastLocation = this.history.location }, delay ?? defaultTransitionDelay) } + + this.ctx.registerPublicMethod("setLocation", this.publicMethods.setLocation) } validateLocationSlash = (location) => { @@ -150,7 +152,7 @@ export class RenderCore extends Core { return key } - bindContexts = (component) => { + static bindContexts = (component) => { let contexts = { main: {}, app: {}, From 4f1098af9e28baad1bd142e30b0e820888437f3c Mon Sep 17 00:00:00 2001 From: srgooglo Date: Mon, 30 May 2022 22:28:17 +0200 Subject: [PATCH 3/4] use correct cores to initialize app --- packages/app/src/App.jsx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/app/src/App.jsx b/packages/app/src/App.jsx index f48bf090..f3b28096 100644 --- a/packages/app/src/App.jsx +++ b/packages/app/src/App.jsx @@ -298,7 +298,7 @@ class App extends React.Component { const initializationTasks = [ async () => { try { - await app.ApiController.attachAPIConnection() + await this.props.cores.ApiCore.attachAPIConnection() app.eventBus.emit("app.initialization.api_success") } catch (error) { @@ -306,7 +306,7 @@ class App extends React.Component { throw { cause: "Cannot connect to API", - details: error.message, + details: error.stack, } } }, @@ -357,8 +357,8 @@ class App extends React.Component { await Promise.tasked(initializationTasks).catch((reason) => { console.error(`[App] Initialization failed: ${reason.cause}`) app.eventBus.emit("runtime.crash", { - message: `App initialization failed`, - details: reason.cause, + message: `App initialization failed (${reason.cause})`, + details: reason.details, }) }) } @@ -384,7 +384,7 @@ class App extends React.Component { return false } - await app.ApiController.attachWSConnection() + await this.props.cores.ApiCore.attachWSConnection() } __UserInit = async () => { From eb17c036a20293f82b2e8847b2ace4ce71609bb6 Mon Sep 17 00:00:00 2001 From: srgooglo Date: Mon, 30 May 2022 22:29:53 +0200 Subject: [PATCH 4/4] fix setLocation --- packages/app/src/cores/render/index.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/app/src/cores/render/index.jsx b/packages/app/src/cores/render/index.jsx index 72205d88..6f347245 100644 --- a/packages/app/src/cores/render/index.jsx +++ b/packages/app/src/cores/render/index.jsx @@ -139,7 +139,7 @@ export class RenderCore extends Core { }, delay ?? defaultTransitionDelay) } - this.ctx.registerPublicMethod("setLocation", this.publicMethods.setLocation) + this.ctx.registerPublicMethod("setLocation", this.ctx.history.setLocation) } validateLocationSlash = (location) => {