diff --git a/desktop/internal/core/github.go b/desktop/internal/core/github.go index d24a9579ac..b3a1a03fe6 100644 --- a/desktop/internal/core/github.go +++ b/desktop/internal/core/github.go @@ -35,6 +35,8 @@ type GitHubRequest struct { Assignees []string `json:"assignees,omitempty"` // Commit is the commit a check read names, as a hexadecimal SHA of at least four digits. Commit string `json:"commit,omitempty"` + // Ref is the branch, tag or HEAD whose newest commit latestCommit looks up. + Ref string `json:"ref,omitempty"` } // GitHubPlan is the HTTP request Core planned: the host it goes to, the method, the path and the diff --git a/desktop/internal/core/marketplace.go b/desktop/internal/core/marketplace.go index 5bd30270a5..2d182bcf67 100644 --- a/desktop/internal/core/marketplace.go +++ b/desktop/internal/core/marketplace.go @@ -42,12 +42,33 @@ func (o marketplaceOutcome) failure(command string) error { return nil } -// MarketplaceSource is Core's canonical index location and its optional repository. +// MarketplaceSource is Core's canonical index location and its optional repository. IndexURL is +// the source's identity; Pinned only says where the same files are at one commit. type MarketplaceSource struct { IndexURL string `json:"indexURL"` RecommendationsURL string `json:"recommendationsURL"` Repository *string `json:"repository"` DisplayName string `json:"displayName"` + // Revision is the GitHub repository and ref a GitHub-hosted index follows; nil for any + // other source and for an index URL already at a commit. + Revision *MarketplaceRevision `json:"revision"` + // Pinned is the index and recommendations at the commit PinMarketplaceSource passed; nil + // when nothing could be pinned. + Pinned *MarketplacePinned `json:"pinned"` +} + +// MarketplaceRevision is the repository and ref whose newest commit pins a source. +type MarketplaceRevision struct { + Repository GitHubRepo `json:"repository"` + Ref string `json:"ref"` +} + +// MarketplacePinned is a source's files at one commit. Branch URLs on raw.githubusercontent.com +// are cached for minutes; a commit URL is not served stale. +type MarketplacePinned struct { + Commit string `json:"commit"` + IndexURL string `json:"indexURL"` + RecommendationsURL string `json:"recommendationsURL"` } // MarketplaceAvailability is Core's platform and capability decision. @@ -115,11 +136,22 @@ type MarketplaceReview struct { // ResolveMarketplaceSource delegates URL validation and canonicalization to Core. func (c *Client) ResolveMarketplaceSource(ctx context.Context, url string) (MarketplaceSource, error) { + return c.resolveMarketplaceSource(ctx, url, "") +} + +// PinMarketplaceSource resolves url like ResolveMarketplaceSource and adds Pinned, its files at +// commit, the newest commit of the source's Revision. +func (c *Client) PinMarketplaceSource(ctx context.Context, url, commit string) (MarketplaceSource, error) { + return c.resolveMarketplaceSource(ctx, url, commit) +} + +func (c *Client) resolveMarketplaceSource(ctx context.Context, url, commit string) (MarketplaceSource, error) { const command = "plugins.marketplace.resolveSource" var result marketplaceOutcome if err := c.Execute(ctx, command, struct { - URL string `json:"url"` - }{url}, &result); err != nil { + URL string `json:"url"` + Commit string `json:"commit,omitempty"` + }{url, commit}, &result); err != nil { return MarketplaceSource{}, err } if err := result.failure(command); err != nil { diff --git a/desktop/internal/core/marketplace_test.go b/desktop/internal/core/marketplace_test.go index f61b6ef4f2..a73be46a83 100644 --- a/desktop/internal/core/marketplace_test.go +++ b/desktop/internal/core/marketplace_test.go @@ -4,6 +4,7 @@ import ( "encoding/json" "os" "path/filepath" + "reflect" "slices" "testing" @@ -26,10 +27,13 @@ func TestMarketplaceSourceFixture(t *testing.T) { var fixture struct { Cases []struct { Input string `json:"input"` + Commit string `json:"commit"` Expected struct { - IndexURL string `json:"indexURL"` - RecommendationsURL string `json:"recommendationsURL"` - DisplayName string `json:"displayName"` + IndexURL string `json:"indexURL"` + RecommendationsURL string `json:"recommendationsURL"` + DisplayName string `json:"displayName"` + Revision *MarketplaceRevision `json:"revision"` + Pinned *MarketplacePinned `json:"pinned"` } `json:"expected"` ExpectedCode string `json:"expectedCode"` } `json:"cases"` @@ -37,8 +41,14 @@ func TestMarketplaceSourceFixture(t *testing.T) { readMarketFixture(t, "marketplace/source-urls.json", &fixture) client := NewClient() for _, item := range fixture.Cases { - t.Run(item.Input, func(t *testing.T) { - source, err := client.ResolveMarketplaceSource(testContext(t), item.Input) + t.Run(item.Input+"@"+item.Commit, func(t *testing.T) { + var source MarketplaceSource + var err error + if item.Commit != "" { + source, err = client.PinMarketplaceSource(testContext(t), item.Input, item.Commit) + } else { + source, err = client.ResolveMarketplaceSource(testContext(t), item.Input) + } if item.ExpectedCode != "" { rejection, ok := err.(*MarketplaceRejection) if !ok || rejection.Code != item.ExpectedCode { @@ -49,7 +59,9 @@ func TestMarketplaceSourceFixture(t *testing.T) { if err != nil || source.IndexURL != item.Expected.IndexURL || source.RecommendationsURL != item.Expected.RecommendationsURL || - source.DisplayName != item.Expected.DisplayName { + source.DisplayName != item.Expected.DisplayName || + !reflect.DeepEqual(source.Revision, item.Expected.Revision) || + !reflect.DeepEqual(source.Pinned, item.Expected.Pinned) { t.Fatalf("source = %#v, error = %v", source, err) } }) diff --git a/desktop/internal/githubapi/types.go b/desktop/internal/githubapi/types.go index c2b4b77011..7c851c37c9 100644 --- a/desktop/internal/githubapi/types.go +++ b/desktop/internal/githubapi/types.go @@ -150,6 +150,33 @@ func DecodeBranches(raw json.RawMessage) ([]Branch, error) { return items, err } +// DecodeReleases reads the normalized listReleases result, newest first. +func DecodeReleases(raw json.RawMessage) ([]Release, error) { + var items []Release + err := json.Unmarshal(raw, &items) + return items, err +} + +// DecodeLatestCommit reads the normalized latestCommit result: the full lowercase SHA. +func DecodeLatestCommit(raw json.RawMessage) (string, error) { + var commit struct { + SHA string `json:"sha"` + } + err := json.Unmarshal(raw, &commit) + return commit.SHA, err +} + +// Release is one published release. Name is empty when the author left the title empty; Body is +// the release notes in Markdown, possibly empty; PublishedAt is RFC 3339 or empty. +type Release struct { + TagName string `json:"tagName"` + Name string `json:"name"` + Body string `json:"body"` + PublishedAt string `json:"publishedAt"` + Prerelease bool `json:"prerelease"` + URL string `json:"url"` +} + // DecodeComparison reads the normalized comparison of two branches. func DecodeComparison(raw json.RawMessage) (Comparison, error) { var comparison Comparison diff --git a/desktop/internal/i18n/shared.generated.go b/desktop/internal/i18n/shared.generated.go index 2c5f41bd81..c0377f890b 100644 --- a/desktop/internal/i18n/shared.generated.go +++ b/desktop/internal/i18n/shared.generated.go @@ -1390,6 +1390,17 @@ var sharedCatalogs = map[string]map[string]string{ "desktop.panel.header": "Tool window header", "desktop.panel.hide": "Hide", "desktop.panel.placeholder": "This tool window is connected in a later version", + "desktop.pluginChangelog.empty": "This repository hasn't published any releases yet.", + "desktop.pluginChangelog.failed": "Couldn't read the releases from GitHub.", + "desktop.pluginChangelog.loading": "Reading the releases…", + "desktop.pluginChangelog.marketFailed": "Couldn't read the marketplace, so this plugin's repository isn't known yet.", + "desktop.pluginChangelog.noNotes": "This release has no notes.", + "desktop.pluginChangelog.noRepository": "The marketplace lists no repository for this plugin, so there is no changelog to show.", + "desktop.pluginChangelog.openRelease": "Open in browser", + "desktop.pluginChangelog.openReleases": "View all releases in the browser", + "desktop.pluginChangelog.prerelease": "Pre-release", + "desktop.pluginChangelog.retry": "Retry", + "desktop.pluginChangelog.unsupported": "The changelog can only be read from GitHub repositories. Open the repository to see this plugin's changes.", "desktop.pluginHost.contentFailed": "Could not open {uri}: the plugin did not provide its content.", "desktop.pluginHost.messageDismiss": "Dismiss", "desktop.pluginHost.messageFrom": "Message from {plugin}", @@ -3825,6 +3836,7 @@ var sharedCatalogs = map[string]map[string]string{ "native.unversionedFiles": "Unversioned Files", "native.update": "Update", "native.updateAvailable.variant2": "Update available", + "native.updateLog": "Update log", "native.updateProject": "Update Project", "native.updateTo.variant2": "Update to {arg1}", "native.updated2": "Updated.", @@ -5315,6 +5327,17 @@ var sharedCatalogs = map[string]map[string]string{ "desktop.panel.header": "工具窗口标题栏", "desktop.panel.hide": "隐藏", "desktop.panel.placeholder": "此工具窗口将在后续版本接入", + "desktop.pluginChangelog.empty": "这个仓库还没有发布任何 Release。", + "desktop.pluginChangelog.failed": "没能从 GitHub 读取 Releases。", + "desktop.pluginChangelog.loading": "正在读取 Releases…", + "desktop.pluginChangelog.marketFailed": "没能读取插件市场,还不知道这个插件的仓库。", + "desktop.pluginChangelog.noNotes": "这个 Release 没有填写说明。", + "desktop.pluginChangelog.noRepository": "插件市场里没有这个插件的仓库地址,没有更新日志可以显示。", + "desktop.pluginChangelog.openRelease": "在浏览器中打开", + "desktop.pluginChangelog.openReleases": "在浏览器中查看全部 Releases", + "desktop.pluginChangelog.prerelease": "预发布", + "desktop.pluginChangelog.retry": "重试", + "desktop.pluginChangelog.unsupported": "更新日志只能从 GitHub 仓库读取。打开仓库查看这个插件的改动。", "desktop.pluginHost.contentFailed": "无法打开 {uri}:插件没有提供其内容。", "desktop.pluginHost.messageDismiss": "关闭", "desktop.pluginHost.messageFrom": "来自 {plugin} 的消息", @@ -7750,6 +7773,7 @@ var sharedCatalogs = map[string]map[string]string{ "native.unversionedFiles": "未版本控制的文件", "native.update": "更新", "native.updateAvailable.variant2": "有可用更新", + "native.updateLog": "更新日志", "native.updateProject": "更新项目", "native.updateTo.variant2": "更新到 {arg1}", "native.updated2": "已更新。", diff --git a/desktop/internal/marketplace/service.go b/desktop/internal/marketplace/service.go index 2cab99d72b..f7224879be 100644 --- a/desktop/internal/marketplace/service.go +++ b/desktop/internal/marketplace/service.go @@ -25,6 +25,9 @@ const ( MaxIndexBytes = 5 << 20 fetchTimeout = 20 * time.Second maxRedirects = 10 + // commitLookupTimeout bounds the newest-commit lookup, so an unreachable GitHub API costs + // a few seconds before the canonical index is read instead of the whole fetch budget. + commitLookupTimeout = 5 * time.Second ) var ( @@ -36,13 +39,21 @@ var ( // Evaluator is the shared Core marketplace contract, supplied by core.Client. type Evaluator interface { ResolveMarketplaceSource(context.Context, string) (core.MarketplaceSource, error) + PinMarketplaceSource(ctx context.Context, url, commit string) (core.MarketplaceSource, error) ValidateMarketplaceIndex(context.Context, json.RawMessage, core.MarketplaceSourceKind, string, map[string][]int) (core.MarketplaceIndex, error) } +// CommitLookup returns the newest commit of ref in repository as a full SHA. +type CommitLookup func(ctx context.Context, repository core.GitHubRepo, ref string) (string, error) + // Service holds a reusable HTTP client. It stores no index inside application resources. type Service struct { core Evaluator http *http.Client + // latest and fallback are set by PinToLatestCommit; with latest nil every file is read + // from its canonical URL. + latest CommitLookup + fallback func(context.Context, error) } // New creates a marketplace service. A nil client uses Go's default transport; @@ -51,6 +62,16 @@ func New(evaluator Evaluator, client *http.Client) *Service { return &Service{core: evaluator, http: marketplaceHTTPClient(client, fetchTimeout)} } +// PinToLatestCommit makes s read a GitHub-hosted source at the newest commit latest reports +// rather than at its branch URL, which raw.githubusercontent.com serves from a cache for up to +// five minutes after a push. When the lookup or the pinned read fails, s reads the canonical URL +// and hands the failure to fallback with the fetch's context; fallback must be safe to call from +// any goroutine. +func (s *Service) PinToLatestCommit(latest CommitLookup, fallback func(context.Context, error)) *Service { + s.latest, s.fallback = latest, fallback + return s +} + // marketplaceHTTPClient preserves the supplied transport and redirect policy, // while refusing redirects that would downgrade or embed credentials. A // positive timeout bounds each request as a whole, keeping a shorter one the @@ -103,7 +124,8 @@ func (s *Service) Fetch(ctx context.Context, input string, kind core.Marketplace if err != nil { return Snapshot{}, err } - data, _, err := s.fetchJSON(ctx, source.IndexURL) + pinned := s.pin(ctx, input, source) + data, err := s.fetchPinned(ctx, source.IndexURL, pinnedIndex(pinned)) if err != nil { return Snapshot{}, err } @@ -127,14 +149,15 @@ func (s *Service) FetchRecommendationBundle(ctx context.Context, input string, k if source.RecommendationsURL == "" { return RecommendationBundle{}, false, nil } - recBody, _, err := s.fetchJSON(ctx, source.RecommendationsURL) + pinned := s.pin(ctx, input, source) + recBody, err := s.fetchPinned(ctx, source.RecommendationsURL, pinnedRecommendations(pinned)) if err != nil { if err == httpStatusError(http.StatusNotFound) { return RecommendationBundle{}, false, nil } return RecommendationBundle{}, false, err } - indexBody, _, err := s.fetchJSON(ctx, source.IndexURL) + indexBody, err := s.fetchPinned(ctx, source.IndexURL, pinnedIndex(pinned)) if err != nil { return RecommendationBundle{}, false, err } @@ -146,6 +169,66 @@ func (s *Service) FetchRecommendationBundle(ctx context.Context, input string, k }, true, nil } +// pin asks for the newest commit of a GitHub-hosted source and has Core place the source's files +// at it. It returns nil, after reporting why, when the lookup or Core fails, and nil without a +// report when s does not pin or the source follows no GitHub branch. +func (s *Service) pin(ctx context.Context, input string, source core.MarketplaceSource) *core.MarketplacePinned { + if s.latest == nil || source.Revision == nil { + return nil + } + lookupCtx, cancel := context.WithTimeout(ctx, commitLookupTimeout) + commit, err := s.latest(lookupCtx, source.Revision.Repository, source.Revision.Ref) + cancel() + if err != nil { + s.reportFallback(ctx, fmt.Errorf("look up the newest commit of %s/%s %s: %w", source.Revision.Repository.Owner, source.Revision.Repository.Name, source.Revision.Ref, err)) + return nil + } + pinned, err := s.core.PinMarketplaceSource(ctx, input, commit) + if err == nil && pinned.Pinned == nil { + err = errors.New("Core placed no file at the commit") + } + if err != nil { + s.reportFallback(ctx, fmt.Errorf("pin %s at %s: %w", source.IndexURL, commit, err)) + return nil + } + return pinned.Pinned +} + +// fetchPinned reads the file at pinnedURL when there is one and at canonical otherwise. A pinned +// read that fails is reported and retried at canonical, except a 404: the commit is the +// repository's newest, so the file is absent from it. +func (s *Service) fetchPinned(ctx context.Context, canonical, pinnedURL string) ([]byte, error) { + if pinnedURL != "" { + data, _, err := s.fetchJSON(ctx, pinnedURL) + if err == nil || err == httpStatusError(http.StatusNotFound) || ctx.Err() != nil { + return data, err + } + s.reportFallback(ctx, fmt.Errorf("read %s: %w", pinnedURL, err)) + } + data, _, err := s.fetchJSON(ctx, canonical) + return data, err +} + +func (s *Service) reportFallback(ctx context.Context, err error) { + if s.fallback != nil { + s.fallback(ctx, err) + } +} + +func pinnedIndex(pinned *core.MarketplacePinned) string { + if pinned == nil { + return "" + } + return pinned.IndexURL +} + +func pinnedRecommendations(pinned *core.MarketplacePinned) string { + if pinned == nil { + return "" + } + return pinned.RecommendationsURL +} + func (s *Service) fetchJSON(ctx context.Context, rawURL string) (data []byte, status int, err error) { request, err := http.NewRequestWithContext(ctx, http.MethodGet, rawURL, nil) if err != nil { diff --git a/desktop/internal/marketplace/service_test.go b/desktop/internal/marketplace/service_test.go index 88e3920086..c31d3dc7eb 100644 --- a/desktop/internal/marketplace/service_test.go +++ b/desktop/internal/marketplace/service_test.go @@ -7,6 +7,7 @@ import ( "io" "net/http" "os" + "slices" "strings" "testing" "time" @@ -269,3 +270,104 @@ func TestFetchRecommendationBundle(t *testing.T) { } }) } + +// pinTestCommit is the newest commit the pinning tests' lookup reports. +const pinTestCommit = "0123456789abcdef0123456789abcdef01234567" + +func TestFetchReadsGitHubIndexAtNewestCommit(t *testing.T) { + index, err := os.ReadFile(contractfixture.Path("fixtures/marketplace/index.json")) + if err != nil { + t.Fatal(err) + } + const pinned = "https://raw.githubusercontent.com/example/lithe-plugins/" + pinTestCommit + "/lithe-plugin-index.json" + var requested []string + client := &http.Client{Transport: transportFunc(func(r *http.Request) (*http.Response, error) { + requested = append(requested, r.URL.String()) + return &http.Response{StatusCode: 200, Header: make(http.Header), Body: io.NopCloser(strings.NewReader(string(index))), Request: r}, nil + })} + var looked []string + var reported []error + service := New(core.NewClient(), client).PinToLatestCommit(func(_ context.Context, repository core.GitHubRepo, ref string) (string, error) { + looked = append(looked, repository.Owner+"/"+repository.Name+"@"+ref) + return pinTestCommit, nil + }, func(_ context.Context, err error) { reported = append(reported, err) }) + ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) + defer cancel() + snapshot, err := service.Fetch(ctx, "https://github.com/example/lithe-plugins", core.MarketplaceThirdParty, "darwin-arm64", map[string][]int{}) + if err != nil { + t.Fatal(err) + } + if !slices.Equal(looked, []string{"example/lithe-plugins@HEAD"}) || !slices.Equal(requested, []string{pinned}) || len(reported) != 0 { + t.Fatalf("looked up %v, requested %v, reported %v", looked, requested, reported) + } + // The source keeps its branch URL: trust records and automatic updates match on it. + const canonical = "https://raw.githubusercontent.com/example/lithe-plugins/HEAD/lithe-plugin-index.json" + if snapshot.Source.IndexURL != canonical { + t.Fatalf("source = %s", snapshot.Source.IndexURL) + } + for _, plugin := range snapshot.Index.Plugins { + if plugin.MarketplaceIndexURL != canonical { + t.Fatalf("plugin %q source = %q", plugin.ID, plugin.MarketplaceIndexURL) + } + } +} + +func TestFetchFallsBackToBranchIndexAndReports(t *testing.T) { + index, err := os.ReadFile(contractfixture.Path("fixtures/marketplace/index.json")) + if err != nil { + t.Fatal(err) + } + const canonical = "https://raw.githubusercontent.com/example/lithe-plugins/HEAD/lithe-plugin-index.json" + const pinned = "https://raw.githubusercontent.com/example/lithe-plugins/" + pinTestCommit + "/lithe-plugin-index.json" + for _, tc := range []struct { + name string + lookupErr error + pinnedOK bool + want []string + }{ + {name: "lookup fails", lookupErr: errors.New("rate limited"), want: []string{canonical}}, + {name: "pinned read fails", pinnedOK: false, want: []string{pinned, canonical}}, + } { + t.Run(tc.name, func(t *testing.T) { + var requested []string + client := &http.Client{Transport: transportFunc(func(r *http.Request) (*http.Response, error) { + requested = append(requested, r.URL.String()) + if r.URL.String() == pinned && !tc.pinnedOK { + return &http.Response{StatusCode: 503, Header: make(http.Header), Body: io.NopCloser(strings.NewReader("")), Request: r}, nil + } + return &http.Response{StatusCode: 200, Header: make(http.Header), Body: io.NopCloser(strings.NewReader(string(index))), Request: r}, nil + })} + var reported []error + service := New(core.NewClient(), client).PinToLatestCommit(func(context.Context, core.GitHubRepo, string) (string, error) { + return pinTestCommit, tc.lookupErr + }, func(_ context.Context, err error) { reported = append(reported, err) }) + ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) + defer cancel() + if _, err := service.Fetch(ctx, "https://github.com/example/lithe-plugins", core.MarketplaceThirdParty, "darwin-arm64", map[string][]int{}); err != nil { + t.Fatal(err) + } + if !slices.Equal(requested, tc.want) || len(reported) != 1 { + t.Fatalf("requested %v, reported %v", requested, reported) + } + }) + } +} + +func TestFetchDoesNotLookUpSourcesOutsideGitHub(t *testing.T) { + index, err := os.ReadFile(contractfixture.Path("fixtures/marketplace/index.json")) + if err != nil { + t.Fatal(err) + } + client := &http.Client{Transport: transportFunc(func(r *http.Request) (*http.Response, error) { + return &http.Response{StatusCode: 200, Header: make(http.Header), Body: io.NopCloser(strings.NewReader(string(index))), Request: r}, nil + })} + service := New(core.NewClient(), client).PinToLatestCommit(func(context.Context, core.GitHubRepo, string) (string, error) { + t.Error("a source outside GitHub was looked up") + return "", errors.New("unexpected lookup") + }, func(_ context.Context, err error) { t.Errorf("reported %v", err) }) + ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) + defer cancel() + if _, err := service.Fetch(ctx, "https://plugins.example.com/index.json", core.MarketplaceThirdParty, "darwin-arm64", map[string][]int{}); err != nil { + t.Fatal(err) + } +} diff --git a/desktop/internal/settingswindow/controller.go b/desktop/internal/settingswindow/controller.go index 247059c423..1234bdd381 100644 --- a/desktop/internal/settingswindow/controller.go +++ b/desktop/internal/settingswindow/controller.go @@ -445,6 +445,11 @@ type Options struct { CommandInstalls CommandInstaller // UninstallPlugin removes the installed version of a plugin. UninstallPlugin func(id string) + // PluginReleases lists the published releases of the source repository a plugin's + // marketplace listing names, newest first, for the Installed tab's changelog. supported is + // false, with no error, when the repository is not one it can read releases from. It runs + // on a worker and must return when ctx is done; nil shows no changelog tab. + PluginReleases func(ctx context.Context, repository string) (releases []PluginRelease, supported bool, err error) // InstallPluginFromFile installs a plugin package the user picked on disk. The // package is reviewed like a marketplace one before anything is written. InstallPluginFromFile func(path string, feedback PluginInstallFeedback) @@ -718,6 +723,10 @@ func (c *Controller) open(application *app.Application, current Values, page pag if page != noPage { open.requestPage(page) } + // A raised window may have shown the plugin page for a while: it reads the store again + // when what it shows is stale. + open.raised.Store(true) + open.inv.Invalidate() c.mu.Unlock() win.Show() return nil @@ -826,6 +835,21 @@ type PluginFacts struct { Path string } +// PluginRelease is one published release of a plugin's source repository, as the changelog +// of the Installed tab shows it. +type PluginRelease struct { + // Tag is the release's tag and Name its title; an untitled release leaves Name empty. + Tag, Name string + // Notes are the release's notes in Markdown; empty when the release has none. + Notes string + // Published is when the release was published; zero when the host does not say. + Published time.Time + // Prerelease says the release is marked as a pre-release. + Prerelease bool + // URL is the release's page on the web. + URL string +} + // Where an installed package came from, as its approval records it. const ( PluginSourceDisk = "disk" diff --git a/desktop/internal/settingswindow/installed_changelog.go b/desktop/internal/settingswindow/installed_changelog.go new file mode 100644 index 0000000000..4788473516 --- /dev/null +++ b/desktop/internal/settingswindow/installed_changelog.go @@ -0,0 +1,341 @@ +package settingswindow + +import ( + "context" + "errors" + "net/url" + "strings" + "time" + + "github.com/1lck/Lithe-IDEA/desktop/internal/i18n" + "github.com/vivaui/viva/components" + "github.com/vivaui/viva/gfx" + "github.com/vivaui/viva/markdown" + "github.com/vivaui/viva/ui" +) + +// The Changelog tab of an installed plugin's detail lists the releases its source repository +// published, newest first, each with its notes in Markdown. The releases are read from the +// repository when the tab is first shown for it and kept until the window closes, so going +// back to the tab, or to another plugin of the same repository, reads nothing again. + +// changelogTimeout bounds one read of a repository's releases. +const changelogTimeout = 15 * time.Second + +// changelogState is the releases the window has read, by repository. Only the window thread +// uses it; the read itself runs on the effect's worker. +type changelogState struct { + effect *ui.EffectState[changelogResult, string] + // want is the repository whose releases are being read, empty while none is. + want string + // read are the answers so far, by repository: the releases, or why there are none. + read map[string]*changelogRead + // report logs a read that failed. + report func(error) +} + +// changelogResult is one finished read. It names its repository, so an answer is kept for +// the repository it is about whichever plugin is chosen when it arrives. +type changelogResult struct { + repository string + releases []PluginRelease + supported bool + err error +} + +// changelogRead is a repository's answer and the notes made from it, one per release, made +// the first time the release is shown. +type changelogRead struct { + releases []PluginRelease + supported bool + err error + notes []*releaseNotes +} + +// newChangelogState prepares the reads of a window. With no reader the tab is not shown. +func newChangelogState(list func(context.Context, string) ([]PluginRelease, bool, error), report func(error)) changelogState { + s := changelogState{read: map[string]*changelogRead{}, report: report} + if list == nil { + return s + } + s.effect = ui.NewEffectKeyed[changelogResult, string](func(parent context.Context, repository string) (changelogResult, error) { + ctx, cancel := context.WithTimeout(parent, changelogTimeout) + defer cancel() + releases, supported, err := list(ctx, repository) + return changelogResult{repository: repository, releases: releases, supported: supported, err: err}, nil + }) + return s +} + +// available says the window can read releases, so the detail shows the tab. +func (s *changelogState) available() bool { return s.effect != nil } + +// ask reads repository's releases unless they were read already or are being read. +func (s *changelogState) ask(repository string) { + if s.effect == nil || s.read[repository] != nil { + return + } + s.want = repository +} + +// retry forgets a failed answer and reads the repository again. +func (s *changelogState) retry(repository string) { + delete(s.read, repository) + s.ask(repository) +} + +// declare keeps the read out alive. It is declared from every paint, so leaving the tab or +// the page does not cancel a read that is out; choosing another repository replaces it. +func (s *changelogState) declare(c ui.C) { + if s.effect != nil && s.want != "" { + ui.Effect(c, s.effect, s.want) + } +} + +// take keeps a finished read on the window thread at the start of a paint and logs a failure. +func (s *changelogState) take() { + if s.effect == nil { + return + } + result, _, ok := s.effect.Take() + if !ok { + return + } + if result.repository == s.want { + s.want = "" + } + // log-exempt: 用户取消:关闭设置窗口撤销尚未返回的读取,结果不再显示。 + if errors.Is(result.err, context.Canceled) { + return + } + s.read[result.repository] = &changelogRead{ + releases: result.releases, supported: result.supported, err: result.err, + notes: make([]*releaseNotes, len(result.releases)), + } + if result.err != nil && s.report != nil { + s.report(result.err) + } +} + +// installedChangelog is the Changelog tab: the releases of the plugin's source repository, +// or why there are none to show. +func (w *window) installedChangelog(c ui.C, language i18n.Language, fact PluginFacts) { + s := &w.changelog + entry, listed := w.marketEntry(fact.ID) + if !listed && (w.market.status == marketIdle || w.market.status == marketLoading) { + // The repository comes from the marketplace listing, which is still on the way. + w.changelogWaiting(c, language) + return + } + if !listed && w.market.status == marketFailed { + w.changelogNote(c, i18n.Shared(language, "desktop.pluginChangelog.marketFailed")) + return + } + if !listed || !webURL(entry.Repository) { + w.changelogNote(c, i18n.Shared(language, "desktop.pluginChangelog.noRepository")) + return + } + repository := strings.TrimSuffix(entry.Repository, "/") + read := s.read[repository] + if read == nil { + s.ask(repository) + w.changelogWaiting(c, language) + return + } + switch { + case read.err != nil: + w.changelogNote(c, i18n.Shared(language, "desktop.pluginChangelog.failed")) + ui.Wrap(c, read.err.Error()).FontSize(11).Color(w.pal.muted) + ui.Row(c).Gap(12).Items(ui.Center).Children(func() { + if ui.Button(c, i18n.Shared(language, "desktop.pluginChangelog.retry")).Clicked() { + s.retry(repository) + } + w.changelogOpen(c, i18n.Shared(language, "desktop.pluginChangelog.openReleases"), repository+"/releases") + }) + case !read.supported: + w.changelogNote(c, i18n.Shared(language, "desktop.pluginChangelog.unsupported")) + w.changelogOpen(c, repositoryName(repository), repository) + case len(read.releases) == 0: + w.changelogNote(c, i18n.Shared(language, "desktop.pluginChangelog.empty")) + w.changelogOpen(c, i18n.Shared(language, "desktop.pluginChangelog.openReleases"), repository+"/releases") + default: + ui.Column(c).FillWidth().Gap(14).Children(func() { + for i := range read.releases { + w.changelogRelease(c.KeyInt(i), language, fact, read, i) + } + }) + w.changelogOpen(c, i18n.Shared(language, "desktop.pluginChangelog.openReleases"), repository+"/releases") + } +} + +// changelogWaiting is the tab while what it shows is on the way. +func (w *window) changelogWaiting(c ui.C, language i18n.Language) { + ui.Row(c).Gap(8).Items(ui.Center).Children(func() { + ui.Spinner(c) + ui.Text(c, i18n.Shared(language, "desktop.pluginChangelog.loading")).FontSize(12).Color(w.pal.muted) + }) +} + +// changelogNote is a line that says why the tab lists no releases. +func (w *window) changelogNote(c ui.C, text string) { + ui.Wrap(c, text).FontSize(12).Color(w.pal.muted) +} + +// changelogOpen is a link to a page of the repository on the web; with no browser to open it +// in, the address is shown instead. +func (w *window) changelogOpen(c ui.C, label, address string) { + if w.ctrl.opts.OpenURL == nil { + ui.Wrap(c, address).FontSize(12).Color(w.pal.muted) + return + } + if w.installedLink(c, label).Tooltip(address).Clicked() { + w.ctrl.opts.OpenURL(address) + } +} + +// changelogRelease is one release: its title, whether it is a pre-release or the installed +// version, when it was published, and its notes. +func (w *window) changelogRelease(c ui.C, language i18n.Language, fact PluginFacts, read *changelogRead, i int) { + release := read.releases[i] + title := release.Name + if title == "" { + title = release.Tag + } + ui.Column(c).FillWidth().Pad(14).Gap(10).Radius(8).Background(w.pal.card).Stroke(1, w.pal.line).Children(func() { + ui.Row(c).FillWidth().Gap(8).Items(ui.Center).Children(func() { + ui.Text(c, title).FontSize(14).Weight(gfx.WeightSemibold).Color(w.pal.text).Shrink(1).MinWidth(0).Ellipsis() + if release.Name != "" && release.Name != release.Tag { + ui.Text(c, release.Tag).Mono().FontSize(11).Color(w.pal.muted).Shrink(0) + } + if release.Prerelease { + w.changelogBadge(c, i18n.Shared(language, "desktop.pluginChangelog.prerelease"), w.pal.warning) + } + if releaseIsVersion(release.Tag, fact.Version) { + w.changelogBadge(c, i18n.Shared(language, "native.installed"), w.pal.success) + } + ui.Row(c).Grow(1) + if !release.Published.IsZero() { + ui.Text(c, release.Published.Local().Format(time.DateOnly)).FontSize(12).Color(w.pal.muted).Shrink(0) + } + if webURL(release.URL) && w.ctrl.opts.OpenURL != nil { + if ui.Button(c, i18n.Shared(language, "desktop.pluginChangelog.openRelease")).Link().Height(installedFieldLine).Clicked() { + w.ctrl.opts.OpenURL(release.URL) + } + } + }) + if strings.TrimSpace(release.Notes) == "" { + ui.Text(c, i18n.Shared(language, "desktop.pluginChangelog.noNotes")).FontSize(12).Color(w.pal.muted) + return + } + notes := read.notes[i] + if notes == nil { + notes = newReleaseNotes(release.Notes, w.ctrl.opts.OpenURL) + read.notes[i] = notes + } + notes.declare(c, title) + }) +} + +// changelogBadge is a small colored word beside a release's title. +func (w *window) changelogBadge(c ui.C, label string, color gfx.Color) { + ui.Row(c).Shrink(0).PadX(7).PadY(2).Radius(100).Background(color.WithAlpha(0.12)).Children(func() { + ui.Text(c, label).FontSize(11).Weight(gfx.WeightMedium).Color(color) + }) +} + +// releaseIsVersion says a release's tag names version, with or without the "v" a tag +// usually starts with. +func releaseIsVersion(tag, version string) bool { + return version != "" && strings.TrimPrefix(tag, "v") == strings.TrimPrefix(version, "v") +} + +// releaseNotes is one release's notes as the tab shows them: the Markdown laid out for the +// width the detail gives it. It is the Layout of the container it is declared in, so the +// notes are measured while the page is laid out and take their own height on the same paint; +// a control inside it paints them and takes the presses on their links. +type releaseNotes struct { + doc markdown.Document + view components.MarkdownView + style components.MarkdownStyle + // canvas is the canvas of the paint being declared, which measures the text; laid is the + // width the view was laid out for. + canvas *gfx.Canvas + laid float32 + input ui.Handlers + draw func(*ui.DrawContext) +} + +// newReleaseNotes parses source into notes whose web links open through open. +func newReleaseNotes(source string, open func(string)) *releaseNotes { + n := &releaseNotes{style: components.MarkdownStyle{Size: 12, LineHeight: 19}} + n.doc.Parse(source) + n.input.Pointer = func(event gfx.PointerEvent) gfx.EventResult { + if event.Kind != gfx.PointerDown || event.Button != gfx.PointerButtonPrimary || open == nil { + return gfx.EventResult{} + } + index, ok := event.Target.In(n.input.Parts()) + if !ok { + return gfx.EventResult{} + } + // The notes are whatever the repository published: only web links are followed. + parsed, err := url.Parse(n.view.Link(index)) + if err != nil || (parsed.Scheme != "https" && parsed.Scheme != "http") || parsed.Host == "" { + return gfx.EventResult{} + } + open(parsed.String()) + return gfx.EventResult{Handled: true} + } + n.draw = n.paint + return n +} + +// declare declares the notes: the container that measures them and the control that paints +// them, named label for assistive technology. +func (n *releaseNotes) declare(c ui.C, label string) { + n.canvas = c.Canvas() + ui.CustomLayout(c, n).FillWidth().Children(func() { + k := c.Part("notes") + ui.Control(k, label, &n.input).Draw(n.draw). + HitWith(ui.ID(k), label, gfx.HitOptions{Role: gfx.RoleGroup}) + }) +} + +// MeasureWidth leaves the notes' width to the detail: they fill it. +func (n *releaseNotes) MeasureWidth(*ui.LayoutContext) float32 { return 0 } + +// PlaceWidth gives the painting control the whole width. +func (n *releaseNotes) PlaceWidth(ctx *ui.LayoutContext, bounds ui.Rect) { + for i := range ctx.Count() { + ctx.SetWidth(i, bounds.Width) + } +} + +// MeasureHeight lays the notes out for the width they were given and is their height there. +func (n *releaseNotes) MeasureHeight(ctx *ui.LayoutContext) float32 { + width := ctx.ContentWidth() + if width > 0 && width != n.laid && n.canvas != nil { + n.view.Layout(n.canvas, n.style, &n.doc, width) + n.laid = width + } + return n.view.Height() +} + +// PlaceHeight gives the painting control the notes' height. +func (n *releaseNotes) PlaceHeight(ctx *ui.LayoutContext, bounds ui.Rect) { + for i := range ctx.Count() { + ctx.SetHeight(i, bounds.Height) + } +} + +// paint draws the notes where the layout put the control. +func (n *releaseNotes) paint(dc *ui.DrawContext) { + if n.laid <= 0 { + return + } + n.view.Paint(dc.Canvas, components.MarkdownPaint{ + Look: components.MarkdownLookFor(*dc.Theme), + X: dc.Rect.X, Y: dc.Rect.Y, + Clip: dc.Rect, + Links: n.input.Parts(), + }) +} diff --git a/desktop/internal/settingswindow/installed_changelog_test.go b/desktop/internal/settingswindow/installed_changelog_test.go new file mode 100644 index 0000000000..934190ee3f --- /dev/null +++ b/desktop/internal/settingswindow/installed_changelog_test.go @@ -0,0 +1,260 @@ +package settingswindow + +import ( + "context" + "errors" + "sync" + "testing" + "time" + + "github.com/1lck/Lithe-IDEA/desktop/internal/core" + "github.com/1lck/Lithe-IDEA/desktop/internal/i18n" + "github.com/1lck/Lithe-IDEA/desktop/internal/marketplace" + "github.com/vivaui/viva/app" + "github.com/vivaui/viva/gfx" +) + +// releaseReader is a PluginReleases that answers from answers in turn, the last one again +// once they run out, and remembers the repositories it was asked about. +type releaseReader struct { + mu sync.Mutex + asked []string + answers []releaseAnswer +} + +type releaseAnswer struct { + releases []PluginRelease + supported bool + err error +} + +func (r *releaseReader) list(_ context.Context, repository string) ([]PluginRelease, bool, error) { + r.mu.Lock() + defer r.mu.Unlock() + r.asked = append(r.asked, repository) + answer := r.answers[min(len(r.asked), len(r.answers))-1] + return answer.releases, answer.supported, answer.err +} + +func (r *releaseReader) reads() []string { + r.mu.Lock() + defer r.mu.Unlock() + return append([]string(nil), r.asked...) +} + +// fixtureReleases are a pre-release newer than the installed 1.2.3, the installed release +// with notes that link to a web page and to a file, and an old release without notes. +func fixtureReleases() []PluginRelease { + // Noon UTC is the same date in every time zone the tests run in. + day := func(d int) time.Time { return time.Date(2026, 11, d, 12, 0, 0, 0, time.UTC) } + return []PluginRelease{ + {Tag: "v1.3.0-beta.1", Notes: "Tries the new layout.", Published: day(21), Prerelease: true, + URL: "https://github.com/example/versions-fixture/releases/tag/v1.3.0-beta.1"}, + {Tag: "v1.2.3", Name: "Faster refresh", Published: day(20), + Notes: "Reads the newest index.\n\n- See [the guide](https://example.com/guide).\n- Or [the file](file:///etc/hosts).", + URL: "https://github.com/example/versions-fixture/releases/tag/v1.2.3"}, + {Tag: "v1.0.0", Published: day(1), URL: "https://github.com/example/versions-fixture/releases/tag/v1.0.0"}, + } +} + +// openChangelog opens the detail of detailFixture on its Changelog tab, reading releases +// from reader, once the marketplace listing is in. +func openChangelog(t *testing.T, reader *releaseReader, adjust ...func(*Options)) (*windowDriver, PluginFacts) { + t.Helper() + w, fact, _ := detailFixture(i18n.English, append([]func(*Options){func(opts *Options) { + opts.PluginReleases = reader.list + }}, adjust...)...) + d := openWindow(t, w, func(config *app.Config) { config.Width, config.Height = 1400, 900 }) + d.until("the marketplace index", func() bool { return w.market.status == marketReady }) + d.click(i18n.Shared(i18n.English, "native.updateLog")) + d.pump() + return d, fact +} + +// painted is where value was last painted, and whether it was. +func (d *windowDriver) painted(value string) (gfx.Rect, bool) { + texts := d.driver.Snapshot().Texts + for i := len(texts) - 1; i >= 0; i-- { + if texts[i].Value == value { + return texts[i].Bounds, true + } + } + return gfx.Rect{}, false +} + +// paintedOnLineOf is whether value is painted on the line of a text painted at line. +func (d *windowDriver) paintedOnLineOf(value string, line gfx.Rect) bool { + for _, text := range d.driver.Snapshot().Texts { + middle := text.Bounds.Y + text.Bounds.Height/2 + if text.Value == value && middle >= line.Y && middle <= line.Y+line.Height { + return true + } + } + return false +} + +// TestInstalledChangelogListsTheRepositoryReleases covers the Changelog tab: it reads the +// releases of the repository the listing names, lists them newest first with their notes laid +// out in full above the next release, marks the pre-release and the installed version, follows +// only the notes' web links, and reads nothing again when the tab is shown again. +func TestInstalledChangelogListsTheRepositoryReleases(t *testing.T) { + reader := &releaseReader{answers: []releaseAnswer{{releases: fixtureReleases(), supported: true}}} + var opened []string + d, _ := openChangelog(t, reader, func(opts *Options) { + opts.OpenURL = func(address string) { opened = append(opened, address) } + }) + d.until("the releases", func() bool { _, ok := d.painted("Faster refresh"); return ok }) + if got := reader.reads(); len(got) != 1 || got[0] != "https://github.com/example/versions-fixture" { + t.Fatalf("the releases of %q were read, want the listing's repository once", got) + } + beta, _ := d.painted("v1.3.0-beta.1") + installed, _ := d.painted("Faster refresh") + old, ok := d.painted("v1.0.0") + if !ok || beta.Y >= installed.Y || installed.Y >= old.Y { + t.Fatalf("the releases are not newest first: %+v, %+v, %+v", beta, installed, old) + } + if !d.paintedOnLineOf(i18n.Shared(i18n.English, "desktop.pluginChangelog.prerelease"), beta) { + t.Error("the pre-release has no pre-release badge") + } + if !d.paintedOnLineOf(i18n.Shared(i18n.English, "native.installed"), installed) { + t.Error("the installed release has no installed badge") + } + if !d.paintedOnLineOf("v1.2.3", installed) || !d.paintedOnLineOf("2026-11-20", installed) { + t.Error("the installed release does not show its tag and date beside its title") + } + if d.paintedOnLineOf(i18n.Shared(i18n.English, "desktop.pluginChangelog.prerelease"), installed) { + t.Error("a release that is not a pre-release has the badge") + } + // The notes are laid out on the paint that shows them: their last line is above the + // next release, not clipped to a first guess at their height. + guide, ok := d.painted("the guide") + if !ok { + t.Fatal("the installed release's notes are not painted") + } + if guide.Y <= installed.Y || guide.Y+guide.Height >= old.Y { + t.Fatalf("the notes at %+v are not between their title at %+v and the next release at %+v", guide, installed, old) + } + if !d.text(i18n.Shared(i18n.English, "desktop.pluginChangelog.noNotes")) { + t.Error("the release without notes does not say so") + } + + file, _ := d.painted("the file") + if err := d.driver.Click(file.X+file.Width/2, file.Y+file.Height/2); err != nil { + t.Fatal(err) + } + if err := d.driver.Click(guide.X+guide.Width/2, guide.Y+guide.Height/2); err != nil { + t.Fatal(err) + } + d.pump() + if len(opened) != 1 || opened[0] != "https://example.com/guide" { + t.Fatalf("clicking the notes' links opened %q, want only the web link", opened) + } + + d.click(i18n.Shared(i18n.English, "native.versionsSource")) + d.pump() + d.click(i18n.Shared(i18n.English, "native.updateLog")) + d.pump() + if _, ok := d.painted("Faster refresh"); !ok { + t.Fatal("the releases are not shown again") + } + if got := reader.reads(); len(got) != 1 { + t.Fatalf("showing the tab again read the releases again: %q", got) + } +} + +// TestInstalledChangelogRetriesAFailedRead covers a read that fails: the tab says so with +// the error, the failure is logged, and Retry reads again and shows the releases. +func TestInstalledChangelogRetriesAFailedRead(t *testing.T) { + reader := &releaseReader{answers: []releaseAnswer{ + {err: errors.New("github: request failed: rate limited")}, + {releases: fixtureReleases(), supported: true}, + }} + var logged []string + d, _ := openChangelog(t, reader, func(opts *Options) { + opts.SettingsError = func(operation string, err error) { logged = append(logged, operation+": "+err.Error()) } + }) + failed := i18n.Shared(i18n.English, "desktop.pluginChangelog.failed") + d.until("the failure", func() bool { return d.wrapped(failed) }) + if !d.wrapped("rate limited") { + t.Error("the failure does not show its error") + } + if len(logged) != 1 || logged[0] != "plugin_releases: github: request failed: rate limited" { + t.Fatalf("logged %q, want the failed read once", logged) + } + d.click(i18n.Shared(i18n.English, "desktop.pluginChangelog.retry")) + d.until("the releases", func() bool { _, ok := d.painted("Faster refresh"); return ok }) + if got := reader.reads(); len(got) != 2 { + t.Fatalf("the releases were read %d times, want twice", len(got)) + } +} + +// TestInstalledChangelogSaysWhyThereAreNoReleases covers the notes in place of the list: a +// repository the reader cannot read, a repository without releases, and a listing without a +// repository, which is not read at all. +func TestInstalledChangelogSaysWhyThereAreNoReleases(t *testing.T) { + t.Run("unsupported", func(t *testing.T) { + d, _ := openChangelog(t, &releaseReader{answers: []releaseAnswer{{supported: false}}}) + note := i18n.Shared(i18n.English, "desktop.pluginChangelog.unsupported") + d.until("the note", func() bool { return d.wrapped(note) }) + if !d.has("example/versions-fixture") { + t.Error("the note does not link to the repository") + } + }) + t.Run("empty", func(t *testing.T) { + d, _ := openChangelog(t, &releaseReader{answers: []releaseAnswer{{supported: true}}}) + note := i18n.Shared(i18n.English, "desktop.pluginChangelog.empty") + d.until("the note", func() bool { return d.wrapped(note) }) + if !d.has(i18n.Shared(i18n.English, "desktop.pluginChangelog.openReleases")) { + t.Error("the note does not link to the releases page") + } + }) + t.Run("no repository", func(t *testing.T) { + reader := &releaseReader{answers: []releaseAnswer{{releases: fixtureReleases(), supported: true}}} + d, _ := openChangelog(t, reader, func(opts *Options) { + listing := opts.Marketplace + opts.Marketplace = func(ctx context.Context) (marketplace.Snapshot, error) { + snapshot, err := listing(ctx) + snapshot.Index.Plugins = append([]core.MarketplacePlugin(nil), snapshot.Index.Plugins...) + snapshot.Index.Plugins[0].Repository = "" + return snapshot, err + } + }) + if !d.wrapped(i18n.Shared(i18n.English, "desktop.pluginChangelog.noRepository")) { + t.Fatal("the tab does not say the listing names no repository") + } + if got := reader.reads(); len(got) != 0 { + t.Fatalf("releases were read without a repository: %q", got) + } + }) +} + +// TestInstalledChangelogNeedsAReader covers a window that cannot read releases: the detail +// has no Changelog tab. +func TestInstalledChangelogNeedsAReader(t *testing.T) { + w, _, _ := detailFixture(i18n.English) + d := openWindow(t, w, func(config *app.Config) { config.Width, config.Height = 1400, 800 }) + d.until("the marketplace index", func() bool { return w.market.status == marketReady }) + if !d.has(i18n.Shared(i18n.English, "native.versionsSource")) { + t.Fatal("the detail's tabs are not shown") + } + if d.has(i18n.Shared(i18n.English, "native.updateLog")) { + t.Fatal("the Changelog tab is shown without a way to read releases") + } +} + +// TestInstalledTabsStayWithinANarrowDetail covers the detail's six tabs in English at the +// window's least width: they wrap onto another line rather than run past the detail's edge. +func TestInstalledTabsStayWithinANarrowDetail(t *testing.T) { + reader := &releaseReader{answers: []releaseAnswer{{supported: true}}} + w, _, _ := detailFixture(i18n.English, func(opts *Options) { opts.PluginReleases = reader.list }) + d := openWindow(t, w, func(config *app.Config) { config.Width, config.Height = windowMinWidth, 700 }) + d.until("the marketplace index", func() bool { return w.market.status == marketReady }) + d.pump() + for tab := range installedTabCount { + title := installedTabTitle(i18n.English, tab) + hit := d.hit(title) + if right := hit.Bounds.X + hit.Bounds.Width; right > windowMinWidth { + t.Errorf("the %q tab ends at x=%.1f, past the window's edge at %d", title, right, windowMinWidth) + } + } +} diff --git a/desktop/internal/settingswindow/installed_changelog_visual_test.go b/desktop/internal/settingswindow/installed_changelog_visual_test.go new file mode 100644 index 0000000000..223405e6d2 --- /dev/null +++ b/desktop/internal/settingswindow/installed_changelog_visual_test.go @@ -0,0 +1,74 @@ +//go:build vivahead && lithevisual + +package settingswindow + +import ( + "context" + "os" + "path/filepath" + "testing" + "time" + + "github.com/1lck/Lithe-IDEA/desktop/internal/i18n" + "github.com/vivaui/viva/headless" +) + +// TestVisualInstalledChangelog renders the Changelog tab of one marketplace plugin with a +// pre-release, the installed release and an older one, their notes in headings, lists, code +// and links. Opt in with -tags 'vivahead lithevisual' and LITHE_VISUAL_OUTPUT_DIR. +func TestVisualInstalledChangelog(t *testing.T) { + out := os.Getenv("LITHE_VISUAL_OUTPUT_DIR") + if out == "" { + t.Skip("set LITHE_VISUAL_OUTPUT_DIR to capture the Changelog tab") + } + if err := os.MkdirAll(out, 0755); err != nil { + t.Fatal(err) + } + for _, look := range []struct { + theme string + language i18n.Language + notes [3]string + }{ + {"dark", i18n.Chinese, [3]string{ + "试用新的设置布局,欢迎反馈。", + "### 新功能\n\n- 设置页显示实际生效的命令,例如 `fixture build --release`\n- 新增两个构建选项\n\n### 修复\n\n- 刷新插件索引后立即看到新版本,见 [说明](https://example.com/guide)", + "首个版本。", + }}, + {"light", i18n.English, [3]string{ + "Tries the new settings layout; feedback welcome.", + "### Features\n\n- The settings show the command that runs, such as `fixture build --release`\n- Two new build options\n\n### Fixes\n\n- A refreshed index shows the new version at once, see [the guide](https://example.com/guide)", + "The first release.", + }}, + } { + t.Run(look.theme, func(t *testing.T) { + releases := fixtureReleases() + for i := range releases { + releases[i].Notes = look.notes[i] + } + releases[1].Name = "" + w, _, _ := detailFixture(look.language, func(opts *Options) { + opts.PluginReleases = func(context.Context, string) ([]PluginRelease, bool, error) { + return releases, true, nil + } + }) + w.sess.values.Theme = look.theme + w.installed.tab = installedChangelog + config := w.config() + config.Width, config.Height = 1100, 720 + session, err := headless.Open(config, nil, headless.Options{}) + if err != nil { + t.Fatal(err) + } + t.Cleanup(session.Close) + d := &windowDriver{t: t, w: w, driver: session.Driver()} + d.until("the releases", func() bool { _, ok := d.painted("v1.2.3"); return ok }) + // The spinner of the read that just finished stops on the next frame. + time.Sleep(20 * time.Millisecond) + w.inv.Invalidate() + d.pump() + if err := session.Screenshot(filepath.Join(out, "installed-changelog-"+look.theme+".png")); err != nil { + t.Fatal(err) + } + }) + } +} diff --git a/desktop/internal/settingswindow/installed_view.go b/desktop/internal/settingswindow/installed_view.go index 29fe8157d5..5dee6d4b78 100644 --- a/desktop/internal/settingswindow/installed_view.go +++ b/desktop/internal/settingswindow/installed_view.go @@ -21,9 +21,10 @@ import ( // The Installed tab of the plugin page, laid out as the macOS client's is: a search with // filter chips over the installed plugins, the enabled ones before the disabled ones, beside -// the chosen plugin's header, its notices and five tabs. What it shows comes from the -// owner's InstalledPlugins, which answers from memory; the marketplace index the page reads -// adds the updates, descriptions and repositories. +// the chosen plugin's header, its notices and six tabs. What it shows comes from the owner's +// InstalledPlugins, which answers from memory; the marketplace index the page reads adds the +// updates, descriptions and repositories, and the repository's releases the changelog +// (installed_changelog.go). // installedState is the Installed tab's own state. Only the window thread uses it. type installedState struct { @@ -114,6 +115,7 @@ const ( installedSettings installedPermissions installedVersions + installedChangelog installedTabCount ) @@ -128,6 +130,8 @@ func installedTabTitle(language i18n.Language, tab int) string { return i18n.Shared(language, "native.permissionsPrograms") case installedVersions: return i18n.Shared(language, "native.versionsSource") + case installedChangelog: + return i18n.Shared(language, "native.updateLog") } return i18n.Shared(language, "native.overview") } @@ -518,6 +522,8 @@ func (w *window) installedDetail(c ui.C, language i18n.Language, fact PluginFact w.installedPermissions(c, language, fact) case installedVersions: w.installedVersions(c, language, fact) + case installedChangelog: + w.installedChangelog(c, language, fact) default: w.installedOverview(c, language, fact) } @@ -665,8 +671,13 @@ func (w *window) installedTabs(c ui.C, language i18n.Language, fact PluginFacts) installedSettings: fact.Settings, installedPermissions: len(fact.Permissions) + len(fact.Programs), } - ui.Row(c).FillWidth().Shrink(0).PadX(22).Gap(18).Items(ui.End).Children(func() { + // The tabs wrap onto a second line where the detail is too narrow for all of them, as in + // English at the window's least width, so none is cut off. + ui.Flow(c).FillWidth().Shrink(0).PadX(22).Gap(18).LineGap(8).Items(ui.End).Children(func() { for tab := range installedTabCount { + if tab == installedChangelog && !w.changelog.available() { + continue + } k := c.KeyInt(tab) title := installedTabTitle(language, tab) chosen := s.tab == tab diff --git a/desktop/internal/settingswindow/installed_view_test.go b/desktop/internal/settingswindow/installed_view_test.go index 015b909e27..c6add2b85a 100644 --- a/desktop/internal/settingswindow/installed_view_test.go +++ b/desktop/internal/settingswindow/installed_view_test.go @@ -246,8 +246,8 @@ func TestInstalledTabShowsPermissionsAndVersions(t *testing.T) { // detailFixture is the detail of one marketplace plugin whose listing names its repository, // with every field of the Versions & Source and the Permissions & Programs tabs filled in. -// It opens on the Versions & Source tab. -func detailFixture(language i18n.Language) (*window, PluginFacts, string) { +// It opens on the Versions & Source tab; adjust changes the window's options before it opens. +func detailFixture(language i18n.Language, adjust ...func(*Options)) (*window, PluginFacts, string) { const repository = "https://github.com/example/versions-fixture" fact := PluginFacts{ ID: "dev.lithe.test.versions", Name: "Versions Fixture", Vendor: "Test", Version: "1.2.3", @@ -265,7 +265,7 @@ func detailFixture(language i18n.Language) (*window, PluginFacts, string) { Availability: core.MarketplaceAvailability{Status: "available", Version: fact.Version}, Versions: []core.MarketplaceVersion{{Version: fact.Version}}, }}} - w := newWindow(NewController(Options{ + opts := Options{ Text: func() *i18n.Messages { return i18n.For(language) }, Language: func() i18n.Language { return language }, SystemLanguage: language, Marketplace: func(context.Context) (marketplace.Snapshot, error) { @@ -276,7 +276,11 @@ func detailFixture(language i18n.Language) (*window, PluginFacts, string) { return PluginState{Installed: true, Version: fact.Version, Enabled: true} }, OpenURL: func(string) {}, - }), Values{Language: language.Code()}) + } + for _, fn := range adjust { + fn(&opts) + } + w := newWindow(NewController(opts), Values{Language: language.Code()}) w.sess.page = pagePlugins w.installed.tab = installedVersions return w, fact, repositoryName(repository) diff --git a/desktop/internal/settingswindow/marketplace_model.go b/desktop/internal/settingswindow/marketplace_model.go index 40b243cdf4..b0e54bfbb1 100644 --- a/desktop/internal/settingswindow/marketplace_model.go +++ b/desktop/internal/settingswindow/marketplace_model.go @@ -5,6 +5,7 @@ import ( "errors" "slices" "strings" + "time" "github.com/1lck/Lithe-IDEA/desktop/internal/core" "github.com/1lck/Lithe-IDEA/desktop/internal/marketplace" @@ -20,6 +21,10 @@ const ( marketFailed ) +// marketStaleAfter is how old the shown plugins may be when the page is entered again or the +// window raised before the page reads them again in the background. +const marketStaleAfter = time.Minute + // marketResult is one finished fetch of an index. type marketResult struct { snapshot marketplace.Snapshot @@ -67,6 +72,12 @@ type marketplaceState struct { active bool status marketStatus snapshot marketplace.Snapshot + // fetched is when the shown plugins were read. quiet says the fetch out is a refresh of + // them: status stays marketReady, they stay shown, and a failure keeps them. now is the + // clock, time.Now outside tests. + fetched time.Time + quiet bool + now func() time.Time selected string // index is rebuilt only when a new catalog arrives, not on every drag frame. index map[string]int @@ -79,7 +90,7 @@ type marketplaceState struct { } func newMarketplaceState(fetch func(context.Context) (marketplace.Snapshot, error)) *marketplaceState { - m := &marketplaceState{fetch: fetch} + m := &marketplaceState{fetch: fetch, now: time.Now} m.buildEffects() m.list.Key, m.list.Label = m.listKey, m.listLabel m.search.bind() @@ -274,7 +285,17 @@ func (m *marketplaceState) start() { return } m.request++ - m.status, m.active = marketLoading, true + m.status, m.active, m.quiet = marketLoading, true, false +} + +// refreshIfStale reads the shown source again in the background when its plugins were read +// more than marketStaleAfter ago. They stay shown while it runs and when it fails. +func (m *marketplaceState) refreshIfStale() { + if m.status != marketReady || m.active || m.fetchOf(m.source) == nil || m.now().Sub(m.fetched) < marketStaleAfter { + return + } + m.request++ + m.active, m.quiet = true, true } func (m *marketplaceState) chooseSource(source int) { @@ -288,25 +309,34 @@ func (m *marketplaceState) chooseSource(source int) { // close stops wanting the fetch, which cancels it, and forgets what the search found. func (m *marketplaceState) close() { - m.active = false + m.active, m.quiet = false, false m.status = marketIdle m.search.invalidate() } -// take applies the finished fetch on the window thread at the start of a paint. -func (m *marketplaceState) take() { +// take applies the finished fetch on the window thread at the start of a paint. ended says a +// fetch finished; kept is the failure of a background refresh, which leaves the plugins it +// refreshed shown. +func (m *marketplaceState) take() (ended bool, kept error) { effect := m.effects[m.source] result, err, ok := effect.Take() if !ok || !m.active { - return + return false, nil } - m.active = false + quiet := m.quiet + m.active, m.quiet = false, false if errors.Is(err, context.Canceled) { - m.status = marketIdle - return + if !quiet { + m.status = marketIdle + } + return false, nil + } + if quiet && err != nil { + return true, err } m.failures = result.failures m.apply(result.snapshot, err) + return true, nil } // declare keeps the wanted fetch alive in the paint. @@ -322,7 +352,7 @@ func (m *marketplaceState) apply(snapshot marketplace.Snapshot, err error) { m.status = marketFailed return } - m.snapshot = snapshot + m.snapshot, m.fetched = snapshot, m.now() m.status = marketReady m.search.setCatalog(snapshot.Index.Plugins) m.index = make(map[string]int, len(snapshot.Index.Plugins)) diff --git a/desktop/internal/settingswindow/marketplace_model_test.go b/desktop/internal/settingswindow/marketplace_model_test.go index e69a0a981d..73d21f7135 100644 --- a/desktop/internal/settingswindow/marketplace_model_test.go +++ b/desktop/internal/settingswindow/marketplace_model_test.go @@ -3,6 +3,7 @@ package settingswindow import ( "context" "errors" + "fmt" "sync" "sync/atomic" "testing" @@ -253,3 +254,60 @@ func TestInstalledMarketplaceSourceWorksWithoutRemoteFetch(t *testing.T) { t.Fatalf("installed source=%d status=%d selected=%q error=%v", w.market.source, w.market.status, w.market.selected, w.market.err) } } + +func TestMarketplaceRefreshesStalePluginsInTheBackground(t *testing.T) { + var calls, reported atomic.Int32 + var fail atomic.Bool + w := newWindow(NewController(Options{ + Marketplace: func(context.Context) (marketplace.Snapshot, error) { + n := calls.Add(1) + if n > 1 && fail.Load() { + return marketplace.Snapshot{}, errors.New("store unreachable") + } + return indexOf(fmt.Sprintf("v%d", n)), nil + }, + MarketplaceError: func(error) { reported.Add(1) }, + }), Values{}) + var clock atomic.Int64 + clock.Store(time.Date(2026, 11, 22, 10, 0, 0, 0, time.UTC).UnixNano()) + w.market.now = func() time.Time { return time.Unix(0, clock.Load()) } + later := func() { clock.Add(int64(marketStaleAfter)) } + w.sess.page = pagePlugins + w.pluginTab = pluginTabMarketplace + d := openWindow(t, w) + d.until("the first index", func() bool { return w.market.status == marketReady }) + shown := func() string { return w.market.snapshot.Index.Plugins[0].ID } + reenter := func() { + w.sess.page = pageGeneral + w.inv.Invalidate() + d.pump() + w.sess.page = pagePlugins + w.inv.Invalidate() + d.pump() + } + + // Plugins read less than marketStaleAfter ago are not read again. + reenter() + if calls.Load() != 1 || w.market.active { + t.Fatalf("fresh plugins were read again: %d fetches", calls.Load()) + } + + // Stale ones are, while the page keeps showing them. + later() + reenter() + if !w.market.active || w.market.status != marketReady || shown() != "v1" { + t.Fatalf("refresh: active=%v status=%v shown=%s", w.market.active, w.market.status, shown()) + } + d.until("the refreshed index", func() bool { return shown() == "v2" }) + + // Raising the window asks too; a refresh that fails keeps the plugins and is reported. + later() + fail.Store(true) + w.raised.Store(true) + w.inv.Invalidate() + d.pump() + d.until("the failed refresh", func() bool { return !w.market.active }) + if calls.Load() != 3 || w.market.status != marketReady || shown() != "v2" || reported.Load() != 1 { + t.Fatalf("failed refresh: %d fetches, status=%v shown=%s reported=%d", calls.Load(), w.market.status, shown(), reported.Load()) + } +} diff --git a/desktop/internal/settingswindow/marketplace_view.go b/desktop/internal/settingswindow/marketplace_view.go index 90e2781355..de4f6fd5d6 100644 --- a/desktop/internal/settingswindow/marketplace_view.go +++ b/desktop/internal/settingswindow/marketplace_view.go @@ -71,9 +71,15 @@ func (w *window) marketSourceLabel(source int) string { // updates, descriptions and repositories in it. func (w *window) marketplacePage(c ui.C) { m := w.market + w.marketShown = true if m.status == marketIdle { m.start() + } else if w.marketRecheck { + // Entering the page again or raising the window shows what the store has now, without + // hiding the plugins already shown while it is read. + m.refreshIfStale() } + w.marketRecheck = false language := w.marketLanguage() ui.Column(c).FillWidth().Grow(1).Shrink(1).MinHeight(0).Children(func() { w.pluginHeader(c, language) diff --git a/desktop/internal/settingswindow/window.go b/desktop/internal/settingswindow/window.go index d945362153..ebbd1f9e77 100644 --- a/desktop/internal/settingswindow/window.go +++ b/desktop/internal/settingswindow/window.go @@ -112,6 +112,8 @@ type window struct { // filter and detail (installed_view.go). pluginTab int installed installedState + // changelog is the releases the Installed tab's changelog has read (installed_changelog.go). + changelog changelogState // pluginMenuOpen says the plugin page's gear menu is open, and repositoriesOpen the // window that manages the plugin repositories. pluginMenuOpen bool @@ -130,6 +132,13 @@ type window struct { // window's own thread. requestedPage atomic.Uint32 pluginRegistryChanged atomic.Bool + // raised says Controller.open raised the window since its last paint; marketRecheck that + // the plugin page, the next time it is painted, reads its plugins again when they are + // stale, which entering the page or raising the window asks for. marketShown is whether + // the last paint showed the plugin page. + raised atomic.Bool + marketRecheck bool + marketShown bool // toolchains is the Build settings page's draft and loaded snapshot. toolchains *toolchainState stepping *steppingState @@ -304,6 +313,7 @@ func newWindow(c *Controller, current Values) *window { w.stepping = newSteppingState(c.opts.SteppingAdapters, c.opts.NormalizeSteppingFilters) w.terminal = newTerminalShellState(c.opts.TerminalShells) w.fonts = newFontListState(c.opts.MonospaceFamilies) + w.changelog = newChangelogState(c.opts.PluginReleases, func(err error) { reportSettingsError(c.opts, "plugin_releases", err) }) w.generation = newAIGeneration(c.opts, func() { w.inv.Invalidate() }) w.nav.Node, w.nav.Key, w.nav.RowHeight, w.nav.Indent = w.navNode, w.navKey, rowHeight, levelIndent return w @@ -400,6 +410,9 @@ func (w *window) wake() { w.searchField.SetText("") w.selectSettingsPage(pageID(requested-1), "") } + if w.raised.Swap(false) { + w.marketRecheck = true + } } // watchSystem makes the window repaint when the system switches between its light and dark @@ -529,15 +542,15 @@ func (w *window) collect() { w.advanceApply(toolchainFailed, steppingResult{done: done, err: err}) w.terminal.take() w.fonts.take() + w.changelog.take() w.takeKeymapImport() w.takeSearchPreferences() w.commands.take() if w.dynamic.take() { w.rowsValid = false } - previous := w.market.status - w.market.take() - w.reportMarket(previous) + ended, kept := w.market.take() + w.reportMarket(ended, kept) w.market.search.take(w.market, w.marketQuery) w.pluginSettings.take() for _, form := range w.pluginForms { @@ -548,12 +561,15 @@ func (w *window) collect() { } // reportMarket tells the owner how the fetch that just ended went: that it failed, or how -// many entries of the index were rejected. -func (w *window) reportMarket(previous marketStatus) { - if previous != marketLoading { +// many entries of the index were rejected. kept is the failure of a background refresh, which +// leaves the plugins it refreshed shown; the owner logs it like any other failure. +func (w *window) reportMarket(ended bool, kept error) { + if !ended { return } switch { + case kept != nil && w.ctrl.opts.MarketplaceError != nil: + w.ctrl.opts.MarketplaceError(kept) case w.market.status == marketFailed && w.ctrl.opts.MarketplaceError != nil: w.ctrl.opts.MarketplaceError(w.market.err) case w.market.status == marketReady && len(w.market.snapshot.Index.Rejected) > 0 && w.ctrl.opts.MarketplaceRejected != nil: @@ -573,6 +589,7 @@ func (w *window) declareWork(c ui.C) { w.stepping.declare(c) w.terminal.declare(c) w.fonts.declare(c) + w.changelog.declare(c) if s := &w.keyImport; s.open && s.effect != nil && s.request != nil { ui.Effect(c, s.effect, s.request) } diff --git a/desktop/internal/settingswindow/window_view.go b/desktop/internal/settingswindow/window_view.go index b11fdb177e..2986b0dfcc 100644 --- a/desktop/internal/settingswindow/window_view.go +++ b/desktop/internal/settingswindow/window_view.go @@ -348,9 +348,13 @@ func (w *window) toolchainProblems() int { // content is the page beside the sidebar: the breadcrumb above the page itself. func (w *window) content(c ui.C) { if w.sess.page != pagePlugins && w.market.status == marketLoading { - // Leaving the page stops wanting the fetch, which cancels it. + // Leaving the page stops wanting the fetch, which cancels it. A background refresh + // goes on: its result replaces plugins the page already shows. w.market.close() } + if w.sess.page != pagePlugins && w.marketShown { + w.marketShown, w.marketRecheck = false, true + } if w.sess.page != pageAbout { w.about = aboutState{} } diff --git a/desktop/internal/workbench/app.go b/desktop/internal/workbench/app.go index 42c9151b22..e6f9483ee6 100644 --- a/desktop/internal/workbench/app.go +++ b/desktop/internal/workbench/app.go @@ -297,6 +297,7 @@ type Kernel interface { QueryReferences(ctx context.Context, request core.ReferencesQuery) (core.ReferencesResult, error) ReferenceLines(ctx context.Context, request core.ReferenceLinesRequest) ([]core.ReferenceLine, error) ResolveMarketplaceSource(context.Context, string) (core.MarketplaceSource, error) + PinMarketplaceSource(ctx context.Context, url, commit string) (core.MarketplaceSource, error) ValidateMarketplaceIndex(context.Context, json.RawMessage, core.MarketplaceSourceKind, string, map[string][]int) (core.MarketplaceIndex, error) RecommendMarketplacePlugins(ctx context.Context, platform string, workspaceFiles []string, catalogs []core.MarketplaceRecommendationCatalog, hostCapabilities map[string][]int, installedPluginIDs []string, dismissedPluginIDs []string) (core.MarketplaceRecommendationResult, error) } diff --git a/desktop/internal/workbench/marketplace_service.go b/desktop/internal/workbench/marketplace_service.go new file mode 100644 index 0000000000..f9852d0253 --- /dev/null +++ b/desktop/internal/workbench/marketplace_service.go @@ -0,0 +1,76 @@ +package workbench + +import ( + "context" + "errors" + "time" + + "github.com/1lck/Lithe-IDEA/desktop/internal/core" + "github.com/1lck/Lithe-IDEA/desktop/internal/githubapi" + "github.com/1lck/Lithe-IDEA/desktop/internal/marketplace" + "github.com/1lck/Lithe-IDEA/desktop/internal/settingswindow" +) + +// pinnedMarketplace is the marketplace service of the reads a user waits on: the plugin page +// and the automatic updates. It reads a GitHub-hosted index at the newest commit, which a +// one-request anonymous lookup finds, so a release that has just reached the store shows at +// once rather than after raw.githubusercontent.com's branch cache expires. A failed lookup or +// pinned read is logged and the canonical index read instead. +func (a *App) pinnedMarketplace() *marketplace.Service { + service := marketplace.New(a.kernel, nil) + client := a.githubAPI() + if client == nil { + return service + } + return service.PinToLatestCommit(func(ctx context.Context, repository core.GitHubRepo, ref string) (string, error) { + // latestCommit needs no account: Core plans it without the token, so none is passed. + raw, err := client.Do(ctx, core.GitHubRequest{Operation: "latestCommit", Repository: &repository, Ref: ref}, "") + if err != nil { + return "", err + } + return githubapi.DecodeLatestCommit(raw) + }, func(ctx context.Context, err error) { + a.backgroundFailedIn(ctx, "plugin_marketplace_pin", err) + }) +} + +// pluginReleases lists the releases of a plugin's source repository for the Installed tab's +// changelog, newest first. A repository GitHub does not host is not an error: supported is +// false and the tab links to the repository instead. The request is anonymous, like the index +// pin, so it works signed out. +func (a *App) pluginReleases(ctx context.Context, repository string) ([]settingswindow.PluginRelease, bool, error) { + kernel, ok := a.kernel.(interface { + GitHubParseRemote(ctx context.Context, remoteURL string) (core.GitHubRepo, error) + }) + client := a.githubAPI() + if !ok || client == nil { + return nil, false, nil + } + repo, err := kernel.GitHubParseRemote(ctx, repository) + var refused *core.Error + // log-exempt: 预期的缺失:Core 认不出的地址不是 GitHub 仓库,没有可读的 Releases,页面改为给出仓库链接。 + if errors.As(err, &refused) && refused.Code == core.CodeInvalidRequest { + return nil, false, nil + } + if err != nil { + return nil, true, err + } + raw, err := client.Do(ctx, core.GitHubRequest{Operation: "listReleases", Repository: &repo}, "") + if err != nil { + return nil, true, err + } + items, err := githubapi.DecodeReleases(raw) + if err != nil { + return nil, true, err + } + releases := make([]settingswindow.PluginRelease, len(items)) + for i, item := range items { + // An unreadable time leaves the date out; the release is still listed. + published, _ := time.Parse(time.RFC3339, item.PublishedAt) + releases[i] = settingswindow.PluginRelease{ + Tag: item.TagName, Name: item.Name, Notes: item.Body, + Published: published, Prerelease: item.Prerelease, URL: item.URL, + } + } + return releases, true, nil +} diff --git a/desktop/internal/workbench/plugin_auto_update.go b/desktop/internal/workbench/plugin_auto_update.go index 57dbe03345..0098bd6cf4 100644 --- a/desktop/internal/workbench/plugin_auto_update.go +++ b/desktop/internal/workbench/plugin_auto_update.go @@ -236,7 +236,7 @@ func (a *App) performPluginAutoUpdates(ctx context.Context, sources []PluginReco // log-exempt: 用户尚未通过插件市场确认安装源,不自动向网络查询。 return 0, nil } - service := marketplace.New(a.kernel, nil) + service := a.pinnedMarketplace() downloader := marketplace.NewArchiveDownloader(nil) attempted := make(map[string]bool) triedOrigins := make(map[string]bool) diff --git a/desktop/internal/workbench/settings.go b/desktop/internal/workbench/settings.go index 2b8f828f7e..244ca53d7b 100644 --- a/desktop/internal/workbench/settings.go +++ b/desktop/internal/workbench/settings.go @@ -24,7 +24,7 @@ import ( // own thread (the language and the look of the frame last painted) and two ways back into // the workbench, both of which only queue the work for the workbench's window thread. func (a *App) newSettingsWindow() *settingswindow.Controller { - service := marketplace.New(a.kernel, nil) + service := a.pinnedMarketplace() var navigation func(context.Context, []core.SettingsNavigationItem, string) ([]core.SettingsNavigationRow, error) if kernel, ok := a.kernel.(interface { SettingsNavigation(context.Context, []core.SettingsNavigationItem, string) ([]core.SettingsNavigationRow, error) @@ -148,6 +148,7 @@ func (a *App) newSettingsWindow() *settingswindow.Controller { UninstallPlugin: func(id string) { a.post(func(a *App) { a.uninstallPlugin(id) }) }, + PluginReleases: a.pluginReleases, CommandInstalls: settingsCommandInstalls{app: a}, Language: func() i18n.Language { if a.shared.text.Load() == i18n.For(i18n.Chinese) { diff --git a/docs/assets/plugin-installed-details/after-changelog-en-light.png b/docs/assets/plugin-installed-details/after-changelog-en-light.png new file mode 100644 index 0000000000..242e8d5463 Binary files /dev/null and b/docs/assets/plugin-installed-details/after-changelog-en-light.png differ diff --git a/docs/assets/plugin-installed-details/after-changelog-zh-Hans-dark.png b/docs/assets/plugin-installed-details/after-changelog-zh-Hans-dark.png new file mode 100644 index 0000000000..63b2b00213 Binary files /dev/null and b/docs/assets/plugin-installed-details/after-changelog-zh-Hans-dark.png differ diff --git a/scripts/desktop/build-desktop-core.sh b/scripts/desktop/build-desktop-core.sh index de53d92d24..1171457f28 100755 --- a/scripts/desktop/build-desktop-core.sh +++ b/scripts/desktop/build-desktop-core.sh @@ -346,7 +346,11 @@ PINNED_CORE_REPOSITORY="https://github.com/Lithe-IDEA/Lithe-core-rust.git" # its message (#2231); #170 (1f05cfe) only fixes the Windows clippy CI step and a test; #171 moves # the Go plugin SDK to Go 1.27.4 like the desktop. The Rust sources are the same as #169's branch # commit edad041 that the desktop pinned before. -PINNED_CORE_REVISION="3cb3c5b9bc0f1b17b0fcd863a1318cd550ccf20a" +# Lithe-core-rust main at 4430719: #172 a host's capabilities report its WSL interop state; +# #173 plugins.marketplace.resolveSource reports the repository and branch an index follows and +# pins its address to a commit past raw.githubusercontent.com's branch cache, and the GitHub +# requests gain latestCommit and listReleases for that pin and the installed plugins' changelog. +PINNED_CORE_REVISION="44307192d7a45cbd586c0dffc29ff1bbeb3fd7d5" PROFILE="debug" CHECKOUT_ONLY="no" while [[ $# -gt 0 ]]; do diff --git a/shared/i18n/features/plugin-changelog.json b/shared/i18n/features/plugin-changelog.json new file mode 100644 index 0000000000..0b97afcf5f --- /dev/null +++ b/shared/i18n/features/plugin-changelog.json @@ -0,0 +1,110 @@ +{ + "schemaVersion": 1, + "messages": [ + { + "id": "desktop.pluginChangelog.loading", + "description": "Installed plugin details, Changelog tab: shown while the releases of the plugin's source repository are being read", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.pluginChangelog.noRepository", + "description": "Installed plugin details, Changelog tab: the plugin's marketplace listing names no web repository, so there are no releases to read", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.pluginChangelog.marketFailed", + "description": "Installed plugin details, Changelog tab: the marketplace could not be read, so the plugin's repository, which the listing names, is not known", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.pluginChangelog.failed", + "description": "Installed plugin details, Changelog tab: reading the releases from GitHub failed; the error text follows on the next line", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.pluginChangelog.retry", + "description": "Installed plugin details, Changelog tab: button that reads the releases again after a failure", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.pluginChangelog.openReleases", + "description": "Installed plugin details, Changelog tab: link that opens the repository's releases page in the browser", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.pluginChangelog.openRelease", + "description": "Installed plugin details, Changelog tab: link beside one release that opens that release's page in the browser", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.pluginChangelog.unsupported", + "description": "Installed plugin details, Changelog tab: the plugin's repository is not on GitHub, so its releases cannot be listed here; a link to the repository follows", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.pluginChangelog.empty", + "description": "Installed plugin details, Changelog tab: the repository has published no releases", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.pluginChangelog.prerelease", + "description": "Installed plugin details, Changelog tab: badge beside a release marked as a pre-release", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.pluginChangelog.noNotes", + "description": "Installed plugin details, Changelog tab: a release was published without any notes", + "platforms": [ + "desktop" + ] + } + ], + "locales": { + "en-US": { + "desktop.pluginChangelog.loading": "Reading the releases…", + "desktop.pluginChangelog.noRepository": "The marketplace lists no repository for this plugin, so there is no changelog to show.", + "desktop.pluginChangelog.marketFailed": "Couldn't read the marketplace, so this plugin's repository isn't known yet.", + "desktop.pluginChangelog.failed": "Couldn't read the releases from GitHub.", + "desktop.pluginChangelog.retry": "Retry", + "desktop.pluginChangelog.openReleases": "View all releases in the browser", + "desktop.pluginChangelog.openRelease": "Open in browser", + "desktop.pluginChangelog.unsupported": "The changelog can only be read from GitHub repositories. Open the repository to see this plugin's changes.", + "desktop.pluginChangelog.empty": "This repository hasn't published any releases yet.", + "desktop.pluginChangelog.prerelease": "Pre-release", + "desktop.pluginChangelog.noNotes": "This release has no notes." + }, + "zh-CN": { + "desktop.pluginChangelog.loading": "正在读取 Releases…", + "desktop.pluginChangelog.noRepository": "插件市场里没有这个插件的仓库地址,没有更新日志可以显示。", + "desktop.pluginChangelog.marketFailed": "没能读取插件市场,还不知道这个插件的仓库。", + "desktop.pluginChangelog.failed": "没能从 GitHub 读取 Releases。", + "desktop.pluginChangelog.retry": "重试", + "desktop.pluginChangelog.openReleases": "在浏览器中查看全部 Releases", + "desktop.pluginChangelog.openRelease": "在浏览器中打开", + "desktop.pluginChangelog.unsupported": "更新日志只能从 GitHub 仓库读取。打开仓库查看这个插件的改动。", + "desktop.pluginChangelog.empty": "这个仓库还没有发布任何 Release。", + "desktop.pluginChangelog.prerelease": "预发布", + "desktop.pluginChangelog.noNotes": "这个 Release 没有填写说明。" + } + } +} diff --git a/shared/i18n/messages.json b/shared/i18n/messages.json index ff59f14371..2e8d1fcdf7 100644 --- a/shared/i18n/messages.json +++ b/shared/i18n/messages.json @@ -93126,7 +93126,8 @@ "id": "native.updateLog", "description": "Native UI: Update log", "platforms": [ - "macos" + "macos", + "desktop" ], "macos": { "key": "Update log", diff --git a/shared/platform-feature-matrix/features/plugin-detail-tabs.json b/shared/platform-feature-matrix/features/plugin-detail-tabs.json index 012b424b4d..2c9131e422 100644 --- a/shared/platform-feature-matrix/features/plugin-detail-tabs.json +++ b/shared/platform-feature-matrix/features/plugin-detail-tabs.json @@ -2,7 +2,7 @@ "id": "plugin-detail-tabs", "area": "插件", "group": "插件管理", - "capability": "已安装插件详情分为概览、功能、设置、权限与程序、版本与来源五个页签,信任与迁移提示固定在头部;权限与程序页签每个权限占一行,程序默认折叠成一行摘要,可展开按编辑器 JSON 配色高亮的完整声明并复制;已安装列表可按能力、更新、来源和启用状态过滤,搜索框输入 / 列出过滤选项;窗口缩放及调整列表宽度时详情保持在分隔线右侧,过窄的设置表单可横向滚动查看完整控件和状态", + "capability": "已安装插件详情分为概览、功能、设置、权限与程序、版本与来源、更新日志六个页签,详情过窄时页签换到第二行,信任与迁移提示固定在头部;更新日志页签读取插件在市场登记的 GitHub 仓库的 Releases,最新在前,标出预发布和当前安装的版本,正文按 Markdown 显示;权限与程序页签每个权限占一行,程序默认折叠成一行摘要,可展开按编辑器 JSON 配色高亮的完整声明并复制;已安装列表可按能力、更新、来源和启用状态过滤,搜索框输入 / 列出过滤选项;窗口缩放及调整列表宽度时详情保持在分隔线右侧,过窄的设置表单可横向滚动查看完整控件和状态", "macos": { "implementationStatus": "partial", "verificationStatus": "pending", @@ -11,7 +11,10 @@ "desktop/internal/settingswindow/marketplace_view.go", "desktop/internal/settingswindow/plugin_settings_view.go", "desktop/internal/settingswindow/installed_view.go", - "desktop/internal/settingswindow/installed_view_test.go" + "desktop/internal/settingswindow/installed_view_test.go", + "desktop/internal/settingswindow/installed_changelog.go", + "desktop/internal/settingswindow/installed_changelog_test.go", + "desktop/internal/workbench/marketplace_service.go" ] }, "windows": { @@ -22,11 +25,14 @@ "desktop/internal/settingswindow/marketplace_view.go", "desktop/internal/settingswindow/plugin_settings_view.go", "desktop/internal/settingswindow/installed_view.go", - "desktop/internal/settingswindow/installed_view_test.go" + "desktop/internal/settingswindow/installed_view_test.go", + "desktop/internal/settingswindow/installed_changelog.go", + "desktop/internal/settingswindow/installed_changelog_test.go", + "desktop/internal/workbench/marketplace_service.go" ] }, "owner": "Plugin Platform", - "verification": "macOS:打开设置 › 插件 › 已安装,选中一个同时声明语言、语言服务器和运行/调试能力的插件(测试内联的合成插件即可)。头部显示名称、官方徽标、版本和状态胶囊,右侧有启用/禁用、卸载按钮。依次切换五个页签:概览显示状态、提供的能力、来源和设置数量,“在设置中配置”可跳到 LSP 和运行配置页;功能页签列出插件声明的语言、语言服务器(及其使用的运行时)以及由 Lithe 提供的运行、测试、调试;设置页签显示最大内存和日志级别,修改后出现“重启语言服务器”,“恢复默认值”可一键还原;权限与程序页签每个权限占一行,说明后面跟等宽淡色的 API 名(如 languageServer.launch),说明换行时盾牌留在第一行;每个程序默认折叠成一行(类型加声明里的顶层字段),点击展开缩进后的完整 JSON(属性名、字符串、数字和标点按编辑器的 Lithe 配色着色,可选中文本按 ⌘C 复制)、再点收起,右侧按钮复制该程序的 JSON;“可以运行的程序”旁的 ⓘ 说明修改设置不需要重新审查;内容与安装确认弹窗一致。版本与来源显示当前版本、插件 ID 和签名,标签和值各自左对齐、每行高度一致,“源码仓库”链接和其他值对齐,“内容 SHA-256”标签后面的 ⓘ 说明每次加载都会重新校验。安装一个社区插件,确认社区提示固定在页签上方,任何页签都能看到。在左侧点“语言服务”“社区 / 磁盘”“已禁用”等过滤芯片,确认列表随之变化并按“已启用 / 已禁用”分组;在搜索框输入 /,确认出现过滤选项,选中后搜索框清空并切换过滤。更新过的插件在版本与来源页签显示上一版本和“回滚…”,确认后需要重启 Lithe。布局:在浅色和深色下缩放设置窗口、往返拖动插件列表分隔条,切换不同插件与各页签,确认标题、页签和正文不越过分隔线;窄设置表单可横向滚动至末尾,输入控件保持同一实例,扩大后恢复填满正文。运行 PluginDetailLayoutTests 检查这些边界。Windows:扩展管理尚未拆分页签。", + "verification": "macOS:打开设置 › 插件 › 已安装,选中一个同时声明语言、语言服务器和运行/调试能力的插件(测试内联的合成插件即可)。头部显示名称、官方徽标、版本和状态胶囊,右侧有启用/禁用、卸载按钮。依次切换六个页签:概览显示状态、提供的能力、来源和设置数量,“在设置中配置”可跳到 LSP 和运行配置页;功能页签列出插件声明的语言、语言服务器(及其使用的运行时)以及由 Lithe 提供的运行、测试、调试;设置页签显示最大内存和日志级别,修改后出现“重启语言服务器”,“恢复默认值”可一键还原;权限与程序页签每个权限占一行,说明后面跟等宽淡色的 API 名(如 languageServer.launch),说明换行时盾牌留在第一行;每个程序默认折叠成一行(类型加声明里的顶层字段),点击展开缩进后的完整 JSON(属性名、字符串、数字和标点按编辑器的 Lithe 配色着色,可选中文本按 ⌘C 复制)、再点收起,右侧按钮复制该程序的 JSON;“可以运行的程序”旁的 ⓘ 说明修改设置不需要重新审查;内容与安装确认弹窗一致。版本与来源显示当前版本、插件 ID 和签名,标签和值各自左对齐、每行高度一致,“源码仓库”链接和其他值对齐,“内容 SHA-256”标签后面的 ⓘ 说明每次加载都会重新校验。更新日志页签:选中一个市场登记了 GitHub 仓库的插件,先看到“正在读取 Releases…”,随后按发布时间从新到旧列出该仓库的 Releases,标题旁显示标签、预发布或“已安装”徽标、发布日期和“在浏览器中打开”,正文的标题、列表、行内代码和链接按 Markdown 显示,点击网页链接用默认浏览器打开、非网页链接不响应,最后一行可在浏览器中查看全部 Releases;切到别的页签再切回不再重新读取;断网时显示读取失败和错误,点“重试”恢复后列出;仓库不在 GitHub 时说明只能读取 GitHub 并给出仓库链接,市场没有登记仓库时说明没有更新日志。英文界面把设置窗口缩到最窄,确认六个页签换行后都完整可见。安装一个社区插件,确认社区提示固定在页签上方,任何页签都能看到。在左侧点“语言服务”“社区 / 磁盘”“已禁用”等过滤芯片,确认列表随之变化并按“已启用 / 已禁用”分组;在搜索框输入 /,确认出现过滤选项,选中后搜索框清空并切换过滤。更新过的插件在版本与来源页签显示上一版本和“回滚…”,确认后需要重启 Lithe。布局:在浅色和深色下缩放设置窗口、往返拖动插件列表分隔条,切换不同插件与各页签,确认标题、页签和正文不越过分隔线;窄设置表单可横向滚动至末尾,输入控件保持同一实例,扩大后恢复填满正文。运行 PluginDetailLayoutTests 检查这些边界。Windows:扩展管理尚未拆分页签。", "legacy": { "revision": "5a54c41aa37a4e6e6b68918a4b05765b9dd07a36", "macos": { @@ -50,5 +56,5 @@ "verificationStatus": "not-applicable" } }, - "notes": "Viva:插件页分为“已安装”和“市场”两个标签,已安装为默认页(installed_view.go)。已安装详情有概览、功能、设置、权限与程序、版本与来源五个页签,社区、磁盘等提示固定在页签上方;头部提供停用/启用、更新到新版本和卸载(先确认)。列表可按语言服务器、构建、调试、界面、可更新、社区、已停用过滤,按“已启用 / 已停用”分组并显示启用数量,搜索框输入 / 列出过滤选项。权限与程序页签每个权限一行,程序折叠成一行摘要、展开看完整 JSON 并可复制,JSON 用编辑器内置的 JSON 语法和 Lithe 配色高亮;TestInstalledVersionsLinesUpItsValues 和 TestInstalledPermissionsKeepsEachEntryToOneLine 在无头窗口里检查版本与来源的对齐、SHA ⓘ 的位置,以及权限、程序的单行布局、展开收起、JSON 高亮和复制。尚缺:版本与来源不能回滚上一版本,安装记录没有保存索引地址,来源只显示笼统的“市场”;窄设置表单横向滚动和整机验收待做。" + "notes": "Viva:插件页分为“已安装”和“市场”两个标签,已安装为默认页(installed_view.go)。已安装详情有概览、功能、设置、权限与程序、版本与来源、更新日志六个页签(详情过窄时换行),社区、磁盘等提示固定在页签上方;头部提供停用/启用、更新到新版本和卸载(先确认)。列表可按语言服务器、构建、调试、界面、可更新、社区、已停用过滤,按“已启用 / 已停用”分组并显示启用数量,搜索框输入 / 列出过滤选项。权限与程序页签每个权限一行,程序折叠成一行摘要、展开看完整 JSON 并可复制,JSON 用编辑器内置的 JSON 语法和 Lithe 配色高亮;TestInstalledVersionsLinesUpItsValues 和 TestInstalledPermissionsKeepsEachEntryToOneLine 在无头窗口里检查版本与来源的对齐、SHA ⓘ 的位置,以及权限、程序的单行布局、展开收起、JSON 高亮和复制。更新日志页签(installed_changelog.go)在打开时通过 Core 的 GitHub listReleases 匿名读取市场登记仓库的前 20 个 Releases,同一设置窗口内按仓库缓存,读取失败记 plugin_releases 并可重试;Release 正文用 Viva 的 MarkdownView 在布局时按实际宽度排版,只打开 http/https 链接;TestInstalledChangelog* 覆盖列表顺序、徽标、正文高度、链接过滤、缓存、失败重试和各种无列表说明,TestInstalledTabsStayWithinANarrowDetail 检查最窄窗口下页签不越界。尚缺:版本与来源不能回滚上一版本,安装记录没有保存索引地址,来源只显示笼统的“市场”;窄设置表单横向滚动和整机验收待做。" } diff --git a/shared/platform-feature-matrix/features/plugin-marketplace.json b/shared/platform-feature-matrix/features/plugin-marketplace.json index e6251b2062..7de7e2e545 100644 --- a/shared/platform-feature-matrix/features/plugin-marketplace.json +++ b/shared/platform-feature-matrix/features/plugin-marketplace.json @@ -35,7 +35,8 @@ "desktop/internal/settingswindow/plugin_install_test.go", "desktop/internal/marketplace/archive_session.go", "desktop/internal/marketplace/archive_session_test.go", - "desktop/internal/settingswindow/plugin_install.go" + "desktop/internal/settingswindow/plugin_install.go", + "desktop/internal/workbench/marketplace_service.go" ] }, "windows": { @@ -65,12 +66,13 @@ "desktop/internal/settingswindow/plugin_install_test.go", "desktop/internal/marketplace/archive_session.go", "desktop/internal/marketplace/archive_session_test.go", - "desktop/internal/settingswindow/plugin_install.go" + "desktop/internal/settingswindow/plugin_install.go", + "desktop/internal/workbench/marketplace_service.go" ] }, "owner": "Extensions", - "notes": "Viva 可分别读取 Lithe Store 社区索引和当前主仓库的官方索引,通过 Core 校验并支持名称或 ID 搜索;旧官方地址指向临时仓库(#1781),当前主仓库官方索引为空。保留官方索引文件以维持客户端已使用的公开地址,不能将社区索引改标为官方来源。离线“已安装”入口读取本机目录并使用 Core 的数字版本选择;禁用插件也可查看和编辑声明偏好。生产启动入口已连接同一个 Core client,通用设置入口会后台读取安装状态并刷新离线目录。离线官方索引、描述及标签搜索、完整可信安装的原生验收仍待完成,Windows 整机验收待做。下载适配器可流式限额并校验索引摘要、清理临时文件,下载不限总时长,一分钟没有收到数据才结束并提示“操作超时”,包的检查与解压仍限 5 分钟;同一设置窗口里下载断开或取消后再下载同一个包,用 HTTP Range 从断开处接着下,服务器不支持时从头下,接上的内容与索引摘要不符时丢弃并报校验失败,会话最多保留一份文件,并已接入设置窗口的安装流程,摘要校验确认包与索引一致。安装器现在同时接受契约的 `/plugin.json` 目录布局和旧的无外层目录布局:内容根由唯一清单确定,内容根目录必须等于插件 ID,内容根外的条目、第二个清单或更深层的清单会拒绝安装,不会 flatten 后继续;磁盘来源没有发布者签名时仍必须经过用户审批,布局支持不改变信任判断。 插件仓库在齿轮菜单的“管理插件仓库…”弹窗中管理:列出社区、官方和自定义索引的实际地址,可添加、刷新和移除自定义索引;市场标签可选单个来源或全部来源聚合,某个来源读取失败时其余来源照常显示。 市场确认只开始下载。包校验后,首次安装或历史批准不覆盖当前包时,在原设置窗口展示完整权限和程序并等待安装确认。历史批准仍适用的市场包可直接安装。本地包始终需要审查确认。;沿用设置窗口下载会话:连接有明确提示、权限附可读说明、技术详情默认折叠;失败展示本地化恢复建议并可重试,成功明确提示完成。原生终态与异常网络验收仍 pending。", - "verification": "macOS 无头界面覆盖来源选择、下载中切换、搜索、取消、迟到结果隔离及并发上限;市场服务以 Core 校验固定的社区和官方索引,搜索使用共享匹配样例。已对照原版窗口截图;完整布局、聚合搜索、可信安装与宿主接入后仍需在 macOS 和 Windows 验收并核对发行包只读。 下载适配器以离线传输测试摘要不匹配、超限、取消、危险重定向及清理,download_resume_test.go 覆盖断开后续传、服务器忽略/错位/拒绝 Range 时从头下、换包只保留一份、一分钟没有数据结束、下载不受总时长限制、保留的内容不对时丢弃且不留文件;workbench 的 TestMarketplaceDownloadIsNotBoundedByThePreparationTime 覆盖市场下载不受检查与解压的 5 分钟限制,设置窗口回归覆盖市场安装。安装器回归同时覆盖契约目录布局与 flat 布局、内容根目录与清单 ID 不一致、两个清单、内容根外文件和深层清单会被拒绝且不留 staging、符号链接与大小写冲突;修复前同一测试以“plugin package has no plugin.json at its root”失败。 macOS 隔离原生窗口已验证从通用设置进入插件页、读取离线已安装条目、七种设置控件的明确保存/冲突/重新加载;此证据不代表市场下载或 settings v2 整体验收。。核对已知大小的包显示已下载量、总量和实际进度,未知大小只显示已下载量,完成后切换到解压校验。首次安装和批准不匹配的市场包在提交前展示完整权限、程序并等待确认,本地包同样需要确认。只有匹配历史批准的市场包可直接进入安装。取消、Escape 或关闭窗口后,没有安装包或新增批准记录。在同一设置窗口重试完整包应复用归档,关闭设置且借用结束后释放临时文件。", + "notes": "Viva 可分别读取 Lithe Store 社区索引和当前主仓库的官方索引,通过 Core 校验并支持名称或 ID 搜索;旧官方地址指向临时仓库(#1781),当前主仓库官方索引为空。保留官方索引文件以维持客户端已使用的公开地址,不能将社区索引改标为官方来源。离线“已安装”入口读取本机目录并使用 Core 的数字版本选择;禁用插件也可查看和编辑声明偏好。生产启动入口已连接同一个 Core client,通用设置入口会后台读取安装状态并刷新离线目录。离线官方索引、描述及标签搜索、完整可信安装的原生验收仍待完成,Windows 整机验收待做。下载适配器可流式限额并校验索引摘要、清理临时文件,下载不限总时长,一分钟没有收到数据才结束并提示“操作超时”,包的检查与解压仍限 5 分钟;同一设置窗口里下载断开或取消后再下载同一个包,用 HTTP Range 从断开处接着下,服务器不支持时从头下,接上的内容与索引摘要不符时丢弃并报校验失败,会话最多保留一份文件,并已接入设置窗口的安装流程,摘要校验确认包与索引一致。安装器现在同时接受契约的 `/plugin.json` 目录布局和旧的无外层目录布局:内容根由唯一清单确定,内容根目录必须等于插件 ID,内容根外的条目、第二个清单或更深层的清单会拒绝安装,不会 flatten 后继续;磁盘来源没有发布者签名时仍必须经过用户审批,布局支持不改变信任判断。 插件仓库在齿轮菜单的“管理插件仓库…”弹窗中管理:列出社区、官方和自定义索引的实际地址,可添加、刷新和移除自定义索引;市场标签可选单个来源或全部来源聚合,某个来源读取失败时其余来源照常显示。 市场确认只开始下载。包校验后,首次安装或历史批准不覆盖当前包时,在原设置窗口展示完整权限和程序并等待安装确认。历史批准仍适用的市场包可直接安装。本地包始终需要审查确认。;沿用设置窗口下载会话:连接有明确提示、权限附可读说明、技术详情默认折叠;失败展示本地化恢复建议并可重试,成功明确提示完成。原生终态与异常网络验收仍 pending。 插件页和自动更新读取托管在 GitHub 的索引时,先用 Core 的 latestCommit 匿名查到索引分支的最新提交,再读该提交下的固定地址,绕过 raw.githubusercontent.com 对分支地址约 5 分钟的缓存;查询失败或固定地址读取失败时记 plugin_marketplace_pin 并改读原地址。设置窗口在插件页重新进入或窗口回到前台时,若数据已超过一分钟会在后台静默刷新,刷新期间列表照常显示、失败保留原数据。", + "verification": "macOS 无头界面覆盖来源选择、下载中切换、搜索、取消、迟到结果隔离及并发上限;市场服务以 Core 校验固定的社区和官方索引,搜索使用共享匹配样例。已对照原版窗口截图;完整布局、聚合搜索、可信安装与宿主接入后仍需在 macOS 和 Windows 验收并核对发行包只读。 下载适配器以离线传输测试摘要不匹配、超限、取消、危险重定向及清理,download_resume_test.go 覆盖断开后续传、服务器忽略/错位/拒绝 Range 时从头下、换包只保留一份、一分钟没有数据结束、下载不受总时长限制、保留的内容不对时丢弃且不留文件;workbench 的 TestMarketplaceDownloadIsNotBoundedByThePreparationTime 覆盖市场下载不受检查与解压的 5 分钟限制,设置窗口回归覆盖市场安装。安装器回归同时覆盖契约目录布局与 flat 布局、内容根目录与清单 ID 不一致、两个清单、内容根外文件和深层清单会被拒绝且不留 staging、符号链接与大小写冲突;修复前同一测试以“plugin package has no plugin.json at its root”失败。 macOS 隔离原生窗口已验证从通用设置进入插件页、读取离线已安装条目、七种设置控件的明确保存/冲突/重新加载;此证据不代表市场下载或 settings v2 整体验收。。核对已知大小的包显示已下载量、总量和实际进度,未知大小只显示已下载量,完成后切换到解压校验。首次安装和批准不匹配的市场包在提交前展示完整权限、程序并等待确认,本地包同样需要确认。只有匹配历史批准的市场包可直接进入安装。取消、Escape 或关闭窗口后,没有安装包或新增批准记录。在同一设置窗口重试完整包应复用归档,关闭设置且借用结束后释放临时文件。 索引新鲜度:Store 合入新版本后,在已打开的设置窗口切到别的页面再回到插件页(或把窗口切到后台再切回),一分钟后应在几秒内看到新版本,不需要等 raw 缓存过期;断网或 GitHub API 不可用时仍读原地址并在日志里看到 plugin_marketplace_pin。marketplace/service_test.go 和 core/marketplace_test.go 覆盖固定提交读取与回退,marketplace_model_test.go 覆盖静默刷新。", "legacy": { "revision": "5a54c41aa37a4e6e6b68918a4b05765b9dd07a36", "macos": {