Repository navigation
feat(app): open a local file in the default browser - #18
Merged
Merged
Conversation
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
marked this pull request as ready for review
November 14, 2026 13:22
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。
24 of 28 tasks
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 和提示,不再同时记一条已执行的操作。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Lithe's HTML preview has an "Open in browser" button. Clicking it fails with
app: external URL must use http, https, or mailto:file:URL and callsapp.OpenURL, which refuses that scheme on purpose.app.OpenPathwould not be right either. It follows the.htmlfile association, but Lithe has always sent pages to the default web browser (thehttphandler).Viva has no call for that.
Change
Adds
app.OpenPathInBrowser(path). On every platform it finds the default browser, thehttp/httpshandler, and gives it the local file:open -a.AssocQueryStringWforhttp, with the file'sfile:URL filled into the registered command.xdg-settings(orxdg-mime) names, with itsExecline expanded.It also adds:
app.ErrNoBrowserfor a system with no default browser.Driver.LastOpenedInBrowser(), which records the call apart fromOpenPath/OpenURL.The full description, verification and cost are in the upstream PR: vivaui#272.
Branches
feat/open-path-in-browser: one commit,96873df, branched from upstreammainb63e4a0. It is the head of feat(app): open a local file in the default browser vivaui/viva#272.lithe/open-path-in-browser-on-main(this PR): the same commit cherry-picked onto forkmain609dd47, as09031a3. merge: bring upstream main (b63e4a0, delta updates) onto main #16 was squashed, sob63e4a0is not an ancestor of forkmain. A PR from the upstream branch would show 231 files, and merging it conflicts in 7 files that this change does not touch.mainnext merges upstream, both copies of the change are identical, so the merge has nothing to resolve.Tests
go test ./app ./internal/platform ./internal/platform/darwin ./headless/... -count=1pass on this branch.go vetpasses for darwin, linux/amd64, js/wasm and-tags vivahead.GOOS=windows go vet ./internal/... ./app/fails on forkmainitself (duplicate case wmSetTitle, the merge: bring upstream main (b63e4a0, delta updates) onto main #16 regression). With fix(windows): give wmSetTitle its own message number #17 merged into a throwaway branch on top of this one, it is clean. So fix(windows): give wmSetTitle its own message number #17 should go in first, or together with this.New tests:
TestOpenPathInBrowserValidatesBeforeAskingTheSystemTestDriverRecordsOpenPathInBrowserAndStartsNothingTestFileURLIsOneWordABrowserResolvesBackToThePathTestBrowserCommandLineFillsInTheRegisteredCommandTestDesktopEntry*