Skip to content

Commit

Permalink
MacOS: Address issues #10 and #11
Browse files Browse the repository at this point in the history
  • Loading branch information
Adrian-Samoticha committed Nov 17, 2021
1 parent 20d4fc4 commit def49ce
Show file tree
Hide file tree
Showing 2 changed files with 883 additions and 35 deletions.
351 changes: 347 additions & 4 deletions lib/flutter_acrylic.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,107 @@ const _kEnterFullscreen = "EnterFullscreen";
/// Exits fullscreen.
const _kExitFullscreen = "ExitFullscreen";

/// Gets the height of the titlebar.
const _kGetTitlebarHeight = "GetTitlebarHeight";

/// Overrides the brightness setting of the window (macOS only).
const _kOverrideMacOSBrightness = "OverrideMacOSBrightness";


/// (macOS only).
const _kSetDocumentEdited = "SetDocumentEdited";

/// (macOS only).
const _kSetDocumentNotEdited = "SetDocumentNotEdited";

/// (macOS only).
const _kSetRepresentedFile = "SetRepresentedFile";

/// (macOS only).
const _kSetRepresentedURL = "SetRepresentedURL";

/// (macOS only).
const _kHideTitlebar = "HideTitlebar";

/// (macOS only).
const _kShowTitlebar = "ShowTitlebar";

/// (macOS only).
const _kMakeTitlebarTransparent = "MakeTitlebarTransparent";

/// (macOS only).
const _kMakeTitlebarOpaque = "MakeTitlebarOpaque";

/// (macOS only).
const _kEnableFullSizeContentView = "EnableFullSizeContentView";

/// (macOS only).
const _kDisableFullSizeContentView = "DisableFullSizeContentView";

/// (macOS only).
const _kZoomWindow = "ZoomWindow";

/// (macOS only).
const _kUnzoomWindow = "UnzoomWindow";

/// (macOS only).
const _kIsWindowZoomed = "IsWindowZoomed";

/// (macOS only).
const _kIsWindowFullscreened = "IsWindowFullscreened";

/// (macOS only).
const _kHideZoomButton = "HideZoomButton";

/// (macOS only).
const _kShowZoomButton = "ShowZoomButton";

/// (macOS only).
const _kHideMiniaturizeButton = "HideMiniaturizeButton";

/// (macOS only).
const _kShowMiniaturizeButton = "ShowMiniaturizeButton";

/// (macOS only).
const _kHideCloseButton = "HideCloseButton";

/// (macOS only).
const _kShowCloseButton = "ShowCloseButton";

/// (macOS only).
const _kEnableZoomButton = "EnableZoomButton";

/// (macOS only).
const _kDisableZoomButton = "DisableZoomButton";

/// (macOS only).
const _kEnableMiniaturizeButton = "EnableMiniaturizeButton";

/// (macOS only).
const _kDisableMiniaturizeButton = "DisableMiniaturizeButton";

/// (macOS only).
const _kEnableCloseButton = "EnableCloseButton";

/// (macOS only).
const _kDisableCloseButton = "DisableCloseButton";

/// (macOS only).
const _kIsWindowInLiveResize = "IsWindowInLiveResize";

/// (macOS only).
const _kSetWindowAlphaValue = "SetWindowAlphaValue";

/// (macOS only).
const _kMakeWindowRestorable = "MakeWindowRestorable";

/// (macOS only).
const _kMakeWindowUnrestorable = "MakeWindowUnrestorable";

/// (macOS only).
const _kIsWindowVisible = "IsWindowVisible";


final MethodChannel _kChannel = const MethodChannel(_kChannelName);
final Completer<void> _kCompleter = new Completer<void>();

Expand Down Expand Up @@ -179,26 +277,271 @@ class Window {
);
}

/// Hides window controls. (Currently not supported on macOS)
/// Hides window controls.
static Future<void> hideWindowControls() async {
await _kChannel.invokeMethod(_kHideWindowControls);
}

/// Shows window controls. (Currently not supported on macOS)
/// Shows window controls.
static Future<void> showWindowControls() async {
await _kChannel.invokeMethod(_kShowWindowControls);
}

