Skip to content

Commit

Permalink
Merge pull request #12 from nini22P/dev
Browse files Browse the repository at this point in the history
v1.3.1
  • Loading branch information
nini22P authored Feb 5, 2025
2 parents 30cd068 + c523ac7 commit 95b7126
Show file tree
Hide file tree
Showing 12 changed files with 106 additions and 22 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
## v1.3.1

### Changelog

* The data save location for the Windows version has been changed to `C:\Users\<user>\AppData\Roaming\nini22P\iris`
* Updated upstream dependencies and fixed the issue with switching subtitles in the FVP player backend

### 更新日志

* Windows 版本数据保存位置已修改为 `C:\Users\<user>\AppData\Roaming\nini22P\iris`
* 更新上游依赖,修复 FVP 播放器后端切换字幕的问题


## v1.3.0

### Changelog
Expand Down
9 changes: 6 additions & 3 deletions lib/hooks/use_fvp_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import 'package:iris/models/store/app_state.dart';
import 'package:iris/store/use_app_store.dart';
import 'package:iris/store/use_history_store.dart';
import 'package:iris/store/use_play_queue_store.dart';
import 'package:iris/store/use_storage_store.dart';
import 'package:iris/utils/check_data_source_type.dart';
import 'package:iris/utils/logger.dart';
import 'package:video_player/video_player.dart';
Expand Down Expand Up @@ -51,16 +52,18 @@ FvpPlayer useFvpPlayer(BuildContext context) {

final controller = useMemoized(() {
if (file == null) return VideoPlayerController.networkUrl(Uri.parse(''));
final storage = useStorageStore().findById(file.storageId);
final auth = storage?.getAuth();
switch (checkDataSourceType(file)) {
case DataSourceType.network:
return VideoPlayerController.networkUrl(
Uri.parse(file.uri),
httpHeaders: file.auth != null ? {'authorization': file.auth!} : {},
httpHeaders: auth != null ? {'authorization': auth} : {},
);
case DataSourceType.file:
return VideoPlayerController.file(
File(file.uri),
httpHeaders: file.auth != null ? {'authorization': file.auth!} : {},
httpHeaders: auth != null ? {'authorization': auth} : {},
);
case DataSourceType.contentUri:
return VideoPlayerController.contentUri(
Expand All @@ -69,7 +72,7 @@ FvpPlayer useFvpPlayer(BuildContext context) {
default:
return VideoPlayerController.networkUrl(
Uri.parse(file.uri),
httpHeaders: file.auth != null ? {'authorization': file.auth!} : {},
httpHeaders: auth != null ? {'authorization': auth} : {},
);
}
}, [file]);
Expand Down
11 changes: 7 additions & 4 deletions lib/hooks/use_media_kit_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import 'package:iris/models/store/app_state.dart';
import 'package:iris/store/use_app_store.dart';
import 'package:iris/store/use_history_store.dart';
import 'package:iris/store/use_play_queue_store.dart';
import 'package:iris/store/use_storage_store.dart';
import 'package:iris/utils/logger.dart';
import 'package:media_kit/media_kit.dart';
import 'package:media_kit_video/media_kit_video.dart';
Expand Down Expand Up @@ -127,12 +128,14 @@ MediaKitPlayer useMediaKitPlayer(BuildContext context) {
if (currentFile == null || playQueue.isEmpty) {
player.stop();
} else {
final storage = useStorageStore().findById(currentFile.storageId);
final auth = storage?.getAuth();
logger('Now playing: ${currentFile.uri}, auto play: $autoPlay');
player.open(
Media(currentFile.uri,
httpHeaders: currentFile.auth != null
? {'authorization': currentFile.auth!}
: {}),
Media(
currentFile.uri,
httpHeaders: auth != null ? {'authorization': auth} : {},
),
play: autoPlay,
);
}
Expand Down
5 changes: 5 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import 'package:iris/pages/home_page.dart';
import 'package:iris/store/use_app_store.dart';
import 'package:iris/store/use_play_queue_store.dart';
import 'package:iris/theme.dart';
import 'package:iris/utils/data_migration.dart';
import 'package:iris/utils/is_desktop.dart';
import 'package:iris/utils/logger.dart';
import 'package:iris/utils/request_storage_permission.dart';
Expand All @@ -28,6 +29,10 @@ void main(List<String> arguments) async {

WidgetsFlutterBinding.ensureInitialized();

if (Platform.isWindows) {
await dataMigration();
}

MediaKit.ensureInitialized();

fvp.registerWith(options: {
Expand Down
1 change: 0 additions & 1 deletion lib/models/file.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ abstract class FileItem implements _$FileItem {
@Default(0) int size,
DateTime? lastModified,
@Default(ContentType.video) ContentType type,
String? auth,
@Default([]) List<Subtitle> subtitles,
}) = _FileItem;

Expand Down
12 changes: 12 additions & 0 deletions lib/models/storages/storage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ abstract class _Storage {
Map<String, dynamic> toJson();

Future<List<FileItem>> getFiles(List<String> path);

String? getAuth();
}

@freezed
Expand Down Expand Up @@ -73,6 +75,16 @@ sealed class Storage with _$Storage implements _Storage {
return [];
}
}

@override
String? getAuth() {
switch (type) {
case StorageType.webdav:
return getWebDAVAuth(this as WebDAVStorage);
default:
return null;
}
}
}

Future<void> openInFolder(BuildContext context, FileItem file) async {
Expand Down
7 changes: 3 additions & 4 deletions lib/models/storages/webdav.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ Future<List<FileItem>> getWebDAVFiles(
debug: false,
);

final String auth =
'Basic ${base64Encode(utf8.encode('$username:$password'))}';

client.setHeaders({'accept-charset': 'utf-8'});
client.setConnectTimeout(8000);
client.setSendTimeout(8000);
Expand All @@ -77,10 +74,12 @@ Future<List<FileItem>> getWebDAVFiles(
type: file.isDir ?? false
? ContentType.dir
: checkContentType(file.name!),
auth: auth,
subtitles: await findSubtitle(
files.map((file) => file.name as String).toList(),
file.name as String,
baseUri),
)));
}

String getWebDAVAuth(WebDAVStorage storage) =>
'Basic ${base64Encode(utf8.encode('${storage.username}:${storage.password}'))}';
16 changes: 10 additions & 6 deletions lib/pages/player/audio.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'dart:ui';
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:iris/models/file.dart';
import 'package:iris/store/use_storage_store.dart';

class Audio extends HookWidget {
const Audio({
Expand All @@ -14,6 +15,12 @@ class Audio extends HookWidget {

@override
Widget build(BuildContext context) {
final storage = useMemoized(
() => cover?.storageId == null
? null
: useStorageStore().findById(cover!.storageId),
[cover?.storageId]);
final auth = useMemoized(() => storage?.getAuth(), [storage]);
return IgnorePointer(
child: Stack(
children: [
Expand All @@ -29,9 +36,7 @@ class Audio extends HookWidget {
)
: Image.network(
cover!.uri,
headers: cover!.auth != null
? {'authorization': cover!.auth!}
: null,
headers: auth != null ? {'authorization': auth} : null,
fit: BoxFit.cover,
)
: null,
Expand Down Expand Up @@ -60,9 +65,8 @@ class Audio extends HookWidget {
)
: Image.network(
cover!.uri,
headers: cover!.auth != null
? {'authorization': cover!.auth!}
: null,
headers:
auth != null ? {'authorization': auth} : null,
fit: BoxFit.contain,
)
: null,
Expand Down
46 changes: 46 additions & 0 deletions lib/utils/data_migration.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import 'dart:io';
import 'package:iris/utils/logger.dart';
import 'package:path_provider/path_provider.dart';
import 'package:path/path.dart' as p;

Future<bool> dataMigration() async {
try {
if (Platform.isWindows) {
final String newDataPath = (await getApplicationSupportDirectory()).path;
final String oldDataPath =
p.normalize('$newDataPath/../../nini22p.iris/iris');
logger('newDataPath: $newDataPath');
logger('oldDataPath: $oldDataPath');
final bool newDataExist =
await File('$newDataPath/flutter_secure_storage.dat').exists();
final bool oldDataExist =
await File('$oldDataPath/flutter_secure_storage.dat').exists();
if (!newDataExist && oldDataExist) {
logger('Find old data in $oldDataPath');
final Directory oldDir = Directory(oldDataPath);
final Directory newDir = Directory(newDataPath);

if (await oldDir.exists()) {
if (!await newDir.exists()) {
await newDir.create(recursive: true);
}

await for (var entity in oldDir.list()) {
if (entity is File) {
final String newFilePath =
p.join(newDir.path, p.basename(entity.path));
await entity.copy(newFilePath);
logger('Copied ${entity.path} to $newFilePath');
}
}
logger('Data migration completed');
return true;
}
}
}
} catch (e) {
return false;
}

return false;
}
2 changes: 1 addition & 1 deletion macos/Runner/Configs/AppInfo.xcconfig
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ PRODUCT_NAME = iris
PRODUCT_BUNDLE_IDENTIFIER = nini22p.iris

// The copyright displayed in application information
PRODUCT_COPYRIGHT = Copyright © 2024 nini22p.iris. All rights reserved.
PRODUCT_COPYRIGHT = Copyright © 2024 nini22P. All rights reserved.
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: iris
description: "A lightweight video player"
publish_to: 'none'
version: 1.3.0+3
version: 1.3.1+3

environment:
sdk: ^3.5.4
Expand Down
4 changes: 2 additions & 2 deletions windows/runner/Runner.rc
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@ BEGIN
BEGIN
BLOCK "040904e4"
BEGIN
VALUE "CompanyName", "nini22p.iris" "\0"
VALUE "CompanyName", "nini22P" "\0"
VALUE "FileDescription", "iris" "\0"
VALUE "FileVersion", VERSION_AS_STRING "\0"
VALUE "InternalName", "iris" "\0"
VALUE "LegalCopyright", "Copyright (C) 2024 nini22p.iris. All rights reserved." "\0"
VALUE "LegalCopyright", "Copyright (C) 2024 nini22P. All rights reserved." "\0"
VALUE "OriginalFilename", "iris.exe" "\0"
VALUE "ProductName", "iris" "\0"
VALUE "ProductVersion", VERSION_AS_STRING "\0"
Expand Down

0 comments on commit 95b7126

Please sign in to comment.