Skip to content

Commit

Permalink
feat: add updater
Browse files Browse the repository at this point in the history
  • Loading branch information
nini22P committed Jan 10, 2025
1 parent 0b89278 commit bc06d99
Show file tree
Hide file tree
Showing 12 changed files with 155 additions and 9 deletions.
1 change: 0 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.create_tag.outputs.TAG_NAME }}
name: Iris ${{ steps.create_tag.outputs.TAG_NAME }}
body_path: CHANGELOG.md
draft: false
prerelease: false
Expand Down
26 changes: 26 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [

{
"name": "iris",
"request": "launch",
"type": "dart"
},
{
"name": "iris (profile mode)",
"request": "launch",
"type": "dart",
"flutterMode": "profile"
},
{
"name": "iris (release mode)",
"request": "launch",
"type": "dart",
"flutterMode": "release"
}
]
}
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
### Changelog
* Supports WebDAV and locally stored video playback
* Windows version support auto update

### 更新日志
* 支持 WebDAV 和本地存储视频播放
* Windows 版本支持自动更新
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ English | [中文](./README_CN.md)

## Download

This application has not been officially released yet. If you want to experience it early, you can download the automatically built version from [GitHub Actions](https://github.com/nini22P/Iris/actions).
Go to [Releases](https://github.com/nini22P/Iris/releases) to download.

## Contribution

Expand Down
2 changes: 1 addition & 1 deletion README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

## 下载

本应用还没有正式发布,如果想要抢先体验,可以前往 [GitHub Actions](https://github.com/nini22P/Iris/actions) 下载自动构建版本
前往 [Releases](https://github.com/nini22P/Iris/releases) 下载

## 贡献

Expand Down
4 changes: 3 additions & 1 deletion lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,7 @@
"always_on_top_off": "Always On Top: Off",
"check_update": "Check Update",
"download": "Download",
"checked_new_version": "Checked New Version"
"download_and_update": "Download and Update",
"checked_new_version": "Checked New Version",
"no_new_version": "No New Version"
}
4 changes: 3 additions & 1 deletion lib/l10n/app_zh.arb
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,7 @@
"always_on_top_off": "窗口置顶: 关",
"check_update": "检查更新",
"download": "下载",
"checked_new_version": "检查到新版本"
"download_and_update": "下载并更新",
"checked_new_version": "检查到新版本",
"no_new_version": "没有新版本"
}
32 changes: 31 additions & 1 deletion lib/pages/dialog/show_release_dialog.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:io';
import 'package:path/path.dart' as p;
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:flutter_markdown/flutter_markdown.dart';
Expand All @@ -23,6 +25,25 @@ class ReleaseDialog extends HookWidget {
Widget build(BuildContext context) {
final t = getLocalizations(context);

void update() async {
if (Platform.isWindows) {
String resolvedExecutablePath = Platform.resolvedExecutable;
String path = p.dirname(resolvedExecutablePath);
String batFilePath = p.join(path, 'iris-updater.bat');

// 执行 bat 文件
await Process.start(
'cmd.exe',
['/c', batFilePath],
mode: ProcessStartMode.detached,
runInShell: true,
);

// 退出应用
exit(0);
}
}

return AlertDialog(
title: Text('${t.checked_new_version}: ${release.version}'),
content: SingleChildScrollView(
Expand All @@ -39,7 +60,16 @@ class ReleaseDialog extends HookWidget {
Navigator.pop(context, 'OK');
},
child: Text(t.download),
)
),
Visibility(
visible: Platform.isWindows || Platform.isLinux || Platform.isMacOS,
child: TextButton(
onPressed: () {
update();
},
child: Text(t.download_and_update),
),
),
],
);
}
Expand Down
5 changes: 5 additions & 0 deletions lib/pages/settings/about.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class About extends HookWidget {
Widget build(BuildContext context) {
final t = getLocalizations(context);
final packageInfo = useState<PackageInfo?>(null);
final noNewVersion = useState(false);

useEffect(() {
void getPackageInfo() async =>
Expand Down Expand Up @@ -43,10 +44,14 @@ class About extends HookWidget {
ListTile(
leading: const Icon(Icons.update_rounded),
title: Text(t.check_update),
subtitle: noNewVersion.value ? Text(t.no_new_version) : null,
onTap: () async {
noNewVersion.value = false;
final release = await getLatestRelease();
if (release != null && context.mounted) {
showReleaseDialog(context, release: release);
} else {
noNewVersion.value = true;
}
}),
ListTile(
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
# In Windows, build-name is used as the major, minor, and patch parts
# of the product and file versions while build-number is used as the build suffix.
version: 1.0.0+1
version: 1.0.1+1

environment:
sdk: ^3.5.4
Expand Down
3 changes: 3 additions & 0 deletions windows/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,6 @@ install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}"
install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}"
CONFIGURATIONS Profile;Release
COMPONENT Runtime)

# Install iris-updater.bat
install(FILES "${CMAKE_SOURCE_DIR}/iris-updater.bat" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime)
79 changes: 79 additions & 0 deletions windows/iris-updater.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
@echo off
title Iris Updater
setlocal enabledelayedexpansion

set "api_url=https://api.github.com/repos/nini22P/Iris/releases/latest"
set "download_folder=%~dp0temps"

:: Try to delete the download folder if it exists
if exist "%download_folder%" (
rd /s /q "%download_folder%"
)

:: Create download folder
mkdir "%download_folder%"

echo Fetching latest release from GitHub...

:: Fetch JSON data using curl
powershell -Command "try { Invoke-WebRequest -Uri '%api_url%' -UseBasicParsing | Select-Object -ExpandProperty Content | Out-File -Encoding UTF8 '%download_folder%\release.json' } catch { Write-Host 'Error fetching release info: ' $_.Exception.Message; exit 1 }"

if not exist "%download_folder%\release.json" (
echo Error: Could not fetch release data. Please check your internet connection.
goto :end
)

for /f "delims=" %%a in ('powershell -command "try { Get-Content '%download_folder%\release.json' | ConvertFrom-Json | Select-Object -ExpandProperty tag_name } catch { Write-Host 'Error parsing JSON: ' $_.Exception.Message; exit 1 }"') do (
set "version_tag=%%a"
if defined version_tag (
goto :version_found
)
)

echo Error: Could not extract version tag from release info.
goto :end

:version_found

set "download_url=https://github.com/nini22P/Iris/releases/latest/download/Iris_windows.zip"
set "zip_file=%download_folder%\Iris_windows.zip"
set "extract_folder=%download_folder%"

title Download Iris !version_tag!

where curl >nul 2>nul
if %errorlevel% equ 0 (
echo Download Iris !version_tag!
curl -L -o "%zip_file%" "%download_url%"
if %errorlevel% neq 0 (
echo Error downloading file with curl.
exit /b 1
)
) else (
echo Download Iris !version_tag!
powershell -Command "try { Invoke-WebRequest -Uri '%download_url%' -OutFile '%zip_file%' } catch { Write-Host 'Error downloading file: ' $_.Exception.Message; exit 1 }"
)

if not exist "%zip_file%" (
echo Error: Failed to download Iris_windows.zip.
goto :end
)

echo Extracting Iris_windows.zip...
powershell -Command "try { Add-Type -Assembly 'System.IO.Compression.FileSystem'; [System.IO.Compression.ZipFile]::ExtractToDirectory('%zip_file%', '%extract_folder%'); } catch { Write-Host 'Error extracting zip: ' $_.Exception.Message; exit 1 }"

:: Check if Iris folder exists before moving
if not exist "%extract_folder%\Iris" (
echo Error: "Iris" folder not found within the extracted files.
goto :cleanup
)

echo Starting file move and cleanup...
:: Start a new cmd window to perform move and cleanup, then current bat will close
start cmd /c "timeout /t 2 /nobreak && xcopy temps\Iris\* .\ /E /I /Y && rd /s /q temps && start iris"

:cleanup
exit

:end
endlocal

0 comments on commit bc06d99

Please sign in to comment.