From b6c325198de18ec1cfd2a06e2ac5e0ce6f79645b Mon Sep 17 00:00:00 2001 From: landaiqing Date: Sat, 3 Jan 2026 23:19:43 +0800 Subject: [PATCH] :art: Removed support for Gitea and optimized update timeouts --- .../voidraft/internal/models/models.ts | 96 +------------ .../voidraft/internal/services/models.ts | 2 +- frontend/src/common/constant/config.ts | 10 +- internal/models/config.go | 39 +----- internal/services/self_update_service.go | 130 ++++-------------- 5 files changed, 33 insertions(+), 244 deletions(-) diff --git a/frontend/bindings/voidraft/internal/models/models.ts b/frontend/bindings/voidraft/internal/models/models.ts index 2d76900..38354e3 100644 --- a/frontend/bindings/voidraft/internal/models/models.ts +++ b/frontend/bindings/voidraft/internal/models/models.ts @@ -564,49 +564,6 @@ export class GitBackupConfig { } } -/** - * GiteaConfig Gitea配置 - */ -export class GiteaConfig { - /** - * Gitea服务器URL - */ - "baseURL": string; - - /** - * 仓库所有者 - */ - "owner": string; - - /** - * 仓库名称 - */ - "repo": string; - - /** Creates a new GiteaConfig instance. */ - constructor($$source: Partial = {}) { - if (!("baseURL" in $$source)) { - this["baseURL"] = ""; - } - if (!("owner" in $$source)) { - this["owner"] = ""; - } - if (!("repo" in $$source)) { - this["repo"] = ""; - } - - Object.assign(this, $$source); - } - - /** - * Creates a new GiteaConfig instance from a string or object. - */ - static createFrom($$source: any = {}): GiteaConfig { - let $$parsedSource = typeof $$source === 'string' ? JSON.parse($$source) : $$source; - return new GiteaConfig($$parsedSource as Partial); - } -} - /** * GithubConfig GitHub配置 */ @@ -1272,26 +1229,6 @@ export enum TabType { TabTypeTab = "tab", }; -/** - * UpdateSourceType 更新源类型 - */ -export enum UpdateSourceType { - /** - * The Go zero value for the underlying type of the enum. - */ - $zero = "", - - /** - * UpdateSourceGithub GitHub更新源 - */ - UpdateSourceGithub = "github", - - /** - * UpdateSourceGitea Gitea更新源 - */ - UpdateSourceGitea = "gitea", -}; - /** * UpdatesConfig 更新设置配置 */ @@ -1306,16 +1243,6 @@ export class UpdatesConfig { */ "autoUpdate": boolean; - /** - * 主要更新源 - */ - "primarySource": UpdateSourceType; - - /** - * 备用更新源 - */ - "backupSource": UpdateSourceType; - /** * 更新前是否备份 */ @@ -1331,11 +1258,6 @@ export class UpdatesConfig { */ "github": GithubConfig; - /** - * Gitea配置 - */ - "gitea": GiteaConfig; - /** Creates a new UpdatesConfig instance. */ constructor($$source: Partial = {}) { if (!("version" in $$source)) { @@ -1344,12 +1266,6 @@ export class UpdatesConfig { if (!("autoUpdate" in $$source)) { this["autoUpdate"] = false; } - if (!("primarySource" in $$source)) { - this["primarySource"] = ("" as UpdateSourceType); - } - if (!("backupSource" in $$source)) { - this["backupSource"] = ("" as UpdateSourceType); - } if (!("backupBeforeUpdate" in $$source)) { this["backupBeforeUpdate"] = false; } @@ -1359,9 +1275,6 @@ export class UpdatesConfig { if (!("github" in $$source)) { this["github"] = (new GithubConfig()); } - if (!("gitea" in $$source)) { - this["gitea"] = (new GiteaConfig()); - } Object.assign(this, $$source); } @@ -1370,14 +1283,10 @@ export class UpdatesConfig { * Creates a new UpdatesConfig instance from a string or object. */ static createFrom($$source: any = {}): UpdatesConfig { - const $$createField6_0 = $$createType9; - const $$createField7_0 = $$createType10; + const $$createField4_0 = $$createType9; let $$parsedSource = typeof $$source === 'string' ? JSON.parse($$source) : $$source; if ("github" in $$parsedSource) { - $$parsedSource["github"] = $$createField6_0($$parsedSource["github"]); - } - if ("gitea" in $$parsedSource) { - $$parsedSource["gitea"] = $$createField7_0($$parsedSource["gitea"]); + $$parsedSource["github"] = $$createField4_0($$parsedSource["github"]); } return new UpdatesConfig($$parsedSource as Partial); } @@ -1399,4 +1308,3 @@ var $$createType6 = (function $$initCreateType6(...args): any { const $$createType7 = $Create.Map($Create.Any, $Create.Any); const $$createType8 = HotkeyCombo.createFrom; const $$createType9 = GithubConfig.createFrom; -const $$createType10 = GiteaConfig.createFrom; diff --git a/frontend/bindings/voidraft/internal/services/models.ts b/frontend/bindings/voidraft/internal/services/models.ts index f99485d..85a31f0 100644 --- a/frontend/bindings/voidraft/internal/services/models.ts +++ b/frontend/bindings/voidraft/internal/services/models.ts @@ -285,7 +285,7 @@ export class SelfUpdateResult { "error": string; /** - * 更新源(github/gitea) + * 更新源(github) */ "source": string; diff --git a/frontend/src/common/constant/config.ts b/frontend/src/common/constant/config.ts index 67ef212..c3ad2ba 100644 --- a/frontend/src/common/constant/config.ts +++ b/frontend/src/common/constant/config.ts @@ -5,7 +5,6 @@ import { LanguageType, SystemThemeType, TabType, - UpdateSourceType } from '@/../bindings/voidraft/internal/models/models'; import {FONT_OPTIONS} from './fonts'; @@ -110,19 +109,12 @@ export const DEFAULT_CONFIG: AppConfig = { updates: { version: "1.0.0", autoUpdate: true, - primarySource: UpdateSourceType.UpdateSourceGithub, - backupSource: UpdateSourceType.UpdateSourceGitea, backupBeforeUpdate: true, - updateTimeout: 30, + updateTimeout: 120, github: { owner: "landaiqing", repo: "voidraft", }, - gitea: { - baseURL: "https://git.landaiqing.cn", - owner: "landaiqing", - repo: "voidraft", - } }, backup: { enabled: false, diff --git a/internal/models/config.go b/internal/models/config.go index 1f5a2f9..1729458 100644 --- a/internal/models/config.go +++ b/internal/models/config.go @@ -39,29 +39,12 @@ const ( SystemThemeAuto SystemThemeType = "auto" ) -// UpdateSourceType 更新源类型 -type UpdateSourceType string - -const ( - // UpdateSourceGithub GitHub更新源 - UpdateSourceGithub UpdateSourceType = "github" - // UpdateSourceGitea Gitea更新源 - UpdateSourceGitea UpdateSourceType = "gitea" -) - // GithubConfig GitHub配置 type GithubConfig struct { Owner string `json:"owner"` // 仓库所有者 Repo string `json:"repo"` // 仓库名称 } -// GiteaConfig Gitea配置 -type GiteaConfig struct { - BaseURL string `json:"baseURL"` // Gitea服务器URL - Owner string `json:"owner"` // 仓库所有者 - Repo string `json:"repo"` // 仓库名称 -} - // GeneralConfig 通用设置配置 type GeneralConfig struct { AlwaysOnTop bool `json:"alwaysOnTop"` // 窗口是否置顶 @@ -120,14 +103,11 @@ type AppearanceConfig struct { // UpdatesConfig 更新设置配置 type UpdatesConfig struct { - Version string `json:"version"` // 当前版本号 - AutoUpdate bool `json:"autoUpdate"` // 是否自动更新 - PrimarySource UpdateSourceType `json:"primarySource"` // 主要更新源 - BackupSource UpdateSourceType `json:"backupSource"` // 备用更新源 - BackupBeforeUpdate bool `json:"backupBeforeUpdate"` // 更新前是否备份 - UpdateTimeout int `json:"updateTimeout"` // 更新超时时间(秒) - Github GithubConfig `json:"github"` // GitHub配置 - Gitea GiteaConfig `json:"gitea"` // Gitea配置 + Version string `json:"version"` // 当前版本号 + AutoUpdate bool `json:"autoUpdate"` // 是否自动更新 + BackupBeforeUpdate bool `json:"backupBeforeUpdate"` // 更新前是否备份 + UpdateTimeout int `json:"updateTimeout"` // 更新超时时间(秒) + Github GithubConfig `json:"github"` // GitHub配置 } // Git备份相关类型定义 @@ -221,19 +201,12 @@ func NewDefaultAppConfig() *AppConfig { Updates: UpdatesConfig{ Version: version.Version, AutoUpdate: true, - PrimarySource: UpdateSourceGitea, - BackupSource: UpdateSourceGithub, BackupBeforeUpdate: true, - UpdateTimeout: 30, + UpdateTimeout: 120, Github: GithubConfig{ Owner: "landaiqing", Repo: "voidraft", }, - Gitea: GiteaConfig{ - BaseURL: "https://git.landaiqing.cn", - Owner: "landaiqing", - Repo: "voidraft", - }, }, Backup: GitBackupConfig{ Enabled: false, diff --git a/internal/services/self_update_service.go b/internal/services/self_update_service.go index d0bbf1a..a503c0a 100644 --- a/internal/services/self_update_service.go +++ b/internal/services/self_update_service.go @@ -25,7 +25,7 @@ type SelfUpdateResult struct { AssetURL string `json:"assetURL"` // 下载链接 ReleaseNotes string `json:"releaseNotes"` // 发布说明 Error string `json:"error"` // 错误信息 - Source string `json:"source"` // 更新源(github/gitea) + Source string `json:"source"` // 更新源(github) } // SelfUpdateService 自我更新服务 @@ -66,33 +66,6 @@ func (s *SelfUpdateService) CheckForUpdates(ctx context.Context) (*SelfUpdateRes return nil, err } - result := &SelfUpdateResult{ - CurrentVersion: config.Updates.Version, - HasUpdate: false, - UpdateApplied: false, - } - - // 尝试主要更新源 - primaryResult, err := s.checkSourceForUpdates(ctx, config.Updates.PrimarySource, config) - if err == nil && primaryResult != nil { - s.handleUpdateBadge(primaryResult) - return primaryResult, nil - } - - // 尝试备用更新源 - backupResult, backupErr := s.checkSourceForUpdates(ctx, config.Updates.BackupSource, config) - if backupErr != nil { - result.Error = fmt.Sprintf("both sources failed: %v; %v", err, backupErr) - s.handleUpdateBadge(result) - return result, errors.New(result.Error) - } - - s.handleUpdateBadge(backupResult) - return backupResult, nil -} - -// checkSourceForUpdates 根据更新源类型检查更新 -func (s *SelfUpdateService) checkSourceForUpdates(ctx context.Context, sourceType models.UpdateSourceType, config *models.AppConfig) (*SelfUpdateResult, error) { timeout := config.Updates.UpdateTimeout if timeout <= 0 { timeout = 30 @@ -104,28 +77,21 @@ func (s *SelfUpdateService) checkSourceForUpdates(ctx context.Context, sourceTyp CurrentVersion: config.Updates.Version, HasUpdate: false, UpdateApplied: false, - Source: string(sourceType), - } - - var release *selfupdate.Release - var found bool - var err error - - switch sourceType { - case models.UpdateSourceGithub: - release, found, err = s.checkGithubUpdates(timeoutCtx, config) - case models.UpdateSourceGitea: - release, found, err = s.checkGiteaUpdates(timeoutCtx, config) - default: - return nil, fmt.Errorf("unsupported source: %s", sourceType) + Source: "github", } + // 检查 GitHub 更新 + release, found, err := s.checkGithubUpdates(timeoutCtx, config) if err != nil { - return result, fmt.Errorf("check failed: %w", err) + result.Error = fmt.Sprintf("check github updates failed: %v", err) + s.handleUpdateBadge(result) + return result, err } if !found { - return result, fmt.Errorf("no release for %s/%s", runtime.GOOS, runtime.GOARCH) + result.Error = fmt.Sprintf("no release for %s/%s", runtime.GOOS, runtime.GOARCH) + s.handleUpdateBadge(result) + return result, errors.New(result.Error) } result.LatestVersion = release.Version() @@ -133,6 +99,7 @@ func (s *SelfUpdateService) checkSourceForUpdates(ctx context.Context, sourceTyp result.ReleaseNotes = release.ReleaseNotes result.HasUpdate = release.GreaterThan(config.Updates.Version) + s.handleUpdateBadge(result) return result, nil } @@ -141,18 +108,6 @@ func (s *SelfUpdateService) createGithubUpdater() (*selfupdate.Updater, error) { return selfupdate.NewUpdater(selfupdate.Config{}) } -// createGiteaUpdater 创建Gitea更新器 -func (s *SelfUpdateService) createGiteaUpdater(config *models.AppConfig) (*selfupdate.Updater, error) { - source, err := selfupdate.NewGiteaSource(selfupdate.GiteaConfig{ - BaseURL: config.Updates.Gitea.BaseURL, - }) - if err != nil { - return nil, fmt.Errorf("create gitea source failed: %w", err) - } - - return selfupdate.NewUpdater(selfupdate.Config{Source: source}) -} - // checkGithubUpdates 检查GitHub更新 func (s *SelfUpdateService) checkGithubUpdates(ctx context.Context, config *models.AppConfig) (*selfupdate.Release, bool, error) { updater, err := s.createGithubUpdater() @@ -164,17 +119,6 @@ func (s *SelfUpdateService) checkGithubUpdates(ctx context.Context, config *mode return updater.DetectLatest(ctx, repo) } -// checkGiteaUpdates 检查Gitea更新 -func (s *SelfUpdateService) checkGiteaUpdates(ctx context.Context, config *models.AppConfig) (*selfupdate.Release, bool, error) { - updater, err := s.createGiteaUpdater(config) - if err != nil { - return nil, false, err - } - - repo := selfupdate.NewRepositorySlug(config.Updates.Gitea.Owner, config.Updates.Gitea.Repo) - return updater.DetectLatest(ctx, repo) -} - // ApplyUpdate 应用更新 func (s *SelfUpdateService) ApplyUpdate(ctx context.Context) (*SelfUpdateResult, error) { s.mu.Lock() @@ -201,23 +145,17 @@ func (s *SelfUpdateService) ApplyUpdate(ctx context.Context) (*SelfUpdateResult, return nil, fmt.Errorf("locate executable failed: %w", err) } - // 尝试主要源 - result, err := s.performUpdate(ctx, config.Updates.PrimarySource, exe, config) - if err == nil { - return result, nil - } - - // 尝试备用源 - result, err = s.performUpdate(ctx, config.Updates.BackupSource, exe, config) + // 执行 GitHub 更新 + result, err := s.performUpdate(ctx, exe, config) if err != nil { - return nil, fmt.Errorf("update failed from both sources: %w", err) + return nil, fmt.Errorf("update failed: %w", err) } return result, nil } // performUpdate 执行更新操作(包括检测、备份、下载、应用) -func (s *SelfUpdateService) performUpdate(ctx context.Context, sourceType models.UpdateSourceType, exe string, config *models.AppConfig) (*SelfUpdateResult, error) { +func (s *SelfUpdateService) performUpdate(ctx context.Context, exe string, config *models.AppConfig) (*SelfUpdateResult, error) { timeout := config.Updates.UpdateTimeout if timeout <= 0 { timeout = 30 @@ -225,8 +163,13 @@ func (s *SelfUpdateService) performUpdate(ctx context.Context, sourceType models checkCtx, cancel := context.WithTimeout(ctx, time.Duration(timeout)*time.Second) defer cancel() - // 获取更新器和版本信息 - updater, release, found, err := s.getUpdateFromSource(checkCtx, sourceType, config) + // 获取 GitHub 更新信息 + updater, err := s.createGithubUpdater() + if err != nil { + return nil, fmt.Errorf("create github updater failed: %w", err) + } + + release, found, err := s.checkGithubUpdates(checkCtx, config) if err != nil || !found { return nil, fmt.Errorf("detect release failed: %w", err) } @@ -236,7 +179,7 @@ func (s *SelfUpdateService) performUpdate(ctx context.Context, sourceType models LatestVersion: release.Version(), AssetURL: release.AssetURL, ReleaseNotes: release.ReleaseNotes, - Source: string(sourceType), + Source: "github", HasUpdate: release.GreaterThan(config.Updates.Version), } @@ -269,33 +212,6 @@ func (s *SelfUpdateService) performUpdate(ctx context.Context, sourceType models return result, nil } -// getUpdateFromSource 从指定源获取更新信息 -func (s *SelfUpdateService) getUpdateFromSource(ctx context.Context, sourceType models.UpdateSourceType, config *models.AppConfig) (*selfupdate.Updater, *selfupdate.Release, bool, error) { - var updater *selfupdate.Updater - var release *selfupdate.Release - var found bool - var err error - - switch sourceType { - case models.UpdateSourceGithub: - updater, err = s.createGithubUpdater() - if err != nil { - return nil, nil, false, err - } - release, found, err = s.checkGithubUpdates(ctx, config) - case models.UpdateSourceGitea: - updater, err = s.createGiteaUpdater(config) - if err != nil { - return nil, nil, false, err - } - release, found, err = s.checkGiteaUpdates(ctx, config) - default: - return nil, nil, false, fmt.Errorf("unsupported source: %s", sourceType) - } - - return updater, release, found, err -} - // handleUpdateSuccess 处理更新成功后的操作 func (s *SelfUpdateService) handleUpdateSuccess(result *SelfUpdateResult) { // 更新配置版本