Skip to content

Commit

Permalink
Run on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
bdlukaa committed Dec 2, 2022
1 parent 678ca33 commit 891c027
Show file tree
Hide file tree
Showing 11 changed files with 107 additions and 25 deletions.
52 changes: 36 additions & 16 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/

import 'dart:io';
import 'package:bluecherry_client/widgets/misc.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:provider/provider.dart';
Expand All @@ -26,6 +27,7 @@ import 'package:permission_handler/permission_handler.dart';
import 'package:status_bar_control/status_bar_control.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:window_manager/window_manager.dart';

import 'package:bluecherry_client/providers/mobile_view_provider.dart';
import 'package:bluecherry_client/providers/settings_provider.dart';
Expand All @@ -52,22 +54,40 @@ Future<void> main() async {
await MobileViewProvider.ensureInitialized();
await ServersProvider.ensureInitialized();
await SettingsProvider.ensureInitialized();
await FirebaseConfiguration.ensureInitialized();
// Restore the navigation bar & status bar styling.
SystemChrome.setSystemUIOverlayStyle(
const SystemUiOverlayStyle(
systemNavigationBarColor: Colors.black,
systemNavigationBarDividerColor: Colors.black,
systemNavigationBarIconBrightness: Brightness.dark,
),
);
StatusBarControl.setStyle(
getStatusBarStyleFromBrightness(
SettingsProvider.instance.themeMode == ThemeMode.light
? Brightness.dark
: Brightness.light,
),
);

/// Firebase messaging isn't available on desktop platforms
if (!isDesktop) {
await FirebaseConfiguration.ensureInitialized();
// Restore the navigation bar & status bar styling.
SystemChrome.setSystemUIOverlayStyle(
const SystemUiOverlayStyle(
systemNavigationBarColor: Colors.black,
systemNavigationBarDividerColor: Colors.black,
systemNavigationBarIconBrightness: Brightness.dark,
),
);
StatusBarControl.setStyle(
getStatusBarStyleFromBrightness(
SettingsProvider.instance.themeMode == ThemeMode.light
? Brightness.dark
: Brightness.light,
),
);
} else {
await WindowManager.instance.ensureInitialized();
windowManager.waitUntilReadyToShow().then((_) async {
await windowManager.setTitleBarStyle(
TitleBarStyle.hidden,
windowButtonVisibility: false,
);
await windowManager.setSize(const Size(855, 645));
await windowManager.setMinimumSize(const Size(350, 600));
await windowManager.center();
await windowManager.show();
await windowManager.setSkipTaskbar(false);
});
}

runApp(const MyApp());
}

Expand Down
1 change: 1 addition & 0 deletions lib/widgets/add_server_wizard.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/

import 'dart:io';
import 'package:bluecherry_client/widgets/desktop_buttons.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:url_launcher/url_launcher.dart';
Expand Down
20 changes: 20 additions & 0 deletions lib/widgets/desktop_buttons.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import 'package:flutter/material.dart';
import 'package:window_manager/window_manager.dart';