/// Makes the Flutter window fullscreen. (Currently not supported on macOS)
/// Makes the Flutter window fullscreen.
static Future<void> enterFullscreen() async {
await _kChannel.invokeMethod(_kEnterFullscreen);
}

/// Restores the Flutter window back to normal from fullscreen mode. (Currently not supported on macOS)
/// Restores the Flutter window back to normal from fullscreen mode.
static Future<void> exitFullscreen() async {
await _kChannel.invokeMethod(_kExitFullscreen);
}

/// Gets the height of the titlebar.
/// This value is used to determine the [[TitlebarSafeArea]] widget.
/// If the full-size content view is enabled, this value will be the height of the titlebar.
/// If the full-size content view is disabled, this value will be 0.
/// This value is only available on macOS.
static Future<double> getTitlebarHeight() async {
await _kCompleter.future;
return await _kChannel.invokeMethod(_kGetTitlebarHeight);
}

/// Sets the document to be edited.
/// This method is only available on macOS.
static Future<void> setDocumentEdited(bool edited) async {
await _kCompleter.future;
await _kChannel.invokeMethod(_kSetDocumentEdited);
}

/// Sets the document to not be edited.
/// This method is only available on macOS.
static Future<void> setDocumentNotEdited() async {
await _kCompleter.future;
await _kChannel.invokeMethod(_kSetDocumentNotEdited);
}

/// Sets the represented file of the window.
/// This method is only available on macOS.
static Future<void> setRepresentedFilename(String filename) async {
await _kCompleter.future;
await _kChannel.invokeMethod(_kSetRepresentedFile, {
'filename': filename,
});
}

/// Sets the represented URL of the window.
/// This method is only available on macOS.
static Future<void> setRepresentedUrl(String url) async {
await _kCompleter.future;
await _kChannel.invokeMethod(_kSetRepresentedURL, {
'url': url,
});
}

/// Hides the titlebar of the window.
/// This method is only available on macOS.
static Future<void> hideTitlebar() async {
await _kCompleter.future;
await _kChannel.invokeMethod(_kHideTitlebar);
}

/// Shows the titlebar of the window.
/// This method is only available on macOS.
static Future<void> showTitlebar() async {
await _kCompleter.future;
await _kChannel.invokeMethod(_kShowTitlebar);
}

/// Makes the window's titlebar transparent.
/// This method is only available on macOS.
static Future<void> makeTitlebarTransparent() async {
await _kCompleter.future;
await _kChannel.invokeMethod(_kMakeTitlebarTransparent);
}

/// Makes the window's titlebar opaque.
/// This method is only available on macOS.
static Future<void> makeTitlebarOpaque() async {
await _kCompleter.future;
await _kChannel.invokeMethod(_kMakeTitlebarOpaque);
}

/// Enables the window's full-size content view.
/// It is recommended to enable the full-size content view when making
/// the titlebar transparent.
/// This method is only available on macOS.
static Future<void> enableFullSizeContentView() async {
await _kCompleter.future;
await _kChannel.invokeMethod(_kEnableFullSizeContentView);
}

/// Disables the window's full-size content view.
/// This method is only available on macOS.
static Future<void> disableFullSizeContentView() async {
await _kCompleter.future;
await _kChannel.invokeMethod(_kDisableFullSizeContentView);
}

/// Zooms the window.
/// This method is only available on macOS.
static Future<void> zoomWindow(double scale) async {
await _kCompleter.future;
await _kChannel.invokeMethod(_kZoomWindow);
}

/// Unzooms the window.
/// This method is only available on macOS.
static Future<void> unzoomWindow() async {
await _kCompleter.future;
await _kChannel.invokeMethod(_kUnzoomWindow);
}

/// Returns if the window is zoomed.
/// This method is only available on macOS.
static Future<bool> isWindowZoomed() async {
await _kCompleter.future;
return await _kChannel.invokeMethod(_kIsWindowZoomed);
}

/// Returns if the window is fullscreened.
/// This method is only available on macOS.
static Future<bool> isWindowFullscreened() async {
await _kCompleter.future;
return await _kChannel.invokeMethod(_kIsWindowFullscreened);
}

/// Hides the window's zoom button.
/// This method is only available on macOS.
static Future<void> hideZoomButton() async {
await _kCompleter.future;
await _kChannel.invokeMethod(_kHideZoomButton);
}

