Skip to content

Commit

Permalink
fix: drag and auto resize on windows table mode
Browse files Browse the repository at this point in the history
  • Loading branch information
nini22P committed Dec 13, 2024
1 parent e2c35ed commit ca34fe1
Show file tree
Hide file tree
Showing 15 changed files with 233 additions and 269 deletions.
1 change: 0 additions & 1 deletion lib/hooks/use_player_core.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'dart:developer';

import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:flutter_zustand/flutter_zustand.dart';
Expand Down
2 changes: 1 addition & 1 deletion lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"version": "Version",
"source_code": "Source Code",
"author": "Author",
"theme_color": "Theme Color",
"theme_mode": "Theme Mode",
"auto": "Auto",
"light": "Light",
"dark": "Datk",
Expand Down
2 changes: 1 addition & 1 deletion lib/l10n/app_zh.arb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"version": "版本",
"source_code": "源码",
"author": "作者",
"theme_color": "主题颜色",
"theme_mode": "主题模式",
"auto": "自动",
"light": "亮色",
"dark": "暗色",
Expand Down
8 changes: 5 additions & 3 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:flutter_zustand/flutter_zustand.dart';
Expand All @@ -6,7 +8,6 @@ import 'package:google_fonts/google_fonts.dart';
import 'package:iris/info.dart';
import 'package:iris/pages/home_page.dart';
import 'package:iris/store/use_app_store.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,18 +16,19 @@ void main() async {
WidgetsFlutterBinding.ensureInitialized();
MediaKit.ensureInitialized();

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

WindowOptions windowOptions = const WindowOptions(
size: Size(1280, 720),
size: Size(800, 600),
minimumSize: Size(480, 270),
center: true,
backgroundColor: Colors.transparent,
skipTaskbar: false,
titleBarStyle: TitleBarStyle.hidden,
title: INFO.title,
);

