Giter Site home page Giter Site logo

lyming1994 / window_manager Goto Github PK

View Code? Open in Web Editor NEW

This project forked from leanflutter/window_manager

0.0 0.0 0.0 568 KB

This plugin allows Flutter desktop apps to resizing and repositioning the window.

License: MIT License

Dart 21.13% Swift 13.64% Ruby 1.34% CMake 10.98% C++ 51.12% C 1.79%

window_manager's Introduction

window_manager

pub version

This plugin allows Flutter desktop apps to resizing and repositioning the window.

Discord


Platform Support

Linux macOS Windows
✔️ ✔️ ✔️

Quick Start

Installation

Add this to your package's pubspec.yaml file:

dependencies:
  window_manager: ^0.1.1

Or

dependencies:
  window_manager:
    git:
      url: https://github.com/leanflutter/window_manager.git
      ref: main

Usage

import 'package:flutter/material.dart';
import 'package:window_manager/window_manager.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  // Must add this line.
  await windowManager.ensureInitialized();

  // Use it only after calling `hiddenWindowAtLaunch`
  windowManager.waitUntilReadyToShow().then((_) async{
    // Set to frameless window
    await windowManager.setAsFrameless();
    await windowManager.setSize(Size(600, 600));
    await windowManager.setPosition(Offset.zero);
    windowManager.show();
  });

  runApp(MyApp());
}

Please see the example app of this plugin for a full example.

Listening events

import 'package:flutter/cupertino.dart';
import 'package:window_manager/window_manager.dart';

class HomePage extends StatefulWidget {
  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> with WindowListener {
  @override
  void initState() {
    windowManager.addListener(this);
    super.initState();
  }

  @override
  void dispose() {
    windowManager.removeListener(this);
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    // ...
  }

  @override
  void onWindowEvent(String eventName) {
    print('[WindowManager] onWindowEvent: $eventName');
  }

  @override
  void onWindowFocus() {
    // do something
  }

  @override
  void onWindowBlur() {
    // do something
  }

  @override
  void onWindowMaximize() {
    // do something
  }

  @override
  void onWindowUnmaximize() {
    // do something
  }

  @override
  void onWindowMinimize() {
    // do something
  }

  @override
  void onWindowRestore() {
    // do something
  }

  @override
  void onWindowResize() {
    // do something
  }

  @override
  void onWindowMove() {
    // do something
  }

  @override
  void onWindowEnterFullScreen() {
    // do something
  }

  @override
  void onWindowLeaveFullScreen() {
    // do something
  }
}

Quit on close

If you need to use the hide method, you need to disable QuitOnClose.

macOS

macos/Runner/AppDelegate.swift

import Cocoa
import FlutterMacOS

@NSApplicationMain
class AppDelegate: FlutterAppDelegate {
  override func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {
-    return true
+    return false
  }
}
Windows

windows/runner/main.cpp

int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev,
                      _In_ wchar_t *command_line, _In_ int show_command) {
  // ...

-  window.SetQuitOnClose(true);
+  window.SetQuitOnClose(false);

  // ...

  return EXIT_SUCCESS;
}

Hidden at launch

macOS
import Cocoa
import FlutterMacOS
+import window_manager

class MainFlutterWindow: NSWindow {
    override func awakeFromNib() {
        let flutterViewController = FlutterViewController.init()
        let windowFrame = self.frame
        self.contentViewController = flutterViewController
        self.setFrame(windowFrame, display: true)

        RegisterGeneratedPlugins(registry: flutterViewController)

        super.awakeFromNib()
    }

+    override public func order(_ place: NSWindow.OrderingMode, relativeTo otherWin: Int) {
+        super.order(place, relativeTo: otherWin)
+        hiddenWindowAtLaunch()
+    }
}

Who's using it?

  • AuthPass - Password Manager based on Flutter for all platforms. Keepass 2.x (kdbx 3.x) compatible.
  • Biyi (比译) - A convenient translation and dictionary app written in dart / Flutter.
  • BlueBubbles - BlueBubbles is an ecosystem of apps bringing iMessage to Android, Windows, and Linux
  • Yukino - Yukino lets you read manga or stream anime ad-free from multiple sources.

Discussion

Welcome to join the discussion group to share your suggestions and ideas with me.

API

WindowManager

