diff --git a/.changes/config.json b/.changes/config.json index 5834d96b..19006ae4 100644 --- a/.changes/config.json +++ b/.changes/config.json @@ -3,12 +3,12 @@ "pkgManagers": { "javascript": { "version": true, - "getPublishedVersion": "pnpm view ${ pkgFile.pkg.name } version", + "getPublishedVersion": "node ../../.scripts/covector/package-latest-version.js npm ${ pkgFile.pkg.name } ${ pkgFile.pkg.version }", "publish": ["pnpm build", "pnpm publish --access public --no-git-checks"] }, "rust": { "version": true, - "getPublishedVersion": "cargo search ${ pkgFile.pkg.package.name } --limit 1 | sed -nE 's/^[^\"]*\"//; s/\".*//1p' -", + "getPublishedVersion": "node ../../.scripts/covector/package-latest-version.js cargo ${ pkgFile.pkg.package.name } ${ pkgFile.pkg.package.version }", "publish": [ { "command": "cargo package --no-verify", diff --git a/.scripts/covector/package-latest-version.js b/.scripts/covector/package-latest-version.js new file mode 100644 index 00000000..d7ec15ad --- /dev/null +++ b/.scripts/covector/package-latest-version.js @@ -0,0 +1,54 @@ +#!/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') + } + }) +}) diff --git a/plugins/fs-watch/README.md b/plugins/fs-watch/README.md index 13b6f42e..a01de8f8 100644 --- a/plugins/fs-watch/README.md +++ b/plugins/fs-watch/README.md @@ -54,13 +54,21 @@ Afterwards all the plugin's APIs are available through the JavaScript guest bind import { watch, watchImmediate } from 'tauri-plugin-fs-watch-api'; // can also watch an array of paths -const stopWatching = await watch('/path/to/something', { recursive: true }, (event) => { +const stopWatching = await watch( + "/path/to/something", + (event) => { const { type, payload } = event; -}); + }, + { recursive: true } +); -const stopRawWatcher = await watchImmediate(['/path/a', '/path/b'], {}, (event) => { +const stopRawWatcher = await watchImmediate( + ["/path/a", "/path/b"], + (event) => { const { path, operation, cookie } = event; -}); + }, + {} +); ``` ## Contributing diff --git a/plugins/fs-watch/guest-js/index.ts b/plugins/fs-watch/guest-js/index.ts index 31d333b2..05ed07e5 100644 --- a/plugins/fs-watch/guest-js/index.ts +++ b/plugins/fs-watch/guest-js/index.ts @@ -44,8 +44,8 @@ async function unwatch(id: number): Promise { export async function watch( paths: string | string[], - options: DebouncedWatchOptions, - cb: (event: DebouncedEvent) => void + cb: (event: DebouncedEvent) => void, + options: DebouncedWatchOptions = {} ): Promise { const opts = { recursive: false, @@ -82,8 +82,8 @@ export async function watch( export async function watchImmediate( paths: string | string[], - options: WatchOptions, - cb: (event: RawEvent) => void + cb: (event: RawEvent) => void, + options: WatchOptions = {} ): Promise { const opts = { recursive: false, diff --git a/plugins/log/guest-js/index.ts b/plugins/log/guest-js/index.ts index bf67c16b..f421b7bc 100644 --- a/plugins/log/guest-js/index.ts +++ b/plugins/log/guest-js/index.ts @@ -52,10 +52,15 @@ async function log( const { file, line, ...keyValues } = options ?? {}; + let location = filtered?.[0]?.filter((v) => v.length > 0).join("@"); + if (location === "Error") { + location = "webview::unknown"; + } + await invoke("plugin:log|log", { level, message, - location: filtered?.[0]?.filter((v) => v.length > 0).join("@"), + location, file, line, keyValues, diff --git a/plugins/log/src/lib.rs b/plugins/log/src/lib.rs index 4f7f3134..cbb6dd29 100644 --- a/plugins/log/src/lib.rs +++ b/plugins/log/src/lib.rs @@ -178,8 +178,8 @@ fn log( let location = location.unwrap_or("webview"); let mut builder = RecordBuilder::new(); builder - .target(location) .level(level.into()) + .target(location) .file(file) .line(line); @@ -251,8 +251,8 @@ impl Builder { out.finish(format_args!( "{}[{}][{}] {}", timezone_strategy.get_now().format(&format).unwrap(), - record.target(), record.level(), + record.target(), message )) }); @@ -311,8 +311,8 @@ impl Builder { out.finish(format_args!( "{}[{}][{}] {}", timezone_strategy.get_now().format(&format).unwrap(), - record.target(), colors.color(record.level()), + record.target(), message )) }) diff --git a/plugins/positioner/README.md b/plugins/positioner/README.md index 099f7575..d5f8fe37 100644 --- a/plugins/positioner/README.md +++ b/plugins/positioner/README.md @@ -30,11 +30,11 @@ You can install the JavaScript Guest bindings using your preferred JavaScript pa > Note: Since most JavaScript package managers are unable to install packages from git monorepos we provide read-only mirrors of each plugin. This makes installation option 2 more ergonomic to use. ```sh -pnpm add tauri-plugin-positioner +pnpm add tauri-plugin-positioner-api # or -npm add tauri-plugin-positioner +npm add tauri-plugin-positioner-api # or -yarn add tauri-plugin-positioner +yarn add tauri-plugin-positioner-api ``` Or through git: diff --git a/plugins/websocket/src/lib.rs b/plugins/websocket/src/lib.rs index ba22d0b9..b61f2537 100644 --- a/plugins/websocket/src/lib.rs +++ b/plugins/websocket/src/lib.rs @@ -79,15 +79,14 @@ enum WebSocketMessage { } #[tauri::command] -fn connect( +async fn connect( window: Window, url: String, callback_function: CallbackFn, config: Option, ) -> Result { let id = rand::random(); - let (ws_stream, _) = - tauri::async_runtime::block_on(connect_async_with_config(url, config.map(Into::into)))?; + let (ws_stream, _) = connect_async_with_config(url, config.map(Into::into)).await?; tauri::async_runtime::spawn(async move { let (write, read) = ws_stream.split();