-
-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(window_manager): rewrite window manager to be platform-safe
- Loading branch information
1 parent
d37e8e2
commit d6aed6c
Showing
7 changed files
with
74 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
5 changes: 5 additions & 0 deletions
5
lib/core/system/window_manager/platform/window_manager_html.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import '../window_manager.dart'; | ||
|
||
bool isPlatformSupported() => false; | ||
LunaWindowManager getWindowManager() => | ||
throw UnsupportedError('LunaWindowManager unsupported'); |
48 changes: 48 additions & 0 deletions
48
lib/core/system/window_manager/platform/window_manager_io.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import 'package:flutter/foundation.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:window_manager/window_manager.dart'; | ||
|
||
import '../../platform.dart'; | ||
import '../window_manager.dart'; | ||
|
||
bool isPlatformSupported() => LunaPlatform().isDesktop; | ||
LunaWindowManager getWindowManager() { | ||
switch (defaultTargetPlatform) { | ||
case TargetPlatform.linux: | ||
case TargetPlatform.macOS: | ||
case TargetPlatform.windows: | ||
return IO(); | ||
default: | ||
throw UnsupportedError('LunaWindowManager unsupported'); | ||
} | ||
} | ||
|
||
class IO implements LunaWindowManager { | ||
@override | ||
Future<void> initialize() async { | ||
await windowManager.ensureInitialized(); | ||
windowManager.waitUntilReadyToShow().then((_) async { | ||
const Size minSize = Size( | ||
LunaWindowManager.MINIMUM_WINDOW_SIZE, | ||
LunaWindowManager.MINIMUM_WINDOW_SIZE, | ||
); | ||
const Size size = Size( | ||
LunaWindowManager.INITIAL_WINDOW_SIZE, | ||
LunaWindowManager.INITIAL_WINDOW_SIZE, | ||
); | ||
|
||
if (!kDebugMode) await windowManager.setSize(size); | ||
await windowManager.setMinimumSize(minSize); | ||
setWindowTitle('LunaSea'); | ||
|
||
windowManager.show(); | ||
}); | ||
} | ||
|
||
@override | ||
Future<void> setWindowTitle(String title) async { | ||
return windowManager | ||
.waitUntilReadyToShow() | ||
.then((_) async => await windowManager.setTitle(title)); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
lib/core/system/window_manager/platform/window_manager_stub.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import '../window_manager.dart'; | ||
|
||
bool isPlatformSupported() => false; | ||
LunaWindowManager getWindowManager() => | ||
throw UnsupportedError('LunaWindowManager unsupported'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import 'platform/window_manager_stub.dart' | ||
if (dart.library.io) 'platform/window_manager_io.dart' | ||
if (dart.library.html) 'platform/window_manager_html.dart'; | ||
|
||
abstract class LunaWindowManager { | ||
static const double MINIMUM_WINDOW_SIZE = 400; | ||
static const double INITIAL_WINDOW_SIZE = 700; | ||
|
||
static bool get isSupported => isPlatformSupported(); | ||
factory LunaWindowManager() => getWindowManager(); | ||
|
||
Future<void> initialize(); | ||
Future<void> setWindowTitle(String title); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters