如何在macOS中登录时启动Rust应用程序

At Hopp, our goal is to make the remote pair programming experience as seamless as possible. For that, our desktop app needs to be ready the moment you want to hop on a code pairing call, so it needs to start automatically when the user logs in.

Hopp,我们的目标是让远程配对编程体验尽可能无缝。为此,我们的桌面应用程序需要在您想要开始代码配对通话的那一刻准备好,因此它需要在用户登录时自动启动。

Hopp is built with Tauri, so the natural step was to use Tauri's autostart plugin. While it worked as expected, we noticed a few limitations that didn't fit our vision for a polished, near-native user experience.

Hopp 是使用 Tauri 构建的,因此自然的步骤是使用 Tauri 的 自动启动插件。虽然它按预期工作,但我们注意到了一些限制,这些限制与我们对精致、接近原生用户体验的愿景不符。

That's why we built smappservice-rs: a Rust wrapper for macOS's ServiceManagement framework.

这就是为什么我们构建了 smappservice-rs:一个用于 macOS 的 Rust 包装器,基于 ServiceManagement 框架。

In this post, I'll share why we made this decision, what you get with our library, and how it helps us deliver a better experience for Hopp's macOS users.

在这篇文章中,我将分享我们做出这个决定的原因,您可以从我们的库中获得什么,以及它如何帮助我们为 Hopp 的 macOS 用户提供更好的体验。

Using Tauri Autostart Plugin for Rust Apps on macOS#

在 macOS 上使用 Tauri 自动启动插件的 Rust 应用程序#

Tauri's autostart plugin works across Windows, macOS, and Linux, allowing your app to start automatically at system startup. Under the hood, it uses the auto-launch crate, which is the Rust equivalent of node-auto-launch.

Tauri 的自动启动插件在 Windows、macOS 和 Linux 上均可工作,允许您的应用程序在系统启动时自动启动。在底层,它使用 auto-launch crate,这是 Rust 版的 node-auto-launch

On macOS, the plugin supports two methods for starting your app on login:

在macOS上,插件支持两种在登录时启动您的应用程序的方法:

  • AppleScript
  • AppleScript
  • LaunchAgent plist file
  • LaunchAgent plist 文件

AppleScript

AppleScript

The AppleScript method executes a script that instructs System Events to add or remove a login item for your app. When this method is used, the user will see two pop-ups:

AppleScript 方法执行一个脚本,该脚本指示系统事件为您的应用程序添加或移除登录项。当使用此方法时,用户将看到两个弹出窗口:

  1. A permission request for access to System Events.

    请求访问系统事件的权限。

    System events permission popup

    System events permission popup

    系统事件权限弹出窗口

  2. A notification that the app was added to the login items ...

开通本站会员,查看完整译文。

Accueil - Wiki
Copyright © 2011-2025 iteam. Current version is 2.144.0. UTC+08:00, 2025-06-17 05:12
浙ICP备14020137号-1 $Carte des visiteurs$