fix cores inits

This commit is contained in:
SrGooglo 2023-03-03 21:39:55 +00:00
parent 4cea075ec3
commit b25249290f
12 changed files with 41 additions and 22 deletions

View File

@ -487,7 +487,7 @@ class ComtyApp extends React.Component {
const userAgentPlatform = window.navigator.userAgent.toLowerCase() const userAgentPlatform = window.navigator.userAgent.toLowerCase()
const isMac = userAgentPlatform.indexOf("mac") !== -1 const isMac = userAgentPlatform.indexOf("mac") !== -1
this.props.cores.ShortcutsCore.register({ this.props.cores.shortcuts.register({
id: "app.openSearcher", id: "app.openSearcher",
key: ",", key: ",",
meta: isMac, meta: isMac,
@ -518,7 +518,7 @@ class ComtyApp extends React.Component {
const initializationTasks = [ const initializationTasks = [
async () => { async () => {
try { try {
await this.props.cores.ApiCore.attach() await this.props.cores.api.attach()
app.eventBus.emit("app.initialization.api_success") app.eventBus.emit("app.initialization.api_success")
} catch (error) { } catch (error) {

View File

@ -52,14 +52,14 @@ export default class PostsLists extends React.Component {
} }
componentDidMount = async () => { componentDidMount = async () => {
window.app.shortcuts.register({ window.app.cores.shortcuts.register({
id: "postsFeed.scrollUp", id: "postsFeed.scrollUp",
key: "ArrowUp", key: "ArrowUp",
preventDefault: true, preventDefault: true,
}, (event) => { }, (event) => {
this.scrollUp() this.scrollUp()
}) })
window.app.shortcuts.register({ window.app.cores.shortcuts.register({
id: "postsFeed.scrollDown", id: "postsFeed.scrollDown",
key: "ArrowDown", key: "ArrowDown",
preventDefault: true, preventDefault: true,

View File

@ -48,6 +48,7 @@ function generateWSFunctionHandler(socket, type = "listen") {
} }
export default class ApiCore extends Core { export default class ApiCore extends Core {
static refName = "api"
static namespace = "api" static namespace = "api"
static depends = ["settings"] static depends = ["settings"]

View File

@ -7,8 +7,14 @@ import ContextMenu from "./components/contextMenu"
import InternalContexts from "schemas/menu-contexts" import InternalContexts from "schemas/menu-contexts"
export default class ContextMenuCore extends Core { export default class ContextMenuCore extends Core {
static namespace = "ContextMenu" static refName = "contextMenu"
static public = ["show", "hide", "registerContext"] static namespace = "contextMenu"
public = {
show: this.show.bind(this),
hide: this.hide.bind(this),
registerContext: this.registerContext.bind(this),
}
contexts = Object() contexts = Object()
@ -19,14 +25,14 @@ export default class ContextMenuCore extends Core {
}) })
async onInitialize() { async onInitialize() {
document.addEventListener("contextmenu", this.handleEvent) document.addEventListener("contextmenu", this.handleEvent.bind(this))
} }
registerContext = (element, context) => { registerContext(element, context) {
this.contexts[element] = context this.contexts[element] = context
} }
generateItems = async (element) => { async generateItems(element) {
let items = [] let items = []
// find the closest context with attribute (context-menu) // find the closest context with attribute (context-menu)
@ -96,7 +102,7 @@ export default class ContextMenuCore extends Core {
return items return items
} }
handleEvent = async (event) => { async handleEvent(event) {
event.preventDefault() event.preventDefault()
// get the cords of the mouse // 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)) this.DOMWindow.render(React.createElement(ContextMenu, payload))
} }
hide = () => { hide() {
this.DOMWindow.remove() this.DOMWindow.remove()
} }
} }

View File

@ -15,6 +15,8 @@ export function extractLocaleFromPath(path = "") {
const messageImports = import.meta.glob("schemas/translations/*.json") const messageImports = import.meta.glob("schemas/translations/*.json")
export default class I18nCore extends Core { export default class I18nCore extends Core {
static refName = "i18n"
onEvents = { onEvents = {
"changeLanguage": (locale) => { "changeLanguage": (locale) => {
this.loadAsyncLanguage(locale) this.loadAsyncLanguage(locale)

View File

@ -6,6 +6,8 @@ import { Translation } from "react-i18next"
import { Haptics } from "@capacitor/haptics" import { Haptics } from "@capacitor/haptics"
export default class NotificationCore extends Core { export default class NotificationCore extends Core {
static refName = "notifications"
onEvents = { onEvents = {
"changeNotificationsSoundVolume": (value) => { "changeNotificationsSoundVolume": (value) => {
this.playAudio({ soundVolume: value }) this.playAudio({ soundVolume: value })

View File

@ -4,6 +4,7 @@ import UserModel from "models/user"
import SessionModel from "models/session" import SessionModel from "models/session"
export default class PermissionsCore extends Core { export default class PermissionsCore extends Core {
static refName = "permissions"
static namespace = "permissions" static namespace = "permissions"
static dependencies = ["api"] static dependencies = ["api"]

View File

@ -31,6 +31,8 @@ class AudioPlayerStorage {
} }
export default class Player extends Core { export default class Player extends Core {
static refName = "player"
static namespace = "player" static namespace = "player"
currentDomWindow = null currentDomWindow = null

View File

@ -4,6 +4,8 @@ import defaultSettings from "schemas/defaultSettings.json"
import { Observable } from "rxjs" import { Observable } from "rxjs"
export default class SettingsCore extends Core { export default class SettingsCore extends Core {
static refName = "settings"
static namespace = "settings" static namespace = "settings"
static storeKey = "app_settings" static storeKey = "app_settings"

View File

@ -1,13 +1,16 @@
import Core from "evite/src/core" import Core from "evite/src/core"
export default class ShortcutsCore extends Core { export default class ShortcutsCore extends Core {
shortcutsRegister = [] static refName = "shortcuts"
static namespace = "shortcuts"
registerToApp = { public = {
shortcuts: this register: this.register.bind(this),
} }
handleEvent = (event, shortcut, fn) => { shortcutsRegister = []
handleEvent(event, shortcut, fn) {
if (typeof shortcut !== "object") { if (typeof shortcut !== "object") {
throw new Error("Shortcut must be an 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) { if (!shortcut) {
throw new Error("`shortcut` is required") throw new Error("`shortcut` is required")
} }
@ -65,7 +68,7 @@ export default class ShortcutsCore extends Core {
return document.addEventListener("keydown", handler) return document.addEventListener("keydown", handler)
} }
remove = (id) => { remove(id) {
if (!id) { if (!id) {
throw new Error("`id` is required") throw new Error("`id` is required")
} }
@ -88,8 +91,4 @@ export default class ShortcutsCore extends Core {
// remove the event handler from the list // remove the event handler from the list
this.shortcutsRegister = this.shortcutsRegister.filter((handler) => handler.id !== id) this.shortcutsRegister = this.shortcutsRegister.filter((handler) => handler.id !== id)
} }
window = {
ShortcutsController: this
}
} }

View File

@ -3,6 +3,8 @@ import { Howl } from "howler"
import config from "config" import config from "config"
export default class SoundCore extends Core { export default class SoundCore extends Core {
static refName = "sound"
static namespace = "sound" static namespace = "sound"
public = { public = {

View File

@ -64,6 +64,8 @@ export class ThemeProvider extends React.Component {
} }
export default class StyleCore extends Core { export default class StyleCore extends Core {
static refName = "style"
static namespace = "style" static namespace = "style"
static themeManifestStorageKey = "theme" static themeManifestStorageKey = "theme"