diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index c749c04..bf3ba78 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -16,99 +16,498 @@ on: - '**/integration_test/**' - '.github/workflows/checks.yml' +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +env: + # The version of Flutter to use should use the minimum Dart SDK version supported by the package. + # Current minimum (N-1 logic) + FLUTTER_VERSION_MINIMUM_DEFAULT: "3.38.10" + # Latest 3.x stable + FLUTTER_VERSION_LATEST_STABLE_CHANNEL_DEFAULT: "3.x" + # Beta channel support + FLUTTER_VERSION_BETA_CHANNEL_DEFAULT: "beta" + jobs: + setup_matrix: + name: Determine Flutter Test Versions + runs-on: ubuntu-latest + outputs: + flutter_versions_json: ${{ steps.set_versions.outputs.versions_json }} + steps: + - name: Determine Flutter versions + id: set_versions + run: | + MIN="${{ env.FLUTTER_VERSION_MINIMUM_DEFAULT }}" + STABLE="${{ env.FLUTTER_VERSION_LATEST_STABLE_CHANNEL_DEFAULT }}" + BETA="${{ env.FLUTTER_VERSION_BETA_CHANNEL_DEFAULT }}" + + # Create JSON array: ["3.38.10", "3.x", "beta"] + VERSIONS_JSON=$(jq -c --null-input '$ARGS.positional' --args "$MIN" "$STABLE" "$BETA") + echo "versions_json=$VERSIONS_JSON" >> $GITHUB_OUTPUT + analyze: - timeout-minutes: 11 + needs: setup_matrix + timeout-minutes: 15 runs-on: ubuntu-latest - name: ${{ matrix.package }} analysis on ${{ matrix.channel }} + name: ${{ matrix.package }} analysis on ${{ matrix.flutter_version }} strategy: matrix: - channel: - - 'stable' - - 'beta' - package: - - 'wakelock_plus' - - 'wakelock_plus_platform_interface' + flutter_version: ${{ fromJson(needs.setup_matrix.outputs.flutter_versions_json) }} + package: [wakelock_plus, wakelock_plus_platform_interface] fail-fast: false - steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v6 - uses: subosito/flutter-action@v2 with: - channel: ${{ matrix.channel }} - - run: flutter pub get + # Logic: If version contains a dot or 'x', it's a version/3.x. Otherwise (beta), it's a channel. + flutter-version: ${{ (contains(matrix.flutter_version, '.') || contains(matrix.flutter_version, 'x')) && matrix.flutter_version || '' }} + channel: ${{ (!contains(matrix.flutter_version, '.') && !contains(matrix.flutter_version, 'x')) && matrix.flutter_version || '' }} + cache: true + cache-key: flutter-:os:-:channel:-:version:-:arch:-:hash:-${{ hashFiles('**/pubspec.lock') }} + + - name: Install dependencies + # --no-example is crucial here so that we only get the library's dependencies + run: flutter pub get --no-example working-directory: ${{ matrix.package }} + - name: Check format - working-directory: ${{ matrix.package }} + # Ensure CI fails if code isn't formatted according to dart style run: dart format . --set-exit-if-changed - # Ignoring formatting issues for now, as we're still supporting versions of Flutter below - # 3.29. - # Once the minimum supported version is 3.29 or later, we can enforce this on more recent - # versions. - continue-on-error: true - - run: flutter analyze working-directory: ${{ matrix.package }} + # Only skip errors if we're on the minimum default version, + # or if we're running the beta channel. + # The only version that matters as far as formatting is concerned is the latest version. + continue-on-error: ${{ matrix.flutter_version == env.FLUTTER_VERSION_MINIMUM_DEFAULT || matrix.flutter_version == env.FLUTTER_VERSION_BETA_CHANNEL_DEFAULT }} - test: - timeout-minutes: 30 - # Using macOS 13 Ventura due to https://github.com/flutter/flutter/issues/118469 - runs-on: macos-13 - name: ${{ matrix.package }} testing on ${{ matrix.channel }} with ${{ matrix.device }} + - name: Analyze + # We explicitly analyze only lib and test to ignore the example app's integration tests + run: flutter analyze lib test + working-directory: ${{ matrix.package }} + + unit_tests: + needs: setup_matrix + runs-on: ubuntu-latest + name: ${{ matrix.package }} unit tests on ${{ matrix.flutter_version }} strategy: matrix: - device: - - 'iPhone 14 Pro Simulator (17.2)' - - 'iPhone 14 Pro Max Simulator (17.2)' - channel: - - 'stable' - - 'beta' - package: - - 'wakelock_plus' - - 'wakelock_plus_platform_interface' + flutter_version: ${{ fromJson(needs.setup_matrix.outputs.flutter_versions_json) }} + package: [wakelock_plus, wakelock_plus_platform_interface] fail-fast: false - steps: - - name: Start iOS simulator - if: matrix.package == 'wakelock_plus' - # Using gawk to be able to use my regex to separate the IDs from the device names - # (because my awk skills suck) to then pipe that to awk to find the right device. - run: | - # Work around an upstream issue with the runner image: - # https://github.com/actions/runner-images/issues/8500 - brew upgrade || brew link --overwrite python@3.12 - brew install gawk - xcrun xctrace list devices - UDID=$( - xcrun xctrace list devices | - gawk 'match($0, /(.+) \(([^.]*)\)/, a) { printf "%s,%s\n", a[1], a[2] }' | - awk -F ',' -v 'device=${{ matrix.device }}' '$1 == device { print $2 }' - ) - xcrun simctl boot "${UDID:?simulator not found}" - - uses: actions/checkout@v4 + - uses: actions/checkout@v6 - uses: subosito/flutter-action@v2 with: - channel: ${{ matrix.channel }} - - run: flutter pub get + flutter-version: ${{ (contains(matrix.flutter_version, '.') || contains(matrix.flutter_version, 'x')) && matrix.flutter_version || '' }} + channel: ${{ (!contains(matrix.flutter_version, '.') && !contains(matrix.flutter_version, 'x')) && matrix.flutter_version || '' }} + cache: true + cache-key: flutter-:os:-:channel:-:version:-:arch:-:hash:-${{ hashFiles('**/pubspec.lock') }} + + - name: Install dependencies + run: flutter pub get --no-example working-directory: ${{ matrix.package }} - - name: Run unit tests (tester) - if: matrix.package == 'wakelock_plus' + + - name: Run unit tests run: flutter test working-directory: ${{ matrix.package }} - # For some reason, Web tests are currently not working. - # - name: Run unit tests (chrome) - # if: matrix.package == 'wakelock_plus' - # run: | - # flutter config --enable-web - # flutter test --platform chrome - # working-directory: ${{ matrix.package }} - - name: Integration tests on iOS - if: matrix.package == 'wakelock_plus' + + # --- ANDROID --- + + android_example_build: + needs: setup_matrix + runs-on: ubuntu-latest + timeout-minutes: 30 + strategy: + matrix: + flutter_version: ${{ fromJson(needs.setup_matrix.outputs.flutter_versions_json) }} + name: Android Example Build (${{ matrix.flutter_version }}) + steps: + - uses: actions/checkout@v6 + - name: Install dependencies (Linux build hosts) + run: | + sudo apt-get update + sudo apt-get install -y clang cmake ninja-build pkg-config libgtk-3-dev liblzma-dev + - uses: subosito/flutter-action@v2 + with: + flutter-version: ${{ (contains(matrix.flutter_version, '.') || contains(matrix.flutter_version, 'x')) && matrix.flutter_version || '' }} + channel: ${{ (!contains(matrix.flutter_version, '.') && !contains(matrix.flutter_version, 'x')) && matrix.flutter_version || '' }} + cache: true + cache-key: flutter-:os:-:channel:-:version:-:arch:-:hash:-${{ hashFiles('**/pubspec.lock') }} + - name: Build Android APK + run: | + cd wakelock_plus/example + flutter pub get + flutter build apk --debug --target=./lib/main.dart + + android_integration_test: + needs: setup_matrix + runs-on: ubuntu-latest + timeout-minutes: 60 + strategy: + matrix: + flutter_version: ${{ fromJson(needs.setup_matrix.outputs.flutter_versions_json) }} + # 24: Min SDK (Nougat) + # 28: Pre-Scoped Storage / Legacy (Pie) + # 31: Android 12 (S) - Significant splash screen and permission changes + # 33: Android 13 (T) - Granular media permissions + # 35: Android 15 (Latest Stable) + api-level: [24, 28, 31, 33, 35] + fail-fast: false + name: Android Integration Test (API ${{ matrix.api-level }} - ${{ matrix.flutter_version }}) + steps: + - uses: actions/checkout@v6 + - uses: subosito/flutter-action@v2 + with: + flutter-version: ${{ (contains(matrix.flutter_version, '.') || contains(matrix.flutter_version, 'x')) && matrix.flutter_version || '' }} + channel: ${{ (!contains(matrix.flutter_version, '.') && !contains(matrix.flutter_version, 'x')) && matrix.flutter_version || '' }} + cache: true + cache-key: flutter-:os:-:channel:-:version:-:arch:-:hash:-${{ hashFiles('**/pubspec.lock') }} + + - name: Enable KVM + # Linux runners require KVM to run Android emulators with hardware acceleration + run: | + echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules + sudo udevadm control --reload-rules + sudo udevadm trigger --name-match=kvm + + - name: Run Integration Tests + uses: reactivecircus/android-emulator-runner@v2 + with: + api-level: ${{ matrix.api-level }} + target: google_apis + arch: x86_64 + force-avd-creation: false + emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none + disable-animations: true + working-directory: wakelock_plus/example + # We use a single line here because the emulator-runner's script block often misinterprets backslashes + script: flutter drive --driver=test_driver/integration_test.dart --target=integration_test/wakelock_plus_test.dart + + # --- IOS --- + + ios_example_build: + needs: setup_matrix + runs-on: macos-26 + timeout-minutes: 30 + strategy: + matrix: + flutter_version: ${{ fromJson(needs.setup_matrix.outputs.flutter_versions_json) }} + name: iOS Example Build (${{ matrix.flutter_version }}) + steps: + - uses: actions/checkout@v6 + - uses: subosito/flutter-action@v2 + with: + flutter-version: ${{ (contains(matrix.flutter_version, '.') || contains(matrix.flutter_version, 'x')) && matrix.flutter_version || '' }} + channel: ${{ (!contains(matrix.flutter_version, '.') && !contains(matrix.flutter_version, 'x')) && matrix.flutter_version || '' }} + cache: true + cache-key: flutter-:os:-:channel:-:version:-:arch:-:hash:-${{ hashFiles('**/pubspec.lock') }} + - name: Build iOS run: | cd wakelock_plus/example - flutter drive --driver=test_driver/integration_test.dart --target=integration_test/wakelock_plus_test.dart - - name: Integration tests on macOS - if: matrix.package == 'wakelock_plus' + flutter pub get + flutter build ios --no-codesign --debug --target=./lib/main.dart + + ios_integration_test: + needs: setup_matrix + # Per requirements: macOS-26 runner is required to access the iPhone 17 simulator environment + runs-on: macos-26 + timeout-minutes: 60 + strategy: + matrix: + flutter_version: ${{ fromJson(needs.setup_matrix.outputs.flutter_versions_json) }} + name: iOS Integration Test (${{ matrix.flutter_version }}) + steps: + - uses: actions/checkout@v6 + - uses: subosito/flutter-action@v2 + with: + flutter-version: ${{ (contains(matrix.flutter_version, '.') || contains(matrix.flutter_version, 'x')) && matrix.flutter_version || '' }} + channel: ${{ (!contains(matrix.flutter_version, '.') && !contains(matrix.flutter_version, 'x')) && matrix.flutter_version || '' }} + cache: true + cache-key: flutter-:os:-:channel:-:version:-:arch:-:hash:-${{ hashFiles('**/pubspec.lock') }} + + - name: Start iOS simulator + # Using standard simulator-action to handle the simulator lifecycle on macOS-26 + uses: futureware-tech/simulator-action@v5 + with: + model: 'iPhone 17' + wait_for_boot: true + boot_timeout_seconds: 600 + boot_retries: 5 + + - name: Run Integration Tests run: | cd wakelock_plus/example + flutter pub get + flutter drive \ + --driver=test_driver/integration_test.dart \ + --target=integration_test/wakelock_plus_test.dart + + # --- MACOS --- + + macos_example_build: + needs: setup_matrix + runs-on: macos-26 + timeout-minutes: 30 + strategy: + matrix: + flutter_version: ${{ fromJson(needs.setup_matrix.outputs.flutter_versions_json) }} + name: macOS Example Build (${{ matrix.flutter_version }}) + steps: + - uses: actions/checkout@v6 + - uses: subosito/flutter-action@v2 + with: + flutter-version: ${{ (contains(matrix.flutter_version, '.') || contains(matrix.flutter_version, 'x')) && matrix.flutter_version || '' }} + channel: ${{ (!contains(matrix.flutter_version, '.') && !contains(matrix.flutter_version, 'x')) && matrix.flutter_version || '' }} + cache: true + cache-key: flutter-:os:-:channel:-:version:-:arch:-:hash:-${{ hashFiles('**/pubspec.lock') }} + - name: Build macOS + run: | flutter config --enable-macos-desktop - flutter drive --driver=test_driver/integration_test.dart --target=integration_test/wakelock_plus_test.dart -d macos + cd wakelock_plus/example + flutter pub get + flutter build macos --debug --target=./lib/main.dart + + macos_integration_test: + needs: setup_matrix + runs-on: macos-26 + timeout-minutes: 30 + strategy: + matrix: + flutter_version: ${{ fromJson(needs.setup_matrix.outputs.flutter_versions_json) }} + name: macOS Integration Test (${{ matrix.flutter_version }}) + steps: + - uses: actions/checkout@v6 + - uses: subosito/flutter-action@v2 + with: + flutter-version: ${{ (contains(matrix.flutter_version, '.') || contains(matrix.flutter_version, 'x')) && matrix.flutter_version || '' }} + channel: ${{ (!contains(matrix.flutter_version, '.') && !contains(matrix.flutter_version, 'x')) && matrix.flutter_version || '' }} + cache: true + cache-key: flutter-:os:-:channel:-:version:-:arch:-:hash:-${{ hashFiles('**/pubspec.lock') }} + + - name: Run Integration Tests + run: | + flutter config --enable-macos-desktop + cd wakelock_plus/example + flutter pub get + flutter drive \ + -d macos \ + --driver=test_driver/integration_test.dart \ + --target=integration_test/wakelock_plus_test.dart + + # --- LINUX --- + + linux_example_build: + needs: setup_matrix + runs-on: ubuntu-latest + timeout-minutes: 30 + strategy: + matrix: + flutter_version: ${{ fromJson(needs.setup_matrix.outputs.flutter_versions_json) }} + name: Linux Example Build (${{ matrix.flutter_version }}) + steps: + - uses: actions/checkout@v6 + - name: Install dependencies + run: | + sudo apt-get update + sudo apt-get install -y clang cmake ninja-build pkg-config libgtk-3-dev liblzma-dev + - uses: subosito/flutter-action@v2 + with: + flutter-version: ${{ (contains(matrix.flutter_version, '.') || contains(matrix.flutter_version, 'x')) && matrix.flutter_version || '' }} + channel: ${{ (!contains(matrix.flutter_version, '.') && !contains(matrix.flutter_version, 'x')) && matrix.flutter_version || '' }} + cache: true + cache-key: flutter-:os:-:channel:-:version:-:arch:-:hash:-${{ hashFiles('**/pubspec.lock') }} + - name: Build Linux + run: | + flutter config --enable-linux-desktop + cd wakelock_plus/example + flutter pub get + flutter build linux --debug --target=./lib/main.dart + + linux_integration_test: + needs: setup_matrix + runs-on: ubuntu-latest + timeout-minutes: 30 + strategy: + matrix: + flutter_version: ${{ fromJson(needs.setup_matrix.outputs.flutter_versions_json) }} + fail-fast: false + name: Linux Integration Test (${{ matrix.flutter_version }}) + steps: + - uses: actions/checkout@v6 + - uses: subosito/flutter-action@v2 + with: + flutter-version: ${{ (contains(matrix.flutter_version, '.') || contains(matrix.flutter_version, 'x')) && matrix.flutter_version || '' }} + channel: ${{ (!contains(matrix.flutter_version, '.') && !contains(matrix.flutter_version, 'x')) && matrix.flutter_version || '' }} + cache: true + cache-key: flutter-:os:-:channel:-:version:-:arch:-:hash:-${{ hashFiles('**/pubspec.lock') }} + + - name: Install dependencies + # dbus-x11 and xvfb are critical for plugins that interact with ScreenSaver services headlessly + run: | + sudo apt-get update + sudo apt-get install -y \ + clang cmake ninja-build pkg-config \ + libgtk-3-dev liblzma-dev xvfb dbus-x11 \ + python3-dbus python3-gi + + - name: Run Integration Tests + run: | + flutter config --enable-linux-desktop + cd wakelock_plus/example + flutter pub get + + # We use xvfb-run (display) and dbus-run-session (bus). + # Inside, we run a Python mock of 'org.freedesktop.ScreenSaver' so the plugin logic succeeds. + xvfb-run dbus-run-session bash -c " + python3 -c \" + import dbus, dbus.service + from dbus.mainloop.glib import DBusGMainLoop + from gi.repository import GLib + class Mock(dbus.service.Object): + def __init__(self): + bus_name = dbus.service.BusName('org.freedesktop.ScreenSaver', bus=dbus.SessionBus()) + dbus.service.Object.__init__(self, bus_name, '/org/freedesktop/ScreenSaver') + @dbus.service.method('org.freedesktop.ScreenSaver', in_signature='ss', out_signature='u') + def Inhibit(self, a, r): return 1 + @dbus.service.method('org.freedesktop.ScreenSaver', in_signature='u', out_signature='') + def UnInhibit(self, c): pass + DBusGMainLoop(set_as_default=True) + Mock() + GLib.MainLoop().run()\" & + sleep 5 && \ + flutter drive \ + -d linux \ + --driver=test_driver/integration_test.dart \ + --target=integration_test/wakelock_plus_test.dart" + + # --- WINDOWS --- + + windows_example_build: + needs: setup_matrix + runs-on: windows-latest + timeout-minutes: 30 + strategy: + matrix: + flutter_version: ${{ fromJson(needs.setup_matrix.outputs.flutter_versions_json) }} + name: Windows Example Build (${{ matrix.flutter_version }}) + steps: + - uses: actions/checkout@v6 + - uses: subosito/flutter-action@v2 + with: + flutter-version: ${{ (contains(matrix.flutter_version, '.') || contains(matrix.flutter_version, 'x')) && matrix.flutter_version || '' }} + channel: ${{ (!contains(matrix.flutter_version, '.') && !contains(matrix.flutter_version, 'x')) && matrix.flutter_version || '' }} + cache: true + cache-key: flutter-:os:-:channel:-:version:-:arch:-:hash:-${{ hashFiles('**/pubspec.lock') }} + - name: Build Windows + run: | + flutter config --enable-windows-desktop + cd wakelock_plus/example + flutter pub get + flutter build windows --debug --target=./lib/main.dart + + windows_integration_test: + needs: setup_matrix + runs-on: windows-latest + timeout-minutes: 30 + strategy: + matrix: + flutter_version: ${{ fromJson(needs.setup_matrix.outputs.flutter_versions_json) }} + name: Windows Integration Test (${{ matrix.flutter_version }}) + steps: + - uses: actions/checkout@v6 + - uses: subosito/flutter-action@v2 + with: + flutter-version: ${{ (contains(matrix.flutter_version, '.') || contains(matrix.flutter_version, 'x')) && matrix.flutter_version || '' }} + channel: ${{ (!contains(matrix.flutter_version, '.') && !contains(matrix.flutter_version, 'x')) && matrix.flutter_version || '' }} + cache: true + cache-key: flutter-:os:-:channel:-:version:-:arch:-:hash:-${{ hashFiles('**/pubspec.lock') }} + + - name: Run Integration Tests + # Use single line to prevent PowerShell ParserErrors with backslashes + run: | + flutter config --enable-windows-desktop + cd wakelock_plus/example + flutter pub get + flutter drive -d windows --driver=test_driver/integration_test.dart --target=integration_test/wakelock_plus_test.dart + + # --- WEB --- + + web_example_build: + needs: setup_matrix + runs-on: ubuntu-latest + timeout-minutes: 30 + strategy: + matrix: + flutter_version: ${{ fromJson(needs.setup_matrix.outputs.flutter_versions_json) }} + name: Web Example Build (${{ matrix.flutter_version }}) + steps: + - uses: actions/checkout@v6 + - uses: subosito/flutter-action@v2 + with: + flutter-version: ${{ (contains(matrix.flutter_version, '.') || contains(matrix.flutter_version, 'x')) && matrix.flutter_version || '' }} + channel: ${{ (!contains(matrix.flutter_version, '.') && !contains(matrix.flutter_version, 'x')) && matrix.flutter_version || '' }} + cache: true + cache-key: flutter-:os:-:channel:-:version:-:arch:-:hash:-${{ hashFiles('**/pubspec.lock') }} + - name: Build Web + run: | + cd wakelock_plus/example + flutter pub get + flutter build web --debug --target=./lib/main.dart + + web_integration_test: + needs: setup_matrix + runs-on: ubuntu-latest + timeout-minutes: 30 + strategy: + matrix: + flutter_version: ${{ fromJson(needs.setup_matrix.outputs.flutter_versions_json) }} + name: Web Integration Test (${{ matrix.flutter_version }}) + steps: + - uses: actions/checkout@v6 + - uses: subosito/flutter-action@v2 + with: + flutter-version: ${{ (contains(matrix.flutter_version, '.') || contains(matrix.flutter_version, 'x')) && matrix.flutter_version || '' }} + channel: ${{ (!contains(matrix.flutter_version, '.') && !contains(matrix.flutter_version, 'x')) && matrix.flutter_version || '' }} + cache: true + cache-key: flutter-:os:-:channel:-:version:-:arch:-:hash:-${{ hashFiles('**/pubspec.lock') }} + + - name: Install Web Dependencies + run: | + sudo apt-get update + # Install xvfb and the specific chromium-chromedriver + sudo apt-get install -y xvfb chromium-chromedriver + + - name: Start ChromeDriver & Xvfb + run: | + # 1. Export DISPLAY so chromedriver knows which screen to use + export DISPLAY=:99 + # 2. Start Xvfb manually with the resolution used by plus_plugins + Xvfb $DISPLAY -screen 0 1024x768x16 & + # 3. Start chromedriver on the port expected by Flutter's web driver + chromedriver --port=4444 & + # 4. Give services time to initialize + sleep 5 + + - name: Run Integration Tests + run: | + # Must re-export DISPLAY in this step as well + export DISPLAY=:99 + + flutter config --enable-web + cd wakelock_plus/example + flutter pub get + + # Use timeout to prevent the CI hang common in headless web environments + timeout 10m flutter drive \ + -d chrome \ + --driver=test_driver/integration_test.dart \ + --target=integration_test/wakelock_plus_test.dart \ + --dart-define=CI=true \ + --no-keep-app-running || { + if [ $? -eq 124 ]; then + echo "Flutter drive reached timeout. Process was killed to prevent CI hang." + else + exit $? + fi + } \ No newline at end of file diff --git a/.github/workflows/pana.yml b/.github/workflows/pana.yml index f9c59aa..f571926 100644 --- a/.github/workflows/pana.yml +++ b/.github/workflows/pana.yml @@ -27,7 +27,7 @@ jobs: fail-fast: false steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v6 - uses: axel-op/dart-package-analyzer@v3 with: relativePath: ${{ matrix.package }} diff --git a/wakelock_plus/.gitignore b/wakelock_plus/.gitignore index b69a950..1d0bf2d 100644 --- a/wakelock_plus/.gitignore +++ b/wakelock_plus/.gitignore @@ -68,6 +68,7 @@ pubspec.lock **/ios/Flutter/flutter_export_environment.sh **/ios/ServiceDefinitions.json **/ios/Runner/GeneratedPluginRegistrant.* +**/.build/ # Exceptions to above rules. !**/ios/**/default.mode1v3 diff --git a/wakelock_plus/analysis_options.yaml b/wakelock_plus/analysis_options.yaml index 031ffd7..bf6c98c 100644 --- a/wakelock_plus/analysis_options.yaml +++ b/wakelock_plus/analysis_options.yaml @@ -7,6 +7,7 @@ analyzer: - ".git/**" # Exclude private git directory - "build/**" # Exclude generated files in the build directory - ".dart_tool/**" # Exclude Dart tool-generated files + - "pigeons/**" # Exclude pigeons linter: rules: diff --git a/wakelock_plus/android/build.gradle b/wakelock_plus/android/build.gradle index 422cc26..d2a1ffe 100644 --- a/wakelock_plus/android/build.gradle +++ b/wakelock_plus/android/build.gradle @@ -46,7 +46,7 @@ android { defaultConfig { // Use flutter.minSdkVersion once the minimum supported Flutter version is 3.35 or higher. - minSdkVersion 21 + minSdkVersion flutter.minSdkVersion testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner' } diff --git a/wakelock_plus/android/src/main/kotlin/dev/fluttercommunity/plus/wakelock/WakelockPlusMessages.g.kt b/wakelock_plus/android/src/main/kotlin/dev/fluttercommunity/plus/wakelock/WakelockPlusMessages.g.kt index 8c7aa32..2d4b1d0 100644 --- a/wakelock_plus/android/src/main/kotlin/dev/fluttercommunity/plus/wakelock/WakelockPlusMessages.g.kt +++ b/wakelock_plus/android/src/main/kotlin/dev/fluttercommunity/plus/wakelock/WakelockPlusMessages.g.kt @@ -1,4 +1,4 @@ -// Autogenerated from Pigeon (v26.0.1), do not edit directly. +// Autogenerated from Pigeon (v26.2.3), do not edit directly. // See also: https://pub.dev/packages/pigeon @file:Suppress("UNCHECKED_CAST", "ArrayInDataClass") @@ -56,7 +56,7 @@ private object WakelockPlusMessagesPigeonUtils { } if (a is Map<*, *> && b is Map<*, *>) { return a.size == b.size && a.all { - (b as Map).containsKey(it.key) && + (b as Map).contains(it.key) && deepEquals(it.value, b[it.key]) } } diff --git a/wakelock_plus/example/ios/Flutter/AppFrameworkInfo.plist b/wakelock_plus/example/ios/Flutter/AppFrameworkInfo.plist index 7c56964..391a902 100644 --- a/wakelock_plus/example/ios/Flutter/AppFrameworkInfo.plist +++ b/wakelock_plus/example/ios/Flutter/AppFrameworkInfo.plist @@ -20,7 +20,5 @@ ???? CFBundleVersion 1.0 - MinimumOSVersion - 12.0 diff --git a/wakelock_plus/example/ios/Podfile b/wakelock_plus/example/ios/Podfile index 06630d1..ed16470 100644 --- a/wakelock_plus/example/ios/Podfile +++ b/wakelock_plus/example/ios/Podfile @@ -1,5 +1,5 @@ # Uncomment this line to define a global platform for your project -platform :ios, '12.0' +platform :ios, '13.0' # CocoaPods analytics sends network stats synchronously affecting flutter build latency. ENV['COCOAPODS_DISABLE_STATS'] = 'true' diff --git a/wakelock_plus/example/ios/Podfile.lock b/wakelock_plus/example/ios/Podfile.lock index 2fd83ad..9acc3a8 100644 --- a/wakelock_plus/example/ios/Podfile.lock +++ b/wakelock_plus/example/ios/Podfile.lock @@ -24,11 +24,11 @@ EXTERNAL SOURCES: :path: ".symlinks/plugins/wakelock_plus/ios" SPEC CHECKSUMS: - Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7 + Flutter: cabc95a1d2626b1b06e7179b784ebcf0c0cde467 integration_test: 4a889634ef21a45d28d50d622cf412dc6d9f586e package_info_plus: af8e2ca6888548050f16fa2f1938db7b5a5df499 wakelock_plus: e29112ab3ef0b318e58cfa5c32326458be66b556 -PODFILE CHECKSUM: beab77b38961de946f08660e554f80ac174dc842 +PODFILE CHECKSUM: a5dd15803c05a42a9ae1068254e24631f03bf853 COCOAPODS: 1.16.2 diff --git a/wakelock_plus/example/ios/Runner.xcodeproj/project.pbxproj b/wakelock_plus/example/ios/Runner.xcodeproj/project.pbxproj index 11e1f77..ba455e4 100644 --- a/wakelock_plus/example/ios/Runner.xcodeproj/project.pbxproj +++ b/wakelock_plus/example/ios/Runner.xcodeproj/project.pbxproj @@ -463,7 +463,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 12.0; + IPHONEOS_DEPLOYMENT_TARGET = 13.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; SUPPORTED_PLATFORMS = iphoneos; @@ -580,7 +580,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 12.0; + IPHONEOS_DEPLOYMENT_TARGET = 13.0; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; @@ -629,7 +629,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 12.0; + IPHONEOS_DEPLOYMENT_TARGET = 13.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; SUPPORTED_PLATFORMS = iphoneos; diff --git a/wakelock_plus/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/wakelock_plus/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme index 7bdc624..d7417c1 100644 --- a/wakelock_plus/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme +++ b/wakelock_plus/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme @@ -26,6 +26,7 @@ buildConfiguration = "Debug" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" + customLLDBInitFile = "$(SRCROOT)/Flutter/ephemeral/flutter_lldbinit" shouldUseLaunchSchemeArgsEnv = "YES"> #import -@interface AppDelegate : FlutterAppDelegate +@interface AppDelegate : FlutterAppDelegate @end diff --git a/wakelock_plus/example/ios/Runner/AppDelegate.m b/wakelock_plus/example/ios/Runner/AppDelegate.m index 70e8393..cebafc9 100644 --- a/wakelock_plus/example/ios/Runner/AppDelegate.m +++ b/wakelock_plus/example/ios/Runner/AppDelegate.m @@ -5,9 +5,12 @@ @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { - [GeneratedPluginRegistrant registerWithRegistry:self]; // Override point for customization after application launch. return [super application:application didFinishLaunchingWithOptions:launchOptions]; } +- (void)didInitializeImplicitFlutterEngine:(NSObject*)engineBridge { + [GeneratedPluginRegistrant registerWithRegistry:engineBridge.pluginRegistry]; +} + @end diff --git a/wakelock_plus/example/ios/Runner/Info.plist b/wakelock_plus/example/ios/Runner/Info.plist index 6745578..013ffbe 100644 --- a/wakelock_plus/example/ios/Runner/Info.plist +++ b/wakelock_plus/example/ios/Runner/Info.plist @@ -2,6 +2,8 @@ + CADisableMinimumFrameDurationOnPhone + CFBundleDevelopmentRegion $(DEVELOPMENT_LANGUAGE) CFBundleDisplayName @@ -24,6 +26,29 @@ $(FLUTTER_BUILD_NUMBER) LSRequiresIPhoneOS + UIApplicationSceneManifest + + UIApplicationSupportsMultipleScenes + + UISceneConfigurations + + UIWindowSceneSessionRoleApplication + + + UISceneClassName + UIWindowScene + UISceneConfigurationName + flutter + UISceneDelegateClassName + FlutterSceneDelegate + UISceneStoryboardFile + Main + + + + + UIApplicationSupportsIndirectInputEvents + UILaunchStoryboardName LaunchScreen UIMainStoryboardFile @@ -41,9 +66,5 @@ UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight - CADisableMinimumFrameDurationOnPhone - - UIApplicationSupportsIndirectInputEvents - diff --git a/wakelock_plus/example/lib/main.dart b/wakelock_plus/example/lib/main.dart index 4098ae0..b935bbf 100644 --- a/wakelock_plus/example/lib/main.dart +++ b/wakelock_plus/example/lib/main.dart @@ -23,16 +23,12 @@ class _WakelockPlusExampleAppState extends State { Widget build(BuildContext context) { return MaterialApp( home: Scaffold( - appBar: AppBar( - title: const Text('Wakelock example app'), - ), + appBar: AppBar(title: const Text('Wakelock example app')), body: Center( child: Column( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ - const Spacer( - flex: 3, - ), + const Spacer(flex: 3), OutlinedButton( onPressed: () { // The following code will enable the wakelock on the device @@ -56,9 +52,7 @@ class _WakelockPlusExampleAppState extends State { }, child: const Text('disable wakelock'), ), - const Spacer( - flex: 2, - ), + const Spacer(flex: 2), FutureBuilder( future: WakelockPlus.enabled, builder: (context, AsyncSnapshot snapshot) { @@ -71,13 +65,13 @@ class _WakelockPlusExampleAppState extends State { return Container(); } - return Text('The wakelock is currently ' - '${data ? 'enabled' : 'disabled'}.'); + return Text( + 'The wakelock is currently ' + '${data ? 'enabled' : 'disabled'}.', + ); }, ), - const Spacer( - flex: 3, - ), + const Spacer(flex: 3), ], ), ), diff --git a/wakelock_plus/example/macos/Podfile b/wakelock_plus/example/macos/Podfile index c795730..b52666a 100644 --- a/wakelock_plus/example/macos/Podfile +++ b/wakelock_plus/example/macos/Podfile @@ -1,4 +1,4 @@ -platform :osx, '10.14' +platform :osx, '10.15' # CocoaPods analytics sends network stats synchronously affecting flutter build latency. ENV['COCOAPODS_DISABLE_STATS'] = 'true' diff --git a/wakelock_plus/example/macos/Podfile.lock b/wakelock_plus/example/macos/Podfile.lock index 2a585cb..7648763 100644 --- a/wakelock_plus/example/macos/Podfile.lock +++ b/wakelock_plus/example/macos/Podfile.lock @@ -19,10 +19,10 @@ EXTERNAL SOURCES: :path: Flutter/ephemeral/.symlinks/plugins/wakelock_plus/macos SPEC CHECKSUMS: - FlutterMacOS: 8f6f14fa908a6fb3fba0cd85dbd81ec4b251fb24 - package_info_plus: fa739dd842b393193c5ca93c26798dff6e3d0e0c - wakelock_plus: 4783562c9a43d209c458cb9b30692134af456269 + FlutterMacOS: d0db08ddef1a9af05a5ec4b724367152bb0500b1 + package_info_plus: f0052d280d17aa382b932f399edf32507174e870 + wakelock_plus: 917609be14d812ddd9e9528876538b2263aaa03b -PODFILE CHECKSUM: 236401fc2c932af29a9fcf0e97baeeb2d750d367 +PODFILE CHECKSUM: 9ebaf0ce3d369aaa26a9ea0e159195ed94724cf3 -COCOAPODS: 1.15.2 +COCOAPODS: 1.16.2 diff --git a/wakelock_plus/example/macos/Runner.xcodeproj/project.pbxproj b/wakelock_plus/example/macos/Runner.xcodeproj/project.pbxproj index bd47dd9..aa2ae1c 100644 --- a/wakelock_plus/example/macos/Runner.xcodeproj/project.pbxproj +++ b/wakelock_plus/example/macos/Runner.xcodeproj/project.pbxproj @@ -195,7 +195,6 @@ 40C6B7F8860B1BE2A6B07ADA /* Pods-RunnerTests.release.xcconfig */, AF138727C3933020F89B6B28 /* Pods-RunnerTests.profile.xcconfig */, ); - name = Pods; path = Pods; sourceTree = ""; }; @@ -342,6 +341,7 @@ }; 33CC111E2044C6BF0003C045 /* ShellScript */ = { isa = PBXShellScriptBuildPhase; + alwaysOutOfDate = 1; buildActionMask = 2147483647; files = ( ); @@ -358,7 +358,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "\"$FLUTTER_ROOT\"/packages/flutter_tools/bin/macos_assemble.sh && touch Flutter/ephemeral/tripwire"; + shellScript = "\"$FLUTTER_ROOT\"/packages/flutter_tools/bin/macos_assemble.sh && touch Flutter/ephemeral/tripwire\n"; }; 4AE49CEDD56F01D3AA086266 /* [CP] Embed Pods Frameworks */ = { isa = PBXShellScriptBuildPhase; @@ -553,7 +553,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - MACOSX_DEPLOYMENT_TARGET = 10.14; + MACOSX_DEPLOYMENT_TARGET = 10.15; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = macosx; SWIFT_COMPILATION_MODE = wholemodule; @@ -632,7 +632,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - MACOSX_DEPLOYMENT_TARGET = 10.14; + MACOSX_DEPLOYMENT_TARGET = 10.15; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = macosx; @@ -679,7 +679,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - MACOSX_DEPLOYMENT_TARGET = 10.14; + MACOSX_DEPLOYMENT_TARGET = 10.15; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = macosx; SWIFT_COMPILATION_MODE = wholemodule; diff --git a/wakelock_plus/example/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/wakelock_plus/example/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme index f798615..26392b6 100644 --- a/wakelock_plus/example/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme +++ b/wakelock_plus/example/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme @@ -59,6 +59,7 @@ ignoresPersistentStateOnLaunch = "NO" debugDocumentVersioning = "YES" debugServiceExtension = "internal" + enableGPUValidationMode = "1" allowLocationSimulation = "YES"> diff --git a/wakelock_plus/example/macos/Runner/AppDelegate.swift b/wakelock_plus/example/macos/Runner/AppDelegate.swift index 8e02df2..b3c1761 100644 --- a/wakelock_plus/example/macos/Runner/AppDelegate.swift +++ b/wakelock_plus/example/macos/Runner/AppDelegate.swift @@ -6,4 +6,8 @@ class AppDelegate: FlutterAppDelegate { override func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool { return true } + + override func applicationSupportsSecureRestorableState(_ app: NSApplication) -> Bool { + return true + } } diff --git a/wakelock_plus/example/pubspec.yaml b/wakelock_plus/example/pubspec.yaml index a08ffa4..9ef7d7c 100644 --- a/wakelock_plus/example/pubspec.yaml +++ b/wakelock_plus/example/pubspec.yaml @@ -5,8 +5,8 @@ description: Demonstrates how to use the wakelock_plus plugin. publish_to: 'none' # Remove this line if you wish to publish to pub.dev environment: - sdk: '>=3.3.0 <4.0.0' - flutter: ">=3.19.0" + sdk: '>=3.10.0 <4.0.0' + flutter: ">=3.38.0" # Dependencies specify other packages that your package needs in order to work. # To automatically upgrade your package dependencies to the latest versions @@ -28,7 +28,7 @@ dependencies: # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. - cupertino_icons: ^1.0.5 + cupertino_icons: ^1.0.8 dev_dependencies: flutter_test: @@ -43,7 +43,7 @@ dev_dependencies: # activated in the `analysis_options.yaml` file located at the root of your # package. See that file for information about deactivating specific lint # rules and activating additional ones. - flutter_lints: ^2.0.1 + flutter_lints: ^6.0.0 # For information on the generic Dart part of this file, see the # following page: https://dart.dev/tools/pub/pubspec diff --git a/wakelock_plus/example/web/index.html b/wakelock_plus/example/web/index.html index be820e8..89e7052 100644 --- a/wakelock_plus/example/web/index.html +++ b/wakelock_plus/example/web/index.html @@ -31,29 +31,14 @@ example - - - - - + + - + \ No newline at end of file diff --git a/wakelock_plus/ios/wakelock_plus/Sources/wakelock_plus/include/wakelock_plus/messages.g.h b/wakelock_plus/ios/wakelock_plus/Sources/wakelock_plus/include/wakelock_plus/messages.g.h index e9ccc22..eea50a3 100644 --- a/wakelock_plus/ios/wakelock_plus/Sources/wakelock_plus/include/wakelock_plus/messages.g.h +++ b/wakelock_plus/ios/wakelock_plus/Sources/wakelock_plus/include/wakelock_plus/messages.g.h @@ -1,7 +1,7 @@ -// Autogenerated from Pigeon (v26.0.1), do not edit directly. +// Autogenerated from Pigeon (v26.2.3), do not edit directly. // See also: https://pub.dev/packages/pigeon -#import +@import Foundation; @protocol FlutterBinaryMessenger; @protocol FlutterMessageCodec; diff --git a/wakelock_plus/ios/wakelock_plus/Sources/wakelock_plus/messages.g.m b/wakelock_plus/ios/wakelock_plus/Sources/wakelock_plus/messages.g.m index 1a2154c..911784b 100644 --- a/wakelock_plus/ios/wakelock_plus/Sources/wakelock_plus/messages.g.m +++ b/wakelock_plus/ios/wakelock_plus/Sources/wakelock_plus/messages.g.m @@ -1,16 +1,12 @@ -// Autogenerated from Pigeon (v26.0.1), do not edit directly. +// Autogenerated from Pigeon (v26.2.3), do not edit directly. // See also: https://pub.dev/packages/pigeon #import "./include/wakelock_plus/messages.g.h" #if TARGET_OS_OSX -#import +@import FlutterMacOS; #else -#import -#endif - -#if !__has_feature(objc_arc) -#error File requires ARC to be enabled. +@import Flutter; #endif static NSArray *wrapResult(id result, FlutterError *error) { diff --git a/wakelock_plus/lib/src/wakelock_plus_linux_plugin.dart b/wakelock_plus/lib/src/wakelock_plus_linux_plugin.dart index 44c1818..187b39b 100644 --- a/wakelock_plus/lib/src/wakelock_plus_linux_plugin.dart +++ b/wakelock_plus/lib/src/wakelock_plus_linux_plugin.dart @@ -18,7 +18,7 @@ class WakelockPlusLinuxPlugin extends WakelockPlusPlatformInterface { /// Constructs an instance of [WakelockPlusLinuxPlugin]. WakelockPlusLinuxPlugin({@visibleForTesting DBusRemoteObject? object}) - : _object = object ?? _createRemoteObject(); + : _object = object ?? _createRemoteObject(); final DBusRemoteObject _object; int? _cookie; diff --git a/wakelock_plus/lib/src/wakelock_plus_macos_plugin.dart b/wakelock_plus/lib/src/wakelock_plus_macos_plugin.dart index 078b451..03ac0a8 100644 --- a/wakelock_plus/lib/src/wakelock_plus_macos_plugin.dart +++ b/wakelock_plus/lib/src/wakelock_plus_macos_plugin.dart @@ -21,9 +21,7 @@ class WakelockPlusMacOSPlugin extends WakelockPlusPlatformInterface { @override Future toggle({required bool enable}) async { - await _channel.invokeMethod('toggle', { - 'enable': enable, - }); + await _channel.invokeMethod('toggle', {'enable': enable}); } @override diff --git a/wakelock_plus/lib/src/wakelock_plus_web_plugin.dart b/wakelock_plus/lib/src/wakelock_plus_web_plugin.dart index 73cf3f3..a21ed32 100644 --- a/wakelock_plus/lib/src/wakelock_plus_web_plugin.dart +++ b/wakelock_plus/lib/src/wakelock_plus_web_plugin.dart @@ -17,7 +17,9 @@ class WakelockPlusWebPlugin extends WakelockPlusPlatformInterface { // Import a version of `NoSleep.js` that was adjusted for the wakelock // plugin. _jsLoaded = importJsLibrary( - url: 'assets/no_sleep.js', flutterPluginName: 'wakelock_plus'); + url: 'assets/no_sleep.js', + flutterPluginName: 'wakelock_plus', + ); WakelockPlusPlatformInterface.instance = WakelockPlusWebPlugin(); } diff --git a/wakelock_plus/lib/src/web_impl/import_js_library.dart b/wakelock_plus/lib/src/web_impl/import_js_library.dart index b998c6d..461b47e 100644 --- a/wakelock_plus/lib/src/web_impl/import_js_library.dart +++ b/wakelock_plus/lib/src/web_impl/import_js_library.dart @@ -8,8 +8,10 @@ import 'package:web/web.dart'; /// Imports a JS script file from the given [url] given the relative /// [flutterPluginName]. -Future importJsLibrary( - {required String url, String? flutterPluginName}) async { +Future importJsLibrary({ + required String url, + String? flutterPluginName, +}) async { if (flutterPluginName == null) { return _importJSLibraries([url]); } else { diff --git a/wakelock_plus/lib/wakelock_plus.dart b/wakelock_plus/lib/wakelock_plus.dart index 8b918ce..23f85da 100644 --- a/wakelock_plus/lib/wakelock_plus.dart +++ b/wakelock_plus/lib/wakelock_plus.dart @@ -63,9 +63,7 @@ class WakelockPlus { /// ``` /// /// You can await the [Future] to wait for the operation to complete. - static Future toggle({ - required bool enable, - }) { + static Future toggle({required bool enable}) { return wakelockPlusPlatformInstance.toggle(enable: enable); } diff --git a/wakelock_plus/pigeons/messages.dart b/wakelock_plus/pigeons/messages.dart index d2f1828..e6100b5 100644 --- a/wakelock_plus/pigeons/messages.dart +++ b/wakelock_plus/pigeons/messages.dart @@ -10,20 +10,22 @@ class IsEnabledMessage { bool? enabled; } -@ConfigurePigeon(PigeonOptions( - dartOut: '../wakelock_plus_platform_interface/lib/messages.g.dart', - dartTestOut: '../wakelock_plus_platform_interface/test/messages.g.dart', - objcHeaderOut: - 'ios/wakelock_plus/Sources/wakelock_plus/include/wakelock_plus/messages.g.h', - objcSourceOut: 'ios/wakelock_plus/Sources/wakelock_plus/messages.g.m', - objcOptions: ObjcOptions( - prefix: 'WAKELOCKPLUS', - headerIncludePath: './include/wakelock_plus/messages.g.h', +@ConfigurePigeon( + PigeonOptions( + dartOut: '../wakelock_plus_platform_interface/lib/messages.g.dart', + dartTestOut: '../wakelock_plus_platform_interface/test/messages.g.dart', + objcHeaderOut: + 'ios/wakelock_plus/Sources/wakelock_plus/include/wakelock_plus/messages.g.h', + objcSourceOut: 'ios/wakelock_plus/Sources/wakelock_plus/messages.g.m', + objcOptions: ObjcOptions( + prefix: 'WAKELOCKPLUS', + headerIncludePath: './include/wakelock_plus/messages.g.h', + ), + kotlinOptions: KotlinOptions(errorClassName: "WakelockPlusFlutterError"), + kotlinOut: + 'android/src/main/kotlin/dev/fluttercommunity/plus/wakelock/WakelockPlusMessages.g.kt', ), - kotlinOptions: KotlinOptions(errorClassName: "WakelockPlusFlutterError"), - kotlinOut: - 'android/src/main/kotlin/dev/fluttercommunity/plus/wakelock/WakelockPlusMessages.g.kt', -)) +) @HostApi(dartHostTestHandler: 'TestWakelockPlusApi') abstract class WakelockPlusApi { void toggle(ToggleMessage msg); diff --git a/wakelock_plus/pubspec.yaml b/wakelock_plus/pubspec.yaml index 2ba3b7e..6c8ce26 100644 --- a/wakelock_plus/pubspec.yaml +++ b/wakelock_plus/pubspec.yaml @@ -6,15 +6,15 @@ version: 1.4.0 repository: https://github.com/fluttercommunity/wakelock_plus/tree/main/wakelock_plus environment: - sdk: '>=3.4.0 <4.0.0' - flutter: ">=3.22.0" + sdk: '>=3.10.0 <4.0.0' + flutter: ">=3.38.0" dependencies: flutter: sdk: flutter flutter_web_plugins: sdk: flutter - meta: ^1.11.0 + meta: ^1.17.0 wakelock_plus_platform_interface: ^1.3.0 # Windows dependencies @@ -22,7 +22,7 @@ dependencies: win32: ">=5.6.1 <6.0.0" # Linux dependencies - dbus: ^0.7.11 + dbus: ^0.7.12 package_info_plus: ^9.0.0 # Web dependencies @@ -32,7 +32,7 @@ dev_dependencies: flutter_test: sdk: flutter flutter_lints: ^6.0.0 - pigeon: ^26.0.1 # dart run pigeon --input "pigeons/messages.dart" + pigeon: ^26.2.3 # dart run pigeon --input "pigeons/messages.dart" # For information on the generic Dart part of this file, see the # following page: https://dart.dev/tools/pub/pubspec diff --git a/wakelock_plus/test/wakelock_plus_web_plugin_test.dart b/wakelock_plus/test/wakelock_plus_web_plugin_test.dart index 869b576..11c0529 100644 --- a/wakelock_plus/test/wakelock_plus_web_plugin_test.dart +++ b/wakelock_plus/test/wakelock_plus_web_plugin_test.dart @@ -15,7 +15,9 @@ void main() { test('$WakelockPlusWebPlugin set as default instance', () { expect( - WakelockPlusPlatformInterface.instance, isA()); + WakelockPlusPlatformInterface.instance, + isA(), + ); }); test('initially disabled', () async { diff --git a/wakelock_plus_platform_interface/lib/messages.g.dart b/wakelock_plus_platform_interface/lib/messages.g.dart index 0546d2e..6a2e4de 100644 --- a/wakelock_plus_platform_interface/lib/messages.g.dart +++ b/wakelock_plus_platform_interface/lib/messages.g.dart @@ -1,21 +1,44 @@ -// Autogenerated from Pigeon (v26.0.1), do not edit directly. +// Autogenerated from Pigeon (v26.2.3), do not edit directly. // See also: https://pub.dev/packages/pigeon -// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import, no_leading_underscores_for_local_identifiers +// ignore_for_file: unused_import, unused_shown_name +// ignore_for_file: type=lint import 'dart:async'; -import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List; +import 'dart:typed_data' show Float64List, Int32List, Int64List; -import 'package:flutter/foundation.dart' show ReadBuffer, WriteBuffer; import 'package:flutter/services.dart'; - -PlatformException _createConnectionError(String channelName) { - return PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel: "$channelName".', - ); +import 'package:meta/meta.dart' show immutable, protected, visibleForTesting; + +Object? _extractReplyValueOrThrow( + List? replyList, + String channelName, { + required bool isNullValid, +}) { + if (replyList == null) { + throw PlatformException( + code: 'channel-error', + message: 'Unable to establish connection on channel: "$channelName".', + ); + } else if (replyList.length > 1) { + throw PlatformException( + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], + ); + } else if (!isNullValid && (replyList.isNotEmpty && replyList[0] == null)) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } + return replyList.firstOrNull; } -List wrapResponse({Object? result, PlatformException? error, bool empty = false}) { +List wrapResponse({ + Object? result, + PlatformException? error, + bool empty = false, +}) { if (empty) { return []; } @@ -24,43 +47,42 @@ List wrapResponse({Object? result, PlatformException? error, bool empty } return [error.code, error.message, error.details]; } + bool _deepEquals(Object? a, Object? b) { if (a is List && b is List) { return a.length == b.length && - a.indexed - .every(((int, dynamic) item) => _deepEquals(item.$2, b[item.$1])); + a.indexed.every( + ((int, dynamic) item) => _deepEquals(item.$2, b[item.$1]), + ); } if (a is Map && b is Map) { - return a.length == b.length && a.entries.every((MapEntry entry) => - (b as Map).containsKey(entry.key) && - _deepEquals(entry.value, b[entry.key])); + return a.length == b.length && + a.entries.every( + (MapEntry entry) => + (b as Map).containsKey(entry.key) && + _deepEquals(entry.value, b[entry.key]), + ); } return a == b; } - /// Message for toggling the wakelock on the platform side. class ToggleMessage { - ToggleMessage({ - this.enable, - }); + ToggleMessage({this.enable}); bool? enable; List _toList() { - return [ - enable, - ]; + return [enable]; } Object encode() { - return _toList(); } + return _toList(); + } static ToggleMessage decode(Object result) { result as List; - return ToggleMessage( - enable: result[0] as bool?, - ); + return ToggleMessage(enable: result[0] as bool?); } @override @@ -77,32 +99,26 @@ class ToggleMessage { @override // ignore: avoid_equals_and_hash_code_on_mutable_classes - int get hashCode => Object.hashAll(_toList()) -; + int get hashCode => Object.hashAll(_toList()); } /// Message for reporting the wakelock state from the platform side. class IsEnabledMessage { - IsEnabledMessage({ - this.enabled, - }); + IsEnabledMessage({this.enabled}); bool? enabled; List _toList() { - return [ - enabled, - ]; + return [enabled]; } Object encode() { - return _toList(); } + return _toList(); + } static IsEnabledMessage decode(Object result) { result as List; - return IsEnabledMessage( - enabled: result[0] as bool?, - ); + return IsEnabledMessage(enabled: result[0] as bool?); } @override @@ -119,11 +135,9 @@ class IsEnabledMessage { @override // ignore: avoid_equals_and_hash_code_on_mutable_classes - int get hashCode => Object.hashAll(_toList()) -; + int get hashCode => Object.hashAll(_toList()); } - class _PigeonCodec extends StandardMessageCodec { const _PigeonCodec(); @override @@ -131,10 +145,10 @@ class _PigeonCodec extends StandardMessageCodec { if (value is int) { buffer.putUint8(4); buffer.putInt64(value); - } else if (value is ToggleMessage) { + } else if (value is ToggleMessage) { buffer.putUint8(129); writeValue(buffer, value.encode()); - } else if (value is IsEnabledMessage) { + } else if (value is IsEnabledMessage) { buffer.putUint8(130); writeValue(buffer, value.encode()); } else { @@ -145,9 +159,9 @@ class _PigeonCodec extends StandardMessageCodec { @override Object? readValueOfType(int type, ReadBuffer buffer) { switch (type) { - case 129: + case 129: return ToggleMessage.decode(readValue(buffer)!); - case 130: + case 130: return IsEnabledMessage.decode(readValue(buffer)!); default: return super.readValueOfType(type, buffer); @@ -159,9 +173,13 @@ class WakelockPlusApi { /// Constructor for [WakelockPlusApi]. The [binaryMessenger] named argument is /// available for dependency injection. If it is left null, the default /// BinaryMessenger will be used which routes to the host platform. - WakelockPlusApi({BinaryMessenger? binaryMessenger, String messageChannelSuffix = ''}) - : pigeonVar_binaryMessenger = binaryMessenger, - pigeonVar_messageChannelSuffix = messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : ''; + WakelockPlusApi({ + BinaryMessenger? binaryMessenger, + String messageChannelSuffix = '', + }) : pigeonVar_binaryMessenger = binaryMessenger, + pigeonVar_messageChannelSuffix = messageChannelSuffix.isNotEmpty + ? '.$messageChannelSuffix' + : ''; final BinaryMessenger? pigeonVar_binaryMessenger; static const MessageCodec pigeonChannelCodec = _PigeonCodec(); @@ -169,53 +187,41 @@ class WakelockPlusApi { final String pigeonVar_messageChannelSuffix; Future toggle(ToggleMessage msg) async { - final String pigeonVar_channelName = 'dev.flutter.pigeon.wakelock_plus_platform_interface.WakelockPlusApi.toggle$pigeonVar_messageChannelSuffix'; - final BasicMessageChannel pigeonVar_channel = BasicMessageChannel( + final pigeonVar_channelName = + 'dev.flutter.pigeon.wakelock_plus_platform_interface.WakelockPlusApi.toggle$pigeonVar_messageChannelSuffix'; + final pigeonVar_channel = BasicMessageChannel( pigeonVar_channelName, pigeonChannelCodec, binaryMessenger: pigeonVar_binaryMessenger, ); - final Future pigeonVar_sendFuture = pigeonVar_channel.send([msg]); - final List? pigeonVar_replyList = - await pigeonVar_sendFuture as List?; - if (pigeonVar_replyList == null) { - throw _createConnectionError(pigeonVar_channelName); - } else if (pigeonVar_replyList.length > 1) { - throw PlatformException( - code: pigeonVar_replyList[0]! as String, - message: pigeonVar_replyList[1] as String?, - details: pigeonVar_replyList[2], - ); - } else { - return; - } + final Future pigeonVar_sendFuture = pigeonVar_channel.send( + [msg], + ); + final pigeonVar_replyList = await pigeonVar_sendFuture as List?; + + _extractReplyValueOrThrow( + pigeonVar_replyList, + pigeonVar_channelName, + isNullValid: true, + ); } Future isEnabled() async { - final String pigeonVar_channelName = 'dev.flutter.pigeon.wakelock_plus_platform_interface.WakelockPlusApi.isEnabled$pigeonVar_messageChannelSuffix'; - final BasicMessageChannel pigeonVar_channel = BasicMessageChannel( + final pigeonVar_channelName = + 'dev.flutter.pigeon.wakelock_plus_platform_interface.WakelockPlusApi.isEnabled$pigeonVar_messageChannelSuffix'; + final pigeonVar_channel = BasicMessageChannel( pigeonVar_channelName, pigeonChannelCodec, binaryMessenger: pigeonVar_binaryMessenger, ); final Future pigeonVar_sendFuture = pigeonVar_channel.send(null); - final List? pigeonVar_replyList = - await pigeonVar_sendFuture as List?; - if (pigeonVar_replyList == null) { - throw _createConnectionError(pigeonVar_channelName); - } else if (pigeonVar_replyList.length > 1) { - throw PlatformException( - code: pigeonVar_replyList[0]! as String, - message: pigeonVar_replyList[1] as String?, - details: pigeonVar_replyList[2], - ); - } else if (pigeonVar_replyList[0] == null) { - throw PlatformException( - code: 'null-error', - message: 'Host platform returned null value for non-null return value.', - ); - } else { - return (pigeonVar_replyList[0] as IsEnabledMessage?)!; - } + final pigeonVar_replyList = await pigeonVar_sendFuture as List?; + + final Object? pigeonVar_replyValue = _extractReplyValueOrThrow( + pigeonVar_replyList, + pigeonVar_channelName, + isNullValid: false, + ); + return pigeonVar_replyValue! as IsEnabledMessage; } } diff --git a/wakelock_plus_platform_interface/pubspec.yaml b/wakelock_plus_platform_interface/pubspec.yaml index 61355df..99f5fb0 100644 --- a/wakelock_plus_platform_interface/pubspec.yaml +++ b/wakelock_plus_platform_interface/pubspec.yaml @@ -7,14 +7,14 @@ repository: >-2 https://github.com/fluttercommunity/wakelock_plus/tree/main/wakelock_plus_platform_interface environment: - sdk: '>=3.4.0 <4.0.0' - flutter: ">=3.22.0" + sdk: '>=3.10.0 <4.0.0' + flutter: ">=3.38.0" dependencies: flutter: sdk: flutter plugin_platform_interface: ^2.1.8 - meta: ^1.11.0 + meta: ^1.17.0 dev_dependencies: flutter_test: diff --git a/wakelock_plus_platform_interface/test/messages.g.dart b/wakelock_plus_platform_interface/test/messages.g.dart index 53a05ae..8fb3d3b 100644 --- a/wakelock_plus_platform_interface/test/messages.g.dart +++ b/wakelock_plus_platform_interface/test/messages.g.dart @@ -1,6 +1,6 @@ -// Autogenerated from Pigeon (v26.0.1), do not edit directly. +// Autogenerated from Pigeon (v26.2.3), do not edit directly. // See also: https://pub.dev/packages/pigeon -// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, unnecessary_import, no_leading_underscores_for_local_identifiers +// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, unnecessary_import, no_leading_underscores_for_local_identifiers, omit_obvious_local_variable_types // ignore_for_file: avoid_relative_lib_imports import 'dart:async'; import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List; @@ -10,7 +10,6 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:wakelock_plus_platform_interface/messages.g.dart'; - class _PigeonCodec extends StandardMessageCodec { const _PigeonCodec(); @override @@ -18,10 +17,10 @@ class _PigeonCodec extends StandardMessageCodec { if (value is int) { buffer.putUint8(4); buffer.putInt64(value); - } else if (value is ToggleMessage) { + } else if (value is ToggleMessage) { buffer.putUint8(129); writeValue(buffer, value.encode()); - } else if (value is IsEnabledMessage) { + } else if (value is IsEnabledMessage) { buffer.putUint8(130); writeValue(buffer, value.encode()); } else { @@ -32,9 +31,9 @@ class _PigeonCodec extends StandardMessageCodec { @override Object? readValueOfType(int type, ReadBuffer buffer) { switch (type) { - case 129: + case 129: return ToggleMessage.decode(readValue(buffer)!); - case 130: + case 130: return IsEnabledMessage.decode(readValue(buffer)!); default: return super.readValueOfType(type, buffer); @@ -43,57 +42,82 @@ class _PigeonCodec extends StandardMessageCodec { } abstract class TestWakelockPlusApi { - static TestDefaultBinaryMessengerBinding? get _testBinaryMessengerBinding => TestDefaultBinaryMessengerBinding.instance; + static TestDefaultBinaryMessengerBinding? get _testBinaryMessengerBinding => + TestDefaultBinaryMessengerBinding.instance; static const MessageCodec pigeonChannelCodec = _PigeonCodec(); void toggle(ToggleMessage msg); IsEnabledMessage isEnabled(); - static void setUp(TestWakelockPlusApi? api, {BinaryMessenger? binaryMessenger, String messageChannelSuffix = '',}) { - messageChannelSuffix = messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : ''; + static void setUp( + TestWakelockPlusApi? api, { + BinaryMessenger? binaryMessenger, + String messageChannelSuffix = '', + }) { + messageChannelSuffix = messageChannelSuffix.isNotEmpty + ? '.$messageChannelSuffix' + : ''; { - final BasicMessageChannel pigeonVar_channel = BasicMessageChannel( - 'dev.flutter.pigeon.wakelock_plus_platform_interface.WakelockPlusApi.toggle$messageChannelSuffix', pigeonChannelCodec, - binaryMessenger: binaryMessenger); + final pigeonVar_channel = BasicMessageChannel( + 'dev.flutter.pigeon.wakelock_plus_platform_interface.WakelockPlusApi.toggle$messageChannelSuffix', + pigeonChannelCodec, + binaryMessenger: binaryMessenger, + ); if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(pigeonVar_channel, null); + _testBinaryMessengerBinding!.defaultBinaryMessenger + .setMockDecodedMessageHandler(pigeonVar_channel, null); } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(pigeonVar_channel, (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.wakelock_plus_platform_interface.WakelockPlusApi.toggle was null.'); - final List args = (message as List?)!; - final ToggleMessage? arg_msg = (args[0] as ToggleMessage?); - assert(arg_msg != null, - 'Argument for dev.flutter.pigeon.wakelock_plus_platform_interface.WakelockPlusApi.toggle was null, expected non-null ToggleMessage.'); - try { - api.toggle(arg_msg!); - return wrapResponse(empty: true); - } on PlatformException catch (e) { - return wrapResponse(error: e); - } catch (e) { - return wrapResponse(error: PlatformException(code: 'error', message: e.toString())); - } - }); + _testBinaryMessengerBinding!.defaultBinaryMessenger + .setMockDecodedMessageHandler(pigeonVar_channel, ( + Object? message, + ) async { + final List args = message! as List; + final ToggleMessage arg_msg = args[0]! as ToggleMessage; + try { + api.toggle(arg_msg); + return wrapResponse(empty: true); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException( + code: 'error', + message: e.toString(), + ), + ); + } + }); } } { - final BasicMessageChannel pigeonVar_channel = BasicMessageChannel( - 'dev.flutter.pigeon.wakelock_plus_platform_interface.WakelockPlusApi.isEnabled$messageChannelSuffix', pigeonChannelCodec, - binaryMessenger: binaryMessenger); + final pigeonVar_channel = BasicMessageChannel( + 'dev.flutter.pigeon.wakelock_plus_platform_interface.WakelockPlusApi.isEnabled$messageChannelSuffix', + pigeonChannelCodec, + binaryMessenger: binaryMessenger, + ); if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(pigeonVar_channel, null); + _testBinaryMessengerBinding!.defaultBinaryMessenger + .setMockDecodedMessageHandler(pigeonVar_channel, null); } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(pigeonVar_channel, (Object? message) async { - try { - final IsEnabledMessage output = api.isEnabled(); - return [output]; - } on PlatformException catch (e) { - return wrapResponse(error: e); - } catch (e) { - return wrapResponse(error: PlatformException(code: 'error', message: e.toString())); - } - }); + _testBinaryMessengerBinding!.defaultBinaryMessenger + .setMockDecodedMessageHandler(pigeonVar_channel, ( + Object? message, + ) async { + try { + final IsEnabledMessage output = api.isEnabled(); + return [output]; + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException( + code: 'error', + message: e.toString(), + ), + ); + } + }); } } } diff --git a/wakelock_plus_platform_interface/test/wakelock_plus_platform_interface_test.dart b/wakelock_plus_platform_interface/test/wakelock_plus_platform_interface_test.dart index 5ac85b3..5713022 100644 --- a/wakelock_plus_platform_interface/test/wakelock_plus_platform_interface_test.dart +++ b/wakelock_plus_platform_interface/test/wakelock_plus_platform_interface_test.dart @@ -1,4 +1,5 @@ import 'package:flutter_test/flutter_test.dart'; +import 'package:plugin_platform_interface/plugin_platform_interface.dart'; import 'package:wakelock_plus_platform_interface/messages.g.dart'; import 'package:wakelock_plus_platform_interface/src/method_channel_wakelock_plus.dart'; import 'package:wakelock_plus_platform_interface/wakelock_plus_platform_interface.dart'; @@ -27,24 +28,26 @@ void main() { group('$WakelockPlusPlatformInterface', () { test('$MethodChannelWakelockPlus() is the default instance', () { - expect(WakelockPlusPlatformInterface.instance, - isInstanceOf()); + expect( + WakelockPlusPlatformInterface.instance, + isInstanceOf(), + ); }); test('Cannot be implemented with `implements`', () { expect(() { WakelockPlusPlatformInterface.instance = - const ImplementsWakelockPlusPlatformInterface(false); - }, throwsA(isInstanceOf())); + ImplementsWakelockPlusPlatformInterface(); + }, throwsA(isA())); }); test('Can be mocked with `implements`', () { WakelockPlusPlatformInterface.instance = - const ImplementsWakelockPlusPlatformInterface(true); + WakelockPlusPlatformInterfaceMock(); }); test('Can be extended', () { - WakelockPlusPlatformInterface.instance = ExtendsVideoPlayerPlatform(); + WakelockPlusPlatformInterface.instance = ExtendsWakelockPlusPlatform(); }); }); @@ -79,17 +82,29 @@ void main() { }); } +/// This class should fail verification because it uses `implements` +/// and does NOT use [MockPlatformInterfaceMixin]. class ImplementsWakelockPlusPlatformInterface implements WakelockPlusPlatformInterface { - const ImplementsWakelockPlusPlatformInterface(this.mocked); + @override + dynamic noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); +} + +/// This class should pass verification because it uses [MockPlatformInterfaceMixin]. +class WakelockPlusPlatformInterfaceMock + with MockPlatformInterfaceMixin + implements WakelockPlusPlatformInterface { + @override + Future get enabled => throw UnimplementedError(); - final bool mocked; + @override + bool get isMock => throw UnimplementedError(); @override - dynamic noSuchMethod(Invocation invocation) { - if (invocation.memberName == #isMock && mocked) return true; - throw NoSuchMethodError.withInvocation(this, invocation); + Future toggle({required bool enable}) { + throw UnimplementedError(); } } -class ExtendsVideoPlayerPlatform extends WakelockPlusPlatformInterface {} +/// This class should pass verification because it uses `extends`. +class ExtendsWakelockPlusPlatform extends WakelockPlusPlatformInterface {}