97 lines
2.1 KiB
JavaScript
Executable File
97 lines
2.1 KiB
JavaScript
Executable File
const Instance = require('./Instance'),
|
|
Launcher = require('./Launcher'),
|
|
{ app } = require('./util/constants')
|
|
|
|
class App {
|
|
constructor() {
|
|
this.name = app.id
|
|
this.categories = app.categories
|
|
this.version = app.version
|
|
this.sessions = []
|
|
this.assets = {}
|
|
this.bundle = $bundle.for('/')
|
|
|
|
let self
|
|
|
|
// Run acts as a proxy of sorts so we can retain access to
|
|
// the app instance as the context
|
|
this.exec = function(cfg) {
|
|
self.run(cfg, this)
|
|
}
|
|
|
|
const openAsset = (name, path) =>
|
|
this.bundle.open(path, 'URL').then(url => {
|
|
self.assets[name] = url
|
|
})
|
|
|
|
// Fake filename so we can target it with CSS to work around
|
|
// how app icons work
|
|
this.icon = 'xash'
|
|
|
|
// Should probably just load all of "import/"
|
|
// but there's not any ls function in abnt
|
|
this.init()
|
|
|
|
this.config = {
|
|
pauseOnLostFocus: true
|
|
}
|
|
|
|
self = this
|
|
}
|
|
|
|
async run(cfg, context) {
|
|
const self = this,
|
|
{ arg, cli } = context
|
|
|
|
console.log(context)
|
|
|
|
if(arg.arguments.length > 0) {
|
|
let path = $fs.utils.resolvePath(arg.arguments[0])
|
|
|
|
if($fs.utils.exist(path) !== false) {
|
|
this.launch(path)
|
|
} else {
|
|
cli.log.error(`Could not open path "${path}"`)
|
|
}
|
|
} else {
|
|
new Launcher(this)
|
|
}
|
|
}
|
|
|
|
launch(path) {
|
|
let sess = new Instance(this, path) //testing path
|
|
|
|
this.sessions.push(sess)
|
|
}
|
|
|
|
cleanInstances() {
|
|
const { sessions } = this
|
|
|
|
for(let i in sessions)
|
|
if(sessions[i].closed)
|
|
delete this.sessions[i]
|
|
}
|
|
|
|
killAll() {
|
|
for(let session of this.sessions)
|
|
session.kill()
|
|
}
|
|
|
|
init() {
|
|
this.bundle.open('global.css', 'URL')
|
|
.then($loader.css)
|
|
|
|
const assets = {
|
|
"trame": "./half-trame.png",
|
|
"play": "./assets/play.svg",
|
|
"icon": "./import/icon.png"
|
|
}
|
|
|
|
for(let name in assets) {
|
|
this.bundle.open(assets[name], 'URL')
|
|
.then(url => document.querySelector(':root').style.setProperty(`--xash3d-${name}`, `url(${url})`) )
|
|
}
|
|
}
|
|
}
|
|
|
|
module.exports = App |