|
@@ -2,22 +2,92 @@
|
|
|
<html>
|
|
|
<body>
|
|
|
<script>
|
|
|
- function notify(route, args) {
|
|
|
+ function callBackEnd (route, args) {
|
|
|
+ console.log(route)
|
|
|
+ console.log(args)
|
|
|
var xhr = new XMLHttpRequest()
|
|
|
+ xhr.onload = function () {
|
|
|
+ console.log(route, args, 'done', xhr.status)
|
|
|
+ }
|
|
|
+ xhr.onerror = function () {
|
|
|
+ console.log(route, args, 'error with ' + xhr.status)
|
|
|
+ }
|
|
|
xhr.open('POST', 'http://localhost:7000/' + route)
|
|
|
xhr.setRequestHeader('Content-type', 'application/json')
|
|
|
xhr.send(JSON.stringify(args))
|
|
|
}
|
|
|
|
|
|
+ function reply (args) {
|
|
|
+ return callBackEnd('reply', args)
|
|
|
+ }
|
|
|
+
|
|
|
+ function sendError (error) {
|
|
|
+ return callBackEnd('error', error)
|
|
|
+ }
|
|
|
+
|
|
|
+ function testFs (dir) {
|
|
|
+ var contents = 'TAURI E2E TEST FILE'
|
|
|
+ var commandSuffix = (dir ? 'WithDir' : '')
|
|
|
+
|
|
|
+ var options = {
|
|
|
+ dir: dir || null
|
|
|
+ }
|
|
|
+
|
|
|
+ return window.tauri.writeFile({
|
|
|
+ file: 'tauri-test.txt',
|
|
|
+ contents: contents
|
|
|
+ }, options).then(function (res) {
|
|
|
+ reply({ cmd: 'writeFile' + commandSuffix })
|
|
|
+ return window.tauri.readTextFile('tauri-test.txt', options).then(function (res) {
|
|
|
+ if (res === contents) {
|
|
|
+ reply({ cmd: 'readFile' + commandSuffix })
|
|
|
+
|
|
|
+ return window.tauri.readDir('.', options).then(res => {
|
|
|
+ reply({ cmd: 'readDir' + commandSuffix })
|
|
|
+
|
|
|
+ return window.tauri.copyFile('tauri-test.txt', 'tauri-test-copy.txt', options)
|
|
|
+ .then(function (res) {
|
|
|
+ reply({ cmd: 'copyFile' + commandSuffix })
|
|
|
+
|
|
|
+ return window.tauri.createDir('tauri-test-dir', options).then(function (res) {
|
|
|
+ reply({ cmd: 'createDir' + commandSuffix })
|
|
|
+ return window.tauri.removeDir('tauri-test-dir', options).then(function (res) {
|
|
|
+ reply({ cmd: 'removeDir' + commandSuffix })
|
|
|
+ })
|
|
|
+ }).then(function (res) {
|
|
|
+ return window.tauri.renameFile('tauri-test.txt', 'tauri.testt.txt', options).then(function (res) {
|
|
|
+ reply({ cmd: 'renameFile' + commandSuffix })
|
|
|
+ return Promise.all([
|
|
|
+ window.tauri.removeFile('tauri.testt.txt', options),
|
|
|
+ window.tauri.removeFile('tauri-test-copy.txt', options)
|
|
|
+ ]).then(function (res) {
|
|
|
+ reply({ cmd: 'removeFile' + commandSuffix })
|
|
|
+ })
|
|
|
+ })
|
|
|
+ })
|
|
|
+ })
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ sendError('expected "' + contents + '" found "' + res + '"')
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }).catch(sendError)
|
|
|
+ }
|
|
|
+
|
|
|
window.onTauriInit = function () {
|
|
|
window.tauri.listen('reply', function (res) {
|
|
|
- notify('reply', res.payload)
|
|
|
+ reply({ cmd: 'listen' })
|
|
|
})
|
|
|
window.tauri.emit('hello')
|
|
|
+
|
|
|
+ testFs(null).then(function () {
|
|
|
+ testFs(window.tauri.Dir.Config)
|
|
|
+ })
|
|
|
+
|
|
|
+ setTimeout(function () {
|
|
|
+ window.tauri.invoke({ cmd: 'exit' })
|
|
|
+ }, 15000)
|
|
|
}
|
|
|
- setTimeout(function () {
|
|
|
- window.tauri.invoke({ cmd: 'exit' })
|
|
|
- }, 1000)
|
|
|
</script>
|
|
|
</body>
|
|
|
|