mirror of
https://github.com/rommapp/romm.git
synced 2026-12-03 10:33:22 +01:00
migrated to event bus system
This commit is contained in:
6
frontend/package-lock.json
generated
6
frontend/package-lock.json
generated
@@ -12,6 +12,7 @@
|
||||
"axios": "^1.3.4",
|
||||
"core-js": "^3.8.3",
|
||||
"file-saver": "^2.0.5",
|
||||
"mitt": "^3.0.0",
|
||||
"roboto-fontface": "*",
|
||||
"vue": "^3.2.13",
|
||||
"vue-router": "^4.0.0",
|
||||
@@ -1694,6 +1695,11 @@
|
||||
"node": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/mitt": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/mitt/-/mitt-3.0.0.tgz",
|
||||
"integrity": "sha512-7dX2/10ITVyqh4aOSVI9gdape+t9l2/8QxHrFmUXu4EEUpdlxl6RudZUPZoc+zuY2hk1j7XxVroIVIan/pD/SQ=="
|
||||
},
|
||||
"node_modules/ms": {
|
||||
"version": "2.1.2",
|
||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
"axios": "^1.3.4",
|
||||
"core-js": "^3.8.3",
|
||||
"file-saver": "^2.0.5",
|
||||
"mitt": "^3.0.0",
|
||||
"roboto-fontface": "*",
|
||||
"vue": "^3.2.13",
|
||||
"vue-router": "^4.0.0",
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
<script setup>
|
||||
import { ref } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { useTheme } from "vuetify";
|
||||
import PlatformsBar from '@/components/PlatformsBar.vue'
|
||||
|
||||
|
||||
const router = useRouter()
|
||||
const viewComponent = ref(null)
|
||||
const platformsBar = ref(null)
|
||||
useTheme().global.name.value = localStorage.getItem('theme') || 'dark'
|
||||
|
||||
@@ -21,7 +18,7 @@ async function gettingRoms(flag){
|
||||
}
|
||||
|
||||
async function getRomDetails(rom) {
|
||||
await router.push(import.meta.env.BASE_URL+'details')
|
||||
|
||||
viewComponent.value.getRomDetails(rom)
|
||||
}
|
||||
</script>
|
||||
@@ -29,13 +26,11 @@ async function getRomDetails(rom) {
|
||||
<template>
|
||||
<v-app>
|
||||
|
||||
<platforms-bar ref="platformsBar" @currentPlatformSlug="(platformSlug) => getRoms(platformSlug)"/>
|
||||
<platforms-bar/>
|
||||
|
||||
<v-main>
|
||||
<v-container fluid>
|
||||
<router-view v-slot="{ Component }">
|
||||
<component ref="viewComponent" :is="Component" @currentRom="(rom) => getRomDetails(rom)" @gettingRoms="(flag) => gettingRoms(flag)"/>
|
||||
</router-view>
|
||||
<router-view />
|
||||
</v-container>
|
||||
</v-main>
|
||||
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
<script setup>
|
||||
import axios from "axios"
|
||||
import { ref } from "vue"
|
||||
import { ref, inject } from "vue"
|
||||
import { useTheme } from "vuetify";
|
||||
|
||||
|
||||
const emit = defineEmits(['currentPlatformSlug'])
|
||||
defineExpose({ gettingRoms })
|
||||
// Props
|
||||
const platforms = ref([])
|
||||
const backPort = import.meta.env.VITE_BACK_PORT
|
||||
const currentPlatformName = ref(localStorage.getItem('currentPlatformName') || "")
|
||||
@@ -17,8 +15,13 @@ const rail = ref(false)
|
||||
const theme = useTheme()
|
||||
const darkMode = (localStorage.getItem('theme') == 'light') ? ref(false) : ref(true)
|
||||
|
||||
// Event listeners bus
|
||||
const emitter = inject('emitter')
|
||||
emitter.on('gettingRoms', (flag) => { gettingRomsFlag.value = flag })
|
||||
|
||||
// Functions
|
||||
async function getPlatforms() {
|
||||
// Get the list of the platforms for the navigation drawer
|
||||
console.log("Getting platforms...")
|
||||
await axios.get('http://'+location.hostname+':'+backPort+'/platforms').then((response) => {
|
||||
console.log("Platforms loaded!")
|
||||
@@ -28,13 +31,15 @@ async function getPlatforms() {
|
||||
}
|
||||
|
||||
function selectPlatform(platform){
|
||||
// Select the current platform
|
||||
localStorage.setItem('currentPlatformSlug', platform.slug)
|
||||
localStorage.setItem('currentPlatformName', platform.name)
|
||||
emitter.emit('currentPlatform', platform.slug)
|
||||
currentPlatformName.value = platform.name
|
||||
emit('currentPlatformSlug', platform.slug)
|
||||
}
|
||||
|
||||
async function scan() {
|
||||
// Scan and then get the platforms again
|
||||
console.log("scanning...")
|
||||
scanning.value = true
|
||||
await axios.get('http://'+location.hostname+':'+backPort+'/scan?overwrite='+scanOverwrite.value).then((response) => {
|
||||
@@ -45,13 +50,16 @@ async function scan() {
|
||||
scanning.value = false
|
||||
}
|
||||
|
||||
function toggleTheme() {
|
||||
theme.global.name.value = darkMode.value ? "dark" : "light"
|
||||
darkMode.value ? localStorage.setItem('theme', 'dark') : localStorage.setItem('theme', 'light')
|
||||
function setFilter(filter) {
|
||||
// Sets the roms filter
|
||||
console.log("Filtering by: "+filter)
|
||||
emitter.emit('romsFilter', filter)
|
||||
}
|
||||
|
||||
function gettingRoms(flag) {
|
||||
gettingRomsFlag.value = flag
|
||||
function toggleTheme() {
|
||||
// Toggle dark/light theme
|
||||
theme.global.name.value = darkMode.value ? "dark" : "light"
|
||||
darkMode.value ? localStorage.setItem('theme', 'dark') : localStorage.setItem('theme', 'light')
|
||||
}
|
||||
|
||||
getPlatforms()
|
||||
@@ -64,7 +72,7 @@ getPlatforms()
|
||||
|
||||
<v-toolbar-title class="d-flex align-center justify-center text-h6">{{ currentPlatformName }}</v-toolbar-title>
|
||||
|
||||
<v-btn icon><v-icon>mdi-magnify</v-icon></v-btn>
|
||||
<v-btn icon @click="setFilter('')"><v-icon>mdi-magnify</v-icon></v-btn>
|
||||
|
||||
<v-menu :close-on-content-click="false" >
|
||||
<template v-slot:activator="{ props }">
|
||||
|
||||
@@ -1,16 +1,19 @@
|
||||
<script setup>
|
||||
import axios from 'axios'
|
||||
import { ref } from "vue";
|
||||
|
||||
import { ref, inject } from "vue";
|
||||
|
||||
// Props
|
||||
const currentRom = ref("")
|
||||
|
||||
// Event listeners bus
|
||||
const emitter = inject('emitter')
|
||||
emitter.on('currentRom', (rom) => { getRomDetails(rom) })
|
||||
|
||||
// Functions
|
||||
function getRomDetails(rom){
|
||||
currentRom.value = rom.name
|
||||
}
|
||||
|
||||
defineExpose({ getRomDetails })
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
||||
@@ -1,34 +1,40 @@
|
||||
<script setup>
|
||||
import axios from 'axios'
|
||||
import { ref, onMounted } from "vue";
|
||||
import { saveAs } from 'file-saver';
|
||||
import { ref, inject , onMounted } from "vue"
|
||||
import { useRouter } from 'vue-router'
|
||||
import { saveAs } from 'file-saver'
|
||||
|
||||
|
||||
const emit = defineEmits(['currentRom', 'gettingRoms'])
|
||||
defineExpose({ getRoms })
|
||||
// Props
|
||||
const roms = ref([])
|
||||
const romsFiltered = ref([])
|
||||
const backPort = import.meta.env.VITE_BACK_PORT
|
||||
const noRoms = ref(false)
|
||||
var currentPlatformSlug = localStorage.getItem('currentPlatformSlug') || ""
|
||||
const router = useRouter()
|
||||
|
||||
// Event listeners bus
|
||||
const emitter = inject('emitter')
|
||||
emitter.on('currentPlatform', (platform) => { getRoms(platform) })
|
||||
emitter.on('romsFilter', (filter) => { setFilter(filter) })
|
||||
|
||||
// Functions
|
||||
async function getRoms(platform) {
|
||||
currentPlatformSlug = platform
|
||||
console.log("Getting roms...")
|
||||
emit('gettingRoms', true)
|
||||
emitter.emit('gettingRoms', true)
|
||||
await axios.get('http://'+location.hostname+':'+backPort+'/platforms/'+platform+'/roms').then((response) => {
|
||||
console.log("Roms loaded!")
|
||||
console.log(response.data.data)
|
||||
roms.value = response.data.data
|
||||
romsFiltered.value = response.data.data
|
||||
if (roms.value.length == 0){ noRoms.value = true }else{ noRoms.value = false }
|
||||
}).catch((error) => {console.log(error)})
|
||||
emit('gettingRoms', false)
|
||||
emitter.emit('gettingRoms', false)
|
||||
}
|
||||
|
||||
function downloadRom(filename) {
|
||||
const url = 'http://'+location.host+'/assets/emulation/'+currentPlatformSlug+'/roms/'+filename
|
||||
console.log("Downloading "+filename)
|
||||
axios.get(url, { responseType: 'blob' }).then(response => {
|
||||
axios.get('http://'+location.host+'/assets/emulation/'+currentPlatformSlug+'/roms/'+filename, { responseType: 'blob' }).then(response => {
|
||||
saveAs(new Blob([response.data], { type: 'application/file' }), filename)
|
||||
}).catch(console.error)
|
||||
}
|
||||
@@ -37,18 +43,25 @@ function downloadSave(name) {
|
||||
console.log("Downloading "+name+" save file")
|
||||
}
|
||||
|
||||
function selectRom(rom){
|
||||
async function selectRom(rom) {
|
||||
console.log("Selected rom "+rom.name)
|
||||
emit('currentRom', rom)
|
||||
await router.push(import.meta.env.BASE_URL+'details')
|
||||
emitter.emit('currentRom', rom)
|
||||
}
|
||||
|
||||
function setFilter(filter) {
|
||||
romsFiltered.value = roms.value.filter(rom => {
|
||||
return rom.name.toLowerCase().includes(filter.toLowerCase())
|
||||
})
|
||||
}
|
||||
|
||||
onMounted(() => { if(currentPlatformSlug){ getRoms(currentPlatformSlug) } })
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
||||
|
||||
<v-row>
|
||||
<v-col v-for="rom in roms" cols="6" xs="6" sm="3" md="3" lg="2">
|
||||
<v-col v-for="rom in romsFiltered" cols="6" xs="6" sm="3" md="3" lg="2" >
|
||||
<v-hover v-slot="{ isHovering, props }">
|
||||
<v-card :elevation="isHovering ? 20 : 3" :class="{ 'on-hover': isHovering }" v-bind="props" >
|
||||
|
||||
|
||||
@@ -13,8 +13,13 @@ import { createApp } from 'vue'
|
||||
// Plugins
|
||||
import { registerPlugins } from '@/plugins'
|
||||
|
||||
// Event bus
|
||||
import mitt from 'mitt'
|
||||
const emitter = mitt()
|
||||
|
||||
const app = createApp(App)
|
||||
|
||||
registerPlugins(app)
|
||||
|
||||
app.provide('emitter', emitter);
|
||||
app.mount('#app')
|
||||
|
||||
Reference in New Issue
Block a user