Fix: add recursive option to directory APIs (#1141)

* Add recursive option

* Fix ESLint

* Fix all other possible code style issues

* Add .changes file
This commit is contained in:
ravenclaw900 2021-01-12 01:16:45 -06:00 committed by GitHub
parent 0753877ab9
commit 2fd1067a4c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 3195 additions and 790 deletions

5
.changes/bugfix.md Normal file
View File

@ -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.

View File

@ -25,6 +25,11 @@ export interface FsOptions {
dir?: BaseDirectory dir?: BaseDirectory
} }
export interface FsDirOptions {
dir?: BaseDirectory
recursive?: boolean
}
export interface FsTextFileOption { export interface FsTextFileOption {
path: string path: string
contents: string contents: string
@ -184,7 +189,7 @@ async function writeBinaryFile(
*/ */
async function readDir( async function readDir(
dir: string, dir: string,
options: FsOptions = {} options: FsDirOptions = {}
): Promise<FileEntry[]> { ): Promise<FileEntry[]> {
return await promisified({ return await promisified({
cmd: 'readDir', cmd: 'readDir',
@ -204,7 +209,10 @@ async function readDir(
* @param [options.dir] base directory * @param [options.dir] base directory
* @return * @return
*/ */
async function createDir(dir: string, options: FsOptions = {}): Promise<void> { async function createDir(
dir: string,
options: FsDirOptions = {}
): Promise<void> {
return await promisified({ return await promisified({
cmd: 'createDir', cmd: 'createDir',
path: dir, path: dir,
@ -222,7 +230,10 @@ async function createDir(dir: string, options: FsOptions = {}): Promise<void> {
* @param [options.dir] base directory * @param [options.dir] base directory
* @return * @return
*/ */
async function removeDir(dir: string, options: FsOptions = {}): Promise<void> { async function removeDir(
dir: string,
options: FsDirOptions = {}
): Promise<void> {
return await promisified({ return await promisified({
cmd: 'removeDir', cmd: 'removeDir',
path: dir, path: dir,

View File

@ -1,5 +1,6 @@
document.getElementById('cli-matches').addEventListener('click', function () { document.getElementById("cli-matches").addEventListener("click", function () {
window.__TAURI__.cli.getMatches() window.__TAURI__.cli
.getMatches()
.then(registerResponse) .then(registerResponse)
.catch(registerResponse) .catch(registerResponse);
}) });

View File

@ -1,22 +1,25 @@
document.getElementById('log').addEventListener('click', function () { document.getElementById("log").addEventListener("click", function () {
window.__TAURI__.tauri.invoke({ window.__TAURI__.tauri.invoke({
cmd: 'logOperation', cmd: "logOperation",
event: 'tauri-click', event: "tauri-click",
payload: 'this payload is optional because we used Option in Rust' payload: "this payload is optional because we used Option in Rust",
}) });
}) });
document.getElementById('request').addEventListener('click', function () { document.getElementById("request").addEventListener("click", function () {
window.__TAURI__.tauri.promisified({ window.__TAURI__.tauri
cmd: 'performRequest', .promisified({
endpoint: 'dummy endpoint arg', cmd: "performRequest",
body: { endpoint: "dummy endpoint arg",
id: 5, body: {
name: 'test' id: 5,
} name: "test",
}).then(registerResponse).catch(registerResponse) },
}) })
.then(registerResponse)
.catch(registerResponse);
});
document.getElementById('event').addEventListener('click', function () { document.getElementById("event").addEventListener("click", function () {
window.__TAURI__.event.emit('js-event', 'this is the payload string') window.__TAURI__.event.emit("js-event", "this is the payload string");
}) });

View File

@ -1,38 +1,47 @@
var defaultPathInput = document.getElementById('dialog-default-path') var defaultPathInput = document.getElementById("dialog-default-path");
var filterInput = document.getElementById('dialog-filter') var filterInput = document.getElementById("dialog-filter");
var multipleInput = document.getElementById('dialog-multiple') var multipleInput = document.getElementById("dialog-multiple");
var directoryInput = document.getElementById('dialog-directory') var directoryInput = document.getElementById("dialog-directory");
document.getElementById('open-dialog').addEventListener('click', function () { document.getElementById("open-dialog").addEventListener("click", function () {
window.__TAURI__.dialog.open({ window.__TAURI__.dialog
defaultPath: defaultPathInput.value || null, .open({
filter: filterInput.value || null, defaultPath: defaultPathInput.value || null,
multiple: multipleInput.checked, filter: filterInput.value || null,
directory: directoryInput.checked multiple: multipleInput.checked,
}).then(function (res) { directory: directoryInput.checked,
console.log(res) })
var pathToRead = res .then(function (res) {
var isFile = pathToRead.match(/\S+\.\S+$/g) console.log(res);
window.__TAURI__.fs.readBinaryFile(pathToRead).then(function (response) { var pathToRead = res;
if (isFile) { var isFile = pathToRead.match(/\S+\.\S+$/g);
if (pathToRead.includes('.png') || pathToRead.includes('.jpg')) { window.__TAURI__.fs
arrayBufferToBase64(new Uint8Array(response), function (base64) { .readBinaryFile(pathToRead)
var src = 'data:image/png;base64,' + base64 .then(function (response) {
registerResponse('<img src="' + src + '"></img>') if (isFile) {
}) if (pathToRead.includes(".png") || pathToRead.includes(".jpg")) {
} else { arrayBufferToBase64(new Uint8Array(response), function (base64) {
registerResponse(res) var src = "data:image/png;base64," + base64;
} registerResponse('<img src="' + src + '"></img>');
} else { });
registerResponse(res) } else {
} registerResponse(res);
}).catch(registerResponse(res)) }
}).catch(registerResponse) } else {
}) registerResponse(res);
}
})
.catch(registerResponse(res));
})
.catch(registerResponse);
});
document.getElementById('save-dialog').addEventListener('click', function () { document.getElementById("save-dialog").addEventListener("click", function () {
window.__TAURI__.dialog.save({ window.__TAURI__.dialog
defaultPath: defaultPathInput.value || null, .save({
filter: filterInput.value || null defaultPath: defaultPathInput.value || null,
}).then(registerResponse).catch(registerResponse) filter: filterInput.value || null,
}) })
.then(registerResponse)
.catch(registerResponse);
});

View File

@ -1,57 +1,66 @@
var dirSelect = document.getElementById('dir') var dirSelect = document.getElementById("dir");
function getDir() { function getDir() {
return dirSelect.value ? parseInt(dir.value) : null return dirSelect.value ? parseInt(dir.value) : null;
} }
function arrayBufferToBase64(buffer, callback) { function arrayBufferToBase64(buffer, callback) {
var blob = new Blob([buffer], { var blob = new Blob([buffer], {
type: 'application/octet-binary' type: "application/octet-binary",
}) });
var reader = new FileReader() var reader = new FileReader();
reader.onload = function (evt) { reader.onload = function (evt) {
var dataurl = evt.target.result var dataurl = evt.target.result;
callback(dataurl.substr(dataurl.indexOf(',') + 1)) callback(dataurl.substr(dataurl.indexOf(",") + 1));
} };
reader.readAsDataURL(blob) reader.readAsDataURL(blob);
} }
var pathInput = document.getElementById('path-to-read') var pathInput = document.getElementById("path-to-read");
addClickEnterHandler( addClickEnterHandler(document.getElementById("read"), pathInput, function () {
document.getElementById('read'), var pathToRead = pathInput.value;
pathInput, var isFile = pathToRead.match(/\S+\.\S+$/g);
function () { var opts = {
var pathToRead = pathInput.value dir: getDir(),
var isFile = pathToRead.match(/\S+\.\S+$/g) };
var opts = { var promise = isFile
dir: getDir() ? window.__TAURI__.fs.readBinaryFile(pathToRead, opts)
} : window.__TAURI__.fs.readDir(pathToRead, opts);
var promise = isFile ? window.__TAURI__.fs.readBinaryFile(pathToRead, opts) : window.__TAURI__.fs.readDir(pathToRead, opts) promise
promise.then(function (response) { .then(function (response) {
if (isFile) { if (isFile) {
if (pathToRead.includes('.png') || pathToRead.includes('.jpg')) { if (pathToRead.includes(".png") || pathToRead.includes(".jpg")) {
arrayBufferToBase64(new Uint8Array(response), function (base64) { arrayBufferToBase64(new Uint8Array(response), function (base64) {
var src = 'data:image/png;base64,' + base64 var src = "data:image/png;base64," + base64;
registerResponse('<img src="' + src + '"></img>') registerResponse('<img src="' + src + '"></img>');
}) });
} else { } else {
var value = String.fromCharCode.apply(null, response) var value = String.fromCharCode.apply(null, response);
registerResponse('<textarea id="file-response" style="height: 400px"></textarea><button id="file-save">Save</button>') registerResponse(
var fileInput = document.getElementById('file-response') '<textarea id="file-response" style="height: 400px"></textarea><button id="file-save">Save</button>'
fileInput.value = value );
document.getElementById('file-save').addEventListener('click', function () { var fileInput = document.getElementById("file-response");
window.__TAURI__.fs.writeFile({ fileInput.value = value;
file: pathToRead, document
contents: fileInput.value .getElementById("file-save")
}, { .addEventListener("click", function () {
dir: getDir() window.__TAURI__.fs
}).catch(registerResponse) .writeFile(
}) {
file: pathToRead,
contents: fileInput.value,
},
{
dir: getDir(),
}
)
.catch(registerResponse);
});
} }
} else { } else {
registerResponse(response) registerResponse(response);
} }
}).catch(registerResponse) })
} .catch(registerResponse);
) });

View File

@ -1,23 +1,29 @@
const methodSelect = document.getElementById('request-method') const methodSelect = document.getElementById("request-method");
const requestUrlInput = document.getElementById('request-url') const requestUrlInput = document.getElementById("request-url");
const requestBodyInput = document.getElementById('request-body') const requestBodyInput = document.getElementById("request-body");
document.getElementById('make-request').addEventListener('click', function () { document.getElementById("make-request").addEventListener("click", function () {
const method = methodSelect.value || 'GET' const method = methodSelect.value || "GET";
const url = requestUrlInput.value || '' const url = requestUrlInput.value || "";
const options = { const options = {
url: url, url: url,
method: method method: method,
} };
let body = requestBodyInput.value || '' let body = requestBodyInput.value || "";
if ((body.startsWith('{') && body.endsWith('}')) || (body.startsWith('[') && body.endsWith(']'))) { if (
body = JSON.parse(body) (body.startsWith("{") && body.endsWith("}")) ||
} else if (body.startsWith('/') || body.match(/\S:\//g)) { (body.startsWith("[") && body.endsWith("]"))
options.bodyAsFile = true ) {
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);
});

View File

@ -1,316 +1,330 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head>
<style>
* {
font-family: Arial, Helvetica, sans-serif;
}
<head> body {
<style> background: #889;
* { }
font-family: Arial, Helvetica, sans-serif;
}
body { .logo-container {
background: #889; width: 95%;
} margin: 0px auto;
overflow: hidden;
}
.logo-container { .logo-link {
width: 95%; font-weight: 700;
margin: 0px auto; position: absolute;
overflow: hidden; top: 150px;
} right: 10px;
}
.logo-link { .logo {
font-weight: 700; width: 32px;
position: absolute; height: 32px;
top: 150px; cursor: pointer;
right: 10px; position: fixed;
} z-index: 10;
top: 7px;
right: 10px;
}
.logo { #response {
width: 32px; position: absolute;
height: 32px; left: 10px;
cursor: pointer; right: 10px;
position: fixed; top: 440px;
z-index: 10; min-height: 110px;
top: 7px; background: #aab;
right: 10px; font-family: "Courier New", Courier, monospace;
} font-size: 12px;
word-wrap: break-word;
padding: 5px;
border-radius: 5px;
overflow-y: auto;
}
#response { input,
position: absolute; select {
left: 10px; background: white;
right: 10px; font-family: system-ui, sans-serif;
top: 440px; border: 0;
min-height: 110px; border-radius: 0.25rem;
background: #aab; font-size: 1rem;
font-family: 'Courier New', Courier, monospace; line-height: 1.2;
font-size: 12px; padding: 0.25rem 0.5rem;
word-wrap: break-word; margin: 0.25rem;
padding: 5px; }
border-radius: 5px;
overflow-y: auto;
}
input, button:hover,
select { button:focus {
background: white; background: #0053ba;
font-family: system-ui, sans-serif; }
border: 0;
border-radius: 0.25rem;
font-size: 1rem;
line-height: 1.2;
padding: 0.25rem 0.5rem;
margin: 0.25rem;
}
button:hover, button:focus {
button:focus { outline: 1px solid #fff;
background: #0053ba; outline-offset: -4px;
} }
button:focus { button:active {
outline: 1px solid #fff; transform: scale(0.99);
outline-offset: -4px; }
}
button:active { .button {
transform: scale(0.99); border: 0;
} border-radius: 0.25rem;
background: #1e88e5;
color: white;
font-family: system-ui, sans-serif;
font-size: 1rem;
line-height: 1.2;
white-space: nowrap;
text-decoration: none;
padding: 0.25rem 0.5rem;
margin: 0.25rem;
cursor: pointer;
}
.button { .bottom {
border: 0; position: fixed;
border-radius: 0.25rem; bottom: 0;
background: #1E88E5; left: 0;
color: white; text-align: center;
font-family: system-ui, sans-serif; width: 100%;
font-size: 1rem; padding: 5px;
line-height: 1.2; background: #333;
white-space: nowrap; color: #eef;
text-decoration: none; }
padding: 0.25rem 0.5rem;
margin: 0.25rem;
cursor: pointer;
}
.bottom { .dark-link {
position: fixed; color: white;
bottom: 0; text-decoration: none !important;
left: 0; }
text-align: center;
width: 100%;
padding: 5px;
background: #333;
color: #eef;
}
.dark-link { .tabs-container {
color: white; position: fixed;
text-decoration: none !important; height: 400px;
} top: 20px;
left: 10px;
right: 10px;
z-index: 9;
}
.tabs-container { .tabs {
position: fixed; position: relative;
height: 400px; min-height: 400px;
top: 20px; clear: both;
left: 10px; }
right: 10px;
z-index: 9;
}
.tabs { .tab {
position: relative; float: left;
min-height: 400px; }
clear: both;
}
.tab { .tab > label {
float: left; background: #eee;
} padding: 10px;
border: 1px solid transparent;
margin-left: -1px;
position: relative;
left: 1px;
}
.tab>label { .tabs > .tabber {
background: #eee; border-top-left-radius: 5px;
padding: 10px; }
border: 1px solid transparent;
margin-left: -1px;
position: relative;
left: 1px;
}
.tabs>.tabber { .tabs > .tabber ~ .tabber {
border-top-left-radius: 5px; border-top-left-radius: none;
} }
.tabs>.tabber~.tabber { .tab [type="radio"] {
border-top-left-radius: none; display: none;
} }
.tab [type=radio] { .content {
display: none; position: absolute;
} top: 28px;
left: 0;
background: #bbc;
right: 0;
bottom: 0;
padding: 20px;
border: 1px solid transparent;
border-top-right-radius: 5px;
border-bottom-left-radius: 5px;
border-bottom-right-radius: 5px;
}
.content { [type="radio"]:checked ~ label {
position: absolute; background: #bbc;
top: 28px; border-bottom: 1px solid transparent;
left: 0; z-index: 2;
background: #bbc; }
right: 0;
bottom: 0;
padding: 20px;
border: 1px solid transparent;
border-top-right-radius: 5px;
border-bottom-left-radius: 5px;
border-bottom-right-radius: 5px;
}
[type=radio]:checked~label { [type="radio"]:checked ~ label ~ .content {
background: #bbc; z-index: 1;
border-bottom: 1px solid transparent; }
z-index: 2; </style>
} </head>
[type=radio]:checked~label~.content { <body>
z-index: 1; <div class="logo-container">
} <img src="icon.png" class="logo" />
</div>
</style> <div class="tabs-container">
</head> <div class="tabs">
<div class="tab">
<input type="radio" id="tab-1" name="tab-group-1" checked />
<label class="tabber" for="tab-1">Messages</label>
<div class="content">
<button class="button" id="log">Call Log API</button>
<button class="button" id="request">
Call Request (async) API
</button>
<button class="button" id="event">Send event to Rust</button>
<button class="button" id="notification">
Send test notification
</button>
<body> <div style="margin-top: 24px">
<div class="logo-container"> <input id="title" value="Awesome Tauri Example!" />
<img src="icon.png" class="logo"> <button class="button" id="set-title">Set title</button>
</div> </div>
<div class="tabs-container">
<div class="tabs">
<div class="tab">
<input type="radio" id="tab-1" name="tab-group-1" checked>
<label class="tabber" for="tab-1">Messages</label>
<div class="content">
<button class="button" id="log">Call Log API</button>
<button class="button" id="request">Call Request (async) API</button>
<button class="button" id="event">Send event to Rust</button>
<button class="button" id="notification">Send test notification</button>
<div style="margin-top: 24px">
<input id="title" value="Awesome Tauri Example!">
<button class="button" id="set-title">Set title</button>
</div> </div>
</div> </div>
</div> <div class="tab">
<div class="tab"> <input type="radio" id="tab-2" name="tab-group-1" />
<input type="radio" id="tab-2" name="tab-group-1"> <label class="tabber" for="tab-2">File System</label>
<label class="tabber" for="tab-2">File System</label> <div class="content">
<div class="content"> <div style="margin-top: 24px">
<div style="margin-top: 24px"> <select class="button" id="dir">
<select class="button" id="dir"> <option value="">None</option>
<option value="">None</option> </select>
</select> <input id="path-to-read" placeholder="Type the path to read..." />
<input id="path-to-read" placeholder="Type the path to read..."> <button class="button" id="read">Read</button>
<button class="button" id="read">Read</button>
</div>
<div style="margin-top: 24px">
<input id="dialog-default-path" placeholder="Default path">
<input id="dialog-filter" placeholder="Extensions filter">
<div>
<input type="checkbox" id="dialog-multiple">
<label>Multiple</label>
</div> </div>
<div> <div style="margin-top: 24px">
<input type="checkbox" id="dialog-directory"> <input id="dialog-default-path" placeholder="Default path" />
<label>Directory</label> <input id="dialog-filter" placeholder="Extensions filter" />
<div>
<input type="checkbox" id="dialog-multiple" />
<label>Multiple</label>
</div>
<div>
<input type="checkbox" id="dialog-directory" />
<label>Directory</label>
</div>
<button class="button" id="open-dialog">Open dialog</button>
<button class="button" id="save-dialog">Open save dialog</button>
</div>
</div>
</div>
<div class="tab">
<input type="radio" id="tab-3" name="tab-group-1" />
<label class="tabber" for="tab-3">Communication</label>
<div class="content">
<div style="margin-top: 24px">
<input id="url" value="https://tauri.studio" />
<button class="button" id="open-url">Open URL</button>
</div> </div>
<button class="button" id="open-dialog">Open dialog</button> <div style="margin-top: 24px">
<button class="button" id="save-dialog">Open save dialog</button> <select class="button" id="request-method">
<option value="GET">GET</option>
<option value="POST">POST</option>
<option value="PUT">PUT</option>
<option value="PATCH">PATCH</option>
<option value="DELETE">DELETE</option>
</select>
<input id="request-url" placeholder="Type the request URL..." />
<br />
<textarea
id="request-body"
placeholder="Request body"
rows="5"
style="width: 100%; margin-right: 10px; font-size: 12px"
></textarea>
<br />
<button class="button" id="make-request">Make request</button>
</div>
</div> </div>
</div> </div>
</div> <div class="tab">
<input type="radio" id="tab-4" name="tab-group-1" />
<div class="tab"> <label class="tabber" for="tab-4">CLI</label>
<input type="radio" id="tab-3" name="tab-group-1"> <div class="content">
<label class="tabber" for="tab-3">Communication</label> <div style="margin-top: 24px">
<div class="content"> <button class="button" id="cli-matches">Get matches</button>
<div style="margin-top: 24px"> </div>
<input id="url" value="https://tauri.studio">
<button class="button" id="open-url">Open URL</button>
</div>
<div style="margin-top: 24px">
<select class="button" id="request-method">
<option value="GET">GET</option>
<option value="POST">POST</option>
<option value="PUT">PUT</option>
<option value="PATCH">PATCH</option>
<option value="DELETE">DELETE</option>
</select>
<input id="request-url" placeholder="Type the request URL...">
<br />
<textarea id="request-body" placeholder="Request body" rows="5"
style="width:100%;margin-right:10px;font-size:12px"></textarea>
</br>
<button class="button" id="make-request">Make request</button>
</div>
</div>
</div>
<div class="tab">
<input type="radio" id="tab-4" name="tab-group-1">
<label class="tabber" for="tab-4">CLI</label>
<div class="content">
<div style="margin-top: 24px">
<button class="button" id="cli-matches">Get matches</button>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
</div> <div id="response"></div>
<div id="response"></div> <div class="bottom">
<div class="bottom"> <a class="dark-link" target="_blank" href="https://tauri.studio"
<a class="dark-link" target="_blank" href="https://tauri.studio">Tauri Documentation</a>&nbsp;&nbsp;&nbsp; >Tauri Documentation</a
<a class="dark-link" target="_blank" href="https://github.com/tauri-apps/tauri">Github Repo</a>&nbsp;&nbsp;&nbsp; >&nbsp;&nbsp;&nbsp;
<a class="dark-link" target="_blank" <a
href="https://github.com/tauri-apps/tauri/tree/dev/tauri/examples/communication">Source for this App</a> class="dark-link"
</div> target="_blank"
<script> href="https://github.com/tauri-apps/tauri"
function registerResponse(response) { >Github Repo</a
document.getElementById('response').innerHTML = typeof response === 'object' ? >&nbsp;&nbsp;&nbsp;
JSON.stringify(response) : <a
response class="dark-link"
} target="_blank"
href="https://github.com/tauri-apps/tauri/tree/dev/tauri/examples/communication"
function addClickEnterHandler(button, input, handler) { >Source for this App</a
button.addEventListener('click', handler) >
input.addEventListener('keyup', function (e) { </div>
if (e.keyCode === 13) { <script>
handler() function registerResponse(response) {
} document.getElementById("response").innerHTML =
}) typeof response === "object" ? JSON.stringify(response) : response;
}
window.__TAURI__.event.listen('rust-event', function (res) {
document.getElementById('response').innerHTML = JSON.stringify(res)
})
document.querySelector('.logo').addEventListener('click', function () {
window.__TAURI__.window.open('https://tauri.studio/')
})
var dirSelect = document.getElementById('dir')
for (var key in window.__TAURI__.fs.Dir) {
if (isNaN(parseInt(key))) {
var value = window.__TAURI__.fs.Dir[key]
var opt = document.createElement("option")
opt.value = value
opt.innerHTML = key
dirSelect.appendChild(opt)
} }
}
</script> function addClickEnterHandler(button, input, handler) {
<script src="communication.js"></script> button.addEventListener("click", handler);
<script src="fs.js"></script> input.addEventListener("keyup", function (e) {
<script src="window.js"></script> if (e.keyCode === 13) {
<script src="dialog.js"></script> handler();
<script src="http.js"></script> }
<script src="cli.js"></script> });
<script src="notification.js"></script> }
</body>
window.__TAURI__.event.listen("rust-event", function (res) {
document.getElementById("response").innerHTML = JSON.stringify(res);
});
document.querySelector(".logo").addEventListener("click", function () {
window.__TAURI__.window.open("https://tauri.studio/");
});
var dirSelect = document.getElementById("dir");
for (var key in window.__TAURI__.fs.Dir) {
if (isNaN(parseInt(key))) {
var value = window.__TAURI__.fs.Dir[key];
var opt = document.createElement("option");
opt.value = value;
opt.innerHTML = key;
dirSelect.appendChild(opt);
}
}
</script>
<script src="communication.js"></script>
<script src="fs.js"></script>
<script src="window.js"></script>
<script src="dialog.js"></script>
<script src="http.js"></script>
<script src="cli.js"></script>
<script src="notification.js"></script>
</body>
</html> </html>

File diff suppressed because one or more lines are too long

View File

@ -1,21 +1,23 @@
function sendNotification() { function sendNotification() {
new Notification('Notification title', { new Notification("Notification title", {
body: 'This is the notification body' body: "This is the notification body",
}) });
} }
document.getElementById('notification').addEventListener('click', function () { document.getElementById("notification").addEventListener("click", function () {
if (Notification.permission === 'default') { if (Notification.permission === "default") {
Notification.requestPermission().then(function (response) { Notification.requestPermission()
if (response === 'granted') { .then(function (response) {
sendNotification() if (response === "granted") {
} else { sendNotification();
registerResponse('Permission is ' + response) } else {
} registerResponse("Permission is " + response);
}).catch(registerResponse) }
} else if (Notification.permission === 'granted') { })
sendNotification() .catch(registerResponse);
} else if (Notification.permission === "granted") {
sendNotification();
} else { } else {
registerResponse('Permission is denied') registerResponse("Permission is denied");
} }
}) });

View File

@ -1,19 +1,19 @@
var urlInput = document.getElementById('url') var urlInput = document.getElementById("url");
addClickEnterHandler( addClickEnterHandler(
document.getElementById('open-url'), document.getElementById("open-url"),
urlInput, urlInput,
function () { function () {
window.__TAURI__.window.open(urlInput.value) window.__TAURI__.window.open(urlInput.value);
} }
) );
var titleInput = document.getElementById('title') var titleInput = document.getElementById("title");
addClickEnterHandler( addClickEnterHandler(
document.getElementById('set-title'), document.getElementById("set-title"),
titleInput, titleInput,
function () { function () {
window.__TAURI__.window.setTitle(titleInput.value) window.__TAURI__.window.setTitle(titleInput.value);
} }
) );

View File

@ -8,31 +8,37 @@
"tauri": { "tauri": {
"cli": { "cli": {
"description": "Tauri communication example", "description": "Tauri communication example",
"args": [{ "args": [
"short": "c", {
"name": "config", "short": "c",
"takesValue": true, "name": "config",
"description": "Config path" "takesValue": true,
}, { "description": "Config path"
"short": "t", },
"name": "theme", {
"takesValue": true, "short": "t",
"description": "App theme", "name": "theme",
"possibleValues": ["light", "dark", "system"] "takesValue": true,
}, { "description": "App theme",
"short": "v", "possibleValues": ["light", "dark", "system"]
"name": "verbose", },
"multipleOccurrences": true, {
"description": "Verbosity level" "short": "v",
}], "name": "verbose",
"multipleOccurrences": true,
"description": "Verbosity level"
}
],
"subcommands": { "subcommands": {
"update": { "update": {
"description": "Updates the app", "description": "Updates the app",
"args": [{ "args": [
"short": "b", {
"name": "background", "short": "b",
"description": "Update in background" "name": "background",
}] "description": "Update in background"
}
]
} }
} }
}, },
@ -43,7 +49,11 @@
"active": true, "active": true,
"identifier": "com.tauri.communication", "identifier": "com.tauri.communication",
"icon": [ "icon": [
"icons/32x32.png", "icons/128x128.png", "icons/128x128@2x.png", "icons/icon.icns", "icons/icon.ico" "icons/32x32.png",
"icons/128x128.png",
"icons/128x128@2x.png",
"icons/icon.icns",
"icons/icon.ico"
] ]
}, },
"allowlist": { "allowlist": {

View File

@ -1 +1 @@
{"devPath": "http://localhost"} { "devPath": "http://localhost" }

View File

@ -1 +1,6 @@
<html><head></head><body><iframe id=mainframe></iframe></body></html> <html>
<head></head>
<body>
<iframe id="mainframe"></iframe>
</body>
</html>