Skip to content

About

SwiftWindowLauncher is an easy way to open any window from the CLI or main function.

Resources

Code of conduct

Contributing

Stars

4 stars

Watchers

0 watching

Forks

Repository files navigation

SwiftWindowLauncher

SwiftWindowLauncher is an easy way to open any window from the CLI or main function. It is also designed to integrate seamlessly with SwiftUI and AppKit.

Requirement

The following environment is required to use this library.

Twitter: @IroIro1234work

Demo

This package includes four executable targets that demonstrate every combination of entry point and UI framework. Each one opens a tab-based window (SwiftUI TabView / AppKit NSTabViewController) and keeps running its own work after the window is on screen.

Target Entry point UI framework
MainFunc-SwiftUI-Example static func main() SwiftUI
MainFunc-AppKit-Example static func main() AppKit
CLI-SwiftUI-Example swift-argument-parser command SwiftUI
CLI-AppKit-Example swift-argument-parser command AppKit
swift run MainFunc-SwiftUI-Example

Usage

By using this package, you can open any window during CLI or main function execution.

SwiftUI

Pass any SwiftUI view to launch. In an async context, launch returns once the content is actually on screen, so your code can keep running while the window stays open. The process terminates after every window has been closed.

import SwiftUI
import WindowLauncher

struct ContentView: View {
    var body: some View {
        Text("Hello, Swift Window Launcher!")
    }
}

@main
struct MyApp {
    static func main() async throws {
        await WindowLauncher.shared.launch {
            ContentView()
        }

        // The window is now visible — you can keep working here.
        print("Still running after the window opened!")
    }
}

Each subsequent launch call opens an additional window. The content is presented through a real SwiftUI WindowGroup scene, so native window chrome — such as the toolbar-integrated tab bar of a TabView and navigationTitle handling — works as in a regular SwiftUI app.

AppKit

You can also pass an NSViewController or NSView. The window is created with NSWindow(contentViewController:), so controller-driven window features — NSToolbar customization, NSTabViewController with tabStyle = .toolbar, and so on — integrate with the window the same way they do in a regular AppKit app.

import AppKit
import WindowLauncher

await WindowLauncher.shared.launch(
    MyViewController(),
    title: "Swift Window Launcher"
)

Synchronous launch

Calling launch from a non-async context starts the application's main run loop on the spot and never returns. Use this form when opening the window is the last thing your program does.

WindowLauncher.shared.launch {
    ContentView()
}
// Never reached.

Install

Add the following files to the Package.swift file for use. For more information, please visit swift.org.

    dependencies: [
        // Add this code
        .package(url: "https://github.com/KC-2001MS/SwiftWindowLauncher.git", from: "0.0.1"),
    ],

Swift-DocC

Swift-DocC is currently being implemented. Documentation

Contribution

See CONTRIBUTING.md if you want to make a contribution.

Licence

SwiftWindowLauncher

Supporting

If you would like to make a donation to this project, please click here. The money you give will be used to improve my programming skills and maintain the application.
Buy Me A Coffee
Pay by PayPal

Author

Keisuke Chinone

About

SwiftWindowLauncher is an easy way to open any window from the CLI or main function.

Resources

Code of conduct

Contributing

Stars

4 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages