commit
6910342d34
@ -1,3 +1,4 @@
|
||||
target
|
||||
node_modules
|
||||
dist
|
||||
dist-js
|
||||
|
@ -0,0 +1,56 @@
|
||||
#!/usr/bin/env node
|
||||
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
/*
|
||||
This script is solely intended to be run as part of the `covector publish` step to
|
||||
check the latest version of a crate, considering the current minor version.
|
||||
*/
|
||||
|
||||
const https = require("https");
|
||||
|
||||
const kind = process.argv[2];
|
||||
const packageName = process.argv[3];
|
||||
const packageVersion = process.argv[4];
|
||||
const target = packageVersion.substring(0, packageVersion.lastIndexOf("."));
|
||||
|
||||
let url = null;
|
||||
switch (kind) {
|
||||
case "cargo":
|
||||
url = `https://crates.io/api/v1/crates/${packageName}`;
|
||||
break;
|
||||
case "npm":
|
||||
url = `https://registry.npmjs.org/${packageName}`;
|
||||
break;
|
||||
default:
|
||||
throw new Error("unexpected kind " + kind);
|
||||
}
|
||||
|
||||
const options = {
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Accept: "application/json",
|
||||
"User-Agent": "tauri (https://github.com/tauri-apps/tauri)",
|
||||
},
|
||||
};
|
||||
|
||||
https.get(url, options, (response) => {
|
||||
let chunks = [];
|
||||
response.on("data", function (chunk) {
|
||||
chunks.push(chunk);
|
||||
});
|
||||
|
||||
response.on("end", function () {
|
||||
const data = JSON.parse(chunks.join(""));
|
||||
if (kind === "cargo") {
|
||||
const versions = data.versions.filter((v) => v.num.startsWith(target));
|
||||
console.log(versions.length ? versions[0].num : "0.0.0");
|
||||
} else if (kind === "npm") {
|
||||
const versions = Object.keys(data.versions).filter((v) =>
|
||||
v.startsWith(target)
|
||||
);
|
||||
console.log(versions[versions.length - 1] || "0.0.0");
|
||||
}
|
||||
});
|
||||
});
|
@ -1,71 +1,71 @@
|
||||
(function () {
|
||||
let permissionSettable = false
|
||||
let permissionValue = 'default'
|
||||
let permissionSettable = false;
|
||||
let permissionValue = "default";
|
||||
|
||||
function isPermissionGranted() {
|
||||
if (window.Notification.permission !== 'default') {
|
||||
return Promise.resolve(window.Notification.permission === 'granted')
|
||||
if (window.Notification.permission !== "default") {
|
||||
return Promise.resolve(window.Notification.permission === "granted");
|
||||
}
|
||||
return __TAURI__.invoke('plugin:notification|is_permission_granted')
|
||||
return window.__TAURI__.invoke("plugin:notification|is_permission_granted");
|
||||
}
|
||||
|
||||
function setNotificationPermission(value) {
|
||||
permissionSettable = true
|
||||
permissionSettable = true;
|
||||
// @ts-expect-error we can actually set this value on the webview
|
||||
window.Notification.permission = value
|
||||
permissionSettable = false
|
||||
window.Notification.permission = value;
|
||||
permissionSettable = false;
|
||||
}
|
||||
|
||||
function requestPermission() {
|
||||
return __TAURI__.invoke('plugin:notification|request_permission')
|
||||
return window.__TAURI__
|
||||
.invoke("plugin:notification|request_permission")
|
||||
.then(function (permission) {
|
||||
setNotificationPermission(permission)
|
||||
return permission
|
||||
})
|
||||
setNotificationPermission(permission);
|
||||
return permission;
|
||||
});
|
||||
}
|
||||
|
||||
function sendNotification(options) {
|
||||
if (typeof options === 'object') {
|
||||
Object.freeze(options)
|
||||
if (typeof options === "object") {
|
||||
Object.freeze(options);
|
||||
}
|
||||
|
||||
return __TAURI__.invoke('plugin:notification|notify', {
|
||||
options: typeof options === 'string'
|
||||
return window.__TAURI__.invoke("plugin:notification|notify", {
|
||||
options:
|
||||
typeof options === "string"
|
||||
? {
|
||||
title: options
|
||||
title: options,
|
||||
}
|
||||
: options
|
||||
})
|
||||
: options,
|
||||
});
|
||||
}
|
||||
|
||||
// @ts-expect-error unfortunately we can't implement the whole type, so we overwrite it with our own version
|
||||
window.Notification = function (title, options) {
|
||||
const opts = options || {}
|
||||
sendNotification(
|
||||
Object.assign(opts, { title })
|
||||
)
|
||||
}
|
||||
const opts = options || {};
|
||||
sendNotification(Object.assign(opts, { title }));
|
||||
};
|
||||
|
||||
window.Notification.requestPermission = requestPermission
|
||||
window.Notification.requestPermission = requestPermission;
|
||||
|
||||
Object.defineProperty(window.Notification, 'permission', {
|
||||
Object.defineProperty(window.Notification, "permission", {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return permissionValue
|
||||
return permissionValue;
|
||||
},
|
||||
set: function (v) {
|
||||
if (!permissionSettable) {
|
||||
throw new Error('Readonly property')
|
||||
}
|
||||
permissionValue = v
|
||||
throw new Error("Readonly property");
|
||||
}
|
||||
})
|
||||
permissionValue = v;
|
||||
},
|
||||
});
|
||||
|
||||
isPermissionGranted().then(function (response) {
|
||||
if (response === null) {
|
||||
setNotificationPermission('default')
|
||||
setNotificationPermission("default");
|
||||
} else {
|
||||
setNotificationPermission(response ? 'granted' : 'denied')
|
||||
setNotificationPermission(response ? "granted" : "denied");
|
||||
}
|
||||
})
|
||||
})()
|
||||
});
|
||||
})();
|
||||
|
Loading…
Reference in new issue