macos

package
v0.5.0-preview....-32e7360 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 7, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

macOS Frameworks

This package also contains platform specific helpers.

Example (MainWithRunApp)

You normally want to start an application using RunApp. This is a simple webview window app. Note that we need to retain the window object.

package main

import (
	"github.com/progrium/macdriver/macos"
	"github.com/progrium/macdriver/macos/appkit"
	"github.com/progrium/macdriver/macos/foundation"
	"github.com/progrium/macdriver/macos/webkit"
	"github.com/progrium/macdriver/objc"
)

func main() {
	// RunApp should only be called from main on the startup thread
	macos.RunApp(func(app appkit.Application, delegate *appkit.ApplicationDelegate) {
		app.SetActivationPolicy(appkit.ApplicationActivationPolicyRegular)
		app.ActivateIgnoringOtherApps(true)

		url := foundation.URL_URLWithString("http://progrium.com")
		req := foundation.NewURLRequestWithURL(url)
		frame := foundation.Rect{Size: foundation.Size{1440, 900}}

		config := webkit.NewWebViewConfiguration()
		wv := webkit.NewWebViewWithFrameConfiguration(frame, config)
		wv.LoadRequest(req)

		w := appkit.NewWindowWithContentRectStyleMaskBackingDefer(frame,
			appkit.ClosableWindowMask|appkit.TitledWindowMask,
			appkit.BackingStoreBuffered, false)
		objc.Retain(&w)
		w.SetContentView(wv)
		w.MakeKeyAndOrderFront(w)
		w.Center()

		delegate.SetApplicationShouldTerminateAfterLastWindowClosed(func(appkit.Application) bool {
			return true
		})
	})
}
Output:

Example (MainWithoutApplication)

You can use some Apple frameworks without starting an application, but you need to lock the main thread and wrap your code with an autorelease pool.

package main

import (
	"fmt"
	"runtime"

	"github.com/progrium/macdriver/macos/appkit"
	"github.com/progrium/macdriver/objc"
)

func main() {
	runtime.LockOSThread()
	objc.WithAutoreleasePool(func() {

		ws := appkit.Workspace_SharedWorkspace()

		for _, app := range ws.RunningApplications() {
			fmt.Println(app.LocalizedName())
		}

	})
}
Output:

Example (MainWithoutRunApp)

You can use appkit APIs directly to start an application, but you need to lock the main thread and build your own application delegate if desired.

package main

import (
	"runtime"

	"github.com/progrium/macdriver/macos/appkit"
	"github.com/progrium/macdriver/macos/foundation"
)

