flutter_desktop_sleep 0.0.2 copy "flutter_desktop_sleep: ^0.0.2" to clipboard
flutter_desktop_sleep: ^0.0.2 copied to clipboard

A plugin for detect sleep and wake up of MacOs and Windows, you can make user offline or online with help of this plugin.

flutter_desktop_sleep #

2022 © Bikramaditya Meher

Pub License: MIT

flutter_window_sleep lets you know your Flutter app if app going to close/sleep/wakeup and has a chance to confirm if the user want to close there running task such as logout function, etc. It works on desktop platforms including Windows and macOS. Thanks to [flutter_window_close] (https://pub.dartlang.org/packages/flutter_window_close) it was help me very much.

macOS Windows

Example #

    FlutterDesktopSleep flutterDesktopSleep = FlutterDesktopSleep();
    flutterDesktopSleep.setWindowSleepHandler((String? s) async {
      Get.log('dsfsadf $s');
      if (s != null) {
        // autoClockOff(note: s, shouldThread: false, shouldOn: true);
        if (s == 'sleep') {
          autoClockOff(note: 'Laptop sleep', shouldOn: false);
        } else if (s == 'woke_up') {
          autoClockOff(note: 'Laptop woke up', shouldOn: true);
        } else if (s == 'terminate_app') {
          await autoClockOff(
              note: 'App Terminate', shouldThread: false, shouldOn: false);
          flutterDesktopSleep.terminateApp();
        }
      }
    });

macOS #

For macOs you need to add following code to your macos/Runner/AppDelegate.swift

import Cocoa
import FlutterMacOS
import Firebase
import flutter_desktop_sleep

@NSApplicationMain
class AppDelegate: FlutterAppDelegate {
var _windowManager = FlutterDesktopSleepPlugin()
  override func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {
    return true
  }
  override func applicationShouldTerminate(_ sender: NSApplication) -> NSApplication.TerminateReply {
  let controller : FlutterViewController = mainFlutterWindow?.contentViewController as! FlutterViewController
  return _windowManager.applicationShouldTerminate(controller);
  }
}

Windows #

no need any setup just

9
likes
160
points
924
downloads

Publisher

unverified uploader

Weekly Downloads

A plugin for detect sleep and wake up of MacOs and Windows, you can make user offline or online with help of this plugin.

Repository (GitHub)

Documentation

API reference

License

MIT (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on flutter_desktop_sleep