-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: add recursive option to directory APIs (#1141)
* Add recursive option * Fix ESLint * Fix all other possible code style issues * Add .changes file
- Loading branch information
1 parent
0753877
commit 2fd1067
Showing
14 changed files
with
3,226 additions
and
821 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"tauri.js": patch | ||
--- | ||
|
||
Fixed a TypeScript issue where it didn't allow you to put the "recursive" option in the directory functions. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
document.getElementById('cli-matches').addEventListener('click', function () { | ||
window.__TAURI__.cli.getMatches() | ||
document.getElementById("cli-matches").addEventListener("click", function () { | ||
window.__TAURI__.cli | ||
.getMatches() | ||
.then(registerResponse) | ||
.catch(registerResponse) | ||
}) | ||
.catch(registerResponse); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,25 @@ | ||
document.getElementById('log').addEventListener('click', function () { | ||
document.getElementById("log").addEventListener("click", function () { | ||
window.__TAURI__.tauri.invoke({ | ||
cmd: 'logOperation', | ||
event: 'tauri-click', | ||
payload: 'this payload is optional because we used Option in Rust' | ||
}) | ||
}) | ||
cmd: "logOperation", | ||
event: "tauri-click", | ||
payload: "this payload is optional because we used Option in Rust", | ||
}); | ||
}); | ||
|
||
document.getElementById('request').addEventListener('click', function () { | ||
window.__TAURI__.tauri.promisified({ | ||
cmd: 'performRequest', | ||
endpoint: 'dummy endpoint arg', | ||
body: { | ||
id: 5, | ||
name: 'test' | ||
} | ||
}).then(registerResponse).catch(registerResponse) | ||
}) | ||
document.getElementById("request").addEventListener("click", function () { | ||
window.__TAURI__.tauri | ||
.promisified({ | ||
cmd: "performRequest", | ||
endpoint: "dummy endpoint arg", | ||
body: { | ||
id: 5, | ||
name: "test", | ||
}, | ||
}) | ||
.then(registerResponse) | ||
.catch(registerResponse); | ||
}); | ||
|
||
document.getElementById('event').addEventListener('click', function () { | ||
window.__TAURI__.event.emit('js-event', 'this is the payload string') | ||
}) | ||
document.getElementById("event").addEventListener("click", function () { | ||
window.__TAURI__.event.emit("js-event", "this is the payload string"); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,47 @@ | ||
var defaultPathInput = document.getElementById('dialog-default-path') | ||
var filterInput = document.getElementById('dialog-filter') | ||
var multipleInput = document.getElementById('dialog-multiple') | ||
var directoryInput = document.getElementById('dialog-directory') | ||
var defaultPathInput = document.getElementById("dialog-default-path"); | ||
var filterInput = document.getElementById("dialog-filter"); | ||
var multipleInput = document.getElementById("dialog-multiple"); | ||
var directoryInput = document.getElementById("dialog-directory"); | ||
|
||
document.getElementById('open-dialog').addEventListener('click', function () { | ||
window.__TAURI__.dialog.open({ | ||
defaultPath: defaultPathInput.value || null, | ||
filter: filterInput.value || null, | ||
multiple: multipleInput.checked, | ||
directory: directoryInput.checked | ||
}).then(function (res) { | ||
console.log(res) | ||
var pathToRead = res | ||
var isFile = pathToRead.match(/\S+\.\S+$/g) | ||
window.__TAURI__.fs.readBinaryFile(pathToRead).then(function (response) { | ||
if (isFile) { | ||
if (pathToRead.includes('.png') || pathToRead.includes('.jpg')) { | ||
arrayBufferToBase64(new Uint8Array(response), function (base64) { | ||
var src = 'data:image/png;base64,' + base64 | ||
registerResponse('<img src="' + src + '"></img>') | ||
}) | ||
} else { | ||
registerResponse(res) | ||
} | ||
} else { | ||
registerResponse(res) | ||
} | ||
}).catch(registerResponse(res)) | ||
}).catch(registerResponse) | ||
}) | ||
document.getElementById("open-dialog").addEventListener("click", function () { | ||
window.__TAURI__.dialog | ||
.open({ | ||
defaultPath: defaultPathInput.value || null, | ||
filter: filterInput.value || null, | ||
multiple: multipleInput.checked, | ||
directory: directoryInput.checked, | ||
}) | ||
.then(function (res) { | ||
console.log(res); | ||
var pathToRead = res; | ||
var isFile = pathToRead.match(/\S+\.\S+$/g); | ||
window.__TAURI__.fs | ||
.readBinaryFile(pathToRead) | ||
.then(function (response) { | ||
if (isFile) { | ||
if (pathToRead.includes(".png") || pathToRead.includes(".jpg")) { | ||
arrayBufferToBase64(new Uint8Array(response), function (base64) { | ||
var src = "data:image/png;base64," + base64; | ||
registerResponse('<img src="' + src + '"></img>'); | ||
}); | ||
} else { | ||
registerResponse(res); | ||
} | ||
} else { | ||
registerResponse(res); | ||
} | ||
}) | ||
.catch(registerResponse(res)); | ||
}) | ||
.catch(registerResponse); | ||
}); | ||
|
||
document.getElementById('save-dialog').addEventListener('click', function () { | ||
window.__TAURI__.dialog.save({ | ||
defaultPath: defaultPathInput.value || null, | ||
filter: filterInput.value || null | ||
}).then(registerResponse).catch(registerResponse) | ||
}) | ||
document.getElementById("save-dialog").addEventListener("click", function () { | ||
window.__TAURI__.dialog | ||
.save({ | ||
defaultPath: defaultPathInput.value || null, | ||
filter: filterInput.value || null, | ||
}) | ||
.then(registerResponse) | ||
.catch(registerResponse); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,66 @@ | ||
var dirSelect = document.getElementById('dir') | ||
var dirSelect = document.getElementById("dir"); | ||
|
||
function getDir() { | ||
return dirSelect.value ? parseInt(dir.value) : null | ||
return dirSelect.value ? parseInt(dir.value) : null; | ||
} | ||
|
||
function arrayBufferToBase64(buffer, callback) { | ||
var blob = new Blob([buffer], { | ||
type: 'application/octet-binary' | ||
}) | ||
var reader = new FileReader() | ||
type: "application/octet-binary", | ||
}); | ||
var reader = new FileReader(); | ||
reader.onload = function (evt) { | ||
var dataurl = evt.target.result | ||
callback(dataurl.substr(dataurl.indexOf(',') + 1)) | ||
} | ||
reader.readAsDataURL(blob) | ||
var dataurl = evt.target.result; | ||
callback(dataurl.substr(dataurl.indexOf(",") + 1)); | ||
}; | ||
reader.readAsDataURL(blob); | ||
} | ||
|
||
var pathInput = document.getElementById('path-to-read') | ||
var pathInput = document.getElementById("path-to-read"); | ||
|
||
addClickEnterHandler( | ||
document.getElementById('read'), | ||
pathInput, | ||
function () { | ||
var pathToRead = pathInput.value | ||
var isFile = pathToRead.match(/\S+\.\S+$/g) | ||
var opts = { | ||
dir: getDir() | ||
} | ||
var promise = isFile ? window.__TAURI__.fs.readBinaryFile(pathToRead, opts) : window.__TAURI__.fs.readDir(pathToRead, opts) | ||
promise.then(function (response) { | ||
addClickEnterHandler(document.getElementById("read"), pathInput, function () { | ||
var pathToRead = pathInput.value; | ||
var isFile = pathToRead.match(/\S+\.\S+$/g); | ||
var opts = { | ||
dir: getDir(), | ||
}; | ||
var promise = isFile | ||
? window.__TAURI__.fs.readBinaryFile(pathToRead, opts) | ||
: window.__TAURI__.fs.readDir(pathToRead, opts); | ||
promise | ||
.then(function (response) { | ||
if (isFile) { | ||
if (pathToRead.includes('.png') || pathToRead.includes('.jpg')) { | ||
if (pathToRead.includes(".png") || pathToRead.includes(".jpg")) { | ||
arrayBufferToBase64(new Uint8Array(response), function (base64) { | ||
var src = 'data:image/png;base64,' + base64 | ||
registerResponse('<img src="' + src + '"></img>') | ||
}) | ||
var src = "data:image/png;base64," + base64; | ||
registerResponse('<img src="' + src + '"></img>'); | ||
}); | ||
} else { | ||
var value = String.fromCharCode.apply(null, response) | ||
registerResponse('<textarea id="file-response" style="height: 400px"></textarea><button id="file-save">Save</button>') | ||
var fileInput = document.getElementById('file-response') | ||
fileInput.value = value | ||
document.getElementById('file-save').addEventListener('click', function () { | ||
window.__TAURI__.fs.writeFile({ | ||
file: pathToRead, | ||
contents: fileInput.value | ||
}, { | ||
dir: getDir() | ||
}).catch(registerResponse) | ||
}) | ||
var value = String.fromCharCode.apply(null, response); | ||
registerResponse( | ||
'<textarea id="file-response" style="height: 400px"></textarea><button id="file-save">Save</button>' | ||
); | ||
var fileInput = document.getElementById("file-response"); | ||
fileInput.value = value; | ||
document | ||
.getElementById("file-save") | ||
.addEventListener("click", function () { | ||
window.__TAURI__.fs | ||
.writeFile( | ||
{ | ||
file: pathToRead, | ||
contents: fileInput.value, | ||
}, | ||
{ | ||
dir: getDir(), | ||
} | ||
) | ||
.catch(registerResponse); | ||
}); | ||
} | ||
} else { | ||
registerResponse(response) | ||
registerResponse(response); | ||
} | ||
}).catch(registerResponse) | ||
} | ||
) | ||
}) | ||
.catch(registerResponse); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,29 @@ | ||
const methodSelect = document.getElementById('request-method') | ||
const requestUrlInput = document.getElementById('request-url') | ||
const requestBodyInput = document.getElementById('request-body') | ||
const methodSelect = document.getElementById("request-method"); | ||
const requestUrlInput = document.getElementById("request-url"); | ||
const requestBodyInput = document.getElementById("request-body"); | ||
|
||
document.getElementById('make-request').addEventListener('click', function () { | ||
const method = methodSelect.value || 'GET' | ||
const url = requestUrlInput.value || '' | ||
document.getElementById("make-request").addEventListener("click", function () { | ||
const method = methodSelect.value || "GET"; | ||
const url = requestUrlInput.value || ""; | ||
|
||
const options = { | ||
url: url, | ||
method: method | ||
} | ||
method: method, | ||
}; | ||
|
||
let body = requestBodyInput.value || '' | ||
if ((body.startsWith('{') && body.endsWith('}')) || (body.startsWith('[') && body.endsWith(']'))) { | ||
body = JSON.parse(body) | ||
} else if (body.startsWith('/') || body.match(/\S:\//g)) { | ||
options.bodyAsFile = true | ||
let body = requestBodyInput.value || ""; | ||
if ( | ||
(body.startsWith("{") && body.endsWith("}")) || | ||
(body.startsWith("[") && body.endsWith("]")) | ||
) { | ||
body = JSON.parse(body); | ||
} else if (body.startsWith("/") || body.match(/\S:\//g)) { | ||
options.bodyAsFile = true; | ||
} | ||
options.body = body | ||
options.body = body; | ||
|
||
window.__TAURI__.http.request(options).then(registerResponse).catch(registerResponse) | ||
}) | ||
window.__TAURI__.http | ||
.request(options) | ||
.then(registerResponse) | ||
.catch(registerResponse); | ||
}); |
Oops, something went wrong.