Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- Install `nsgo test`'s builds on the iOS, tvOS and watchOS simulators under the app's ID followed by `.nsgotest` and uninstall them when the run ends, leaving an installed build of the app and its data as they were (#898 by @houko).
- Hold the starting value of macOS and iOS style and border animations across the update that replaces it, which could crash an app showing a `ui.Select` (#995 by @houko).
- Stop a disposed computation from subscribing to what it reads, which left links that later crashed `Scope.Dispose` with an index out of range (#997 by @houko).
- Add `nsgo.StartHidden`, which opens the main window on macOS, Windows and Linux without showing it until the app shows it, for tray apps and launches at login (#670 by @houko).
- Keep macOS target test windows at the requested `nsgotest.Size` and `Resize` content size instead of silently constraining them to the screen (#697 by @houko).
- Add `nsgo publish -extra`, which signs a file's bytes into the package as `pkg.Contents.Extra` (#924 by @houko).
- Add `core.Scroll.NoShrink`, and `noShrink` on TSX scroll views, to keep a scroll view at its requested size when its parent is short (#967 by @houko).
Expand Down
2 changes: 1 addition & 1 deletion docs/public/en/components.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ Themes give `ui`'s components their look in light and dark.

## Desktop apps

`nsgo.Run(Root)` shows one root view. A desktop app can open what it shows itself instead: `nsgo.Run(App)` runs `func App(app *core.Scope)` once, and it opens windows, panels, tray icons and global shortcuts with `desktop`, which share its signals. This works on macOS, Windows and Linux; on macOS `examples/tray` keeps out of the Dock and lives in the menu bar.
`nsgo.Run(Root)` shows one root view. A desktop app can open what it shows itself instead: `nsgo.Run(App)` runs `func App(app *core.Scope)` once, and it opens windows, panels, tray icons and global shortcuts with `desktop`, which share its signals. This works on macOS, Windows and Linux; on macOS `examples/tray` keeps out of the Dock and lives in the menu bar. `nsgo.Run(App, nsgo.StartHidden())` opens the main window without showing it, so a tray app, or one the system launched at login (`desktop.LaunchedAtLogin`), does not flash it; the app shows it with `app.MainWindow().Show()`. Phones and the web show the app as they launch it.

`desktop.SetWindowLevel` keeps a window above the others, as a timer or a desktop pet does, or below them, and `desktop.SetWindowFrame` moves and sizes it. `desktop.CanSetWindowLevel` and `desktop.CanPlaceWindows` say whether they take effect in a window's scope: both do on macOS and Windows, only the level on Linux under X11, and neither under Wayland, whose compositor stacks and places windows itself.

Expand Down
2 changes: 1 addition & 1 deletion docs/public/zh/components.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ core.Text{Content: "Done", Class: "self-start rounded-full bg-zinc-100 px-3 py-1

## 桌面应用

`nsgo.Run(Root)` 显示一个根视图。桌面应用也可以自己决定显示什么:`nsgo.Run(App)` 运行一次 `func App(app *core.Scope)`,由它通过 `desktop` 打开窗口、面板、托盘图标和全局快捷键,它们共享它的 signal。目前支持 macOS、Windows 和 Linux;在 macOS 上 `examples/tray` 不出现在程序坞中,只驻留在菜单栏。
`nsgo.Run(Root)` 显示一个根视图。桌面应用也可以自己决定显示什么:`nsgo.Run(App)` 运行一次 `func App(app *core.Scope)`,由它通过 `desktop` 打开窗口、面板、托盘图标和全局快捷键,它们共享它的 signal。目前支持 macOS、Windows 和 Linux;在 macOS 上 `examples/tray` 不出现在程序坞中,只驻留在菜单栏。`nsgo.Run(App, nsgo.StartHidden())` 打开主窗口但不显示它,托盘应用或随登录启动的应用(`desktop.LaunchedAtLogin`)因此不会闪出窗口;应用用 `app.MainWindow().Show()` 显示它。手机和 Web 照常在启动时显示应用。

`desktop.SetWindowLevel` 让窗口保持在其他窗口之上(比如计时器或桌面宠物),或置于其下;`desktop.SetWindowFrame` 移动窗口并调整大小。`desktop.CanSetWindowLevel` 和 `desktop.CanPlaceWindows` 说明它们在窗口的 scope 中是否生效:macOS 和 Windows 上都生效,Linux 在 X11 下只有层级生效,在 Wayland 下都不生效,因为窗口的层叠和位置由合成器决定。

Expand Down
13 changes: 11 additions & 2 deletions internal/backend/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ type Options struct {
HideDock bool
// Transparent, NoShadow and SkipTaskbar are the main window's (core.WindowOptions).
Transparent, NoShadow, SkipTaskbar bool
// Hidden opens the main window without showing it (nsgo.StartHidden).
Hidden bool
// Parent is the window NewView's view is made in (Windows).
Parent uintptr
}
Expand Down Expand Up @@ -94,11 +96,18 @@ func appOf(root engine.App, app func(*core.Scope)) func(*core.Scope) {
return func(cx *core.Scope) { cx.SetMainView(root) }
}

// rootOf returns the root view of what Run runs on a platform that
// opens no windows: root, or app's main view.
// rootOf returns the root view of what Run runs on a platform that opens no windows: root, or app's main view.
func rootOf(root engine.App, app func(*core.Scope)) engine.App {
if app != nil {
return core.AppRoot(app)
}
return root
}

// hiddenMain returns what Run runs with o.Hidden on Windows and Linux, which open a hidden main window only from the app's function: root as the app's main view.
func hiddenMain(root engine.App, app func(*core.Scope), o Options) (engine.App, func(*core.Scope)) {
if o.Hidden && app == nil {
return nil, appOf(root, nil)
}
return root, app
}
3 changes: 2 additions & 1 deletion internal/backend/run_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ func run(root engine.App, app func(*core.Scope), o Options) {
updates := updateConfig()
updates.Store = linux.InstalledBy()
root, app = withUpdateChecks(root, app, updates, false)
linux.Run(rootOf(root, app), linux.Options{Title: name, Name: core.App().Name, Width: o.Width, Height: o.Height, Hidden: app != nil, ID: id,
root, app = hiddenMain(root, app, o)
linux.Run(rootOf(root, app), linux.Options{Title: name, Name: core.App().Name, Width: o.Width, Height: o.Height, Hidden: app != nil, MainHidden: o.Hidden, ID: id,
Components: o.Components, Constraints: o.Constraints, Fonts: o.Fonts, Appearance: o.Appearance, Perf: o.Monitor,
Transparent: o.Transparent, NoShadow: o.NoShadow, SkipTaskbar: o.SkipTaskbar,
Updates: updates, LaunchedAtLogin: launch.launchedAtLogin, InstanceKey: o.InstanceKey})
Expand Down
1 change: 1 addition & 0 deletions internal/backend/run_macos.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
func run(root engine.App, app func(*core.Scope), o Options) {
macos.Run(core.AppRoot(appOf(root, app)), macos.Options{
Title: name, Width: o.Width, Height: o.Height, Frame: o.Frame, ID: id,
Hidden: o.Hidden,
Components: o.Components, Perf: o.Monitor, Material: o.Material, Constraints: o.Constraints, Fonts: o.Fonts,
Appearance: o.Appearance, HideDock: o.HideDock, LaunchedAtLogin: launch.launchedAtLogin,
Transparent: o.Transparent, NoShadow: o.NoShadow, SkipTaskbar: o.SkipTaskbar,
Expand Down
3 changes: 2 additions & 1 deletion internal/backend/run_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import (
)

func run(root engine.App, app func(*core.Scope), o Options) {
windows.Run(rootOf(root, app), windows.Options{Title: name, Width: o.Width, Height: o.Height, Frame: o.Frame, Hidden: app != nil, ID: id,
root, app = hiddenMain(root, app, o)
windows.Run(rootOf(root, app), windows.Options{Title: name, Width: o.Width, Height: o.Height, Frame: o.Frame, Hidden: app != nil, MainHidden: o.Hidden, ID: id,
Components: o.Components, Material: o.Material, Constraints: o.Constraints, Fonts: o.Fonts, Appearance: o.Appearance, Perf: o.Monitor,
Transparent: o.Transparent, NoShadow: o.NoShadow, SkipTaskbar: o.SkipTaskbar,
Updates: updateConfig(), RegisterToast: launch.registerToast, UnregisterToast: launch.unregisterToast, DockTask: launch.dockTask, LaunchedAtLogin: launch.launchedAtLogin, InstanceKey: o.InstanceKey})
Expand Down
7 changes: 4 additions & 3 deletions internal/platform/linux/linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,10 @@ import (
type Options struct {
Title string
Width, Height driver.Points
// Hidden keeps the backend's root window out of the screen while it
// hosts app-level services such as tray icons.
// Hidden keeps the backend's root window out of the screen while it hosts app-level services such as tray icons.
Hidden bool
// MainHidden opens the main window the app's function opens without showing it (nsgo.StartHidden).
MainHidden bool
// ID names the app's directories and storage (engine.AppDirs).
ID string
// Name is the app's name, nsgo.yaml's (core.App().Name), "" where the tool set none; unlike Title, a surface's windows keep it.
Expand Down Expand Up @@ -415,7 +416,7 @@ func (w *window) startEngine(app engine.App, opts Options, size driver.Size) {
}
if opts.Hidden {
eopts.Windows = &engine.WindowOptions{Title: opts.Title, Width: opts.Width, Height: opts.Height,
Constraints: opts.Constraints, Transparent: opts.Transparent, NoShadow: opts.NoShadow, SkipTaskbar: opts.SkipTaskbar}
Constraints: opts.Constraints, Transparent: opts.Transparent, NoShadow: opts.NoShadow, SkipTaskbar: opts.SkipTaskbar, Hidden: opts.MainHidden}
}
eopts.SetDirs(engine.AppDirs(opts.ID))
if opts.test != nil {
Expand Down
2 changes: 1 addition & 1 deletion internal/platform/macos/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func startOwn(app engine.App, opts Options) *surface {
Appearance: opts.Appearance, Host: opts.Host, Secrets: apple.Keychain{},
Windows: &engine.WindowOptions{Title: opts.Title, Width: opts.Width, Height: opts.Height, Frame: opts.Frame,
Material: opts.Material, Constraints: opts.Constraints, Transparent: opts.Transparent, NoShadow: opts.NoShadow,
SkipTaskbar: opts.SkipTaskbar}}
SkipTaskbar: opts.SkipTaskbar, Hidden: opts.Hidden}}
eopts.SetDirs(engine.AppDirs(opts.ID))
imageload.UseDiskCache(eopts.CacheDir)
s.engine = engine.Start(s, app, eopts)
Expand Down
2 changes: 2 additions & 0 deletions internal/platform/macos/macos.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ func init() {
type Options struct {
Title string
Width, Height driver.Points
// Hidden opens the main window without showing it (nsgo.StartHidden).
Hidden bool
// ID names the app's directories and storage (engine.AppDirs).
ID string
// Components are the native components Native elements name.
Expand Down
8 changes: 4 additions & 4 deletions internal/platform/windows/windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ func init() {
type Options struct {
Title string
Width, Height driver.Points
// Hidden keeps the backend's root window off the screen as the app's
// own surface (nsgo.Run(App)), which opens the windows the app shows
// and shows only as an alert's window.
// Hidden keeps the backend's root window off the screen as the app's own surface (nsgo.Run(App)), which opens the windows the app shows and shows only as an alert's window.
Hidden bool
// MainHidden opens the main window the app's function opens without showing it (nsgo.StartHidden).
MainHidden bool
// Frame is where the window opens (nsgo.WindowFrame).
Frame driver.WindowFrame
// ID names the app's directories and storage (engine.AppDirs).
Expand Down Expand Up @@ -871,7 +871,7 @@ func (w *window) startEngine(app engine.App, opts Options, size driver.Size) {
if opts.Hidden {
eopts.Windows = &engine.WindowOptions{Title: opts.Title, Width: opts.Width, Height: opts.Height,
Frame: opts.Frame, Material: opts.Material, Constraints: opts.Constraints, Transparent: opts.Transparent,
NoShadow: opts.NoShadow, SkipTaskbar: opts.SkipTaskbar}
NoShadow: opts.NoShadow, SkipTaskbar: opts.SkipTaskbar, Hidden: opts.MainHidden}
}
data, cache, logs := engine.AppDirs(opts.ID)
eopts.SetDirs(data, cache, logs)
Expand Down
5 changes: 5 additions & 0 deletions nsgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ func WindowFrame(f core.WindowFrame) Option {
return func(o *options) { o.platform.Frame = f }
}

// StartHidden opens the main window on macOS, Windows and Linux without showing it, as a tray app or one launched at login (desktop.LaunchedAtLogin) does: the app shows it with core.Scope.MainWindow's Show. Phones and the web show the app as they launch it.
func StartHidden() Option {
return func(o *options) { o.platform.Hidden = true }
}

// WindowConstraints limits the main window's content size and what the
// user may do to it: desktop.SetWindowConstraints says how, and changes
// them later. desktop.OpenWindow's windows take their own from
Expand Down
2 changes: 1 addition & 1 deletion skills/nsgo/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func main() { nsgo.Run(Root) }
- Keep tokens, API keys and passwords in `cx.Secrets()`, the platform's keychain or keystore, never in `cx.Storage()`, a plain file; its calls may wait for the system, so make them on a goroutine too.
- Apps use `ui`'s components, which have a look and follow the theme; `base` holds the same controls without a look, for component authors; `mobile` and `desktop` hold what only phones or only desktops have. [references/components.md](references/components.md) maps needs to components.
- Tooltips provide their controls' accessibility descriptions before focus, omitting text that repeats the label and preserving an explicit description; their bubbles are hidden from screen readers ([accessibility](https://nsgo.dev/docs/accessibility.md)).
- A desktop app that opens its own windows, panels, tray icons and shortcuts runs `nsgo.Run(App)` with `func App(app *core.Scope)` and opens them with `desktop`. A popup card is a panel with `PanelOptions` `Transparent` and `FitContent` whose content draws its own corners and shadow, and a background where `desktop.Transparent` is false.
- A desktop app that opens its own windows, panels, tray icons and shortcuts runs `nsgo.Run(App)` with `func App(app *core.Scope)` and opens them with `desktop`. A popup card is a panel with `PanelOptions` `Transparent` and `FitContent` whose content draws its own corners and shadow, and a background where `desktop.Transparent` is false. `nsgo.StartHidden()` opens the main window hidden, for a tray app or a launch at login, until `cx.MainWindow().Show()`.
- A window that lets the pointer through to the windows below sets `PointerEvents` in `desktop.WindowOptions` or `desktop.PanelOptions`, or calls `desktop.SetWindowPointerEvents`: `desktop.WindowPointerPainted` takes it only over views that draw or hear it, as around a desktop pet; `desktop.WindowPointerNone` takes none, so the app gives it back from a shortcut or a tray icon.
- A desktop pet, widget or HUD opens its window with `desktop.WindowOptions{Transparent: true}` (the main window with `nsgo.WindowTransparent()`), leaves its root view without a background, and moves it by a view's `Desktop.WindowDrag`; `NoShadow` and `SkipTaskbar` drop the shadow and the taskbar button, and `desktop.CanMakeWindowsTransparent` and `desktop.CanSkipTaskbar` say whether they take effect, as on X11 without a compositor or on Wayland they do not.
- TSX apps embed their sources and run `compiler.App(src, "App.tsx")`, importing `nsgo`, `nsgo/base` and `nsgo/ui`; Go components and functions reach TSX through `tsx.Register` and `tsx.RegisterFunctions` ([TSX apps](https://nsgo.dev/docs/tsx.md)).
Expand Down