receiveshare

package
v0.0.13 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package receiveshare puts your app in the share sheet, so people can send it text, links, pictures and files from other apps.

nimbus native plugin add receive-share

go receiveshare.Watch(ctx, receiveshare.Options{}, func(s receiveshare.Share) {
	if s.URL != "" {
		save(s.URL)
	}
	for _, f := range s.Files {
		upload(f.Name, f.Data)
	}
})

On Android, the share opens your app. On iOS it goes through a Share Extension, which plugin add puts in the Xcode project: the person sees a short "Sent" sheet and stays where they were, and the share waits for your app's next time on screen. iOS doesn't let a share extension open its app.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Watch

func Watch(ctx context.Context, o Options, f func(Share)) error

Watch calls f with each share as it arrives, including any waiting from before, until ctx ends. It blocks, so run it from a goroutine in an effect.

Types

type File

type File struct {
	Name string `json:"name"` // its file name
	Type string `json:"type"` // its media type, such as "image/jpeg"
	Size int64  `json:"size"` // in bytes
	// Data is its contents, or empty when it's larger than Options.MaxBytes.
	Data []byte `json:"data"`
}

File is a shared file. It comes as bytes, so it works under `nimbus native dev` too.

type Options

type Options struct {
	// MaxBytes is the largest file that comes with its Data; 0 means 20 MB.
	// Larger ones still come, with their name, type and size.
	MaxBytes int64 `json:"maxBytes,omitempty"`
}

Options say what to take.

type Share

type Share struct {
	Text    string `json:"text"`    // what they shared as text; may hold a link too
	URL     string `json:"url"`     // a web address, when they shared one
	Subject string `json:"subject"` // a title some apps send with it
	Files   []File `json:"files"`   // pictures, videos, documents
	// At is when it arrived.
	At   time.Time `json:"-"`
	Time float64   `json:"time"` // the same, in seconds since 1970
}

Share is one thing someone sent, from one share sheet.

func Take

func Take(ctx context.Context, o Options) ([]Share, error)

Take gives the shares that have arrived, oldest first, and forgets them: each comes once. Call it when the app starts, so one that launched the app isn't missed.

Jump to

Keyboard shortcuts

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