搜索插件、代码仓与 APP 分类

插件详情v0.5.1

launch_at_startup

此插件允许 Flutter 桌面应用程序在启动/登录时自动运行。

macOSWindowsLinux
近 30 天下载
4.7万
喜欢数
151
Pub 分数
125

安装插件

flutter pub add launch_at_startup

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

launch_at_startup 包使 Flutter 桌面应用程序能够在 macOS、Windows 或 Linux 上用户登录时自动启动。它提供了一个简单的 API,可在跨平台环境中检查、启用或禁用自动启动行为。这对于需要在后台持续运行的应用程序(如系统监控工具、通知工具或生产力工具)特别有用。该插件与 Flutter 的桌面支持无缝集成,无需更改原生代码。它利用平台特定机制可靠地管理启动项。

适合场景

  • 后台监控应用
  • 系统实用工具
  • 通知服务
  • 自动启动生产力应用
  • 持久化桌面应用程序

主要特点

  • 跨平台启动控制
  • 简单启用/禁用 API
  • 平台特定实现
  • 无需原生代码
  • 支持 macOS、Windows 和 Linux

适合对象

  • 需要自动启动的桌面应用程序
  • 系统级工具
  • 需要持续存在的应用
  • 面向多个桌面操作系统的开发者
  • 无需人工干预即可运行的工具

使用建议

  • 某些系统需要用户权限
  • 可能与其他自动启动应用冲突
  • 行为因操作系统而略有不同
  • 不适合用于移动应用
  • 用户可能需要在系统设置中手动启用

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

🚀 Ship Your App Faster: Try Fastforge - The simplest way to build, package and distribute your Flutter apps.

launch_at_startup

pub version

This plugin allows Flutter desktop apps to Auto launch on startup / login.


English | 简体中文


Platform Support

Linux macOS* Windows
✔️ ✔️ ✔️

*Required macOS support installation instructions below

Quick Start

Installation

Add this to your package's pubspec.yaml file:

dependencies:
  launch_at_startup: ^0.5.1

Or

dependencies:
  launch_at_startup:
    git:
      url: https://github.com/leanflutter/launch_at_startup.git
      ref: main
Usage
import 'dart:io';

import 'package:launch_at_startup/launch_at_startup.dart';
import 'package:package_info_plus/package_info_plus.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();

  PackageInfo packageInfo = await PackageInfo.fromPlatform();

  launchAtStartup.setup(
    appName: packageInfo.appName,
    appPath: Platform.resolvedExecutable,
    // Set packageName parameter to support MSIX.
    packageName: 'dev.leanflutter.examples.launchatstartupexample',
  );

  await launchAtStartup.enable();
  await launchAtStartup.disable();
  bool isEnabled = await launchAtStartup.isEnabled();

  runApp(const MyApp());
}

// ...

Please see the example app of this plugin for a full example.

macOS Support

Setup

Add platform channel code to your macos/Runner/MainFlutterWindow.swift file.

import Cocoa
import FlutterMacOS
// Add the LaunchAtLogin module
import LaunchAtLogin
//

class MainFlutterWindow: NSWindow {
  override func awakeFromNib() {
    let flutterViewController = FlutterViewController.init()
    let windowFrame = self.frame
    self.contentViewController = flutterViewController
    self.setFrame(windowFrame, display: true)

    // Add FlutterMethodChannel platform code
    FlutterMethodChannel(
      name: "launch_at_startup", binaryMessenger: flutterViewController.engine.binaryMessenger
    )
    .setMethodCallHandler { (_ call: FlutterMethodCall, result: @escaping FlutterResult) in
      switch call.method {
      case "launchAtStartupIsEnabled":
        result(LaunchAtLogin.isEnabled)
      case "launchAtStartupSetEnabled":
        if let arguments = call.arguments as? [String: Any] {
          LaunchAtLogin.isEnabled = arguments["setEnabledValue"] as! Bool
        }
        result(nil)
      default:
        result(FlutterMethodNotImplemented)
      }
    }
    //

    RegisterGeneratedPlugins(registry: flutterViewController)

    super.awakeFromNib()
  }
}

then open your macos/ folder in Xcode and do the following:

Instructions referenced from "LaunchAtLogin" package repository. Read for more details and FAQ's.

Requirements

macOS 10.13+

Install

Add https://github.com/sindresorhus/LaunchAtLogin in the “Swift Package Manager” tab in Xcode.

Usage

Skip this step if your app targets macOS 13 or later.

Add a new “Run Script Phase” below (not into) “Copy Bundle Resources” in “Build Phases” with the following:

"${BUILT_PRODUCTS_DIR}/LaunchAtLogin_LaunchAtLogin.bundle/Contents/Resources/copy-helper-swiftpm.sh"

And uncheck “Based on dependency analysis”.

The build phase cannot run with "User Script Sandboxing" enabled. With Xcode 15 or newer where it is enabled by default, disable "User Script Sandboxing" in build settings.

(It needs some extra works to have our script to comply with the build phase sandbox.) (I would name the run script Copy “Launch at Login Helper”)

Who's using it?

License

MIT

所属分类

依赖

依赖清单 1 项

源码仓库

使用此插件的项目