func main() {
	runtime.LockOSThread()
	app := appkit.Application_SharedApplication()
	delegate := &appkit.ApplicationDelegate{}
	delegate.SetApplicationDidFinishLaunching(func(notification foundation.Notification) {
		app.SetActivationPolicy(appkit.ApplicationActivationPolicyRegular)
		app.ActivateIgnoringOtherApps(true)

		// ... app started code ...

	})
	app.SetDelegate(delegate)
	app.Run()
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func RunApp

func RunApp(didLaunch func(appkit.Application, *appkit.ApplicationDelegate))

RunApp builds a delegate, sets it on the shared application, and runs the event loop. It uses didLaunch to set ApplicationDidFinishLaunching on the delegate. It also wraps run with runtime.LockOSThread() and should be called from main.

Types

This section is empty.

Directories

Path Synopsis
_examples
_wip
WIP
avfaudio
WIP
WIP
WIP
WIP
WIP
metalkit
WIP
WIP
modelio
WIP
WIP
scenekit
WIP
WIP
spritekit
WIP
WIP
Construct and manage a graphical, event-driven user interface for your macOS app.
Construct and manage a graphical, event-driven user interface for your macOS app.
Work with audiovisual assets, control device cameras, process audio, and configure system audio interactions.
Work with audiovisual assets, control device cameras, process audio, and configure system audio interactions.
Create user interfaces for media playback, complete with transport controls, chapter navigation, picture-in-picture support, and display of subtitles and closed captions.
Create user interfaces for media playback, complete with transport controls, chapter navigation, picture-in-picture support, and display of subtitles and closed captions.
Store structured app and user data in iCloud containers that all users of your app can share.
Store structured app and user data in iCloud containers that all users of your app can share.
Access the user's contacts, and format and localize contact information.
Access the user's contacts, and format and localize contact information.
Display information about users’ contacts in a graphical interface.
Display information about users’ contacts in a graphical interface.
Use the Core Audio framework to interact with device’s audio hardware.
Use the Core Audio framework to interact with device’s audio hardware.
Use specialized data types to interact with audio streams, complex buffers, and audiovisual timestamps.
Use specialized data types to interact with audio streams, complex buffers, and audiovisual timestamps.
Persist or cache data on a single device, or sync data to multiple devices with CloudKit.
Persist or cache data on a single device, or sync data to multiple devices with CloudKit.
Access low-level functions, primitive data types, and various collection types that are bridged seamlessly with the Foundation framework.
Access low-level functions, primitive data types, and various collection types that are bridged seamlessly with the Foundation framework.
Harness the power of Quartz technology to perform lightweight 2D rendering with high-fidelity output.
Harness the power of Quartz technology to perform lightweight 2D rendering with high-fidelity output.
Use built-in or custom filters to process still and video images.
Use built-in or custom filters to process still and video images.
Obtain the geographic location and orientation of a device.
Obtain the geographic location and orientation of a device.
Represent time-based audio-visual assets with essential data types.
Represent time-based audio-visual assets with essential data types.
Securely support custom camera devices in macOS.
Securely support custom camera devices in macOS.
Communicate with MIDI devices such as hardware keyboards and synthesizers.
Communicate with MIDI devices such as hardware keyboards and synthesizers.
Integrate machine learning models into your app.
Integrate machine learning models into your app.
Index your app so users can search the content from Spotlight and Safari.
Index your app so users can search the content from Spotlight and Safari.
Process digital video, including manipulation of individual frames, using a pipeline-based API and support for both Metal and OpenGL.
Process digital video, including manipulation of individual frames, using a pipeline-based API and support for both Metal and OpenGL.
An extension other apps use to access files and folders managed by your app and synced with a remote storage.
An extension other apps use to access files and folders managed by your app and synced with a remote storage.
Access essential data types, collections, and operating-system services to define the base layer of functionality for your app.
Access essential data types, collections, and operating-system services to define the base layer of functionality for your app.
Read and write most image file formats, and access an image’s metadata.
Read and write most image file formats, and access an image’s metadata.
Share hardware-accelerated buffer data (framebuffers and textures) across multiple processes.
Share hardware-accelerated buffer data (framebuffers and textures) across multiple processes.
Find and play songs, audio podcasts, audio books, and more from within your app.
Find and play songs, audio podcasts, audio books, and more from within your app.
Render advanced 3D graphics and compute data in parallel with graphics processors.
Render advanced 3D graphics and compute data in parallel with graphics processors.
Optimize graphics and compute performance with kernels that are fine-tuned for the unique characteristics of each Metal GPU family.
Optimize graphics and compute performance with kernels that are fine-tuned for the unique characteristics of each Metal GPU family.
Build, compile, and execute customized multidimensional compute graphs for linear algebra, machine learning, computer vision, and other similar domains.
Build, compile, and execute customized multidimensional compute graphs for linear algebra, machine learning, computer vision, and other similar domains.
Allow users to browse, edit, and save images, using slideshows and Core Image filters.
Allow users to browse, edit, and save images, using slideshows and Core Image filters.
Render, compose, and animate visual elements.
Render, compose, and animate visual elements.
Allow applications to access a device’s network configuration settings.
Allow applications to access a device’s network configuration settings.
Provide uniform type identifiers that describe file types for storage or transfer.
Provide uniform type identifiers that describe file types for storage or transfer.
Apply computer vision algorithms to perform a variety of tasks on input images and video.
Apply computer vision algorithms to perform a variety of tasks on input images and video.
Integrate web content seamlessly into your app, and customize content interactions to meet your app’s needs.
Integrate web content seamlessly into your app, and customize content interactions to meet your app’s needs.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL