diff --git a/packages/app/src/App.jsx b/packages/app/src/App.jsx index 95a42114..4af1c555 100755 --- a/packages/app/src/App.jsx +++ b/packages/app/src/App.jsx @@ -487,7 +487,7 @@ class ComtyApp extends React.Component { const userAgentPlatform = window.navigator.userAgent.toLowerCase() const isMac = userAgentPlatform.indexOf("mac") !== -1 - this.props.cores.ShortcutsCore.register({ + this.props.cores.shortcuts.register({ id: "app.openSearcher", key: ",", meta: isMac, @@ -518,7 +518,7 @@ class ComtyApp extends React.Component { const initializationTasks = [ async () => { try { - await this.props.cores.ApiCore.attach() + await this.props.cores.api.attach() app.eventBus.emit("app.initialization.api_success") } catch (error) { diff --git a/packages/app/src/components/PostsList/index.jsx b/packages/app/src/components/PostsList/index.jsx index c9c26aa1..f6ce09d6 100755 --- a/packages/app/src/components/PostsList/index.jsx +++ b/packages/app/src/components/PostsList/index.jsx @@ -52,14 +52,14 @@ export default class PostsLists extends React.Component { } componentDidMount = async () => { - window.app.shortcuts.register({ + window.app.cores.shortcuts.register({ id: "postsFeed.scrollUp", key: "ArrowUp", preventDefault: true, }, (event) => { this.scrollUp() }) - window.app.shortcuts.register({ + window.app.cores.shortcuts.register({ id: "postsFeed.scrollDown", key: "ArrowDown", preventDefault: true, diff --git a/packages/app/src/cores/api/index.js b/packages/app/src/cores/api/index.js index 78e06074..3f278f36 100755 --- a/packages/app/src/cores/api/index.js +++ b/packages/app/src/cores/api/index.js @@ -48,6 +48,7 @@ function generateWSFunctionHandler(socket, type = "listen") { } export default class ApiCore extends Core { + static refName = "api" static namespace = "api" static depends = ["settings"] diff --git a/packages/app/src/cores/contextMenu/index.js b/packages/app/src/cores/contextMenu/index.js index 610f272f..de6199fa 100755 --- a/packages/app/src/cores/contextMenu/index.js +++ b/packages/app/src/cores/contextMenu/index.js @@ -7,8 +7,14 @@ import ContextMenu from "./components/contextMenu" import InternalContexts from "schemas/menu-contexts" export default class ContextMenuCore extends Core { - static namespace = "ContextMenu" - static public = ["show", "hide", "registerContext"] + static refName = "contextMenu" + static namespace = "contextMenu" + + public = { + show: this.show.bind(this), + hide: this.hide.bind(this), + registerContext: this.registerContext.bind(this), + } contexts = Object() @@ -19,14 +25,14 @@ export default class ContextMenuCore extends Core { }) async onInitialize() { - document.addEventListener("contextmenu", this.handleEvent) + document.addEventListener("contextmenu", this.handleEvent.bind(this)) } - registerContext = (element, context) => { + registerContext(element, context) { this.contexts[element] = context } - generateItems = async (element) => { + async generateItems(element) { let items = [] // find the closest context with attribute (context-menu) @@ -96,7 +102,7 @@ export default class ContextMenuCore extends Core { return items } - handleEvent = async (event) => { + async handleEvent(event) { event.preventDefault() // get the cords of the mouse @@ -131,11 +137,11 @@ export default class ContextMenuCore extends Core { }) } - show = (payload) => { + show(payload) { this.DOMWindow.render(React.createElement(ContextMenu, payload)) } - hide = () => { + hide() { this.DOMWindow.remove() } } \ No newline at end of file diff --git a/packages/app/src/cores/i18n/index.js b/packages/app/src/cores/i18n/index.js index b366f01e..241b235e 100755 --- a/packages/app/src/cores/i18n/index.js +++ b/packages/app/src/cores/i18n/index.js @@ -15,6 +15,8 @@ export function extractLocaleFromPath(path = "") { const messageImports = import.meta.glob("schemas/translations/*.json") export default class I18nCore extends Core { + static refName = "i18n" + onEvents = { "changeLanguage": (locale) => { this.loadAsyncLanguage(locale) diff --git a/packages/app/src/cores/notifications/index.jsx b/packages/app/src/cores/notifications/index.jsx index 6b624d03..2cfb2213 100755 --- a/packages/app/src/cores/notifications/index.jsx +++ b/packages/app/src/cores/notifications/index.jsx @@ -6,6 +6,8 @@ import { Translation } from "react-i18next" import { Haptics } from "@capacitor/haptics" export default class NotificationCore extends Core { + static refName = "notifications" + onEvents = { "changeNotificationsSoundVolume": (value) => { this.playAudio({ soundVolume: value }) diff --git a/packages/app/src/cores/permissions/index.js b/packages/app/src/cores/permissions/index.js index 927ffc21..bd09389e 100755 --- a/packages/app/src/cores/permissions/index.js +++ b/packages/app/src/cores/permissions/index.js @@ -4,6 +4,7 @@ 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"] diff --git a/packages/app/src/cores/player/index.jsx b/packages/app/src/cores/player/index.jsx index c85edc1b..8b049fd2 100755 --- a/packages/app/src/cores/player/index.jsx +++ b/packages/app/src/cores/player/index.jsx @@ -31,6 +31,8 @@ class AudioPlayerStorage { } export default class Player extends Core { + static refName = "player" + static namespace = "player" currentDomWindow = null diff --git a/packages/app/src/cores/settings/index.js b/packages/app/src/cores/settings/index.js index b8fee9b8..234c0948 100755 --- a/packages/app/src/cores/settings/index.js +++ b/packages/app/src/cores/settings/index.js @@ -4,6 +4,8 @@ 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/index.js b/packages/app/src/cores/shortcuts/index.js index 3b730418..7fbc7132 100755 --- a/packages/app/src/cores/shortcuts/index.js +++ b/packages/app/src/cores/shortcuts/index.js @@ -1,13 +1,16 @@ import Core from "evite/src/core" export default class ShortcutsCore extends Core { - shortcutsRegister = [] + static refName = "shortcuts" + static namespace = "shortcuts" - registerToApp = { - shortcuts: this + public = { + register: this.register.bind(this), } - handleEvent = (event, shortcut, fn) => { + shortcutsRegister = [] + + handleEvent(event, shortcut, fn) { if (typeof shortcut !== "object") { throw new Error("Shortcut must be an object") } @@ -42,7 +45,7 @@ export default class ShortcutsCore extends Core { } } - register = (shortcut, fn) => { + register(shortcut, fn) { if (!shortcut) { throw new Error("`shortcut` is required") } @@ -65,7 +68,7 @@ export default class ShortcutsCore extends Core { return document.addEventListener("keydown", handler) } - remove = (id) => { + remove(id) { if (!id) { throw new Error("`id` is required") } @@ -88,8 +91,4 @@ export default class ShortcutsCore extends Core { // remove the event handler from the list this.shortcutsRegister = this.shortcutsRegister.filter((handler) => handler.id !== id) } - - window = { - ShortcutsController: this - } } \ No newline at end of file diff --git a/packages/app/src/cores/sound/index.js b/packages/app/src/cores/sound/index.js index 2fb2cf11..4cf930a1 100755 --- a/packages/app/src/cores/sound/index.js +++ b/packages/app/src/cores/sound/index.js @@ -3,6 +3,8 @@ import { Howl } from "howler" import config from "config" export default class SoundCore extends Core { + static refName = "sound" + static namespace = "sound" public = { diff --git a/packages/app/src/cores/style/index.jsx b/packages/app/src/cores/style/index.jsx index e6fd53bc..96b9c12b 100755 --- a/packages/app/src/cores/style/index.jsx +++ b/packages/app/src/cores/style/index.jsx @@ -64,6 +64,8 @@ export class ThemeProvider extends React.Component { } export default class StyleCore extends Core { + static refName = "style" + static namespace = "style" static themeManifestStorageKey = "theme"