2020-03-07 19:40:24 +03:00
|
|
|
<!DOCTYPE html>
|
|
|
|
<html>
|
2020-06-27 18:20:00 +03:00
|
|
|
|
2020-03-07 19:40:24 +03:00
|
|
|
<body>
|
|
|
|
<script>
|
2020-06-27 18:20:00 +03:00
|
|
|
function callBackEnd(route, args) {
|
2020-03-30 05:41:45 +03:00
|
|
|
console.log(route)
|
|
|
|
console.log(args)
|
2020-03-07 19:40:24 +03:00
|
|
|
var xhr = new XMLHttpRequest()
|
2020-03-30 05:41:45 +03:00
|
|
|
xhr.onload = function () {
|
|
|
|
console.log(route, args, 'done', xhr.status)
|
|
|
|
}
|
|
|
|
xhr.onerror = function () {
|
|
|
|
console.log(route, args, 'error with ' + xhr.status)
|
|
|
|
}
|
2020-03-07 19:40:24 +03:00
|
|
|
xhr.open('POST', 'http://localhost:7000/' + route)
|
|
|
|
xhr.setRequestHeader('Content-type', 'application/json')
|
|
|
|
xhr.send(JSON.stringify(args))
|
|
|
|
}
|
|
|
|
|
2020-06-27 18:20:00 +03:00
|
|
|
function reply(args) {
|
2020-03-30 05:41:45 +03:00
|
|
|
return callBackEnd('reply', args)
|
|
|
|
}
|
|
|
|
|
2020-06-27 18:20:00 +03:00
|
|
|
function sendError(error) {
|
2020-03-30 05:41:45 +03:00
|
|
|
return callBackEnd('error', error)
|
|
|
|
}
|
|
|
|
|
2020-06-27 18:20:00 +03:00
|
|
|
function testFs(dir) {
|
2020-03-30 05:41:45 +03:00
|
|
|
var contents = 'TAURI E2E TEST FILE'
|
|
|
|
var commandSuffix = (dir ? 'WithDir' : '')
|
|
|
|
|
|
|
|
var options = {
|
|
|
|
dir: dir || null
|
|
|
|
}
|
|
|
|
|
2020-06-27 18:20:00 +03:00
|
|
|
return window.__TAURI__.fs.writeFile({
|
2020-03-30 05:41:45 +03:00
|
|
|
file: 'tauri-test.txt',
|
|
|
|
contents: contents
|
|
|
|
}, options).then(function (res) {
|
2020-06-27 18:20:00 +03:00
|
|
|
reply({
|
|
|
|
cmd: 'writeFile' + commandSuffix
|
|
|
|
})
|
|
|
|
return window.__TAURI__.fs.readTextFile('tauri-test.txt', options).then(function (res) {
|
2020-03-30 05:41:45 +03:00
|
|
|
if (res === contents) {
|
2020-06-27 18:20:00 +03:00
|
|
|
reply({
|
|
|
|
cmd: 'readFile' + commandSuffix
|
|
|
|
})
|
2020-03-30 05:41:45 +03:00
|
|
|
|
2020-06-27 18:20:00 +03:00
|
|
|
return window.__TAURI__.fs.readDir('.', options).then(res => {
|
|
|
|
reply({
|
|
|
|
cmd: 'readDir' + commandSuffix
|
|
|
|
})
|
|
|
|
|
|
|
|
return window.__TAURI__.fs.copyFile('tauri-test.txt', 'tauri-test-copy.txt', options)
|
2020-03-30 05:41:45 +03:00
|
|
|
.then(function (res) {
|
2020-06-27 18:20:00 +03:00
|
|
|
reply({
|
|
|
|
cmd: 'copyFile' + commandSuffix
|
|
|
|
})
|
2020-03-30 05:41:45 +03:00
|
|
|
|
2020-06-27 18:20:00 +03:00
|
|
|
return window.__TAURI__.fs.createDir('tauri-test-dir', options).then(function (res) {
|
|
|
|
reply({
|
|
|
|
cmd: 'createDir' + commandSuffix
|
2020-03-30 05:41:45 +03:00
|
|
|
})
|
2020-06-27 18:20:00 +03:00
|
|
|
return window.__TAURI__.fs.removeDir('tauri-test-dir', options).then(function (res) {
|
|
|
|
reply({
|
|
|
|
cmd: 'removeDir' + commandSuffix
|
2020-03-30 05:41:45 +03:00
|
|
|
})
|
|
|
|
})
|
2020-06-27 18:20:00 +03:00
|
|
|
}).then(function (res) {
|
|
|
|
return window.__TAURI__.fs.renameFile('tauri-test.txt', 'tauri.testt.txt', options)
|
|
|
|
.then(function (res) {
|
|
|
|
reply({
|
|
|
|
cmd: 'renameFile' + commandSuffix
|
|
|
|
})
|
|
|
|
return Promise.all([
|
|
|
|
window.__TAURI__.fs.removeFile('tauri.testt.txt', options),
|
|
|
|
window.__TAURI__.fs.removeFile('tauri-test-copy.txt', options)
|
|
|
|
]).then(function (res) {
|
|
|
|
reply({
|
|
|
|
cmd: 'removeFile' + commandSuffix
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
2020-03-30 05:41:45 +03:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
sendError('expected "' + contents + '" found "' + res + '"')
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}).catch(sendError)
|
|
|
|
}
|
|
|
|
|
2020-06-27 18:20:00 +03:00
|
|
|
window.__TAURI__.event.listen('reply', function (res) {
|
|
|
|
reply({
|
|
|
|
cmd: 'listen'
|
|
|
|
})
|
2020-05-05 15:10:39 +03:00
|
|
|
})
|
2020-03-07 19:40:24 +03:00
|
|
|
window.onTauriInit = function () {
|
2020-06-27 18:20:00 +03:00
|
|
|
window.__TAURI__.event.emit('hello')
|
2020-05-05 15:10:39 +03:00
|
|
|
}
|
2020-03-30 05:41:45 +03:00
|
|
|
|
2020-05-05 15:10:39 +03:00
|
|
|
testFs(null).then(function () {
|
2020-06-27 18:20:00 +03:00
|
|
|
testFs(window.__TAURI__.fs.Dir.Config)
|
2020-05-05 15:10:39 +03:00
|
|
|
})
|
2020-03-30 05:41:45 +03:00
|
|
|
|
2020-05-05 15:10:39 +03:00
|
|
|
setTimeout(function () {
|
2020-06-27 18:20:00 +03:00
|
|
|
window.__TAURI__.invoke({
|
|
|
|
cmd: 'exit'
|
|
|
|
})
|
2020-05-05 15:10:39 +03:00
|
|
|
}, 15000)
|
2020-06-27 18:20:00 +03:00
|
|
|
|
2020-03-07 19:40:24 +03:00
|
|
|
</script>
|
|
|
|
</body>
|
|
|
|
|
2020-06-27 18:20:00 +03:00
|
|
|
</html>
|