Editor:
- Toggles (Tiptap Details). Open state is per reader, not saved.
- Embeds for YouTube, Vimeo, Loom, Figma, CodePen, Spotify, Google Docs
and Maps, in sandboxed frames. Other addresses become link cards.
- Link cards with title, description and picture read by docwell-server
(GET /link-preview). The fetcher refuses private, loopback, link-local
and CGNAT addresses after DNS resolution, redirects included.
- Block links: a margin button gives a block a short id and copies
/p/<id>#b-<block>. Opening one jumps to the block and flashes it.
- Markdown, HTML and PDF exports handle the new blocks; HTML import reads
<details> as a toggle.
Pages and spaces:
- History gets a Changes view: block and word diff against the previous
version or the page as it is now.
- Archive: archived pages leave the tree and become read-only but stay
readable; a space's Archive lists them with Unarchive. New migration
(pages.archived_at) and page.archived / page.unarchived webhook events.
- Full space export (GET /spaces/{id}/export): a zip of Markdown or HTML
files with subpages in folders, an index, and attachments under _files/.
Links between exported pages and to attachments become relative paths.
Desktop 1.0:
- Several servers, each with its own sign-in; old settings files carry over.
- Session tokens in the system keychain (go-keyring), moved out of
localStorage on first start.
- Native menu bar (File, Edit, View, Window, Help) with a Server submenu.
- docwell:// links may point at a block.
- Release workflow builds Windows NSIS, macOS DMG and Linux deb, rpm and
AppImage installers and attaches them to the release;
build/set-version.mjs stamps the version into their metadata.
Not yet run: the release workflow, the desktop menus by eye, and macOS or
Linux builds.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
115 lines
3.3 KiB
Go
115 lines
3.3 KiB
Go
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
package main
|
|
|
|
import (
|
|
"errors"
|
|
"log/slog"
|
|
"net/url"
|
|
"regexp"
|
|
"slices"
|
|
"strings"
|
|
"sync"
|
|
)
|
|
|
|
// deepLinkScheme is registered with the OS by the installers (build/config.yml).
|
|
const deepLinkScheme = "docwell"
|
|
|
|
// openRouteEvent carries an app route (e.g. "/p/abc123") to the frontend.
|
|
const openRouteEvent = "docwell:open-route"
|
|
|
|
// deepLinkRoutes are the app routes a link may open: a page or a space.
|
|
var deepLinkRoutes = []string{"p", "s"}
|
|
|
|
var recordID = regexp.MustCompile(`^[A-Za-z0-9]{1,32}$`)
|
|
|
|
// blockFragment is a link to one block of a page: docwell://p/<id>#b-<block>.
|
|
var blockFragment = regexp.MustCompile(`^b-[a-z0-9]{6,16}$`)
|
|
|
|
// routeFromDeepLink turns docwell://p/<id> into the app route /p/<id>
|
|
// (keeping a #b-<block> fragment that points at one block).
|
|
// Anything else is refused: links come from other apps and web pages, so
|
|
// they may only navigate, never change settings such as the server address.
|
|
func routeFromDeepLink(raw string) (string, error) {
|
|
u, err := url.Parse(strings.TrimSpace(raw))
|
|
if err != nil || !strings.EqualFold(u.Scheme, deepLinkScheme) {
|
|
return "", errors.New("not a docwell:// link")
|
|
}
|
|
if u.Host == "" && strings.Trim(u.Path, "/") == "" {
|
|
return "/", nil
|
|
}
|
|
parts := strings.Split(strings.Trim(u.Host+u.Path, "/"), "/")
|
|
if len(parts) != 2 || !slices.Contains(deepLinkRoutes, parts[0]) || !recordID.MatchString(parts[1]) {
|
|
return "", errors.New("unsupported docwell:// link")
|
|
}
|
|
route := "/" + parts[0] + "/" + parts[1]
|
|
if u.Fragment != "" {
|
|
if parts[0] != "p" || !blockFragment.MatchString(u.Fragment) {
|
|
return "", errors.New("unsupported docwell:// link")
|
|
}
|
|
route += "#" + u.Fragment
|
|
}
|
|
return route, nil
|
|
}
|
|
|
|
// deepLinkFromArgs finds a docwell:// link among command-line arguments,
|
|
// which is how Windows and Linux pass it to the app.
|
|
func deepLinkFromArgs(args []string) (string, bool) {
|
|
for _, a := range args {
|
|
if strings.HasPrefix(strings.ToLower(a), deepLinkScheme+"://") {
|
|
return a, true
|
|
}
|
|
}
|
|
return "", false
|
|
}
|
|
|
|
// LinkService routes docwell:// links into the app. It is bound to the
|
|
// frontend, which asks for a link that arrived before it was listening (the
|
|
// one the app was launched with) and then follows openRouteEvent.
|
|
type LinkService struct {
|
|
mu sync.Mutex
|
|
pending string
|
|
// emit sends a route to the frontend; set once the app exists.
|
|
emit func(route string)
|
|
// listening turns true when the frontend first calls TakePending.
|
|
listening bool
|
|
}
|
|
|
|
// open handles a link from the OS. Bad links are logged and ignored.
|
|
func (s *LinkService) open(raw string) {
|
|
route, err := routeFromDeepLink(raw)
|
|
if err != nil {
|
|
slog.Warn("ignoring link", "link", raw, "err", err)
|
|
return
|
|
}
|
|
slog.Info("opening link", "route", route)
|
|
s.mu.Lock()
|
|
var emit func(string)
|
|
if s.listening {
|
|
emit = s.emit
|
|
} else {
|
|
s.pending = route
|
|
}
|
|
s.mu.Unlock()
|
|
if emit != nil {
|
|
emit(route)
|
|
}
|
|
}
|
|
|
|
// TakePending returns the route the app was opened with, once. The frontend
|
|
// calls it after subscribing to openRouteEvent, so later links are emitted.
|
|
func (s *LinkService) TakePending() string {
|
|
s.mu.Lock()
|
|
defer s.mu.Unlock()
|
|
s.listening = s.emit != nil
|
|
route := s.pending
|
|
s.pending = ""
|
|
return route
|
|
}
|
|
|
|
func (s *LinkService) setEmitter(emit func(route string)) {
|
|
s.mu.Lock()
|
|
defer s.mu.Unlock()
|
|
s.emit = emit
|
|
}
|