/// Shows the window's zoom button.
/// The zoom button is visible by default.
/// This method is only available on macOS.
static Future<void> showZoomButton() async {
await _kCompleter.future;
await _kChannel.invokeMethod(_kShowZoomButton);
}

/// Hides the window's miniaturize button.
/// This method is only available on macOS.
static Future<void> hideMiniaturizeButton() async {
await _kCompleter.future;
await _kChannel.invokeMethod(_kHideMiniaturizeButton);
}

/// Shows the window's miniaturize button.
/// The miniaturize button is visible by default.
/// This method is only available on macOS.
static Future<void> showMiniaturizeButton() async {
await _kCompleter.future;
await _kChannel.invokeMethod(_kShowMiniaturizeButton);
}

/// Hides the window's close button.
/// This method is only available on macOS.
static Future<void> hideCloseButton() async {
await _kCompleter.future;
await _kChannel.invokeMethod(_kHideCloseButton);
}

/// Shows the window's close button.
/// The close button is visible by default.
/// This method is only available on macOS.
static Future<void> showCloseButton() async {
await _kCompleter.future;
await _kChannel.invokeMethod(_kShowCloseButton);
}

/// Enables the window's zoom button.
/// The zoom button is enabled by default.
/// This method is only available on macOS.
static Future<void> enableZoomButton() async {
await _kCompleter.future;
await _kChannel.invokeMethod(_kEnableZoomButton);
}

/// Disables the window's zoom button.
/// This method is only available on macOS.
static Future<void> disableZoomButton() async {
await _kCompleter.future;
await _kChannel.invokeMethod(_kDisableZoomButton);
}

/// Enables the window's miniaturize button.
/// The miniaturize button is enabled by default.
/// This method is only available on macOS.
static Future<void> enableMiniaturizeButton() async {
await _kCompleter.future;
await _kChannel.invokeMethod(_kEnableMiniaturizeButton);
}

/// Disables the window's miniaturize button.
/// This method is only available on macOS.
static Future<void> disableMiniaturizeButton() async {
await _kCompleter.future;
await _kChannel.invokeMethod(_kDisableMiniaturizeButton);
}

/// Enables the window's close button.
/// The close button is enabled by default.
/// This method is only available on macOS.
static Future<void> enableCloseButton() async {
await _kCompleter.future;
await _kChannel.invokeMethod(_kEnableCloseButton);
}

/// Disables the window's close button.
/// This method is only available on macOS.
static Future<void> disableCloseButton() async {
await _kCompleter.future;
await _kChannel.invokeMethod(_kDisableCloseButton);
}

/// Gets whether the window is currently being resized by the user.
/// This method is only available on macOS.
static Future<bool> isWindowInLiveResize() async {
await _kCompleter.future;
return await _kChannel.invokeMethod(_kIsWindowInLiveResize);
}

/// Sets the window's alpha value.
/// This method is only available on macOS.
static Future<void> setWindowAlphaValue(double value) async {
await _kCompleter.future;
await _kChannel.invokeMethod(_kSetWindowAlphaValue, <String, dynamic>{
'value': value,
});
}

/// Makes the window restorable.
/// If the window is restorable, its configuration will be preserved between
/// application launches.
/// This method is only available on macOS.
static Future<void> makeWindowRestorable() async {
await _kCompleter.future;
await _kChannel.invokeMethod(_kMakeWindowRestorable);
}

/// Makes the window unrestorable.
/// If the window is unrestorable, its configuration will be cleared between
/// application launches.
/// This method is only available on macOS.
static Future<void> makeWindowUnrestorable() async {
await _kCompleter.future;
await _kChannel.invokeMethod(_kMakeWindowUnrestorable);
}

/// Gets if the window is visible.
/// This method is only available on macOS.
static Future<bool> isWindowVisible() async {
await _kCompleter.future;
return await _kChannel.invokeMethod(_kIsWindowVisible);
}

/// Overrides the brightness setting of the window (macOS only).
static Future<void> overrideMacOSBrightness({
required bool dark,
Expand Down
Loading

0 comments on commit def49ce

Please sign in to comment.