diff --git a/android/app/build.gradle.kts b/android/app/build.gradle.kts index f41fa4c..320eca6 100644 --- a/android/app/build.gradle.kts +++ b/android/app/build.gradle.kts @@ -17,11 +17,11 @@ android { namespace = "com.driftinblock.zvmanager" compileSdk { version = release(37) { - minorApiLevel = 1 + minorApiLevel = 2 } } buildToolsVersion = "37.0.0" - ndkVersion = "30.0.16138531" + ndkVersion = "30.0.16248370" compileOptions { isCoreLibraryDesugaringEnabled = true @@ -35,12 +35,6 @@ android { targetSdk = 37 versionCode = flutter.versionCode versionName = flutter.versionName - - // 仅保留 ARMv8 (arm64-v8a):先清空默认集合再添加,排除 ARMv7 与 x86_64 - ndk { - abiFilters.clear() - abiFilters.add("arm64-v8a") - } } signingConfigs { diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index 6216aef..b91a393 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -13,7 +13,7 @@ android:name=".MainActivity" android:exported="true" android:launchMode="singleTop" - android:taskAZV Manager + android:taskAffinity="" android:theme="@style/LaunchTheme" android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode" android:hardwareAccelerated="true" diff --git a/android/build.gradle.kts b/android/build.gradle.kts index 362da11..896a12a 100644 --- a/android/build.gradle.kts +++ b/android/build.gradle.kts @@ -28,7 +28,7 @@ gradle.beforeProject { } if (field != null) { field.isAccessible = true - field.set(flutterExt, "30.0.16138531") + field.set(flutterExt, "30.0.16248370") } } catch (e: Exception) { logger.warn("无法反射修改 flutter.ndkVersion: ${e.message}") @@ -51,7 +51,7 @@ gradle.beforeProject { val libExt = extensions.findByType() if (libExt != null) { libExt.compileSdk = 37 - libExt.compileSdkMinor = 1 + libExt.compileSdkMinor = 2 } } } diff --git a/android/gradle/wrapper/gradle-wrapper.jar b/android/gradle/wrapper/gradle-wrapper.jar index 13372ae..eddabd2 100644 Binary files a/android/gradle/wrapper/gradle-wrapper.jar and b/android/gradle/wrapper/gradle-wrapper.jar differ diff --git a/android/gradle/wrapper/gradle-wrapper.properties b/android/gradle/wrapper/gradle-wrapper.properties index ffcd530..9b7cb4a 100644 --- a/android/gradle/wrapper/gradle-wrapper.properties +++ b/android/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,9 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-9.8.0-bin.zip +networkTimeout=10000 +retries=0 +retryBackOffMs=500 +validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-9.7.1-all.zip diff --git a/android/gradlew b/android/gradlew old mode 100644 new mode 100755 index 9d82f78..249efbb --- a/android/gradlew +++ b/android/gradlew @@ -1,74 +1,128 @@ -#!/usr/bin/env bash +#!/bin/sh + +# +# Copyright © 2015 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 +# ############################################################################## -## -## Gradle start up script for UN*X -## +# +# gradlew start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh gradlew +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/3d91ce3b8caaf77ad09f381f43615b715b53f72c/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# ############################################################################## -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS="" +# Attempt to set APP_HOME -APP_NAME="Gradle" -APP_BASE_NAME=`basename "$0"` +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD="maximum" +MAX_FD=maximum -warn ( ) { +warn () { echo "$*" -} +} >&2 -die ( ) { +die () { echo echo "$*" echo exit 1 -} +} >&2 # OS specific support (must be 'true' or 'false'). cygwin=false msys=false darwin=false -case "`uname`" in - CYGWIN* ) - cygwin=true - ;; - Darwin* ) - darwin=true - ;; - MINGW* ) - msys=true - ;; +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; esac -# Attempt to set APP_HOME -# Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi -done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >/dev/null -APP_HOME="`pwd -P`" -cd "$SAVED" >/dev/null -CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar # Determine the Java command to use to start the JVM. if [ -n "$JAVA_HOME" ] ; then if [ -x "$JAVA_HOME/jre/sh/java" ] ; then # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" + JAVACMD=$JAVA_HOME/jre/sh/java else - JAVACMD="$JAVA_HOME/bin/java" + JAVACMD=$JAVA_HOME/bin/java fi if [ ! -x "$JAVACMD" ] ; then die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME @@ -77,84 +131,118 @@ Please set the JAVA_HOME variable in your environment to match the location of your Java installation." fi else - JAVACMD="java" - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + JAVACMD=java + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation." + fi fi # Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then - MAX_FD_LIMIT=`ulimit -H -n` - if [ $? -eq 0 ] ; then - if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then - MAX_FD="$MAX_FD_LIMIT" - fi - ulimit -n $MAX_FD - if [ $? -ne 0 ] ; then - warn "Could not set maximum file descriptor limit: $MAX_FD" - fi - else - warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" - fi -fi - -# For Darwin, add options to specify how the application appears in the dock -if $darwin; then - GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" -fi - -# For Cygwin, switch paths to Windows format before running java -if $cygwin ; then - APP_HOME=`cygpath --path --mixed "$APP_HOME"` - CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` - JAVACMD=`cygpath --unix "$JAVACMD"` - - # We build the pattern for arguments to be converted via cygpath - ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` - SEP="" - for dir in $ROOTDIRSRAW ; do - ROOTDIRS="$ROOTDIRS$SEP$dir" - SEP="|" - done - OURCYGPATTERN="(^($ROOTDIRS))" - # Add a user-defined pattern to the cygpath arguments - if [ "$GRADLE_CYGPATTERN" != "" ] ; then - OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" - fi - # Now convert the arguments - kludge to limit ourselves to /bin/sh - i=0 - for arg in "$@" ; do - CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` - CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option - - if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition - eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` - else - eval `echo args$i`="\"$arg\"" - fi - i=$((i+1)) - done - case $i in - (0) set -- ;; - (1) set -- "$args0" ;; - (2) set -- "$args0" "$args1" ;; - (3) set -- "$args0" "$args1" "$args2" ;; - (4) set -- "$args0" "$args1" "$args2" "$args3" ;; - (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" esac fi -# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules -function splitJvmOpts() { - JVM_OPTS=("$@") -} -eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS -JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. -exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/android/gradlew.bat b/android/gradlew.bat index 8a0b282..a51ec4f 100644 --- a/android/gradlew.bat +++ b/android/gradlew.bat @@ -1,90 +1,82 @@ -@if "%DEBUG%" == "" @echo off +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem +@rem SPDX-License-Identifier: Apache-2.0 +@rem + +@if "%DEBUG%"=="" @echo off @rem ########################################################################## @rem -@rem Gradle startup script for Windows +@rem gradlew startup script for Windows @rem @rem ########################################################################## -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal - -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS= +@rem Set local scope for the variables, and ensure extensions are enabled +setlocal EnableExtensions set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + @rem Find java.exe if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto init +if %ERRORLEVEL% equ 0 goto execute -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 -goto fail +"%COMSPEC%" /c exit 1 :findJavaFromJavaHome set JAVA_HOME=%JAVA_HOME:"=% set JAVA_EXE=%JAVA_HOME%/bin/java.exe -if exist "%JAVA_EXE%" goto init +if exist "%JAVA_EXE%" goto execute -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 -goto fail - -:init -@rem Get command-line arguments, handling Windowz variants - -if not "%OS%" == "Windows_NT" goto win9xME_args -if "%@eval[2+2]" == "4" goto 4NT_args - -:win9xME_args -@rem Slurp the command line arguments. -set CMD_LINE_ARGS= -set _SKIP=2 - -:win9xME_args_slurp -if "x%~1" == "x" goto execute - -set CMD_LINE_ARGS=%* -goto execute - -:4NT_args -@rem Get arguments from the 4NT Shell from JP Software -set CMD_LINE_ARGS=%$ +"%COMSPEC%" /c exit 1 :execute @rem Setup the command line -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar -@rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% -:end -@rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd +@rem Execute gradlew +@rem endlocal doesn't take effect until after the line is parsed and variables are expanded +@rem which allows us to clear the local environment before executing the java command +endlocal & "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %* & call :exitWithErrorLevel -:fail -rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of -rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 - -:mainEnd -if "%OS%"=="Windows_NT" endlocal - -:omega +:exitWithErrorLevel +@rem Use "%COMSPEC%" /c exit to allow operators to work properly in scripts +"%COMSPEC%" /c exit %ERRORLEVEL% diff --git a/lib/app.dart b/lib/app.dart index 9efd141..a64aa93 100644 --- a/lib/app.dart +++ b/lib/app.dart @@ -3,9 +3,11 @@ import 'package:flutter/material.dart'; import 'package:flutter_localizations/flutter_localizations.dart'; import 'package:package_info_plus/package_info_plus.dart'; import 'package:provider/provider.dart'; +import 'package:shared_preferences/shared_preferences.dart'; import 'core/theme/app_theme.dart'; import 'core/utils/update_service.dart'; import 'core/widgets/background_widget.dart'; +import 'core/widgets/user_agreement_dialog.dart'; // 新增 import 'features/server_list/server_list_page.dart'; import 'providers/theme_provider.dart'; import 'providers/server_provider.dart'; @@ -23,9 +25,35 @@ class ZVManagerApp extends StatefulWidget { class ZVManagerAppState extends State { final GlobalKey _bgKey = GlobalKey(); + bool _showAgreement = false; + bool _isReady = false; + @override void initState() { super.initState(); + _checkAgreement(); + } + + // 新增:检查是否已同意用户守则 + Future _checkAgreement() async { + final prefs = await SharedPreferences.getInstance(); + final agreed = prefs.getBool('user_agreed') ?? false; + setState(() { + _showAgreement = !agreed; + _isReady = true; + }); + if (agreed) { + _checkUpdateSilently(); + } + } + + // 新增:同意后保存并进入 + Future _onAgree() async { + final prefs = await SharedPreferences.getInstance(); + await prefs.setBool('user_agreed', true); + setState(() { + _showAgreement = false; + }); _checkUpdateSilently(); } @@ -81,7 +109,21 @@ class ZVManagerAppState extends State { builder: (context, child) { return BackgroundWidget( key: _bgKey, - child: child!, + child: Stack( + children: [ + child!, + // 新增:用户守则弹窗 + if (_isReady && _showAgreement) + Positioned.fill( + child: Container( + color: Colors.black.withOpacity(0.6), + child: Center( + child: UserAgreementDialog(onAgree: _onAgree), + ), + ), + ), + ], + ), ); }, ); diff --git a/lib/core/widgets/background_widget.dart b/lib/core/widgets/background_widget.dart index 23fe2ea..d1fc2f5 100644 --- a/lib/core/widgets/background_widget.dart +++ b/lib/core/widgets/background_widget.dart @@ -12,27 +12,44 @@ class BackgroundWidget extends StatefulWidget { State createState() => BackgroundWidgetState(); } -// 导出 State 供外部调用 -class BackgroundWidgetState extends State { +class BackgroundWidgetState extends State + with WidgetsBindingObserver { VideoPlayerController? _controller; + FileImage? _cachedImage; String? _currentType; String? _currentPath; bool _isLoading = true; + bool _isInForeground = true; @override void initState() { super.initState(); + WidgetsBinding.instance.addObserver(this); _loadBackground(); } + @override + void didChangeAppLifecycleState(AppLifecycleState state) { + // 后台时暂停视频,省电 + 减少卡顿 + if (state == AppLifecycleState.paused) { + _isInForeground = false; + _controller?.pause(); + } else if (state == AppLifecycleState.resumed) { + _isInForeground = true; + if (_controller != null && _controller!.value.isInitialized) { + _controller!.play(); + } + } + } + Future _loadBackground() async { final data = await BackgroundService.getBackground(); final type = data['type']; final path = data['path']; - // 如果没变化就不重新加载 + // 路径没变,不重新加载 if (_currentType == type && _currentPath == path && _controller != null) { - setState(() => _isLoading = false); + if (mounted) setState(() => _isLoading = false); return; } @@ -44,78 +61,113 @@ class BackgroundWidgetState extends State { _currentType = type; _currentPath = path; + _cachedImage = null; + // ===== 视频背景 ===== if (type == 'video' && path != null) { try { + final file = File(path); + if (!file.existsSync()) { + if (mounted) setState(() => _isLoading = false); + return; + } + final videoSound = await BackgroundService.getVideoSound(); - final controller = VideoPlayerController.file(File(path)); - await controller.initialize(); + final controller = VideoPlayerController.file(file); + + // 超时保护,避免卡住 + await controller.initialize().timeout( + const Duration(seconds: 10), + onTimeout: () { + throw Exception('视频初始化超时'); + }, + ); + controller.setLooping(true); controller.setVolume(videoSound ? 1.0 : 0.0); - controller.play(); - setState(() { - _controller = controller; - _isLoading = false; - }); + if (_isInForeground) controller.play(); + + if (mounted) { + setState(() { + _controller = controller; + _isLoading = false; + }); + } return; } catch (e) { - print('视频加载失败: $e'); + debugPrint('视频加载失败: $e'); } } - setState(() => _isLoading = false); + // ===== 图片背景 ===== + if (type == 'image' && path != null) { + final file = File(path); + if (file.existsSync()) { + _cachedImage = FileImage(file); + } + } + + if (mounted) setState(() => _isLoading = false); } - // 供外部调用的刷新方法 + /// 供外部调用刷新壁纸 void refreshBackground() { _loadBackground(); } @override void dispose() { + WidgetsBinding.instance.removeObserver(this); _controller?.dispose(); super.dispose(); } @override Widget build(BuildContext context) { - if (_isLoading) { - return widget.child; - } + // 还在加载,直接显示子组件 + if (_isLoading) return widget.child; - // 有视频背景 + // ===== 视频背景 ===== if (_controller != null && _controller!.value.isInitialized) { - return Stack( - fit: StackFit.expand, - children: [ - SizedBox.expand( - child: FittedBox( - fit: BoxFit.cover, - child: SizedBox( - width: _controller!.value.size.width, - height: _controller!.value.size.height, - child: VideoPlayer(_controller!), + return RepaintBoundary( + child: Stack( + fit: StackFit.expand, + children: [ + SizedBox.expand( + child: FittedBox( + fit: BoxFit.cover, + child: SizedBox( + width: _controller!.value.size.width, + height: _controller!.value.size.height, + child: VideoPlayer(_controller!), + ), ), ), - ), - Container(color: Colors.black.withOpacity(0.3)), - _wrapWithTransparentTheme(widget.child), - ], + Container(color: Colors.black.withOpacity(0.3)), + _wrapWithTransparentTheme(widget.child), + ], + ), ); } - // 有图片背景 - if (_currentType == 'image' && _currentPath != null) { - return Stack( - fit: StackFit.expand, - children: [ - Image.file(File(_currentPath!), fit: BoxFit.cover), - _wrapWithTransparentTheme(widget.child), - ], + // ===== 图片背景 ===== + if (_cachedImage != null) { + return RepaintBoundary( + child: Stack( + fit: StackFit.expand, + children: [ + Image( + image: _cachedImage!, + fit: BoxFit.cover, + gaplessPlayback: true, // 避免切换时闪白 + ), + _wrapWithTransparentTheme(widget.child), + ], + ), ); } - // 无背景 + // ===== 无背景 ===== return widget.child; } diff --git a/lib/core/widgets/user_agreement_dialog.dart b/lib/core/widgets/user_agreement_dialog.dart new file mode 100644 index 0000000..6171366 --- /dev/null +++ b/lib/core/widgets/user_agreement_dialog.dart @@ -0,0 +1,188 @@ +import 'package:flutter/material.dart'; +import 'package:shared_preferences/shared_preferences.dart'; + +class UserAgreementDialog extends StatefulWidget { + final VoidCallback onAgree; + + const UserAgreementDialog({super.key, required this.onAgree}); + + @override + State createState() => _UserAgreementDialogState(); +} + +class _UserAgreementDialogState extends State { + bool _isChecked = false; + + @override + Widget build(BuildContext context) { + return WillPopScope( + onWillPop: () async => false, + child: Dialog( + shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)), + insetPadding: const EdgeInsets.symmetric(horizontal: 20), + child: Container( + width: double.infinity, + padding: const EdgeInsets.all(24), + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + // 图标 + const Text('📜', style: TextStyle(fontSize: 48)), + const SizedBox(height: 12), + + // 标题 + const Text( + '用户守则', + style: TextStyle( + fontSize: 22, + fontWeight: FontWeight.bold, + color: Color(0xFF1A1A2E), + ), + ), + const SizedBox(height: 16), + + // 内容 + Container( + height: 260, + padding: const EdgeInsets.all(16), + decoration: BoxDecoration( + color: const Color(0xFFF8F9FA), + borderRadius: BorderRadius.circular(12), + border: Border.all(color: const Color(0xFFE0E0E0)), + ), + child: const SingleChildScrollView( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + _SectionTitle('一、总则'), + _SectionText('欢迎使用 ZV Manager。本守则旨在规范用户行为,保障服务器与用户权益。使用本软件即表示你已阅读并同意本守则。'), + + _SectionTitle('二、使用规范'), + _SectionText('1. 本软件仅供 Minecraft 服务器管理使用,不得用于任何违法用途。'), + _SectionText('2. 不得利用本软件对他人服务器进行未经授权的访问或攻击。'), + _SectionText('3. 不得利用本软件传播违法信息或进行任何破坏行为。'), + + _SectionTitle('三、账号与安全'), + _SectionText('1. 请妥善保管你的 RCON 密码,因密码泄露造成的损失由用户自行承担。'), + _SectionText('2. 本软件采用加密方式存储密码,但不对因设备丢失导致的信息泄露负责。'), + + _SectionTitle('四、免责声明'), + _SectionText('1. 本软件为社区开源项目,并非 Mojang Studios 或 Microsoft 官方产品。'), + _SectionText('2. 使用本软件产生的任何后果由用户自行承担。'), + _SectionText('3. 开发者保留随时修改本守则的权利。'), + + _SectionTitle('五、其他'), + _SectionText('本守则最终解释权归 ZV Team 所有。如有疑问,请联系开发者。'), + + SizedBox(height: 16), + Text( + '© 2026 ZV Team · 与 Mojang 无关', + style: TextStyle(fontSize: 12, color: Color(0xFF999999)), + ), + ], + ), + ), + ), + const SizedBox(height: 16), + + // 同意勾选 + GestureDetector( + onTap: () { + setState(() { + _isChecked = !_isChecked; + }); + }, + child: Row( + children: [ + SizedBox( + width: 24, + height: 24, + child: Checkbox( + value: _isChecked, + onChanged: (value) { + setState(() { + _isChecked = value ?? false; + }); + }, + activeColor: const Color(0xFF28A745), + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(4), + ), + ), + ), + const SizedBox(width: 8), + const Text( + '我已阅读并同意《用户守则》', + style: TextStyle(fontSize: 14, color: Color(0xFF555555)), + ), + ], + ), + ), + const SizedBox(height: 16), + + // 按钮 + SizedBox( + width: double.infinity, + child: FilledButton( + onPressed: _isChecked ? widget.onAgree : null, + style: FilledButton.styleFrom( + backgroundColor: const Color(0xFF28A745), + disabledBackgroundColor: const Color(0xFFCCCCCC), + padding: const EdgeInsets.symmetric(vertical: 14), + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(12), + ), + ), + child: const Text( + '同意并进入', + style: TextStyle(fontSize: 16, fontWeight: FontWeight.w600), + ), + ), + ), + ], + ), + ), + ), + ); + } +} + +class _SectionTitle extends StatelessWidget { + final String text; + const _SectionTitle(this.text); + + @override + Widget build(BuildContext context) { + return Padding( + padding: const EdgeInsets.only(top: 12, bottom: 4), + child: Text( + text, + style: const TextStyle( + fontSize: 14, + fontWeight: FontWeight.bold, + color: Color(0xFF1A1A2E), + ), + ), + ); + } +} + +class _SectionText extends StatelessWidget { + final String text; + const _SectionText(this.text); + + @override + Widget build(BuildContext context) { + return Padding( + padding: const EdgeInsets.only(bottom: 4), + child: Text( + text, + style: const TextStyle( + fontSize: 13, + color: Color(0xFF666666), + height: 1.6, + ), + ), + ); + } +} \ No newline at end of file diff --git a/lib/features/settings/settings_page.dart b/lib/features/settings/settings_page.dart index e8753b6..c0388f9 100644 --- a/lib/features/settings/settings_page.dart +++ b/lib/features/settings/settings_page.dart @@ -130,13 +130,10 @@ class _SettingsPageState extends State { } Future _pickVideo() async { - final result = await FilePicker.pickFiles( - type: FileType.video, - allowMultiple: false, - ); - if (result.isEmpty) return; + final result = await FilePicker.pickFile(type: FileType.video); + if (result == null) return; - final filePath = result.single.path; + final filePath = result.path; if (filePath == null) return; final path = await _saveFileToAssets(filePath, 'video'); diff --git a/pubspec.yaml b/pubspec.yaml index 213b971..9d68756 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: zv_manager description: Minecraft服务器管理工具 -version: 1.5.3+10 +version: 1.5.4+11 environment: sdk: ">=3.0.0 <4.0.0" @@ -16,7 +16,7 @@ dependencies: package_info_plus: ^10.2.1 video_player: ^2.8.1 image_picker: ^1.0.4 - file_picker: ^12.0.0 + file_picker: ^13.1.0 path_provider: ^2.1.1 dev_dependencies: diff --git a/zvmanager-main.zip b/zvmanager-main.zip deleted file mode 100644 index 6042e2c..0000000 Binary files a/zvmanager-main.zip and /dev/null differ