diff --git a/packages/app/src/cores/api/api.core.js b/packages/app/src/cores/api/api.core.js index ed11dcad..db9fe271 100644 --- a/packages/app/src/cores/api/api.core.js +++ b/packages/app/src/cores/api/api.core.js @@ -8,9 +8,11 @@ import useRequest from "comty.js/hooks/useRequest" import { reconnectWebsockets } from "comty.js" export default class APICore extends Core { - static refName = "api" static namespace = "api" + static bgColor = "coral" + static textColor = "black" + instance = null public = { @@ -37,7 +39,7 @@ export default class APICore extends Core { createPingIntervals() { Object.keys(this.instance.wsInstances).forEach((instance) => { - console.debug(`[API] Creating ping interval for ${instance}`) + this.console.debug(`[API] Creating ping interval for ${instance}`) if (this.instance.wsInstances[instance].pingInterval) { clearInterval(this.instance.wsInstances[instance].pingInterval) @@ -45,14 +47,14 @@ export default class APICore extends Core { this.instance.wsInstances[instance].pingInterval = setInterval(() => { if (this.instance.wsInstances[instance].pendingPingTry && this.instance.wsInstances[instance].pendingPingTry > 3) { - console.debug(`[API] Ping timeout for ${instance}`) + this.console.debug(`[API] Ping timeout for ${instance}`) return clearInterval(this.instance.wsInstances[instance].pingInterval) } const timeStart = Date.now() - //console.debug(`[API] Ping ${instance}`, this.instance.wsInstances[instance].pendingPingTry) + //this.console.debug(`[API] Ping ${instance}`, this.instance.wsInstances[instance].pendingPingTry) this.instance.wsInstances[instance].emit("ping", () => { this.instance.wsInstances[instance].latency = Date.now() - timeStart @@ -92,7 +94,7 @@ export default class APICore extends Core { method: "GET", url: "/ping", }).catch((error) => { - console.error("[API] Ping error", error) + this.console.error("[API] Ping error", error) throw new Error(` Could not connect to the API. @@ -100,7 +102,7 @@ export default class APICore extends Core { `) }) - console.debug("[API] Attached to", this.instance) + this.console.debug("[API] Attached to", this.instance) this.createPingIntervals() diff --git a/packages/app/src/cores/contextMenu/context_menu.core.js b/packages/app/src/cores/contextMenu/context_menu.core.js index 93ce9569..78a09f05 100755 --- a/packages/app/src/cores/contextMenu/context_menu.core.js +++ b/packages/app/src/cores/contextMenu/context_menu.core.js @@ -7,7 +7,6 @@ import ContextMenu from "./components/contextMenu" import InternalContexts from "schemas/menu-contexts" export default class ContextMenuCore extends Core { - static refName = "contextMenu" static namespace = "contextMenu" public = { @@ -26,7 +25,7 @@ export default class ContextMenuCore extends Core { async onInitialize() { if (app.isMobile) { - console.warn("Context menu is not available on mobile") + this.console.warn("Context menu is not available on mobile") return false } @@ -125,7 +124,7 @@ export default class ContextMenuCore extends Core { const items = await this.generateItems(component) if (!items) { - console.warn("No context menu items found, aborting") + this.console.warn("No context menu items found, aborting") return false } diff --git a/packages/app/src/cores/haptics/haptics.core.js b/packages/app/src/cores/haptics/haptics.core.js index b21b50f5..23978b63 100644 --- a/packages/app/src/cores/haptics/haptics.core.js +++ b/packages/app/src/cores/haptics/haptics.core.js @@ -9,8 +9,8 @@ const vibrationPatterns = { } export default class HapticsCore extends Core { - static refName = "haptics" static namespace = "haptics" + static dependencies = [ "settings" ] diff --git a/packages/app/src/cores/i18n/i18n.core.js b/packages/app/src/cores/i18n/i18n.core.js index 241b235e..f12f3c09 100755 --- a/packages/app/src/cores/i18n/i18n.core.js +++ b/packages/app/src/cores/i18n/i18n.core.js @@ -15,7 +15,7 @@ export function extractLocaleFromPath(path = "") { const messageImports = import.meta.glob("schemas/translations/*.json") export default class I18nCore extends Core { - static refName = "i18n" + static namespace = "i18n" onEvents = { "changeLanguage": (locale) => { @@ -67,7 +67,7 @@ export default class I18nCore extends Core { i18n.changeLanguage(locale) } } catch (error) { - console.error(error) + this.console.error(error) } } } \ No newline at end of file diff --git a/packages/app/src/cores/nfc/nfc.core.js b/packages/app/src/cores/nfc/nfc.core.js index 759dd354..2132455b 100644 --- a/packages/app/src/cores/nfc/nfc.core.js +++ b/packages/app/src/cores/nfc/nfc.core.js @@ -77,8 +77,6 @@ function parseNdefMessage(ndefMessage) { } export default class NFC extends Core { - static refName = "NFC" - static namespace = "nfc" isNativeMode = false @@ -141,7 +139,7 @@ export default class NFC extends Core { this.public.scanning = false this.public.incompatible = true - console.error(error) + this.console.error(error) } } @@ -153,7 +151,7 @@ export default class NFC extends Core { } handleRead(tag) { - console.debug(`[NFC] READ >`, tag) + this.console.debug(`[NFC] READ >`, tag) // send to subscribers this.subscribers.forEach((subscriber) => { @@ -173,7 +171,7 @@ export default class NFC extends Core { } handleNativeRead(tag) { - console.debug(`[NFC] NATIVE READ >`, tag) + this.console.debug(`[NFC] NATIVE READ >`, tag) tag.serialNumber = resolveSerialNumber(tag) @@ -230,7 +228,7 @@ export default class NFC extends Core { } async writeNdef(payload, options) { - console.debug(`[NFC] WRITE >`, payload) + this.console.debug(`[NFC] WRITE >`, payload) if (!this.isNativeMode) { return this.instance.write(payload, options) diff --git a/packages/app/src/cores/notifications/notifications.core.jsx b/packages/app/src/cores/notifications/notifications.core.jsx index b5b5d12c..b0034322 100755 --- a/packages/app/src/cores/notifications/notifications.core.jsx +++ b/packages/app/src/cores/notifications/notifications.core.jsx @@ -13,7 +13,7 @@ const NotfTypeToAudio = { } export default class NotificationCore extends Core { - static refName = "notifications" + static namespace = "notifications" onEvents = { "changeNotificationsSoundVolume": (value) => { diff --git a/packages/app/src/cores/permissions/permissions.core.js b/packages/app/src/cores/permissions/permissions.core.js index bd09389e..54da853a 100755 --- a/packages/app/src/cores/permissions/permissions.core.js +++ b/packages/app/src/cores/permissions/permissions.core.js @@ -4,8 +4,8 @@ import UserModel from "models/user" import SessionModel from "models/session" export default class PermissionsCore extends Core { - static refName = "permissions" static namespace = "permissions" + static dependencies = ["api"] public = { diff --git a/packages/app/src/cores/remoteStorage/remoteStorage.core.js b/packages/app/src/cores/remoteStorage/remoteStorage.core.js index 06de5918..63fa9bf2 100755 --- a/packages/app/src/cores/remoteStorage/remoteStorage.core.js +++ b/packages/app/src/cores/remoteStorage/remoteStorage.core.js @@ -151,7 +151,7 @@ class ChunkedUpload { .catch((err) => { if (this.paused || this.offline) return - console.error(err) + this.console.error(err) // this type of error can happen after network disconnection on CORS setup this.manageRetries() @@ -208,7 +208,7 @@ export default class RemoteStorage extends Core { }) uploader.on("error", ({ message }) => { - console.error("[Uploader] Error", message) + this.console.error("[Uploader] Error", message) if (typeof onError === "function") { onError(file, message) @@ -219,7 +219,7 @@ export default class RemoteStorage extends Core { }) uploader.on("progress", ({ percentProgress }) => { - //console.debug(`[Uploader] Progress: ${percentProgress}%`) + //this.console.debug(`[Uploader] Progress: ${percentProgress}%`) if (typeof onProgress === "function") { onProgress(file, percentProgress) @@ -227,7 +227,7 @@ export default class RemoteStorage extends Core { }) uploader.on("finish", (data) => { - console.debug("[Uploader] Finish", data) + this.console.debug("[Uploader] Finish", data) if (typeof onFinish === "function") { onFinish(file, data) diff --git a/packages/app/src/cores/rooms/rooms.core.js b/packages/app/src/cores/rooms/rooms.core.js index d725f84a..c51ec60a 100644 --- a/packages/app/src/cores/rooms/rooms.core.js +++ b/packages/app/src/cores/rooms/rooms.core.js @@ -4,7 +4,6 @@ import remotes from "comty.js/remotes" import SessionModel from "comty.js/models/session" export default class RoomsController extends Core { - static refName = "rooms" static namespace = "rooms" connectedRooms = [] diff --git a/packages/app/src/cores/settings/settings.core.js b/packages/app/src/cores/settings/settings.core.js index 234c0948..b8fee9b8 100755 --- a/packages/app/src/cores/settings/settings.core.js +++ b/packages/app/src/cores/settings/settings.core.js @@ -4,8 +4,6 @@ import defaultSettings from "schemas/defaultSettings.json" import { Observable } from "rxjs" export default class SettingsCore extends Core { - static refName = "settings" - static namespace = "settings" static storeKey = "app_settings" diff --git a/packages/app/src/cores/shortcuts/shortcuts.core.js b/packages/app/src/cores/shortcuts/shortcuts.core.js index 7fbc7132..f31f6230 100755 --- a/packages/app/src/cores/shortcuts/shortcuts.core.js +++ b/packages/app/src/cores/shortcuts/shortcuts.core.js @@ -1,7 +1,6 @@ import Core from "evite/src/core" export default class ShortcutsCore extends Core { - static refName = "shortcuts" static namespace = "shortcuts" public = { @@ -81,7 +80,7 @@ export default class ShortcutsCore extends Core { const register = this.shortcutsRegister.find((handler) => handler.id === id) if (!register) { - console.warn(`Shortcut with id "${id}" not found`) + this.console.warn(`Shortcut with id "${id}" not found`) return false } diff --git a/packages/app/src/cores/sound/sound.core.js b/packages/app/src/cores/sound/sound.core.js index c61d122e..b6e83ad0 100755 --- a/packages/app/src/cores/sound/sound.core.js +++ b/packages/app/src/cores/sound/sound.core.js @@ -5,8 +5,6 @@ import axios from "axios" import store from "store" export default class SoundCore extends Core { - static refName = "sound" - static namespace = "sound" soundsPool = {} @@ -20,7 +18,7 @@ export default class SoundCore extends Core { this.play(audio_id) } } catch (error) { - console.error(error) + this.console.error(error) } }.bind(this) } @@ -49,17 +47,17 @@ export default class SoundCore extends Core { soundpack = data } else { - console.error(`Soundpack [${storedCustomSoundpack}] is not a valid url.`) + this.console.error(`Soundpack [${storedCustomSoundpack}] is not a valid url.`) return false } } if (typeof soundpack.sounds !== "object") { - console.error(`Soundpack [${soundpack.id}] is not a valid soundpack.`) + this.console.error(`Soundpack [${soundpack.id}] is not a valid soundpack.`) return false } - console.log(`Loading soundpack [${soundpack.id} | ${soundpack.name}] by ${soundpack.author} (${soundpack.version})`) + this.console.log(`Loading soundpack [${soundpack.id} | ${soundpack.name}] by ${soundpack.author} (${soundpack.version})`) for (const [name, path] of Object.entries(soundpack.sounds)) { this.soundsPool[name] = new Howl({ @@ -93,7 +91,7 @@ export default class SoundCore extends Core { const audioInstance = this.soundsPool[name] if (!audioInstance) { - console.error(`Sound [${name}] not found or is not available.`) + this.console.error(`Sound [${name}] not found or is not available.`) return false } diff --git a/packages/app/src/cores/style/style.core.jsx b/packages/app/src/cores/style/style.core.jsx index bdc730e6..d079eb50 100755 --- a/packages/app/src/cores/style/style.core.jsx +++ b/packages/app/src/cores/style/style.core.jsx @@ -1,6 +1,4 @@ import React from "react" -import ReactDOM from "react-dom" -import SVG from "react-inlinesvg" import Core from "evite/src/core" import config from "config" @@ -66,11 +64,10 @@ export class ThemeProvider extends React.Component { } export default class StyleCore extends Core { - static refName = "style" - static dependencies = ["settings"] - static namespace = "style" + static dependencies = ["settings"] + static themeManifestStorageKey = "theme" static modificationStorageKey = "themeModifications" @@ -140,7 +137,7 @@ export default class StyleCore extends Core { // handle auto prefered color scheme window.matchMedia("(prefers-color-scheme: light)").addListener(() => { - console.log(`[THEME] Auto color scheme changed`) + this.console.log(`[THEME] Auto color scheme changed`) this.applyVariant(StyleCore.variant) }) @@ -250,7 +247,7 @@ export default class StyleCore extends Core { const values = this.public.theme.variants[variant] if (!values) { - console.error(`Variant [${variant}] not found`) + this.console.error(`Variant [${variant}] not found`) return false } diff --git a/packages/app/src/cores/sync/sync.core.js b/packages/app/src/cores/sync/sync.core.js index e501dc19..11b306b9 100644 --- a/packages/app/src/cores/sync/sync.core.js +++ b/packages/app/src/cores/sync/sync.core.js @@ -7,6 +7,8 @@ import SyncRoomCard from "components/SyncRoomCard" import Image from "components/Image" import { openModal as OpenUserSelectorModal } from "components/UserSelector" +import SyncModel from "comty.js/models/sync" + // TODO: Sync current state with server class MusicSyncSubCore { constructor(ctx) { @@ -40,7 +42,7 @@ class MusicSyncSubCore { hubEvents = { "invite:received": (data) => { - console.log("invite:received", data) + this.console.log("invite:received", data) app.notification.new({ title: "Sync", @@ -60,7 +62,7 @@ class MusicSyncSubCore { }) }, "room:joined": (data) => { - console.log("room:joined", data) + this.console.log("room:joined", data) this.currentRoomData = data @@ -72,7 +74,7 @@ class MusicSyncSubCore { this.eventBus.emit("room:joined", data) }, "room:left": (data) => { - console.log("room:left", data) + this.console.log("room:left", data) this.dettachCard() @@ -106,7 +108,7 @@ class MusicSyncSubCore { this.eventBus.emit("room:user:left", data) }, "room:current-data": (data) => { - console.log("room:current-data", data) + this.console.log("room:current-data", data) this.currentRoomData = data this.eventBus.emit("room:current-data", data) @@ -167,7 +169,7 @@ class MusicSyncSubCore { } }, "room:moderation:kicked": (data) => { - console.log("room:moderation:kicked", data) + this.console.log("room:moderation:kicked", data) this.dettachCard() @@ -208,7 +210,7 @@ class MusicSyncSubCore { let state = app.cores.player.currentState() - console.log("state", state) + this.console.log("state", state) this.musicWs.emit("music:state:update", { ...state, @@ -235,7 +237,7 @@ class MusicSyncSubCore { } if (!app.layout.floatingStack) { - console.error("Floating stack not found") + this.console.error("Floating stack not found") return false } @@ -248,7 +250,7 @@ class MusicSyncSubCore { } if (!app.layout.floatingStack) { - console.error("Floating stack not found") + this.console.error("Floating stack not found") return false } @@ -259,7 +261,7 @@ class MusicSyncSubCore { joinRoom(roomId, options) { if (this.currentRoomData) { - console.warn(`Already joined room ${this.currentRoomData}`) + this.console.warn(`Already joined room ${this.currentRoomData}`) return false } @@ -280,7 +282,7 @@ class MusicSyncSubCore { this.dettachCard() if (!roomId && !this.currentRoomData) { - console.warn(`Not joined any room`) + this.console.warn(`Not joined any room`) return false } @@ -307,7 +309,7 @@ class MusicSyncSubCore { inviteToUser(userId) { if (!this.currentRoomData) { - console.warn(`Not joined any room`) + this.console.warn(`Not joined any room`) return false } @@ -320,7 +322,7 @@ class MusicSyncSubCore { createSyncRoom() { if (this.currentRoomData) { - console.warn(`Already joined room ${this.currentRoomData}`) + this.console.warn(`Already joined room ${this.currentRoomData}`) return false } @@ -336,14 +338,14 @@ class MusicSyncSubCore { //open invite modal OpenUserSelectorModal({ onFinished: (selected_ids) => { - console.log("selected_ids", selected_ids) + this.console.log("selected_ids", selected_ids) } }) } kickUser(userId) { if (!this.currentRoomData) { - console.warn(`Not joined any room`) + this.console.warn(`Not joined any room`) return false } @@ -356,7 +358,7 @@ class MusicSyncSubCore { transferOwner(userId) { if (!this.currentRoomData) { - console.warn(`Not joined any room`) + this.console.warn(`Not joined any room`) return false } @@ -369,11 +371,16 @@ class MusicSyncSubCore { } export default class SyncCore extends Core { - static refName = "sync" static namespace = "sync" static dependencies = ["api", "player"] - public = {} + activeLinkedServices = {} + + public = { + getActiveLinkedServices: function () { + return this.activeLinkedServices + }.bind(this), + } async onInitialize() { const subCores = [ @@ -390,8 +397,20 @@ export default class SyncCore extends Core { this.public[subCore.constructor.namespace] = subCore.public } } catch (error) { - console.error(error) + this.console.error(error) } } } + + async initializeAfterCoresInit() { + const activeServices = await SyncModel.getLinkedServices().catch((error) => { + this.console.error(error) + return null + }) + + if (activeServices) { + this.console.log(`Active services`, activeServices) + this.activeLinkedServices = activeServices + } + } } \ No newline at end of file diff --git a/packages/app/src/cores/tasksQueue/tasksQueue.core.js b/packages/app/src/cores/tasksQueue/tasksQueue.core.js index d5150d73..a0e3fff1 100644 --- a/packages/app/src/cores/tasksQueue/tasksQueue.core.js +++ b/packages/app/src/cores/tasksQueue/tasksQueue.core.js @@ -21,13 +21,13 @@ export default class TasksQueue extends Core { processTasks() { if (this.runningTasksIds.length >= TasksQueue.maxRunningTasks ?? 1) { - console.log("We are already running the maximum number of tasks") + this.console.log("We are already running the maximum number of tasks") return false } // check if there are new tasks in the queue and move them to the tasks array with the maximum number of tasks can be run if (this.taskQueue.length === 0) { - console.log("No tasks in the queue") + this.console.log("No tasks in the queue") return false } @@ -67,7 +67,7 @@ export default class TasksQueue extends Core { this.processTasks() }) .catch((error) => { - console.error(error) + this.console.error(error) this.processTasks() }) } diff --git a/packages/app/src/cores/widgets/widgets.core.js b/packages/app/src/cores/widgets/widgets.core.js index 9f0b9baa..260263c9 100644 --- a/packages/app/src/cores/widgets/widgets.core.js +++ b/packages/app/src/cores/widgets/widgets.core.js @@ -29,7 +29,7 @@ export default class WidgetsCore extends Core { store.set(WidgetsCore.storeKey, []) } } catch (error) { - console.error(error) + this.console.error(error) } } @@ -40,7 +40,7 @@ export default class WidgetsCore extends Core { isInstalled(widget_id) { const widgets = this.getInstalled() - console.log(widgets) + this.console.log(widgets) const widget = widgets.find((widget) => widget._id === widget_id) @@ -52,14 +52,14 @@ export default class WidgetsCore extends Core { throw new Error("Widget id must be a string.") } - console.debug(`🧩 Installing widget with id [${widget_id}]`) + this.console.debug(`🧩 Installing widget with id [${widget_id}]`) // get manifest let manifest = await WidgetsCore.apiInstance({ method: "GET", url: `/widgets/${widget_id}/manifest`, }).catch((error) => { - console.error(error) + this.console.error(error) app.message.error("Cannot install widget.") return false @@ -125,7 +125,7 @@ export default class WidgetsCore extends Core { throw new Error("Widget id must be a string.") } - console.debug(`🧩 Uninstalling widget with id [${widget_id}]`) + this.console.debug(`🧩 Uninstalling widget with id [${widget_id}]`) // check if already installed if (!this.isInstalled(widget_id)) {