From 92b01ea05020e431a13ab96a1c0402be7877279e Mon Sep 17 00:00:00 2001 From: Fabian-Lars Date: Thu, 27 Apr 2023 12:23:49 +0200 Subject: [PATCH 1/5] refactor(fs-watch): make options arg optional, closes #3 (#334) * refactor(fs-watch): make options arg optional, closes #3 * fmt * readme --- plugins/fs-watch/README.md | 8 ++++---- plugins/fs-watch/guest-js/index.ts | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/plugins/fs-watch/README.md b/plugins/fs-watch/README.md index 8162d1fe..59729b4d 100644 --- a/plugins/fs-watch/README.md +++ b/plugins/fs-watch/README.md @@ -56,18 +56,18 @@ 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 { type, payload } = event; - } + }, + { recursive: true } ); const stopRawWatcher = await watchImmediate( ["/path/a", "/path/b"], - {}, (event) => { const { path, operation, cookie } = event; - } + }, + {} ); ``` 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, From 46f4a949c93fbefcbf9d0e2d77e72d637876669d Mon Sep 17 00:00:00 2001 From: Fabian-Lars Date: Thu, 27 Apr 2023 12:52:29 +0200 Subject: [PATCH 2/5] docs(positioner): Fix npm package name, fixes #6 --- plugins/positioner/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/positioner/README.md b/plugins/positioner/README.md index ebac8500..1fb9a01c 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: From 8de442113f51bf0016fd8cddb71eeba354d3e6d9 Mon Sep 17 00:00:00 2001 From: Fabian-Lars Date: Fri, 28 Apr 2023 21:20:10 +0200 Subject: [PATCH 3/5] fix(ws): Don't block main thread while connecting (#337) --- plugins/websocket/src/lib.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/plugins/websocket/src/lib.rs b/plugins/websocket/src/lib.rs index c3e08ace..1f06da32 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(); From d02432df065eaf9510d08f67bcff90cf618b6098 Mon Sep 17 00:00:00 2001 From: Fabian-Lars Date: Sun, 30 Apr 2023 17:02:25 +0200 Subject: [PATCH 4/5] fix(log): Replace unknown js location with `webview::unknown`, fixes #41 (#338) --- plugins/log/guest-js/index.ts | 7 ++++++- plugins/log/src/lib.rs | 8 ++++---- 2 files changed, 10 insertions(+), 5 deletions(-) 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 5f40cab0..9db4aa4e 100644 --- a/plugins/log/src/lib.rs +++ b/plugins/log/src/lib.rs @@ -146,8 +146,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); @@ -178,8 +178,8 @@ impl Default for Builder { out.finish(format_args!( "{}[{}][{}] {}", DEFAULT_TIMEZONE_STRATEGY.get_now().format(&format).unwrap(), - record.target(), record.level(), + record.target(), message )) }); @@ -213,8 +213,8 @@ impl Builder { out.finish(format_args!( "{}[{}][{}] {}", timezone_strategy.get_now().format(&format).unwrap(), - record.target(), record.level(), + record.target(), message )) }); @@ -273,8 +273,8 @@ impl Builder { out.finish(format_args!( "{}[{}][{}] {}", timezone_strategy.get_now().format(&format).unwrap(), - record.target(), colors.color(record.level()), + record.target(), message )) }) From 882fcf8ab13b2851faf92f10df692afa90ce1371 Mon Sep 17 00:00:00 2001 From: Lucas Fernandes Nogueira Date: Tue, 2 May 2023 09:42:52 -0700 Subject: [PATCH 5/5] feat(ci): update covector getPublishedVersion (#339) --- .changes/config.json | 4 +- .scripts/covector/package-latest-version.js | 54 +++++++++++++++++++++ 2 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 .scripts/covector/package-latest-version.js diff --git a/.changes/config.json b/.changes/config.json index d527385d..8de61c38 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') + } + }) +})