windowManager.waitUntilReadyToShow(windowOptions, () async {
await windowManager.show();
await windowManager.focus();
Expand Down
12 changes: 0 additions & 12 deletions lib/models/store/app_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ class AppState {
bool autoPlay;
bool loop;
int volume;
bool isMaximized;
bool isFullScreen;
bool isMuted;
String theme;
String subtitleLanguage;
Expand All @@ -14,8 +12,6 @@ class AppState {
this.autoPlay = false,
this.loop = false,
this.volume = 100,
this.isMaximized = false,
this.isFullScreen = false,
this.isMuted = false,
this.theme = 'auto',
this.subtitleLanguage = 'auto',
Expand All @@ -27,8 +23,6 @@ class AppState {
bool? autoPlay,
bool? loop,
int? volume,
bool? isMaximized,
bool? isFullScreen,
bool? isMuted,
String? theme,
String? subtitleLanguage,
Expand All @@ -39,8 +33,6 @@ class AppState {
autoPlay: autoPlay ?? this.autoPlay,
loop: loop ?? this.loop,
volume: volume ?? this.volume,
isMaximized: isMaximized ?? this.isMaximized,
isFullScreen: isFullScreen ?? this.isFullScreen,
isMuted: isMuted ?? this.isMuted,
theme: theme ?? this.theme,
subtitleLanguage: subtitleLanguage ?? this.subtitleLanguage,
Expand All @@ -53,8 +45,6 @@ class AppState {
'autoPlay': autoPlay,
'loop': loop,
'volume': volume,
'isMaximized': isMaximized,
'isFullScreen': isFullScreen,
'isMuted': isMuted,
'theme': theme,
'subtitleLanguage': subtitleLanguage,
Expand All @@ -68,8 +58,6 @@ class AppState {
autoPlay: json['autoPlay'] ?? true,
loop: json['loop'] ?? false,
volume: json['volume'] ?? 100,
isMaximized: json['isMaximized'] ?? false,
isFullScreen: json['isFullScreen'] ?? false,
isMuted: json['isMuted'] ?? false,
theme: json['theme'] ?? 'auto',
subtitleLanguage: json['subtitleLanguage'] ?? 'auto',
Expand Down
63 changes: 39 additions & 24 deletions lib/pages/player/control_bar.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'dart:io';
import 'dart:ui';
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
Expand All @@ -7,11 +8,10 @@ import 'package:iris/hooks/use_player_core.dart';
import 'package:iris/models/storages/local_storage.dart';
import 'package:iris/pages/player/subtitles_menu_button.dart';
import 'package:iris/pages/settings/settings.dart';
import 'package:iris/store/use_app_store.dart';
import 'package:iris/store/use_play_queue_store.dart';
import 'package:iris/utils/get_localizations.dart';
import 'package:iris/utils/is_desktop.dart';
import 'package:iris/pages/player/play_queue.dart';
import 'package:iris/utils/resize_window.dart';
import 'package:iris/widgets/show_popup.dart';
import 'package:iris/pages/storages/storages.dart';
import 'package:window_manager/window_manager.dart';
Expand Down Expand Up @@ -39,8 +39,9 @@ class ControlBar extends HookWidget {
@override
Widget build(BuildContext context) {
final t = getLocalizations(context);
final isFullScreen =
useAppStore().select(context, (state) => state.isFullScreen);
bool isDesktop = useMemoized(
(() => Platform.isWindows || Platform.isLinux || Platform.isMacOS));

final playQueueLength =
usePlayQueueStore().select(context, (state) => state.playQueue.length);
final currentIndex =
Expand All @@ -64,7 +65,8 @@ class ControlBar extends HookWidget {
Text(
formatDurationToMinutes(playerCore.position),
style: TextStyle(
color: Theme.of(context).colorScheme.onSurface,
color:
Theme.of(context).colorScheme.onSurfaceVariant,
fontSize: 14,
decoration: TextDecoration.none),
),
Expand All @@ -73,7 +75,7 @@ class ControlBar extends HookWidget {
data: SliderTheme.of(context).copyWith(
thumbColor: Theme.of(context)
.colorScheme
.onSurface
.onSurfaceVariant
.withAlpha(222),
thumbShape: const RoundSliderThumbShape(
enabledThumbRadius: 6,
Expand All @@ -86,11 +88,11 @@ class ControlBar extends HookWidget {
overlayRadius: 12),
activeTrackColor: Theme.of(context)
.colorScheme
.onSurface
.onSurfaceVariant
.withOpacity(0.75),
inactiveTrackColor: Theme.of(context)
.colorScheme
.onSurface
.onSurfaceVariant
.withOpacity(0.5),
trackHeight: 4,
),
Expand Down Expand Up @@ -119,7 +121,8 @@ class ControlBar extends HookWidget {
Text(
formatDurationToMinutes(playerCore.duration),
style: TextStyle(
color: Theme.of(context).colorScheme.onSurface,
color:
Theme.of(context).colorScheme.onSurfaceVariant,
fontSize: 14,
decoration: TextDecoration.none),
),
Expand Down Expand Up @@ -208,7 +211,7 @@ class ControlBar extends HookWidget {
if (playerCore.playing == true) {
playerController.pause();
} else {
if (isDesktop()) {
if (isDesktop) {
windowManager.setTitle(playerCore.title);
}
playerController.play();
Expand Down Expand Up @@ -256,21 +259,33 @@ class ControlBar extends HookWidget {
child: SubtitlesMenuButton(playerCore: playerCore),
),
Visibility(
visible: isDesktop() &&
visible: isDesktop &&
MediaQuery.of(context).size.width > 600,
child: IconButton(
tooltip: isFullScreen
? t.exit_fullscreen
: t.enter_fullscreen,
icon: Icon(
isFullScreen
? Icons.close_fullscreen_rounded
: Icons.open_in_full_rounded,
size: 18,
),
onPressed: () {
showControl();
useAppStore().toggleFullScreen();
child: FutureBuilder<bool>(
future: windowManager.isFullScreen(),
builder: (BuildContext context,
AsyncSnapshot<bool> snapshot) {
final isFullScreen = snapshot.data ?? false;
return IconButton(
tooltip: isFullScreen
? t.exit_fullscreen
: t.enter_fullscreen,
icon: Icon(
isFullScreen
? Icons.close_fullscreen_rounded
: Icons.open_in_full_rounded,
size: 18,
),
onPressed: () async {
showControl();
if (isFullScreen) {
await windowManager.setFullScreen(false);
await resizeWindow(playerCore.aspectRatio);
} else {
await windowManager.setFullScreen(true);
}
},
);
},
),
),
Expand Down
Loading

0 comments on commit ca34fe1

Please sign in to comment.