use new core class from runtime

This commit is contained in:
SrGooglo 2025-02-05 02:42:09 +00:00
parent 29e3ad5878
commit 11b52595c1
15 changed files with 99 additions and 82 deletions

View File

@ -1,4 +1,4 @@
import { Core } from "vessel"
import { Core } from "@ragestudio/vessel"
import createClient from "comty.js"
@ -8,87 +8,99 @@ import useRequest from "comty.js/hooks/useRequest"
import { reconnectWebsockets, disconnectWebsockets } from "comty.js"
export default class APICore extends Core {
static namespace = "api"
static namespace = "api"
static bgColor = "coral"
static textColor = "black"
static bgColor = "coral"
static textColor = "black"
client = null
client = null
public = {
client: function () {
return this.client
}.bind(this),
customRequest: request,
listenEvent: this.listenEvent.bind(this),
unlistenEvent: this.unlistenEvent.bind(this),
measurePing: measurePing,
useRequest: useRequest,
reconnectWebsockets: reconnectWebsockets,
disconnectWebsockets: disconnectWebsockets,
}
public = {
client: function () {
return this.client
}.bind(this),
customRequest: request,
listenEvent: this.listenEvent.bind(this),
unlistenEvent: this.unlistenEvent.bind(this),
measurePing: measurePing,
useRequest: useRequest,
reconnectWebsockets: reconnectWebsockets,
disconnectWebsockets: disconnectWebsockets,
}
listenEvent(key, handler, instance = "default") {
if (!this.client.sockets[instance]) {
this.console.error(`[API] Websocket instance ${instance} not found`)
registerSocketListeners = (map) => {
Object.entries(map).forEach(([namespace, listeners]) => {
Object.entries(listeners).forEach(([event, handler]) => {
this.listenEvent(event, handler, namespace)
})
})
}
return false
}
listenEvent(key, handler, instance = "default") {
if (!this.client.sockets[instance]) {
this.console.error(`[API] Websocket instance ${instance} not found`)
return this.client.sockets[instance].on(key, handler)
}
return false
}
unlistenEvent(key, handler, instance = "default") {
if (!this.client.sockets[instance]) {
this.console.error(`[API] Websocket instance ${instance} not found`)
return this.client.sockets[instance].on(key, handler)
}
return false
}
unlistenEvent(key, handler, instance = "default") {
if (!this.client.sockets[instance]) {
this.console.error(`[API] Websocket instance ${instance} not found`)
return this.client.sockets[instance].off(key, handler)
}
return false
}
async onInitialize() {
this.client = await createClient({
enableWs: true,
})
return this.client.sockets[instance].off(key, handler)
}
this.client.eventBus.on("ws:disconnected", () => {
app.cores.notifications.new({
title: "Failed to connect to server",
description: "The connection to the server was lost. Some features may not work properly.",
})
})
async onInitialize() {
this.client = await createClient({
enableWs: true,
//origin: "https://indev.comty.app/api"
})
this.client.eventBus.on("auth:login_success", () => {
app.eventBus.emit("auth:login_success")
})
this.client.eventBus.on("ws:disconnected", () => {
app.cores.notifications.new({
title: "Failed to connect to server",
description:
"The connection to the server was lost. Some features may not work properly.",
})
})
this.client.eventBus.on("auth:logout_success", () => {
app.eventBus.emit("auth:logout_success")
})
this.client.eventBus.on("auth:login_success", () => {
app.eventBus.emit("auth:login_success")
})
this.client.eventBus.on("session.invalid", (error) => {
app.eventBus.emit("session.invalid", error)
})
this.client.eventBus.on("auth:logout_success", () => {
app.eventBus.emit("auth:logout_success")
})
this.client.eventBus.on("auth:disabled_account", () => {
app.eventBus.emit("auth:disabled_account")
})
this.client.eventBus.on("session.invalid", (error) => {
app.eventBus.emit("session.invalid", error)
})
// make a basic request to check if the API is available
await this.client.baseRequest({
method: "head",
url: "/",
}).catch((error) => {
this.console.error("[API] Ping error", error)
this.client.eventBus.on("auth:disabled_account", () => {
app.eventBus.emit("auth:disabled_account")
})
throw new Error(`
Could not connect to the API.
// make a basic request to check if the API is available
await this.client
.baseRequest({
method: "head",
url: "/",
})
.catch((error) => {
this.console.error("[API] Ping error", error)
throw new Error(`
Could not connect to the API.
Please check your connection and try again.
`)
})
})
return this.client
}
}
return this.client
}
}

View File

@ -1,6 +1,6 @@
import React from "react"
import { Core, EventBus } from "vessel"
import { Core, EventBus } from "@ragestudio/vessel"
import ContextMenu from "./components/contextMenu"

View File

@ -1,4 +1,4 @@
import { Core } from "vessel"
import { Core } from "@ragestudio/vessel"
import { FFmpeg } from "@ffmpeg/ffmpeg"
import { fetchFile, toBlobURL } from "@ffmpeg/util"
import isURL from "@utils/isURL"

View File

@ -1,4 +1,4 @@
import { Core } from "vessel"
import { Core } from "@ragestudio/vessel"
import { Haptics } from "@capacitor/haptics"
const vibrationPatterns = {

View File

@ -1,4 +1,4 @@
import { Core } from "vessel"
import { Core } from "@ragestudio/vessel"
import i18n from "i18next"
import { initReactI18next } from "react-i18next"

View File

@ -1,4 +1,4 @@
import { Core } from "vessel"
import { Core } from "@ragestudio/vessel"
import TapShareDialog from "@components/TapShare/Dialog"
const RecordTypes = {

View File

@ -1,4 +1,4 @@
import { Core } from "vessel"
import { Core } from "@ragestudio/vessel"
import NotificationUI from "./ui"
import NotificationFeedback from "./feedback"
@ -10,13 +10,14 @@ export default class NotificationCore extends Core {
"settings",
]
#newNotifications = []
listenSockets = {
"notifications": {
"notification.new": (data) => {
this.new(data)
}
},
"notification.broadcast": (data) => {
this.new(data)
},
}
}
@ -25,6 +26,10 @@ export default class NotificationCore extends Core {
close: this.close,
}
async onInitialize() {
this.ctx.CORES.api.registerSocketListeners(this.listenSockets)
}
async new(notification) {
NotificationUI.notify(notification)
NotificationFeedback.feedback(notification)

View File

@ -1,4 +1,4 @@
import { Core } from "vessel"
import { Core } from "@ragestudio/vessel"
import store from "store"
import { Observable } from "rxjs"

View File

@ -1,4 +1,4 @@
import { Core } from "vessel"
import { Core } from "@ragestudio/vessel"
import { Howl } from "howler"
import axios from "axios"
import store from "store"

View File

@ -1,4 +1,4 @@
import { Core } from "vessel"
import { Core } from "@ragestudio/vessel"
export default class ShortcutsCore extends Core {
static namespace = "shortcuts"

View File

@ -1,5 +1,5 @@
import React from "react"
import { Core } from "vessel"
import { Core } from "@ragestudio/vessel"
import { ConfigProvider, theme } from "antd"
import store from "store"

View File

@ -1,4 +1,4 @@
import { Core } from "vessel"
import { Core } from "@ragestudio/vessel"
import SyncModel from "comty.js/models/sync"
export default class SyncCore extends Core {

View File

@ -1,4 +1,4 @@
import { Core } from "vessel"
import { Core } from "@ragestudio/vessel"
import { Observable } from "object-observer"
export default class TasksQueue extends Core {

View File

@ -1,4 +1,4 @@
import { Core } from "vessel"
import { Core } from "@ragestudio/vessel"
import store from "store"
export default class WidgetsCore extends Core {

View File

@ -1,5 +1,5 @@
import React from "react"
import { Core } from "vessel"
import { Core } from "@ragestudio/vessel"
import { createRoot } from "react-dom/client"