Skip to content

Commit

Permalink
Merge branch '1.x' into fix/updater-relaunch-args
Browse files Browse the repository at this point in the history
  • Loading branch information
amrbashir authored Aug 31, 2023
2 parents 1cb2496 + 49beb67 commit fa3c9ca
Show file tree
Hide file tree
Showing 11 changed files with 174 additions and 45 deletions.
6 changes: 6 additions & 0 deletions .changes/enhance-cli-cargo-tauri-cli-version-info.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"tauri-cli": minor:enhance
"@tauri-apps/cli": minor:enhance
---

Add version of Rust Tauri CLI installed with Cargo to `tauri info` command.
6 changes: 6 additions & 0 deletions .changes/support-bun.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'tauri-cli': 'patch:feat'
'@tauri-apps/cli': 'patch:feat'
---

Support Bun package manager in CLI
9 changes: 0 additions & 9 deletions core/tauri-build/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,15 +406,6 @@ pub fn try_build(attributes: Attributes) -> Result<()> {
res.set_manifest(include_str!("window-app-manifest.xml"));
}

if let Some(sdk_dir) = &attributes.windows_attributes.sdk_dir {
if let Some(sdk_dir_str) = sdk_dir.to_str() {
res.set_toolkit_path(sdk_dir_str);
} else {
return Err(anyhow!(
"sdk_dir path is not valid; only UTF-8 characters are allowed"
));
}
}
if let Some(version_str) = &config.package.version {
if let Ok(v) = Version::parse(version_str) {
let version = v.major << 48 | v.minor << 32 | v.patch << 16;
Expand Down
49 changes: 25 additions & 24 deletions core/tauri-runtime-wry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
//! The [`wry`] Tauri [`Runtime`].

use raw_window_handle::{HasRawDisplayHandle, HasRawWindowHandle, RawDisplayHandle};
use std::rc::Rc;
use tauri_runtime::{
http::{header::CONTENT_TYPE, Request as HttpRequest, RequestParts, Response as HttpResponse},
menu::{AboutMetadata, CustomMenuItem, Menu, MenuEntry, MenuHash, MenuId, MenuItem, MenuUpdate},
Expand Down Expand Up @@ -251,7 +252,7 @@ pub struct DispatcherMainThreadContext<T: UserEvent> {
pub global_shortcut_manager: Arc<Mutex<WryShortcutManager>>,
#[cfg(feature = "clipboard")]
pub clipboard_manager: Arc<Mutex<Clipboard>>,
pub windows: Arc<RefCell<HashMap<WebviewId, WindowWrapper>>>,
pub windows: Rc<RefCell<HashMap<WebviewId, WindowWrapper>>>,
#[cfg(all(desktop, feature = "system-tray"))]
system_tray_manager: SystemTrayManager,
}
Expand Down Expand Up @@ -1671,7 +1672,7 @@ impl<T: UserEvent> Dispatch<T> for WryDispatcher<T> {
#[derive(Clone)]
enum WindowHandle {
Webview {
inner: Arc<WebView>,
inner: Rc<WebView>,
context_store: WebContextStore,
// the key of the WebContext if it's not shared
context_key: Option<PathBuf>,
Expand All @@ -1687,7 +1688,7 @@ impl Drop for WindowHandle {
context_key,
} = self
{
if Arc::get_mut(inner).is_some() {
if Rc::get_mut(inner).is_some() {
context_store.lock().unwrap().remove(context_key);
}
}
Expand Down Expand Up @@ -1941,7 +1942,7 @@ impl<T: UserEvent> Wry<T> {
#[cfg(feature = "clipboard")]
let clipboard_manager = Arc::new(Mutex::new(Clipboard::new()));

let windows = Arc::new(RefCell::new(HashMap::default()));
let windows = Rc::new(RefCell::new(HashMap::default()));
let webview_id_map = WebviewIdStore::default();

#[cfg(all(desktop, feature = "system-tray"))]
Expand Down Expand Up @@ -2088,7 +2089,7 @@ impl<T: UserEvent> Runtime<T> for Wry<T> {
let id = system_tray.id;
let mut listeners = Vec::new();
if let Some(l) = system_tray.on_event.take() {
listeners.push(Arc::new(l));
listeners.push(Rc::new(l));
}
let (tray, items) = create_tray(WryTrayId(id), system_tray, &self.event_loop)?;
self
Expand All @@ -2101,9 +2102,9 @@ impl<T: UserEvent> Runtime<T> for Wry<T> {
.insert(
id,
TrayContext {
tray: Arc::new(Mutex::new(Some(tray))),
listeners: Arc::new(Mutex::new(listeners)),
items: Arc::new(Mutex::new(items)),
tray: Rc::new(Mutex::new(Some(tray))),
listeners: Rc::new(RefCell::new(listeners)),
items: Rc::new(RefCell::new(items)),
},
);

Expand Down Expand Up @@ -2304,7 +2305,7 @@ impl<T: UserEvent> Runtime<T> for Wry<T> {
pub struct EventLoopIterationContext<'a, T: UserEvent> {
pub callback: &'a mut (dyn FnMut(RunEvent<T>) + 'static),
pub webview_id_map: WebviewIdStore,
pub windows: Arc<RefCell<HashMap<WebviewId, WindowWrapper>>>,
pub windows: Rc<RefCell<HashMap<WebviewId, WindowWrapper>>>,
#[cfg(all(desktop, feature = "global-shortcut"))]
pub global_shortcut_manager: Arc<Mutex<WryShortcutManager>>,
#[cfg(all(desktop, feature = "global-shortcut"))]
Expand All @@ -2316,7 +2317,7 @@ pub struct EventLoopIterationContext<'a, T: UserEvent> {
}

struct UserMessageContext {
windows: Arc<RefCell<HashMap<WebviewId, WindowWrapper>>>,
windows: Rc<RefCell<HashMap<WebviewId, WindowWrapper>>>,
webview_id_map: WebviewIdStore,
#[cfg(all(desktop, feature = "global-shortcut"))]
global_shortcut_manager: Arc<Mutex<WryShortcutManager>>,
Expand Down Expand Up @@ -2645,16 +2646,16 @@ fn handle_user_message<T: UserEvent>(
if let TrayMessage::Create(mut tray, tx) = tray_message {
let mut listeners = Vec::new();
if let Some(l) = tray.on_event.take() {
listeners.push(Arc::new(l));
listeners.push(Rc::new(l));
}
match create_tray(WryTrayId(tray_id), tray, event_loop) {
Ok((tray, items)) => {
trays.insert(
tray_id,
TrayContext {
tray: Arc::new(Mutex::new(Some(tray))),
listeners: Arc::new(Mutex::new(listeners)),
items: Arc::new(Mutex::new(items)),
tray: Rc::new(Mutex::new(Some(tray))),
listeners: Rc::new(RefCell::new(listeners)),
items: Rc::new(RefCell::new(items)),
},
);

Expand All @@ -2668,7 +2669,7 @@ fn handle_user_message<T: UserEvent>(
} else if let Some(tray_context) = trays.get(&tray_id) {
match tray_message {
TrayMessage::UpdateItem(menu_id, update) => {
let mut tray = tray_context.items.as_ref().lock().unwrap();
let mut tray = tray_context.items.as_ref().borrow_mut();
let item = tray.get_mut(&menu_id).expect("menu item not found");
match update {
MenuUpdate::SetEnabled(enabled) => item.set_enabled(enabled),
Expand All @@ -2684,7 +2685,7 @@ fn handle_user_message<T: UserEvent>(
if let Some(tray) = &mut *tray_context.tray.lock().unwrap() {
let mut items = HashMap::new();
tray.set_menu(&to_wry_context_menu(&mut items, menu));
*tray_context.items.lock().unwrap() = items;
*tray_context.items.borrow_mut() = items;
}
}
TrayMessage::UpdateIcon(icon) => {
Expand Down Expand Up @@ -2716,8 +2717,8 @@ fn handle_user_message<T: UserEvent>(
}
TrayMessage::Destroy(tx) => {
*tray_context.tray.lock().unwrap() = None;
tray_context.listeners.lock().unwrap().clear();
tray_context.items.lock().unwrap().clear();
tray_context.listeners.borrow_mut().clear();
tray_context.items.borrow_mut().clear();
tx.send(Ok(())).unwrap();
}
}
Expand Down Expand Up @@ -2843,11 +2844,11 @@ fn handle_event_loop<T: UserEvent>(
let (mut listeners, mut tray_id) = (None, 0);
for (id, tray_context) in trays_iter {
let has_menu = {
let items = tray_context.items.lock().unwrap();
let items = tray_context.items.borrow();
items.contains_key(&menu_id.0)
};
if has_menu {
listeners.replace(tray_context.listeners.lock().unwrap().clone());
listeners.replace(tray_context.listeners.borrow().clone());
tray_id = *id;
break;
}
Expand Down Expand Up @@ -2886,7 +2887,7 @@ fn handle_event_loop<T: UserEvent>(
};
let trays = system_tray_manager.trays.lock().unwrap();
if let Some(tray_context) = trays.get(&id.0) {
let listeners = tray_context.listeners.lock().unwrap();
let listeners = tray_context.listeners.borrow();
let iter = listeners.iter();
for handler in iter {
handler(&event);
Expand Down Expand Up @@ -3016,7 +3017,7 @@ fn handle_event_loop<T: UserEvent>(
fn on_close_requested<'a, T: UserEvent>(
callback: &'a mut (dyn FnMut(RunEvent<T>) + 'static),
window_id: WebviewId,
windows: Arc<RefCell<HashMap<WebviewId, WindowWrapper>>>,
windows: Rc<RefCell<HashMap<WebviewId, WindowWrapper>>>,
) {
let (tx, rx) = channel();
let windows_ref = windows.borrow();
Expand Down Expand Up @@ -3044,7 +3045,7 @@ fn on_close_requested<'a, T: UserEvent>(
}
}

fn on_window_close(window_id: WebviewId, windows: Arc<RefCell<HashMap<WebviewId, WindowWrapper>>>) {
fn on_window_close(window_id: WebviewId, windows: Rc<RefCell<HashMap<WebviewId, WindowWrapper>>>) {
if let Some(window_wrapper) = windows.borrow_mut().get_mut(&window_id) {
window_wrapper.inner = None;
}
Expand Down Expand Up @@ -3289,7 +3290,7 @@ fn create_webview<T: UserEvent>(
Ok(WindowWrapper {
label,
inner: Some(WindowHandle::Webview {
inner: Arc::new(webview),
inner: Rc::new(webview),
context_store: web_context_store.clone(),
context_key: if automation_enabled {
None
Expand Down
8 changes: 5 additions & 3 deletions core/tauri-runtime-wry/src/system_tray.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,23 @@ use crate::{send_user_message, Context, Error, Message, Result, TrayId, TrayMess
use tauri_runtime::{menu::MenuHash, SystemTray, UserEvent};

use std::{
cell::RefCell,
collections::HashMap,
fmt,
rc::Rc,
sync::{Arc, Mutex},
};

pub type GlobalSystemTrayEventHandler = Box<dyn Fn(TrayId, &SystemTrayEvent) + Send>;
pub type GlobalSystemTrayEventListeners = Arc<Mutex<Vec<Arc<GlobalSystemTrayEventHandler>>>>;

pub type SystemTrayEventHandler = Box<dyn Fn(&SystemTrayEvent) + Send>;
pub type SystemTrayEventListeners = Arc<Mutex<Vec<Arc<SystemTrayEventHandler>>>>;
pub type SystemTrayItems = Arc<Mutex<HashMap<u16, WryCustomMenuItem>>>;
pub type SystemTrayEventListeners = Rc<RefCell<Vec<Rc<SystemTrayEventHandler>>>>;
pub type SystemTrayItems = Rc<RefCell<HashMap<u16, WryCustomMenuItem>>>;

#[derive(Clone, Default)]
pub struct TrayContext {
pub tray: Arc<Mutex<Option<WrySystemTray>>>,
pub tray: Rc<Mutex<Option<WrySystemTray>>>,
pub listeners: SystemTrayEventListeners,
pub items: SystemTrayItems,
}
Expand Down
2 changes: 1 addition & 1 deletion tooling/cli/node/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Tauri is a polyglot and generic system that is very composable and allows engine

Tauri apps can have custom menus and have tray-type interfaces. They can be updated, and are managed by the user's operating system as expected. They are very small, because they use the system's webview. They do not ship a runtime, since the final binary is compiled from rust. This makes the reversing of Tauri apps not a trivial task.
## This module
Written in Typescript and packaged such that it can be used with `npm`, `pnpm`, and `yarn`, this library provides a node.js runner for common tasks when using Tauri, like `yarn tauri dev`. For the most part it is a wrapper around [tauri-cli](https://github.com/tauri-apps/tauri/blob/dev/tooling/cli).
Written in Typescript and packaged such that it can be used with `npm`, `pnpm`, `yarn`, and `bun`, this library provides a node.js runner for common tasks when using Tauri, like `yarn tauri dev`. For the most part it is a wrapper around [tauri-cli](https://github.com/tauri-apps/tauri/blob/dev/tooling/cli).

To learn more about the details of how all of these pieces fit together, please consult this [ARCHITECTURE.md](https://github.com/tauri-apps/tauri/blob/dev/ARCHITECTURE.md) document.

Expand Down
10 changes: 5 additions & 5 deletions tooling/cli/node/tauri.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
const cli = require('./main')
const path = require('path')

const [bin, script, ...arguments] = process.argv
const [bin, script, ...args] = process.argv
const binStem = path.parse(bin).name.toLowerCase()

// We want to make a helpful binary name for the underlying CLI helper, if we
Expand All @@ -20,7 +20,7 @@ if (bin === '@tauri-apps/cli') {
}
// Even if started by a package manager, the binary will be NodeJS.
// Some distribution still use "nodejs" as the binary name.
else if (binStem.match(/(nodejs|node)\-?([0-9]*)*$/g)) {
else if (binStem.match(/(nodejs|node|bun)\-?([0-9]*)*$/g)) {
const managerStem = process.env.npm_execpath
? path.parse(process.env.npm_execpath).name.toLowerCase()
: null
Expand All @@ -32,7 +32,7 @@ else if (binStem.match(/(nodejs|node)\-?([0-9]*)*$/g)) {
manager = 'npm'
break

// Yarn and pnpm have the same stem name as their bin.
// Yarn, pnpm, and bun have the same stem name as their bin.
// We assume all unknown package managers do as well.
default:
manager = managerStem
Expand All @@ -48,10 +48,10 @@ else if (binStem.match(/(nodejs|node)\-?([0-9]*)*$/g)) {
}
} else {
// We don't know what started it, assume it's already stripped.
arguments.unshift(bin)
args.unshift(bin)
}

cli.run(arguments, binName).catch((err) => {
cli.run(args, binName).catch((err) => {
cli.logError(err.message)
process.exit(1)
})
6 changes: 4 additions & 2 deletions tooling/cli/src/completions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use log::info;

use std::{fs::write, path::PathBuf};

const PKG_MANAGERS: &[&str] = &["cargo", "pnpm", "npm", "yarn"];
const PKG_MANAGERS: &[&str] = &["cargo", "pnpm", "npm", "yarn", "bun"];

#[derive(Debug, Clone, Parser)]
#[clap(about = "Shell completions")]
Expand All @@ -25,7 +25,7 @@ pub struct Options {

fn completions_for(shell: Shell, manager: &'static str, cmd: Command) -> Vec<u8> {
let tauri = cmd.name("tauri");
let mut command = if manager == "npm" {
let mut command = if manager == "npm" || manager == "bun" {
Command::new(manager)
.bin_name(manager)
.subcommand(Command::new("run").subcommand(tauri))
Expand All @@ -47,6 +47,8 @@ fn get_completions(shell: Shell, cmd: Command) -> Result<String> {
"complete -F _cargo -o bashdefault -o default {} tauri\n",
if manager == &"npm" {
"npm run"
} else if manager == &"bun" {
"bun run"
} else {
manager
}
Expand Down
22 changes: 22 additions & 0 deletions tooling/cli/src/info/env_nodejs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,28 @@ pub fn items(metadata: &VersionMetadata) -> (Vec<SectionItem>, Option<String>) {
|| None,
false,
),
SectionItem::new(
|| {
cross_command("bun")
.arg("-v")
.output()
.map(|o| {
if o.status.success() {
let v = String::from_utf8_lossy(o.stdout.as_slice()).to_string();
Some((
format!("bun: {}", v.split('\n').next().unwrap()),
Status::Neutral,
))
} else {
None
}
})
.ok()
.unwrap_or_default()
},
|| None,
false,
),
SectionItem::new(
move || {
yarn_version_c
Expand Down
Loading

0 comments on commit fa3c9ca

Please sign in to comment.