Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/v1' into chore/merge-v1-into-v2
Browse files Browse the repository at this point in the history
  • Loading branch information
FabianLars committed Apr 15, 2024
2 parents 1f9e7ab + 5c97db9 commit ed46dca
Show file tree
Hide file tree
Showing 65 changed files with 1,075 additions and 371 deletions.
5 changes: 5 additions & 0 deletions .changes/feat-log-attachlogger.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"log-js": patch
---

Added `attachLogger` helper function to register a function that should be called for each log entry.
5 changes: 5 additions & 0 deletions .changes/feat-single-instance-semver.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"single-instance": patch
---

Added the `semver` feature flag to make the single instance mechanism only trigger for semver compatible versions.
5 changes: 5 additions & 0 deletions .changes/feat-websocket-tls-connector.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"websocket": patch
---

**Breaking change:** Enable rustls by default and added a method to configure the TLS Connector for tungstenite.
6 changes: 6 additions & 0 deletions .changes/upload-returnval.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"upload": patch
"upload-js": patch
---

Return the upload response as a string and error out if the status code is not within 200-299.
2 changes: 1 addition & 1 deletion .github/workflows/covector-version-or-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,5 @@ jobs:
title: "Publish New Versions"
commit-message: "publish new versions"
labels: "version updates"
branch: "release"
branch: "ci/release-v1"
body: ${{ steps.covector.outputs.change }}
13 changes: 13 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@
"@rollup/plugin-node-resolve": "15.2.3",
"@rollup/plugin-terser": "0.4.4",
"@rollup/plugin-typescript": "11.1.6",
"@typescript-eslint/eslint-plugin": "6.20.0",
"@typescript-eslint/parser": "6.20.0",
"@typescript-eslint/eslint-plugin": "7.6.0",
"@typescript-eslint/parser": "7.6.0",
"covector": "^0.10.2",
"eslint": "8.56.0",
"eslint": "8.57.0",
"eslint-config-prettier": "9.1.0",
"eslint-config-standard-with-typescript": "43.0.1",
"eslint-plugin-import": "2.29.1",
"eslint-plugin-n": "16.6.2",
"eslint-plugin-n": "17.2.1",
"eslint-plugin-promise": "6.1.1",
"eslint-plugin-security": "2.1.0",
"prettier": "3.2.2",
"rollup": "4.9.6",
"eslint-plugin-security": "3.0.0",
"prettier": "3.2.5",
"rollup": "4.14.3",
"tslib": "2.6.2",
"typescript": "5.3.3"
"typescript": "5.4.5"
},
"resolutions": {
"semver": ">=7.5.2",
Expand Down
4 changes: 3 additions & 1 deletion plugins/log/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ tauri-plugin-log = "2.0.0-beta"
tauri-plugin-log = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v2" }
```

You can install the JavaScript Guest bindings using your preferred JavaScript package manager:
If you want the single instance mechanism to only trigger for semver compatible instances of your apps, for example if you expect users to have multiple installations of your app installed, you can add `features = ["semver"]` to the dependency declaration in `Cargo.toml`.

Then you can install the JavaScript Guest bindings using your preferred JavaScript package manager:

> 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.
Expand Down
2 changes: 1 addition & 1 deletion plugins/log/api-iife.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 26 additions & 8 deletions plugins/log/guest-js/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT

import { listen, UnlistenFn } from "@tauri-apps/api/event";

import { invoke } from "@tauri-apps/api/core";
import { listen, type UnlistenFn, type Event } from "@tauri-apps/api/event";

export type LogOptions = {
file?: string;
Expand Down Expand Up @@ -189,19 +188,38 @@ interface RecordPayload {
message: string;
}

export async function attachConsole(): Promise<UnlistenFn> {
return await listen("log://log", (event) => {
const payload = event.payload as RecordPayload;
type LoggerFn = (fn: RecordPayload) => void;

/**
* Attaches a listener for the log, and calls the passed function for each log entry.
* @param fn
*
* @returns a function to cancel the listener.
*/
export async function attachLogger(fn: LoggerFn): Promise<UnlistenFn> {
return await listen("log://log", (event: Event<RecordPayload>) => {
const { level } = event.payload;
let { message } = event.payload;

// Strip ANSI escape codes
const message = payload.message.replace(
message = message.replace(
// TODO: Investigate security/detect-unsafe-regex
// eslint-disable-next-line no-control-regex, security/detect-unsafe-regex
/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g,
"",
);
fn({ message, level });
});
}

switch (payload.level) {
/**
* Attaches a listener that writes log entries to the console as they come in.
*
* @returns a function to cancel the listener.
*/
export async function attachConsole(): Promise<UnlistenFn> {
return attachLogger(({ level, message }: RecordPayload) => {
switch (level) {
case LogLevel.Trace:
console.log(message);
break;
Expand All @@ -219,7 +237,7 @@ export async function attachConsole(): Promise<UnlistenFn> {
break;
default:
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
throw new Error(`unknown log level ${payload.level}`);
throw new Error(`unknown log level ${level}`);
}
});
}
5 changes: 5 additions & 0 deletions plugins/positioner/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@

- [`717ae67`](https://github.com/tauri-apps/plugins-workspace/commit/717ae670978feb4492fac1f295998b93f2b9347f)([#371](https://github.com/tauri-apps/plugins-workspace/pull/371)) First v2 alpha release!

## \[1.0.5]

- `TrayLeft`, `TrayRight` and `TrayCenter` will now position the window according to the tray position relative to the monitor dimensions to prevent windows being displayed partially off-screen.
- [3d27909](https://github.com/tauri-apps/plugins-workspace/commit/3d279094d44be78cdc5d1de3938f1414e13db6b0) fix(positioner): Prevent tray relative windows from being moved off-screen ([#291](https://github.com/tauri-apps/plugins-workspace/pull/291)) on 2023-09-27

## \[0.2.7]

- Update Tauri to v1.0.0
Expand Down
10 changes: 4 additions & 6 deletions plugins/positioner/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,11 @@ struct Tray(std::sync::Mutex<Option<(PhysicalPosition<f64>, PhysicalSize<f64>)>>
#[cfg(feature = "tray-icon")]
pub fn on_tray_event<R: Runtime>(app: &AppHandle<R>, event: &TrayIconEvent) {
let position = PhysicalPosition {
x: event.x,
y: event.y,
};
let size = PhysicalSize {
width: event.icon_rect.right - event.icon_rect.left,
height: event.icon_rect.bottom - event.icon_rect.top,
x: event.position.x,
y: event.position.y,
};
// tray-icon emits PhysicalSize so the scale factor should not matter.
let size = event.icon_rect.size.to_physical(1.0);
app.state::<Tray>()
.0
.lock()
Expand Down
4 changes: 4 additions & 0 deletions plugins/single-instance/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ serde_json = { workspace = true }
tauri = { workspace = true }
log = { workspace = true }
thiserror = { workspace = true }
semver = { version = "1", optional = true }

[target."cfg(target_os = \"windows\")".dependencies.windows-sys]
version = "0.52"
Expand All @@ -34,3 +35,6 @@ features = [

[target."cfg(target_os = \"linux\")".dependencies]
zbus = "4"

[features]
semver = ["dep:semver"]
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ edition = "2021"
rust-version = "1.75"

[dependencies]
serde_json = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
tauri = { workspace = true }
tauri-plugin-single-instance = { path = "../../../" }
tauri-plugin-cli = { path = "../../../../cli" }
Expand Down
3 changes: 3 additions & 0 deletions plugins/single-instance/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ mod platform_impl;
#[path = "platform_impl/macos.rs"]
mod platform_impl;

#[cfg(feature = "semver")]
mod semver_compat;

pub(crate) type SingleInstanceCallback<R> =
dyn FnMut(&AppHandle<R>, Vec<String>, String) + Send + Sync + 'static;

Expand Down
26 changes: 25 additions & 1 deletion plugins/single-instance/src/platform_impl/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

#![cfg(target_os = "linux")]

#[cfg(feature = "semver")]
use crate::semver_compat::semver_compat_string;

use crate::SingleInstanceCallback;
use tauri::{
plugin::{self, TauriPlugin},
Expand All @@ -28,14 +31,27 @@ impl<R: Runtime> SingleInstanceDBus<R> {
}
}

#[cfg(feature = "semver")]
fn dbus_id(config: &Config, version: semver::Version) -> String {
let mut id = config.identifier.replace(['.', '-'], "_");
id.push('_');
id.push_str(semver_compat_string(version).as_str());
id
}

#[cfg(not(feature = "semver"))]
fn dbus_id(config: &Config) -> String {
config.identifier.replace(['.', '-'], "_")
}

pub fn init<R: Runtime>(f: Box<SingleInstanceCallback<R>>) -> TauriPlugin<R> {
plugin::Builder::new("single-instance")
.setup(|app, _api| {
#[cfg(feature = "semver")]
let id = dbus_id(app.config(), app.package_info().version.clone());
#[cfg(not(feature = "semver"))]
let id = dbus_id(app.config());

let single_instance_dbus = SingleInstanceDBus {
callback: f,
app_handle: app.clone(),
Expand Down Expand Up @@ -88,7 +104,15 @@ pub fn init<R: Runtime>(f: Box<SingleInstanceCallback<R>>) -> TauriPlugin<R> {

pub fn destroy<R: Runtime, M: Manager<R>>(manager: &M) {
if let Some(connection) = manager.try_state::<ConnectionHandle>() {
let dbus_name = format!("org.{}.SingleInstance", dbus_id(manager.config()));
#[cfg(feature = "semver")]
let id = dbus_id(
manager.config(),
manager.app_handle().package_info().version.clone(),
);
#[cfg(not(feature = "semver"))]
let id = dbus_id(manager.config());

let dbus_name = format!("org.{id}.SingleInstance",);
let _ = connection.0.release_name(dbus_name);
}
}
15 changes: 12 additions & 3 deletions plugins/single-instance/src/platform_impl/macos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ use std::{
path::PathBuf,
};

#[cfg(feature = "semver")]
use crate::semver_compat::semver_compat_string;
use crate::SingleInstanceCallback;
use tauri::{
plugin::{self, TauriPlugin},
Expand All @@ -19,7 +21,7 @@ use tauri::{
pub fn init<R: Runtime>(cb: Box<SingleInstanceCallback<R>>) -> TauriPlugin<R> {
plugin::Builder::new("single-instance")
.setup(|app, _api| {
let socket = socket_path(app.config());
let socket = socket_path(app.config(), app.package_info());

// Notify the singleton which may or may not exist.
match notify_singleton(&socket) {
Expand Down Expand Up @@ -53,12 +55,19 @@ pub fn init<R: Runtime>(cb: Box<SingleInstanceCallback<R>>) -> TauriPlugin<R> {
}

pub fn destroy<R: Runtime, M: Manager<R>>(manager: &M) {
let socket = socket_path(manager.config());
let socket = socket_path(manager.config(), manager.package_info());
socket_cleanup(&socket);
}

fn socket_path(config: &Config) -> PathBuf {
fn socket_path(config: &Config, _package_info: &tauri::PackageInfo) -> PathBuf {
let identifier = config.identifier.replace(['.', '-'].as_ref(), "_");

#[cfg(feature = "semver")]
let identifier = format!(
"{identifier}_{}",
semver_compat_string(_package_info.version.clone()),
);

// Use /tmp as socket path must be shorter than 100 chars.
PathBuf::from(format!("/tmp/{}_si.sock", identifier))
}
Expand Down
11 changes: 10 additions & 1 deletion plugins/single-instance/src/platform_impl/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

#![cfg(target_os = "windows")]

#[cfg(feature = "semver")]
use crate::semver_compat::semver_compat_string;

use crate::SingleInstanceCallback;
use std::ffi::CStr;
use tauri::{
Expand Down Expand Up @@ -33,7 +36,13 @@ const WMCOPYDATA_SINGLE_INSTANCE_DATA: usize = 1542;
pub fn init<R: Runtime>(f: Box<SingleInstanceCallback<R>>) -> TauriPlugin<R> {
plugin::Builder::new("single-instance")
.setup(|app, _api| {
let id = &app.config().identifier;
#[allow(unused_mut)]
let mut id = app.config().identifier.clone();
#[cfg(feature = "semver")]
{
id.push('_');
id.push_str(semver_compat_string(app.package_info().version.clone()).as_str());
}

let class_name = encode_wide(format!("{id}-sic"));
let window_name = encode_wide(format!("{id}-siw"));
Expand Down
21 changes: 21 additions & 0 deletions plugins/single-instance/src/semver_compat.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT

#![cfg(feature = "semver")]

/// Takes a version and spits out a String with trailing _x, thus only considering the digits
/// relevant regarding semver compatibility
pub fn semver_compat_string(version: semver::Version) -> String {
// for pre-release always treat each version separately
if !version.pre.is_empty() {
return version.to_string().replace(['.', '-'], "_");
}
match version.major {
0 => match version.minor {
0 => format!("0_0_{}", version.patch),
_ => format!("0_{}_x", version.minor),
},
_ => format!("{}_x_x", version.major),
}
}
Loading

0 comments on commit ed46dca

Please sign in to comment.