Skip to content

feat(app): open a local file in the default browser - #18

Merged
xiaoyumuxi merged 2 commits into
mainfrom
lithe/open-path-in-browser-on-main
Nov 14, 2026
Merged

xiaoyumuxi merged 2 commits into
mainfrom
lithe/open-path-in-browser-on-main

Conversation

@xiaoyumuxi

Copy link
Copy Markdown

Problem

Lithe's HTML preview has an "Open in browser" button. Clicking it fails with app: external URL must use http, https, or mailto:

  • The desktop builds a file: URL and calls app.OpenURL, which refuses that scheme on purpose.
  • app.OpenPath would not be right either. It follows the .html file association, but Lithe has always sent pages to the default web browser (the http handler).

Viva has no call for that.

Change

Adds app.OpenPathInBrowser(path). On every platform it finds the default browser, the http/https handler, and gives it the local file:

  • macOS: LaunchServices, then open -a.
  • Windows: AssocQueryStringW for http, with the file's file: URL filled into the registered command.
  • Linux: the desktop entry xdg-settings (or xdg-mime) names, with its Exec line expanded.

It also adds:

  • app.ErrNoBrowser for a system with no default browser.
  • Driver.LastOpenedInBrowser(), which records the call apart from OpenPath/OpenURL.

The full description, verification and cost are in the upstream PR: vivaui#272.

Branches

Tests

New tests:

  • TestOpenPathInBrowserValidatesBeforeAskingTheSystem
  • TestDriverRecordsOpenPathInBrowserAndStartsNothing
  • TestFileURLIsOneWordABrowserResolvesBackToThePath
  • TestBrowserCommandLineFillsInTheRegisteredCommand
  • TestDesktopEntry*

app.OpenPathInBrowser hands a regular file to the default web browser, the
application http and https links open in, whatever application the file's
type is associated with. An editor that previews HTML needs this: OpenPath
opens a page in whatever the .html association names, often the editor
itself, and OpenURL refuses file: URLs on purpose.

- macOS asks LaunchServices which application opens https links and opens
  the file with it through open -a, whose exit status reports the handoff.
- Windows reads the http protocol's command with AssocQueryStringW, fills
  the file's file: URL into it as the shell would, and starts it without a
  shell.
- Linux takes the desktop entry xdg-settings names as the default web
  browser (xdg-mime for x-scheme-handler/https without it), finds it in the
  XDG data directories and runs its Exec line with the file's URL; a
  terminal browser is ErrUnsupported.
- Without a default browser the call returns app.ErrNoBrowser; the browser
  target returns ErrUnsupported.
- The headless Driver records the request as LastOpenedInBrowser, apart from
  LastOpenedPath and LastOpenedURL, and starts nothing.

The command-line filling, the file URL and the desktop-entry parsing are
pure helpers in internal/platform, tested on every host.
@xiaoyumuxi
xiaoyumuxi marked this pull request as ready for review November 14, 2026 13:22
@xiaoyumuxi
xiaoyumuxi merged commit 4829f2b into main Nov 14, 2026
18 of 22 checks passed
xiaoyumuxi added a commit to 1lck/Lithe-IDEA that referenced this pull request Nov 14, 2026
desktop/go.mod 的 replace 从 fork main 609dd47 升到 4829f2b,
多出两项补丁:

- Lithe-IDEA/Lithe-viva#17:wmSetTitle 改用 0x8053,修复 #16 合入上游
  后与 wmSetSize 撞号导致的 Windows 编译失败。补的是 fork 独有的
  Window.SetTitle,上游没有对应 PR。
- Lithe-IDEA/Lithe-viva#18:新增 app.OpenPathInBrowser,上游 PR 为
  vivaui/viva#272。

require 仍是上游基线 b63e4a0,没有变化。

功能矩阵 embedded-viewers:Viva 的“在浏览器中打开”写明交给默认网页
浏览器、不跟随 .html 的文件关联,并注明 Windows 需实机确认;证据补上
browser_preview.go 及其测试,自动回归的 -run 加上 OpenInBrowser。
xiaoyumuxi added a commit to 1lck/Lithe-IDEA that referenced this pull request Nov 14, 2026
* wip(desktop): 在浏览器中打开 HTML 的回归测试(待 Viva 默认浏览器 API)

* fix(desktop): 在浏览器中打开 HTML 改为交给默认浏览器

预览栏的“在浏览器中打开”原来拼出 file:// 地址交给 app.OpenURL,
Viva 只接受 http、https、mailto,于是总是报错。改为调用 Viva 新增的
app.OpenPathInBrowser:交给默认浏览器(打开 http 链接的应用),
不跟随 .html 的文件关联,与旧客户端一致。

- 在后台调用,macOS 上要等 open 报告结果,不阻塞窗口线程。
- 失败时记录 app.operation_failed(operation=editor_open_in_browser),
  并在日志目录测试里登记。
- 回归测试断言文件交给了 LastOpenedInBrowser,既不是 OpenPath 也不是 OpenURL。

依赖 Lithe-IDEA/Lithe-viva#18(上游 vivaui/viva#272)合入 fork main
后升级 desktop/go.mod 的固定版本,在此之前本分支编译不过。

* fix(desktop): Viva 固定到含 OpenPathInBrowser 的 fork main

desktop/go.mod 的 replace 从 fork main 609dd47 升到 4829f2b,
多出两项补丁:

- Lithe-IDEA/Lithe-viva#17:wmSetTitle 改用 0x8053,修复 #16 合入上游
  后与 wmSetSize 撞号导致的 Windows 编译失败。补的是 fork 独有的
  Window.SetTitle,上游没有对应 PR。
- Lithe-IDEA/Lithe-viva#18:新增 app.OpenPathInBrowser,上游 PR 为
  vivaui/viva#272。

require 仍是上游基线 b63e4a0,没有变化。

功能矩阵 embedded-viewers:Viva 的“在浏览器中打开”写明交给默认网页
浏览器、不跟随 .html 的文件关联,并注明 Windows 需实机确认;证据补上
browser_preview.go 及其测试,自动回归的 -run 加上 OpenInBrowser。

* fix(desktop): 在浏览器中打开成功后才记录 app.action.performed

与设置页链接和修复前的行为一致:打开失败时只记录 app.operation_failed 和提示,不再同时记一条已执行的操作。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant