123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- <!DOCTYPE html>
- <html>
- <body>
- <script>
- function callBackEnd(route, args) {
- console.log(route)
- console.log(args)
- window.__TAURI__.http
- .fetch('http://localhost:7000/' + route, {
- method: 'POST',
- body: window.__TAURI__.http.Body.json(args),
- responseType: window.__TAURI__.http.ResponseType.Binary
- })
- .catch(console.error)
- }
- 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__.fs
- .writeFile(
- {
- path: 'tauri-test.txt',
- contents: contents
- },
- options
- )
- .then(function (res) {
- reply({
- cmd: 'writeFile' + commandSuffix
- })
- return window.__TAURI__.fs
- .readTextFile('tauri-test.txt', options)
- .then(function (res) {
- if (res === contents) {
- reply({
- cmd: 'readFile' + commandSuffix
- })
- 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
- )
- .then(function (res) {
- reply({
- cmd: 'copyFile' + commandSuffix
- })
- return window.__TAURI__.fs
- .createDir('tauri-test-dir', options)
- .then(function (res) {
- reply({
- cmd: 'createDir' + commandSuffix
- })
- return window.__TAURI__.fs
- .removeDir('tauri-test-dir', options)
- .then(function (res) {
- reply({
- cmd: 'removeDir' + commandSuffix
- })
- })
- })
- .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
- })
- })
- })
- })
- })
- })
- } else {
- sendError('expected "' + contents + '" found "' + res + '"')
- }
- })
- })
- .catch(sendError)
- }
- window.__TAURI__.event.listen('reply', function (res) {
- reply({
- cmd: 'listen'
- })
- })
- window.onTauriInit = function () {
- window.__TAURI__.event.emit('hello')
- }
- testFs(null).then(function () {
- testFs(window.__TAURI__.fs.Dir.Config)
- })
- setTimeout(function () {
- window.__TAURI__.invoke('exit')
- }, 15000)
- </script>
- </body>
- </html>
|