Method Description Linux macOS Windows
focus Focuses on the window. ✔️ ✔️
blur Removes focus from the window. ✔️
show Shows and gives focus to the window. ✔️ ✔️ ✔️
hide Hides the window. ✔️ ✔️ ✔️
isVisible Returns bool - Whether the window is visible to the user. ✔️ ✔️ ✔️
isMaximized Returns bool - Whether the window is maximized. ✔️ ✔️ ✔️
maximize Maximizes the window. ✔️ ✔️ ✔️
unmaximize Unmaximizes the window. ✔️ ✔️ ✔️
isMinimized Returns bool - Whether the window is minimized. ✔️ ✔️ ✔️
minimize Minimizes the window. ✔️ ✔️ ✔️
restore Restores the window from minimized state to its previous state. ✔️ ✔️ ✔️
isFullScreen Returns bool - Whether the window is in fullscreen mode. ✔️ ✔️ ✔️
setFullScreen Sets whether the window should be in fullscreen mode. ✔️ ✔️ ✔️
getBounds Returns Rect - The bounds of the window as Object. ✔️ ✔️ ✔️
setBounds Resizes and moves the window to the supplied bounds. ✔️ ✔️ ✔️
getPosition Returns Offset - Contains the window's current position. ✔️ ✔️ ✔️
setPosition Moves window to x and y. ✔️ ✔️ ✔️
getSize Returns Size - Contains the window's width and height. ✔️ ✔️ ✔️
setSize Resizes the window to width and height. ✔️ ✔️ ✔️
setMinimumSize Sets the minimum size of window to width and height. ✔️ ✔️ ✔️
setMaximumSize Sets the maximum size of window to width and height. ✔️ ✔️ ✔️
isResizable Returns bool - Whether the window can be manually resized by the user. ✔️ ✔️ ✔️
setResizable Sets whether the window can be manually resized by the user. ✔️ ✔️ ✔️
isMovable Returns bool - Whether the window can be moved by user. On Linux always returns true. ✔️
setMovable Sets whether the window can be moved by user. On Linux does nothing. ✔️
isMinimizable Returns bool - Whether the window can be manually minimized by the user. On Linux always returns true. ✔️ ✔️
setMinimizable Sets whether the window can be manually minimized by user. On Linux does nothing. ✔️ ✔️
isClosable Returns bool - Whether the window can be manually closed by user. On Linux always returns true. ✔️ ✔️ ✔️
setClosable Sets whether the window can be manually closed by user. On Linux does nothing. ✔️ ✔️ ✔️
isAlwaysOnTop Returns bool - Whether the window is always on top of other windows. ✔️ ✔️ ✔️
setAlwaysOnTop Sets whether the window should show always on top of other windows. ✔️ ✔️ ✔️
getTitle Returns String - The title of the native window. ✔️ ✔️ ✔️
setTitle Changes the title of native window to title. ✔️ ✔️ ✔️
setSkipTaskbar Makes the window not show in the taskbar / dock. ✔️ ✔️ ✔️
hasShadow Returns bool - Whether the window has a shadow. ✔️
setHasShadow Sets whether the window should have a shadow. ✔️
startDragging - ✔️ ✔️ ✔️

WindowListener

Method Description Linux macOS Windows
onWindowFocus Emitted when the window gains focus. ✔️ ✔️ ✔️
onWindowBlur Emitted when the window loses focus. ✔️ ✔️ ✔️
onWindowMaximize Emitted when window is maximized. ✔️ ✔️ ✔️
onWindowUnmaximize Emitted when the window exits from a maximized state. ✔️ ✔️ ✔️
onWindowMinimize Emitted when the window is minimized. ✔️ ✔️ ✔️
onWindowRestore Emitted when the window is restored from a minimized state. ✔️ ✔️ ✔️
onWindowResize Emitted after the window has been resized. ✔️ ✔️ ✔️
onWindowMove Emitted when the window is being moved to a new position. ✔️ ✔️ ✔️
onWindowEnterFullScreen Emitted when the window enters a full-screen state. ✔️ ✔️ ✔️
onWindowLeaveFullScreen Emitted when the window leaves a full-screen state. ✔️ ✔️ ✔️

License

MIT

window_manager's People

Contributors

lijy91 avatar lyming99 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.