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" import createClient from "comty.js"
@ -28,6 +28,14 @@ export default class APICore extends Core {
disconnectWebsockets: disconnectWebsockets, disconnectWebsockets: disconnectWebsockets,
} }
registerSocketListeners = (map) => {
Object.entries(map).forEach(([namespace, listeners]) => {
Object.entries(listeners).forEach(([event, handler]) => {
this.listenEvent(event, handler, namespace)
})
})
}
listenEvent(key, handler, instance = "default") { listenEvent(key, handler, instance = "default") {
if (!this.client.sockets[instance]) { if (!this.client.sockets[instance]) {
this.console.error(`[API] Websocket instance ${instance} not found`) this.console.error(`[API] Websocket instance ${instance} not found`)
@ -51,12 +59,14 @@ export default class APICore extends Core {
async onInitialize() { async onInitialize() {
this.client = await createClient({ this.client = await createClient({
enableWs: true, enableWs: true,
//origin: "https://indev.comty.app/api"
}) })
this.client.eventBus.on("ws:disconnected", () => { this.client.eventBus.on("ws:disconnected", () => {
app.cores.notifications.new({ app.cores.notifications.new({
title: "Failed to connect to server", title: "Failed to connect to server",
description: "The connection to the server was lost. Some features may not work properly.", description:
"The connection to the server was lost. Some features may not work properly.",
}) })
}) })
@ -77,10 +87,12 @@ export default class APICore extends Core {
}) })
// make a basic request to check if the API is available // make a basic request to check if the API is available
await this.client.baseRequest({ await this.client
.baseRequest({
method: "head", method: "head",
url: "/", url: "/",
}).catch((error) => { })
.catch((error) => {
this.console.error("[API] Ping error", error) this.console.error("[API] Ping error", error)
throw new Error(` throw new Error(`

View File

@ -1,6 +1,6 @@
import React from "react" import React from "react"
import { Core, EventBus } from "vessel" import { Core, EventBus } from "@ragestudio/vessel"
import ContextMenu from "./components/contextMenu" 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 { FFmpeg } from "@ffmpeg/ffmpeg"
import { fetchFile, toBlobURL } from "@ffmpeg/util" import { fetchFile, toBlobURL } from "@ffmpeg/util"
import isURL from "@utils/isURL" 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" import { Haptics } from "@capacitor/haptics"
const vibrationPatterns = { const vibrationPatterns = {

View File

@ -1,4 +1,4 @@
import { Core } from "vessel" import { Core } from "@ragestudio/vessel"
import i18n from "i18next" import i18n from "i18next"
import { initReactI18next } from "react-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" import TapShareDialog from "@components/TapShare/Dialog"
const RecordTypes = { const RecordTypes = {

View File

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

View File

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

View File

@ -1,4 +1,4 @@
import { Core } from "vessel" import { Core } from "@ragestudio/vessel"
import { Howl } from "howler" import { Howl } from "howler"
import axios from "axios" import axios from "axios"
import store from "store" 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 { export default class ShortcutsCore extends Core {
static namespace = "shortcuts" static namespace = "shortcuts"

View File

@ -1,5 +1,5 @@
import React from "react" import React from "react"
import { Core } from "vessel" import { Core } from "@ragestudio/vessel"
import { ConfigProvider, theme } from "antd" import { ConfigProvider, theme } from "antd"
import store from "store" 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" import SyncModel from "comty.js/models/sync"
export default class SyncCore extends Core { 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" import { Observable } from "object-observer"
export default class TasksQueue extends Core { 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" import store from "store"
export default class WidgetsCore extends Core { export default class WidgetsCore extends Core {

View File

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