class WindowButtons extends StatelessWidget {
const WindowButtons({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
final theme = Theme.of(context);

return SizedBox(
width: 138,
height: 50,
child: WindowCaption(
brightness: theme.brightness,
backgroundColor: Colors.transparent,
),
);
}
}
15 changes: 7 additions & 8 deletions lib/widgets/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:bluecherry_client/widgets/device_grid.dart';
import 'package:bluecherry_client/widgets/events_screen.dart';
import 'package:bluecherry_client/widgets/settings.dart';
import 'package:bluecherry_client/widgets/misc.dart';
import 'package:bluecherry_client/utils/methods.dart';
import 'package:bluecherry_client/providers/server_provider.dart';
import 'package:bluecherry_client/widgets/add_server_wizard.dart';
Expand All @@ -37,13 +36,13 @@ class Home extends StatelessWidget {

@override
Widget build(BuildContext context) {
if (isDesktop) {
// TODO: missing implementation.
// WIP: [MobileHome].
throw Exception('[DeviceGrid] is not supported on desktop.');
} else {
return const MobileHome();
}
// if (isDesktop) {
// // TODO: missing implementation.
// // WIP: [MobileHome].
// throw Exception('[DeviceGrid] is not supported on desktop.');
// } else {
return const MobileHome();
// }
}
}

Expand Down
11 changes: 10 additions & 1 deletion lib/widgets/misc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,19 @@
import 'dart:io';
import 'dart:async';

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

const double kDesktopAppBarHeight = 64.0;
final isDesktop = Platform.isWindows || Platform.isLinux || Platform.isMacOS;
bool get isDesktop {
if (kIsWeb) return false;
return [
TargetPlatform.windows,
TargetPlatform.linux,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
}

final isMobile = Platform.isAndroid || Platform.isIOS;
final desktopTitleBarHeight = Platform.isWindows ? 0.0 : 0.0;

Expand Down
8 changes: 8 additions & 0 deletions linux/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,18 @@

#include "generated_plugin_registrant.h"

#include <screen_retriever/screen_retriever_plugin.h>
#include <url_launcher_linux/url_launcher_plugin.h>
#include <window_manager/window_manager_plugin.h>

void fl_register_plugins(FlPluginRegistry* registry) {
g_autoptr(FlPluginRegistrar) screen_retriever_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "ScreenRetrieverPlugin");
screen_retriever_plugin_register_with_registrar(screen_retriever_registrar);
g_autoptr(FlPluginRegistrar) url_launcher_linux_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "UrlLauncherPlugin");
url_launcher_plugin_register_with_registrar(url_launcher_linux_registrar);
g_autoptr(FlPluginRegistrar) window_manager_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "WindowManagerPlugin");
window_manager_plugin_register_with_registrar(window_manager_registrar);
}
2 changes: 2 additions & 0 deletions linux/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
#

list(APPEND FLUTTER_PLUGIN_LIST
screen_retriever
url_launcher_linux
window_manager
)

list(APPEND FLUTTER_FFI_PLUGIN_LIST
Expand Down
14 changes: 14 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,13 @@ packages:
url: "https://github.com/alexmercerind/reorderable_grid_view.git"
source: git
version: "2.2.2"
screen_retriever:
dependency: transitive
description:
name: screen_retriever
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.4"
sky_engine:
dependency: transitive
description: flutter
Expand Down Expand Up @@ -625,6 +632,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "2.6.1"
window_manager:
dependency: "direct main"
description:
name: window_manager
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.8"
xdg_directories:
dependency: transitive
description:
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ dependencies:
hive_flutter: ^1.1.0
video_thumbnail: ^0.5.0
permission_handler: ^10.1.0
window_manager: ^0.2.8

dev_dependencies:
flutter_test:
Expand Down
6 changes: 6 additions & 0 deletions windows/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,17 @@
#include "generated_plugin_registrant.h"

#include <permission_handler_windows/permission_handler_windows_plugin.h>
#include <screen_retriever/screen_retriever_plugin.h>
#include <url_launcher_windows/url_launcher_windows.h>
#include <window_manager/window_manager_plugin.h>

void RegisterPlugins(flutter::PluginRegistry* registry) {
PermissionHandlerWindowsPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("PermissionHandlerWindowsPlugin"));
ScreenRetrieverPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("ScreenRetrieverPlugin"));
UrlLauncherWindowsRegisterWithRegistrar(
registry->GetRegistrarForPlugin("UrlLauncherWindows"));
WindowManagerPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("WindowManagerPlugin"));
}
2 changes: 2 additions & 0 deletions windows/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

list(APPEND FLUTTER_PLUGIN_LIST
permission_handler_windows
screen_retriever
url_launcher_windows
window_manager
)

list(APPEND FLUTTER_FFI_PLUGIN_LIST
Expand Down

0 comments on commit 891c027

Please sign in to comment.