Skip to content

Commit

Permalink
Merge pull request #3 from nini22P/dev
Browse files Browse the repository at this point in the history
v1.0.3
  • Loading branch information
nini22P authored Jan 15, 2025
2 parents c154a2a + 51cd29e commit 6d915f6
Show file tree
Hide file tree
Showing 19 changed files with 228 additions and 62 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ jobs:
git tag "$TAG_NAME"
git push origin "$TAG_NAME"
- name: Eextract log
id: extract_log
run: python extract_log.py ${{ steps.create_tag.outputs.TAG_NAME }}
- name: Download Windows artifact
uses: actions/download-artifact@v4
Expand All @@ -117,7 +116,7 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.create_tag.outputs.TAG_NAME }}
body: ${{ steps.extract_log.outputs.result }}
body_path: CHANGELOG_${{ steps.create_tag.outputs.TAG_NAME }}.md
draft: false
prerelease: false
files: |
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
## 1.0.3
### Changelog
* Improve Windows version installation updates
* Fixes an issue where subtitles may not be found

### 更新日志
* 改进 Windows 版本安装更新
* 修复可能无法找到字幕的问题

## v1.0.2
### Changelog
* Support for switching built-in audio tracks
Expand Down
9 changes: 7 additions & 2 deletions extract_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,17 @@ def extract_log(version):
changelog_lines.pop()

output = "".join(changelog_lines).strip()
print(output)

output_file = f"CHANGELOG_{version}.md"
with open(output_file, "w", encoding="utf-8") as file:
file.write(output)

print(f"Changelog for {version} saved to {output_file}")

if __name__ == "__main__":
if len(sys.argv) != 2:
print("Usage: python extract_log.py <version>")
sys.exit(1)

version = sys.argv[1]
extract_log(version)
extract_log(version)
4 changes: 4 additions & 0 deletions lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@
"check_update": "Check Update",
"checked_new_version": "Checked New Version",
"close": "Close",
"confirmUpdate": "Confirm update",
"connection_test": "Connection Test",
"dark": "Datk",
"download": "Download",
"download_and_update": "Download and Update",
"download_error": "Download Error",
"edit": "Edit",
"edit_local_storage": "Edit Local Storage",
"edit_webdav_storage": "Edit WebDAV Storage",
Expand Down Expand Up @@ -49,8 +51,10 @@
"play_queue": "Play Queue",
"port": "Port",
"previous": "Previous",
"releasePage": "Release Page",
"remove": "Remove",
"remove_favorite": "Remove Favorite",
"retry": "Retry",
"save": "Save",
"select_language": "Select Language",
"settings": "Settings",
Expand Down
4 changes: 4 additions & 0 deletions lib/l10n/app_zh.arb
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@
"check_update": "检查更新",
"checked_new_version": "检查到新版本",
"close": "关闭",
"confirmUpdate": "确认更新",
"connection_test": "连接测试",
"dark": "暗色",
"download": "下载",
"download_and_update": "下载并更新",
"download_error": "下载错误",
"edit": "编辑",
"edit_local_storage": "编辑本地存储",
"edit_webdav_storage": "编辑 WebDAV 存储",
Expand Down Expand Up @@ -49,8 +51,10 @@
"play_queue": "播放队列",
"port": "端口",
"previous": "上一个",
"releasePage": "发布页面",
"remove": "移除",
"remove_favorite": "移除收藏",
"retry": "重试",
"save": "保存",
"select_language": "选择语言",
"settings": "设置",
Expand Down
4 changes: 2 additions & 2 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:flutter_zustand/flutter_zustand.dart';
Expand All @@ -7,6 +6,7 @@ import 'package:iris/info.dart';
import 'package:iris/pages/home_page.dart';
import 'package:iris/store/use_app_store.dart';
import 'package:iris/theme.dart';
import 'package:iris/utils/is_desktop.dart';
import 'package:media_kit/media_kit.dart';
import 'package:window_manager/window_manager.dart';
import 'package:dynamic_color/dynamic_color.dart';
Expand All @@ -15,7 +15,7 @@ void main() async {
WidgetsFlutterBinding.ensureInitialized();
MediaKit.ensureInitialized();

if (Platform.isWindows || Platform.isLinux || Platform.isMacOS) {
if (isDesktop) {
await windowManager.ensureInitialized();

WindowOptions windowOptions = const WindowOptions(
Expand Down
4 changes: 2 additions & 2 deletions lib/models/storages/local_storage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'package:iris/store/use_app_store.dart';
import 'package:iris/store/use_play_queue_store.dart';
import 'package:iris/utils/files_filter.dart';
import 'package:iris/utils/files_sort.dart';
import 'package:iris/utils/find_sub_title.dart';
import 'package:iris/utils/find_subtitle.dart';
import 'package:iris/utils/path_converter.dart';
import 'package:path/path.dart' as p;
import 'package:iris/models/file.dart';
Expand Down Expand Up @@ -55,7 +55,7 @@ class LocalStorage implements Storage {
type: entity is Directory
? 'dir'
: checkFileType(p.basename(entity.path)),
subtitles: findSubTitle(
subtitles: findSubtitle(
directory
.listSync()
.map((entity) => p.basename(entity.path))
Expand Down
4 changes: 2 additions & 2 deletions lib/models/storages/webdav_storage.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'dart:convert';
import 'dart:developer';
import 'package:iris/utils/check_file_type.dart';
import 'package:iris/utils/find_sub_title.dart';
import 'package:iris/utils/find_subtitle.dart';
import 'package:uuid/uuid.dart';
import 'package:webdav_client/webdav_client.dart' as webdav;
import 'package:iris/models/file.dart';
Expand Down Expand Up @@ -111,7 +111,7 @@ class WebdavStorage implements Storage {
size: file.size ?? 0,
type: file.isDir ?? false ? 'dir' : checkFileType(file.name!),
auth: auth,
subtitles: findSubTitle(
subtitles: findSubtitle(
files.map((file) => file.name as String).toList(),
file.name as String,
baseUri),
Expand Down
5 changes: 1 addition & 4 deletions lib/pages/custom_app_bar.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:iris/hooks/use_player_core.dart';
import 'package:iris/info.dart';
import 'package:iris/utils/get_localizations.dart';
import 'package:iris/utils/is_desktop.dart';
import 'package:iris/utils/resize_window.dart';
import 'package:window_manager/window_manager.dart';

Expand All @@ -22,9 +22,6 @@ class CustomAppBar extends HookWidget {
Widget build(BuildContext context) {
final t = getLocalizations(context);

bool isDesktop = useMemoized(
(() => Platform.isWindows || Platform.isLinux || Platform.isMacOS));

return Container(
padding: isDesktop
? const EdgeInsets.fromLTRB(12, 4, 4, 8)
Expand Down
153 changes: 134 additions & 19 deletions lib/pages/dialog/show_release_dialog.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import 'dart:async';
import 'dart:io';
import 'package:iris/utils/file_size_convert.dart';
import 'package:iris/utils/is_desktop.dart';
import 'package:iris/utils/path.dart';
import 'package:path/path.dart' as p;
import 'package:http/http.dart' as http;
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:flutter_markdown/flutter_markdown.dart';
Expand All @@ -24,50 +29,160 @@ class ReleaseDialog extends HookWidget {
@override
Widget build(BuildContext context) {
final t = getLocalizations(context);
final progress = useState(0.0);
final isError = useState(false);
final isDownload = useState(false);
final downloadingTask = useState<StreamSubscription?>(null);
const downloadFileName = 'Iris.zip';

void update() async {
if (Platform.isWindows) {
String resolvedExecutablePath = Platform.resolvedExecutable;
String path = p.dirname(resolvedExecutablePath);
String batFilePath = p.join(path, 'iris-updater.bat');
final String executableDirPath = await getExecutableDirPath();
final String tempPath = await getTempPath();
final String filePath = p.join(tempPath, downloadFileName);
final String executablePath = p.join(executableDirPath, 'iris.exe');

if (!File(filePath).existsSync()) {
return;
}

final commands = [
'title Iris',
'timeout /t 2 /nobreak',
'powerShell Expand-Archive -Path "$filePath" -DestinationPath "$tempPath" -Force',
'xcopy $tempPath\\Iris\\* $executableDirPath /s /E /I /Y',
'rd /s /q $tempPath',
'start $executablePath',
];

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

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

Future<StreamSubscription> downloadFile(String url, String filePath) async {
final client = http.Client();
final request = http.Request('GET', Uri.parse(url));
final response = await client.send(request);
if (response.statusCode == 200) {
final totalBytes = response.contentLength ?? 0;

var file = File(filePath);
var sink = file.openWrite();

final streamSubscription = response.stream.listen(
(List<int> chunk) {
sink.add(chunk);
progress.value += chunk.length / totalBytes;
},
onDone: () async {
await sink.close();
client.close();
},
onError: (error) {
sink.close();
client.close();
isError.value = true;
isDownload.value = false;
},
cancelOnError: true,
);
return streamSubscription;
} else {
throw Exception('Download failed with status ${response.statusCode}');
}
}

Future<void> download() async {
if (isDesktop && !isDownload.value) {
final String tempPath = await getTempPath();
final String filePath = p.join(tempPath, downloadFileName);

try {
isDownload.value = true;
isError.value = false;
final sub = await downloadFile(release.url, filePath);
downloadingTask.value = sub;
} catch (e) {
isError.value = true;
}
} else {
launchURL(release.url);
Navigator.pop(context, 'OK');
}
}

Future<void> cancel() async {
if (!(progress.value == 0) && downloadingTask.value != null) {
await downloadingTask.value!.cancel();
progress.value = 0.0;
}

if (context.mounted) {
Navigator.pop(context, 'Cancel');
}
}

return AlertDialog(
title: Text('${t.checked_new_version}: ${release.version}'),
content: SingleChildScrollView(
child: MarkdownBody(data: release.changeLog, shrinkWrap: true),
child: isError.value
? SizedBox(
height: 100,
width: 100,
child: Center(
child: Text(t.download_error),
),
)
: isDownload.value
? SizedBox(
height: 100,
width: 100,
child: Center(
child: CircularProgressIndicator(value: progress.value),
),
)
: MarkdownBody(data: release.changeLog, shrinkWrap: true),
),
actions: <Widget>[
TextButton(
onPressed: () => Navigator.pop(context, 'Cancel'),
onPressed: cancel,
child: Text(t.cancel),
),
TextButton(
onPressed: () {
launchURL(release.url);
Navigator.pop(context, 'OK');
},
child: Text(t.download),
onPressed: () => launchURL(release.url),
child: Text(t.releasePage),
),
Visibility(
visible: !isDesktop,
child: TextButton(
onPressed: download,
child: Text(t.download),
),
),
Visibility(
visible: Platform.isWindows || Platform.isLinux || Platform.isMacOS,
visible: isDesktop,
child: TextButton(
onPressed: () {
update();
},
child: Text(t.download_and_update),
onPressed: progress.value >= 1
? update
: isDownload.value
? null
: download,
child: isError.value
? Text(t.retry)
: progress.value >= 1
? Text(t.confirmUpdate)
: isDownload.value
? Text('${(progress.value * 100).toStringAsFixed(2)} %')
: Text(
'${t.download} (${fileSizeConvert(release.size)} MB)'),
),
),
],
Expand Down
4 changes: 1 addition & 3 deletions lib/pages/player/control_bar.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:flutter_zustand/flutter_zustand.dart';
Expand All @@ -11,6 +10,7 @@ import 'package:iris/pages/settings/settings.dart';
import 'package:iris/store/use_play_queue_store.dart';
import 'package:iris/utils/get_localizations.dart';
import 'package:iris/pages/player/play_queue.dart';
import 'package:iris/utils/is_desktop.dart';
import 'package:iris/utils/resize_window.dart';
import 'package:iris/pages/show_popup.dart';
import 'package:iris/pages/storages/storages.dart';
Expand All @@ -33,8 +33,6 @@ class ControlBar extends HookWidget {
@override
Widget build(BuildContext context) {
final t = getLocalizations(context);
bool isDesktop = useMemoized(
(() => Platform.isWindows || Platform.isLinux || Platform.isMacOS));

final playQueueLength =
usePlayQueueStore().select(context, (state) => state.playQueue.length);
Expand Down
Loading

0 comments on commit 6d915f6

Please sign in to comment.