diff --git a/docs/windows-updates.md b/docs/windows-updates.md index 841a7dd..81c79b8 100644 --- a/docs/windows-updates.md +++ b/docs/windows-updates.md @@ -1,6 +1,6 @@ # Windows 更新与 Gitea 发布 -Cutdex 使用 deskup 0.2.0 的 Gitea 更新源,下载、校验、安装和重启由 +Cutdex 使用 deskup 0.3.0 的 Gitea 更新源,下载、校验、安装和重启由 Velopack 1.2.161 完成。正式版构建固定使用公开仓库 `https://git.orangraph.com/lingjhf/cutdex`,包身份为 `Cutdex`,更新频道为 `win-x64`。正式版不读取开发更新源环境变量,也不包含 Gitea 访问令牌。 @@ -51,11 +51,23 @@ Gitea SDK 查询最近 10 个 Release,跳过标为预发布的 Release,并 ## 开发与验证 -development 包身份为 `Cutdex.Dev`,默认不配置更新源,避免连接正式频道。 -设置 `CUTDEX_WINDOWS_UPDATE_URL` 可显式启用独立开发 Gitea 仓库。 -本地 HTTP 目录测试还需设置 `CUTDEX_WINDOWS_UPDATE_SOURCE=web` 和 -`CUTDEX_UPDATE_TEST_HTTP=1`,HTTP 仅允许带端口的 localhost/127.0.0.1。 -生产构建忽略这些开发配置。 +development 包身份为 `Cutdex.Dev`,默认不配置更新源。 +更新策略通过 Dart 的 `WindowsUpdateConfiguration` 传入,不再使用 CMake +更新源变量。正式版固定选用正式 Gitea 仓库,保留 `Cutdex` 注册表偏好命名空间; +安装时显式传入静默和自动重启选项。 + +开发更新源通过编译期 Dart defines 配置,修改后需重新构建。例如本地测试: + +```powershell +flutter build windows --release --flavor development ` + --dart-define=CUTDEX_WINDOWS_UPDATE_SOURCE=web ` + --dart-define=CUTDEX_WINDOWS_UPDATE_URL=http://127.0.0.1:8765 ` + --dart-define=CUTDEX_UPDATE_TEST_HTTP=true +``` + +Gitea 开发仓库使用 `CUTDEX_WINDOWS_UPDATE_SOURCE=gitea` 和仓库 URL。 +仅设置进程环境变量不会配置 Dart 更新源。正式版忽略开发 defines。 +原生 SDK 离线缓存仍通过 `DESKUP_VELOPACK_ARCHIVE` 环境变量指定。 ```powershell python -m unittest discover -s tool/gitea -p 'test_*.py' diff --git a/lib/integrations/app_update_bridge.dart b/lib/integrations/app_update_bridge.dart index c0eeb04..24aa1bb 100644 --- a/lib/integrations/app_update_bridge.dart +++ b/lib/integrations/app_update_bridge.dart @@ -1,6 +1,7 @@ import 'dart:async'; import '../diagnostics/app_diagnostics.dart'; +import 'app_update_configuration.dart'; import 'package:deskup/deskup.dart'; import 'package:flutter/foundation.dart'; @@ -26,7 +27,11 @@ AppUpdateBridge appUpdateBridge(Ref ref) { // Application adapter: Riverpod ownership and the macOS workspace quit gate. class AppUpdateBridge { AppUpdateBridge([MethodChannel channel = appUpdatesChannel]) - : _updater = Deskup(channel: channel); + : _updater = Deskup( + channel: channel, + windows: windowsUpdateConfiguration(), + macos: macosUpdateConfiguration(), + ); final Deskup _updater; Stream get events => _updater.events; @@ -65,7 +70,7 @@ class AppUpdateBridge { Future check() => _updater.check(); Future download() => _updater.download(); Future validateInstall() => _updater.validateInstall(); - Future install() => _updater.install(); + Future install() => _updater.install(silent: true, restart: true); Future setAutomaticChecks(bool enabled) => _updater.setAutomaticChecks(enabled); diff --git a/lib/integrations/app_update_configuration.dart b/lib/integrations/app_update_configuration.dart new file mode 100644 index 0000000..e7301af --- /dev/null +++ b/lib/integrations/app_update_configuration.dart @@ -0,0 +1,48 @@ +import 'package:deskup/deskup.dart'; +import 'package:flutter/services.dart'; + +// Values are compiled from Dart defines; process environment does not redirect production. +MacOSUpdateConfiguration macosUpdateConfiguration() => + const MacOSUpdateConfiguration( + allowLocalHttp: + appFlavor == 'development' && + bool.fromEnvironment('CUTDEX_UPDATE_TEST_HTTP'), + ); + +WindowsUpdateConfiguration? windowsUpdateConfiguration({ + String? flavor, + String developmentUrl = const String.fromEnvironment( + 'CUTDEX_WINDOWS_UPDATE_URL', + ), + String developmentSource = const String.fromEnvironment( + 'CUTDEX_WINDOWS_UPDATE_SOURCE', + defaultValue: 'gitea', + ), + bool allowLocalHttp = const bool.fromEnvironment('CUTDEX_UPDATE_TEST_HTTP'), +}) { + final development = (flavor ?? appFlavor) == 'development'; + if (development && developmentUrl.isEmpty) return null; + final WindowsUpdateSource source; + if (!development) { + source = GiteaUpdateSource( + repositoryUrl: Uri.parse('https://git.orangraph.com/lingjhf/cutdex'), + ); + } else if (developmentSource == 'gitea') { + source = GiteaUpdateSource( + repositoryUrl: Uri.parse(developmentUrl), + allowLocalHttp: allowLocalHttp, + ); + } else if (developmentSource == 'web') { + source = WebUpdateSource( + url: Uri.parse(developmentUrl), + allowLocalHttp: allowLocalHttp, + ); + } else { + throw ArgumentError.value(developmentSource, 'developmentSource'); + } + return WindowsUpdateConfiguration( + source: source, + expectedPackageId: development ? 'Cutdex.Dev' : 'Cutdex', + preferenceNamespace: 'Cutdex', + ); +} diff --git a/pubspec.lock b/pubspec.lock index 251c87f..f37b818 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -302,11 +302,12 @@ packages: deskup: dependency: "direct main" description: - name: deskup - sha256: "722cd3c4aa51ebe886cd0fe0a842b7312a4235a4b2e097015aab51c10c010c4e" - url: "https://pub.dev" - source: hosted - version: "0.2.0" + path: "." + ref: ccbeb02ed1bbf6b4388981a0e641aff7404637bd + resolved-ref: ccbeb02ed1bbf6b4388981a0e641aff7404637bd + url: "https://github.com/lingjhf/deskup.git" + source: git + version: "0.3.0" drift: dependency: "direct main" description: diff --git a/pubspec.yaml b/pubspec.yaml index b533dca..41bba2e 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -13,7 +13,10 @@ workspace: dependencies: cutdex_ui: ^0.1.0 cutdex_native: ^0.1.0 - deskup: ^0.2.0 + deskup: + git: + url: https://github.com/lingjhf/deskup.git + ref: ccbeb02ed1bbf6b4388981a0e641aff7404637bd flutter: sdk: flutter diff --git a/test/app_update_configuration_test.dart b/test/app_update_configuration_test.dart new file mode 100644 index 0000000..8dec600 --- /dev/null +++ b/test/app_update_configuration_test.dart @@ -0,0 +1,30 @@ +import 'package:flutter_test/flutter_test.dart'; +import 'package:cutdex/integrations/app_update_configuration.dart'; + +void main() { + test('production ignores development source overrides', () { + final config = windowsUpdateConfiguration( + flavor: 'production', + developmentUrl: 'http://127.0.0.1:8765', + developmentSource: 'web', + allowLocalHttp: true, + )!; + final map = config.toMap(); + expect( + (map['source'] as Map)['url'], + 'https://git.orangraph.com/lingjhf/cutdex', + ); + expect(map['expectedPackageId'], 'Cutdex'); + }); + test('development requires opt-in and uses an isolated identity', () { + expect(windowsUpdateConfiguration(flavor: 'development'), isNull); + final map = windowsUpdateConfiguration( + flavor: 'development', + developmentUrl: 'http://127.0.0.1:8765', + developmentSource: 'web', + allowLocalHttp: true, + )!.toMap(); + expect(map['expectedPackageId'], 'Cutdex.Dev'); + expect((map['source'] as Map)['type'], 'web'); + }); +} diff --git a/tool/README.md b/tool/README.md index 78560b7..51603bc 100644 --- a/tool/README.md +++ b/tool/README.md @@ -75,6 +75,8 @@ python3 tool/windows/windows_updates.py pack --help 提升应用构建号,保留当前线上更新索引供版本检查;development 与 production 使用独立发布目录。脚本只生成产物,不上传。完整升级模拟使用各平台的 `test_*_updates.py`,参数见 `--help`,测试包不用于分发。 +deskup 0.3.0 的开发更新源由 Dart 参数配置。Windows 的编译期配置示例见 [Windows 更新文档](../docs/windows-updates.md)。macOS 本地 HTTP 更新测试的源应用需使用 `--flavor development --dart-define=CUTDEX_UPDATE_TEST_HTTP=true` 构建,再运行 `test_macos_updates.py`;签名公钥和 appcast 仍由打包工具写入应用 Info.plist。 + ## 诊断与共享测试入口 - `diagnostics/frame_budget.py`:读取 `CUTDEX_FRAME_TIMINGS` JSONL,可带阶段标记文件;报告帧耗时。 diff --git a/tool/testing/windows_update_smoke.dart b/tool/testing/windows_update_smoke.dart index 6af2681..2e94a74 100644 --- a/tool/testing/windows_update_smoke.dart +++ b/tool/testing/windows_update_smoke.dart @@ -5,11 +5,15 @@ import 'dart:io'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; +import 'package:deskup/deskup.dart'; const channel = MethodChannel('deskup'); const smokeRoot = String.fromEnvironment('CUTDEX_UPDATE_SMOKE_ROOT'); -void main() { +List restartArguments = []; + +void main(List arguments) { + restartArguments = arguments; WidgetsFlutterBinding.ensureInitialized(); // The isolated smoke fixture depends only on Flutter, without Riverpod. // ignore: riverpod_lint/missing_provider_scope @@ -48,13 +52,33 @@ Future runSmoke() async { throw StateError('Set CUTDEX_UPDATE_SMOKE_ROOT for this test app'); } try { - await channel.invokeMethod('ready'); + final updater = Deskup( + windows: WindowsUpdateConfiguration( + source: WebUpdateSource( + url: Uri.parse( + const String.fromEnvironment('CUTDEX_WINDOWS_UPDATE_URL'), + ), + allowLocalHttp: true, + ), + expectedPackageId: 'Cutdex.Dev', + preferenceNamespace: 'Cutdex.UpdateSmoke', + automaticCheckInterval: const Duration(minutes: 5), + maximumDeltas: -1, + ), + ); + await updater.initialize(); final initial = await waitFor( (value) => value['configured'] == true && value['canCheck'] == true, ); await channel.invokeMethod('check'); var checked = await waitFor((value) => value['canCheck'] == true); if (initial['build'] == '900002') { + if (!restartArguments.contains('--deskup-smoke-restart') || + !restartArguments.contains('文档 with spaces')) { + throw StateError( + 'Restart arguments were not preserved: $restartArguments', + ); + } if (checked['phase'] != 'current') { throw StateError('Updated version was offered again: $checked'); } @@ -78,7 +102,11 @@ Future runSmoke() async { } await record('before', checked); await channel.invokeMethod('validateInstall'); - await channel.invokeMethod('install'); + await updater.install( + silent: true, + restart: true, + restartArguments: ['--deskup-smoke-restart', '文档 with spaces'], + ); } catch (error, stack) { await record('failure', {'error': '$error', 'stack': '$stack'}); exit(1); diff --git a/tool/windows/test_update_configuration_unit.py b/tool/windows/test_update_configuration_unit.py deleted file mode 100644 index 13e4a73..0000000 --- a/tool/windows/test_update_configuration_unit.py +++ /dev/null @@ -1,46 +0,0 @@ -import os -from pathlib import Path -import shutil -import subprocess -import tempfile -import unittest - -ROOT = Path(__file__).resolve().parents[2] - - -@unittest.skipUnless(shutil.which('cmake'), 'CMake required') -class UpdateConfigurationTests(unittest.TestCase): - def configuration(self, flavor, **overrides): - environment = {name: value for name, value in os.environ.items() - if not name.startswith('CUTDEX_WINDOWS_UPDATE_') and name != 'CUTDEX_UPDATE_TEST_HTTP'} - environment.update(overrides) - with tempfile.TemporaryDirectory() as directory: - root = Path(directory) - script = root / 'config.cmake' - script.write_text(f'set(FLUTTER_APP_FLAVOR "{flavor}")\n' - 'function(configure_updates)\n' - f'include("{ROOT.as_posix()}/windows/runner/update_configuration.cmake")\n' - 'endfunction()\nconfigure_updates()\n' - f'file(WRITE "{root.as_posix()}/result.txt" ' - '"${DESKUP_WINDOWS_UPDATE_SOURCE}|${DESKUP_WINDOWS_UPDATE_URL}|${DESKUP_UPDATE_PACKAGE_ID}|${DESKUP_ALLOW_LOCAL_HTTP}|${DESKUP_GITEA_INCLUDE_PRERELEASES}")\n') - result = subprocess.run(['cmake', '-P', str(script)], env=environment, - capture_output=True, text=True) - self.assertEqual(result.returncode, 0, result.stderr) - return (root / 'result.txt').read_text().split('|') - - def test_production_always_uses_public_gitea_repository(self): - values = self.configuration('production', CUTDEX_WINDOWS_UPDATE_SOURCE='web', - CUTDEX_WINDOWS_UPDATE_URL='http://127.0.0.1:9999', CUTDEX_UPDATE_TEST_HTTP='1') - self.assertEqual(values, ['gitea', 'https://git.orangraph.com/lingjhf/cutdex', 'Cutdex', '0', 'OFF']) - - def test_development_has_no_implicit_production_feed(self): - self.assertEqual(self.configuration('development'), ['gitea', '', 'Cutdex.Dev', '0', 'OFF']) - - def test_development_supports_explicit_loopback_web_test_feed(self): - self.assertEqual(self.configuration('development', CUTDEX_WINDOWS_UPDATE_SOURCE='web', - CUTDEX_WINDOWS_UPDATE_URL='http://127.0.0.1:8765', CUTDEX_UPDATE_TEST_HTTP='1'), - ['web', 'http://127.0.0.1:8765', 'Cutdex.Dev', '1', 'OFF']) - - -if __name__ == '__main__': - unittest.main() diff --git a/tool/windows/test_windows_updates.py b/tool/windows/test_windows_updates.py index 3a41615..18052ea 100644 --- a/tool/windows/test_windows_updates.py +++ b/tool/windows/test_windows_updates.py @@ -15,7 +15,7 @@ import sys import threading import time -from windows_updates import DESKUP_VERSION, ROOT, check_tool, pack_release, update_version, vpk_command +from windows_updates import DESKUP_ROOT, ROOT, check_tool, pack_release, update_version, vpk_command class TestHandler(SimpleHTTPRequestHandler): @@ -52,26 +52,22 @@ def main(): command = vpk_command(args.vpk) check_tool(command) definitions = work / 'defines.json' - definitions.write_text(json.dumps({'CUTDEX_UPDATE_SMOKE_ROOT': work.as_posix()}), encoding='utf-8') - environment = dict(os.environ, CUTDEX_WINDOWS_UPDATE_URL=f'http://127.0.0.1:{args.port}', - CUTDEX_WINDOWS_UPDATE_SOURCE='web', - CUTDEX_UPDATE_TEST_HTTP='1') + definitions.write_text(json.dumps({'CUTDEX_UPDATE_SMOKE_ROOT': work.as_posix(), + 'CUTDEX_WINDOWS_UPDATE_URL': f'http://127.0.0.1:{args.port}'}), encoding='utf-8') + environment = dict(os.environ) # Isolate Flutter caches, generated runner files and output from live builds. source = work / 'source' source.mkdir() for name in ['windows']: shutil.copytree(ROOT / name, source / name, ignore=shutil.ignore_patterns('ephemeral', 'build', '__pycache__')) - configuration = source / 'windows/runner/update_configuration.cmake' - configuration.write_text(configuration.read_text().replace( - r'Software\\\\Cutdex\\\\', r'Software\\\\Cutdex\\\\UpdateSmoke\\\\')) # Exercise the real Runner/update bridge with a small Flutter test entry. # Media processing is covered separately and need not be rebuilt here. (source / 'pubspec.yaml').write_text( 'name: cutdex_update_smoke\nversion: 1.0.0+1\n' 'environment:\n sdk: ^3.13.4\n' 'dependencies:\n flutter:\n sdk: flutter\n' - f' deskup: {DESKUP_VERSION}\n' + f' deskup:\n path: {DESKUP_ROOT.as_posix()}\n' 'flutter:\n uses-material-design: true\n', encoding='utf-8') entry = source / 'tool/testing/windows_update_smoke.dart' entry.parent.mkdir(parents=True) diff --git a/tool/windows/windows_updates.py b/tool/windows/windows_updates.py index 451090d..b31c25b 100644 --- a/tool/windows/windows_updates.py +++ b/tool/windows/windows_updates.py @@ -117,9 +117,13 @@ def package_app(app, output, vpk, *, development=False, require_processing=True) check_tool(command) version = file_version(app) package_id = 'Cutdex.Dev' if development else 'Cutdex' - # deskup compiles the identity into the plugin, rather than the runner. - identity = package_id.encode('ascii') + b'\0' - if identity not in (app / 'deskup_plugin.dll').read_bytes(): + # The updater is generic; verify the host flavor through its PE branding. + import pefile + with pefile.PE(str(app / 'cutdex.exe')) as pe: + products = [table.entries.get(b'ProductName', b'').decode('utf-8') + for group in pe.FileInfo for block in group + if block.Key == b'StringFileInfo' for table in block.StringTable] + if ('Cutdex Dev' if development else 'Cutdex') not in products: raise ValueError('Package identity does not match the Flutter build flavor') validate_previous(output, package_id, version) output.mkdir(parents=True, exist_ok=True) diff --git a/windows/runner/CMakeLists.txt b/windows/runner/CMakeLists.txt index b2663e4..7001296 100644 --- a/windows/runner/CMakeLists.txt +++ b/windows/runner/CMakeLists.txt @@ -60,7 +60,6 @@ target_compile_definitions(${BINARY_NAME} PRIVATE "NOMINMAX") # dependencies here. target_link_libraries(${BINARY_NAME} PRIVATE flutter flutter_wrapper_app dwmapi) target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}") -include("${CMAKE_CURRENT_SOURCE_DIR}/update_configuration.cmake") # Run the Flutter tool portions of the build. This must not be removed. add_dependencies(${BINARY_NAME} flutter_assemble) diff --git a/windows/runner/update_configuration.cmake b/windows/runner/update_configuration.cmake deleted file mode 100644 index 072555c..0000000 --- a/windows/runner/update_configuration.cmake +++ /dev/null @@ -1,26 +0,0 @@ -# Configuration is baked into the binary; a user's environment cannot redirect it. -set(CUTDEX_WINDOWS_UPDATE_SOURCE "gitea") -set(CUTDEX_WINDOWS_UPDATE_URL "https://git.orangraph.com/lingjhf/cutdex") -set(CUTDEX_UPDATE_PACKAGE_ID "Cutdex") -set(CUTDEX_UPDATE_TEST_HTTP 0) -if(FLUTTER_APP_FLAVOR STREQUAL "development") - set(CUTDEX_UPDATE_PACKAGE_ID "Cutdex.Dev") - # Development updates must opt into a separate repository/feed explicitly. - set(CUTDEX_WINDOWS_UPDATE_URL "$ENV{CUTDEX_WINDOWS_UPDATE_URL}") - if(DEFINED ENV{CUTDEX_WINDOWS_UPDATE_SOURCE}) - set(CUTDEX_WINDOWS_UPDATE_SOURCE "$ENV{CUTDEX_WINDOWS_UPDATE_SOURCE}") - endif() - if("$ENV{CUTDEX_UPDATE_TEST_HTTP}" STREQUAL "1") - set(CUTDEX_UPDATE_TEST_HTTP 1) - endif() -endif() -# deskup validates feed URLs; the host limits local HTTP to development. -if(DEFINED ENV{CUTDEX_VELOPACK_ARCHIVE}) - set(ENV{DESKUP_VELOPACK_ARCHIVE} "$ENV{CUTDEX_VELOPACK_ARCHIVE}") -endif() -set(DESKUP_WINDOWS_UPDATE_URL "${CUTDEX_WINDOWS_UPDATE_URL}" PARENT_SCOPE) -set(DESKUP_WINDOWS_UPDATE_SOURCE "${CUTDEX_WINDOWS_UPDATE_SOURCE}" PARENT_SCOPE) -set(DESKUP_GITEA_INCLUDE_PRERELEASES OFF PARENT_SCOPE) -set(DESKUP_UPDATE_PACKAGE_ID "${CUTDEX_UPDATE_PACKAGE_ID}" PARENT_SCOPE) -set(DESKUP_PREFERENCE_ROOT "Software\\\\Cutdex\\\\" PARENT_SCOPE) -set(DESKUP_ALLOW_LOCAL_HTTP "${CUTDEX_UPDATE_TEST_HTTP}" PARENT_SCOPE)