77 lines
1.3 KiB
JavaScript
77 lines
1.3 KiB
JavaScript
{
|
|
|
|
let userHome
|
|
|
|
const handleNeutralinoError = err => {
|
|
throw new Error(err.code + ': ' + err.message)
|
|
}
|
|
|
|
window.Platform = {
|
|
//
|
|
// Paths
|
|
//
|
|
|
|
dirname(path) {
|
|
let index = path.lastIndexOf('/')
|
|
|
|
return index === -1 ? '' : path.slice(0, index)
|
|
},
|
|
|
|
filename(path) {
|
|
let index = path.lastIndexOf('/')
|
|
|
|
return index === -1 ? path : path.slice(index + 1)
|
|
},
|
|
|
|
ext(path) {
|
|
let filename = this.filename(path)
|
|
let index = filename.lastIndexOf('.')
|
|
|
|
return index === -1 ? '' : filename.slice(index + 1)
|
|
},
|
|
|
|
join(...args) {
|
|
return args.join('/')
|
|
},
|
|
|
|
// TODO: support non-posix
|
|
absolute(path) {
|
|
return path.charAt(0) === '/'
|
|
},
|
|
|
|
//
|
|
// FS
|
|
//
|
|
|
|
async access(path) {
|
|
try {
|
|
await Neutralino.filesystem.getStats(path)
|
|
return
|
|
} catch(err) {
|
|
if(err.name = 'NE_FS_NOPATHE') {
|
|
return false
|
|
} else {
|
|
throw err
|
|
}
|
|
}
|
|
},
|
|
|
|
writeText(path, content) {
|
|
return Neutralino.filesystem.writeFile(path, content)
|
|
.catch(handleNeutralinoError)
|
|
},
|
|
|
|
readText(path) {
|
|
return Neutralino.filesystem.readFile(path)
|
|
.catch(handleNeutralinoError)
|
|
},
|
|
|
|
//
|
|
// OS
|
|
//
|
|
async getHome() {
|
|
return userHome ?? (userHome = await Neutralino.os.getEnv('HOME'))
|
|
},
|
|
}
|
|
|
|
} |