Documentation
¶
Overview ¶
Package config reads what the desktop app writes: the runtime config (`zennotes.config.json`, where the known vaults and saved servers live) and the portable preferences (`config.toml`). It never writes the former; zn follows the app, it does not steer it.
Index ¶
- Constants
- Variables
- func ConfigTomlPath() string
- func CredentialsPath() string
- func CustomThemesDir() string
- func DefaultServerName(baseURL string) string
- func DeleteToken(baseURL string) error
- func ExpandHome(target string) string
- func LoadToken(baseURL string) string
- func MCPInstructionsPath() string
- func PortableConfigDir() string
- func ResolveVaultRoot(selector string) (string, error)
- func ResolveVaultSelector(selector string) (string, error)
- func SaveToken(baseURL, token string) error
- func SaveWorkspaces(ws Workspaces) error
- func UserDataDir() string
- func VaultRootFromConfig() string
- func WorkspacesPath() string
- type ActiveWorkspace
- type KnownVault
- type LocalWorkspace
- type Prefs
- type RemoteProfile
- type ServerWorkspace
- type Workspaces
- func (ws *Workspaces) AddServer(name, baseURL string) ServerWorkspace
- func (ws *Workspaces) AddVault(name, root string) LocalWorkspace
- func (ws Workspaces) FindServer(selector string) *ServerWorkspace
- func (ws Workspaces) FindVault(selector string) *LocalWorkspace
- func (ws Workspaces) Names() []string
- func (ws *Workspaces) Remove(name string) (string, bool)
- func (ws Workspaces) SortedVaults() []LocalWorkspace
- func (ws Workspaces) UniqueName(base string) string
Constants ¶
const AppConfigFile = "zennotes.config.json"
AppConfigFile is the runtime config the desktop app maintains.
const DefaultConfigTOML = `` /* 1848-byte string literal not displayed */
DefaultConfigTOML is the commented starter file `zn config` writes when no config.toml exists yet. Every key matches the desktop app's names.
Variables ¶
var ErrNoVault = errors.New("No vault is set up for zn yet. Run `zn setup` for a guided start, or one of: `zn init ~/Notes` (create a vault), `zn vault add <folder>` (use an existing one), `zn connect <server-url>` (a ZenNotes server). Opening a vault in the ZenNotes app works too.")
ErrNoVault says nothing names a vault at all.
var ErrNoWorkspace = errors.New("no saved vault or server has that name")
ErrNoWorkspace says a name matches nothing zn saved.
Functions ¶
func CredentialsPath ¶
func CredentialsPath() string
CredentialsPath is where server tokens live (mode 0600).
func CustomThemesDir ¶ added in v0.3.0
func CustomThemesDir() string
CustomThemesDir is where the desktop app keeps user-authored themes, one folder each, next to config.toml.
func DefaultServerName ¶
DefaultServerName names a server after its host: notes.example.com, or localhost for a local address.
func ExpandHome ¶
ExpandHome turns `~` and `~/x` into absolute paths.
func MCPInstructionsPath ¶
func MCPInstructionsPath() string
MCPInstructionsPath is where a user override of the MCP instructions lives.
func PortableConfigDir ¶
func PortableConfigDir() string
PortableConfigDir is where `config.toml` lives: an XDG-style location the user can sync. Deliberately NOT UserDataDir.
func ResolveVaultRoot ¶
ResolveVaultRoot picks the vault root: an explicit selector, else ZENNOTES_VAULT, else the app's active vault.
func ResolveVaultSelector ¶
ResolveVaultSelector resolves a `--vault` selector: a known vault name first (case-insensitive), then a directory path. Errors name the available vaults so a typo is self-correcting.
func SaveWorkspaces ¶
func SaveWorkspaces(ws Workspaces) error
SaveWorkspaces writes the list atomically.
func UserDataDir ¶
func UserDataDir() string
UserDataDir mirrors Electron's `app.getPath('userData')` for the product name "ZenNotes". ZENNOTES_CONFIG_DIR overrides it, for tests and automation.
func VaultRootFromConfig ¶
func VaultRootFromConfig() string
VaultRootFromConfig is the vault the app last opened, or "".
func WorkspacesPath ¶
func WorkspacesPath() string
WorkspacesPath is where zn's vault and server list lives.
Types ¶
type ActiveWorkspace ¶
type ActiveWorkspace struct {
// Kind is "local" or "remote".
Kind string
Root string
BaseURL string
Name string
ProfileID string
AuthToken string
}
ActiveWorkspace is what the desktop app currently has open.
func ActiveWorkspaceFromConfig ¶
func ActiveWorkspaceFromConfig() ActiveWorkspace
ActiveWorkspaceFromConfig reads the workspace the app has open. The app keeps server tokens in the OS secret store, so the token here is only a legacy plaintext one; callers layer ZENNOTES_REMOTE_TOKEN on top.
type KnownVault ¶
type KnownVault struct {
Root string `json:"root"`
Name string `json:"name"`
LastOpenedAt *int64 `json:"lastOpenedAt"`
}
KnownVault is one local vault the app knows about.
func KnownVaults ¶
func KnownVaults() []KnownVault
KnownVaults lists every local vault the app knows: its `localVaults` list plus the active `vaultRoot` when it is not listed. Most recently opened first.
type LocalWorkspace ¶
LocalWorkspace is a vault directory zn remembers.
type Prefs ¶
type Prefs struct {
VimMode bool
VimInsertEscape string
VimYankToClipboard bool
WhichKeyHints bool
WhichKeyHintMode string
WhichKeyHintTimeoutMs int
SyncTitleHeadingOnRename bool
EditorTabSize int
EditorScrollOff int
WordWrap bool
DefaultPaneMode string
LineNumberMode string
CompletedTaskStyle string
TimeFormat string
AutoPairs bool
MarkdownSnippets bool
HideBuiltinTemplates bool
TextReplacementsEnabled bool
TextReplacements map[string]string
// ThemeFamily, ThemeMode and ThemeID are the desktop's theme selection;
// ThemeTweaks its Quick tweaks (accent and syntax hues, by slug).
ThemeFamily string
ThemeMode string
ThemeID string
ThemeTweaks map[string]string
UnifiedSidebar bool
NoteSortOrder string
GroupByKind bool
NestedTags bool
QuickNoteDateTitle bool
QuickNoteTitlePrefix string
CalendarWeekStart string
CalendarShowWeekNumbers bool
TasksViewMode string
ShowArchivedTasks bool
KanbanGroupBy string
KanbanStatuses []string
KanbanColumnTitles map[string]string
SystemFolderLabels map[string]string
WorkflowsEnabled bool
AtlasEnabled bool
KeymapOverrides map[string]string
// Terminal-only preferences, from [terminal] in config.toml. The desktop
// app ignores the table.
TerminalMouse bool
PreviewStyle string
// TerminalImages is auto, kitty or off: whether the preview paints
// pictures with the Kitty graphics protocol.
TerminalImages string
// TerminalTheme names a theme for zn alone: a family, a theme id or a
// custom theme. Empty follows the desktop's [appearance] selection.
TerminalTheme string
}
Prefs is the slice of the portable preferences the CLI and the terminal UI honor. Defaults match the desktop's PORTABLE_DEFAULTS; a missing file or key keeps the default.
type RemoteProfile ¶
type RemoteProfile struct {
ID string
Name string
BaseURL string
AuthToken string
LastConnectedAt *int64
}
RemoteProfile is a saved ZenNotes server.
func RemoteProfiles ¶
func RemoteProfiles() []RemoteProfile
RemoteProfiles lists every server the app has been connected to, newest first, the legacy single-server `remoteWorkspace` key folded in.
type ServerWorkspace ¶
ServerWorkspace is a ZenNotes server zn remembers; its token is stored separately, keyed by URL.
type Workspaces ¶
type Workspaces struct {
// Default names the workspace zn uses when no flag or environment
// variable picks one; empty means follow the desktop app.
Default string `toml:"default"`
Vaults []LocalWorkspace `toml:"vault"`
Servers []ServerWorkspace `toml:"server"`
}
Workspaces is the content of workspaces.toml.
func LoadWorkspaces ¶
func LoadWorkspaces() Workspaces
LoadWorkspaces reads the list; a missing file is an empty list.
func (*Workspaces) AddServer ¶
func (ws *Workspaces) AddServer(name, baseURL string) ServerWorkspace
AddServer remembers a server; the same URL replaces its entry.
func (*Workspaces) AddVault ¶
func (ws *Workspaces) AddVault(name, root string) LocalWorkspace
AddVault remembers a vault directory; the same root replaces its entry.
func (Workspaces) FindServer ¶
func (ws Workspaces) FindServer(selector string) *ServerWorkspace
FindServer matches a saved server by name (case-insensitive) or URL.
func (Workspaces) FindVault ¶
func (ws Workspaces) FindVault(selector string) *LocalWorkspace
FindVault matches a saved vault by name (case-insensitive) or root.
func (Workspaces) Names ¶
func (ws Workspaces) Names() []string
Names lists every saved workspace name, vaults first.
func (*Workspaces) Remove ¶
func (ws *Workspaces) Remove(name string) (string, bool)
Remove forgets a workspace by name; it reports the kind removed.
func (Workspaces) SortedVaults ¶
func (ws Workspaces) SortedVaults() []LocalWorkspace
SortedVaults returns the vaults by name, for stable listings.
func (Workspaces) UniqueName ¶
func (ws Workspaces) UniqueName(base string) string
UniqueName appends 2, 3… to a name until no saved workspace carries it.