From 9070b24c08c9e55a8fd64c1870970ee1106eb29a Mon Sep 17 00:00:00 2001 From: Miguel Beltran Date: Mon, 11 Apr 2022 14:33:25 +0200 Subject: [PATCH] [all] Fix formatting issues (#832) * formatting fixes * format Objective-C code in default style and not in Google style * quick format * add cpp, m, h files to editorconfig --- .editorconfig | 12 ++ .github/workflows/all_plugins.yaml | 2 +- .../Classes/AndroidAlarmManagerPlusPlugin.m | 16 +- .../example/ios/Runner/AppDelegate.m | 3 +- .../example/ios/Runner/main.m | 7 +- .../battery_plus/example/linux/main.cc | 2 +- .../example/linux/my_application.cc | 14 +- .../example/linux/my_application.h | 4 +- .../example/windows/runner/flutter_window.cpp | 10 +- .../example/windows/runner/flutter_window.h | 14 +- .../example/windows/runner/run_loop.cpp | 4 +- .../example/windows/runner/run_loop.h | 16 +- .../example/windows/runner/utils.h | 2 +- .../example/windows/runner/win32_window.cpp | 96 ++++----- .../example/windows/runner/win32_window.h | 14 +- .../ios/Classes/FLTBatteryPlusPlugin.m | 66 ++++--- .../windows/battery_plus_windows_plugin.cpp | 22 +-- .../battery_plus_windows_plugin.h | 4 +- .../battery_plus_windows/system_battery.h | 6 +- .../windows/system_battery.cpp | 28 +-- .../connectivity_plus/example/linux/main.cc | 2 +- .../example/linux/my_application.cc | 14 +- .../example/linux/my_application.h | 4 +- .../example/windows/runner/flutter_window.cpp | 10 +- .../example/windows/runner/flutter_window.h | 14 +- .../example/windows/runner/run_loop.cpp | 4 +- .../example/windows/runner/run_loop.h | 16 +- .../example/windows/runner/utils.cpp | 6 +- .../example/windows/runner/utils.h | 4 +- .../example/windows/runner/win32_window.cpp | 94 ++++----- .../example/windows/runner/win32_window.h | 14 +- .../ios/Classes/ConnectivityPlusPlugin.h | 2 +- .../ios/Classes/ConnectivityPlusPlugin.m | 2 +- .../connectivity_plus_windows_plugin.cpp | 56 +++--- .../connectivity_plus_windows_plugin.h | 4 +- .../network_manager.h | 6 +- .../windows/network_manager.cpp | 16 +- .../device_info_plus/example/linux/main.cc | 2 +- .../example/linux/my_application.cc | 14 +- .../example/linux/my_application.h | 4 +- .../example/windows/runner/flutter_window.cpp | 10 +- .../example/windows/runner/flutter_window.h | 14 +- .../example/windows/runner/run_loop.cpp | 4 +- .../example/windows/runner/run_loop.h | 16 +- .../example/windows/runner/utils.cpp | 6 +- .../example/windows/runner/utils.h | 4 +- .../example/windows/runner/win32_window.cpp | 94 ++++----- .../example/windows/runner/win32_window.h | 14 +- .../ios/Classes/FLTDeviceInfoPlusPlugin.m | 24 +-- .../example/ios/Runner/AppDelegate.m | 3 +- .../example/ios/Runner/main.m | 7 +- .../network_info_plus/example/linux/main.cc | 2 +- .../example/linux/my_application.cc | 14 +- .../example/linux/my_application.h | 4 +- .../example/windows/runner/flutter_window.cpp | 10 +- .../example/windows/runner/flutter_window.h | 14 +- .../example/windows/runner/run_loop.cpp | 4 +- .../example/windows/runner/run_loop.h | 16 +- .../example/windows/runner/utils.cpp | 6 +- .../example/windows/runner/utils.h | 4 +- .../example/windows/runner/win32_window.cpp | 94 ++++----- .../example/windows/runner/win32_window.h | 14 +- .../Classes/FLTCaptiveNetworkInfoProvider.h | 2 +- .../Classes/FLTCaptiveNetworkInfoProvider.m | 9 +- .../Classes/FLTHotspotNetworkInfoProvider.h | 2 +- .../Classes/FLTHotspotNetworkInfoProvider.m | 9 +- .../FLTNetworkInfoLocationPlusHandler.h | 3 +- .../FLTNetworkInfoLocationPlusHandler.m | 3 +- .../ios/Classes/FLTNetworkInfoPlusPlugin.m | 134 +++++++------ .../ios/Classes/FLTNetworkInfoProvider.h | 2 +- .../ios/Classes/getgateway.h | 2 +- .../network_info_plus/ios/Classes/route.h | 104 +++++----- .../network_info_plus_windows/network_info.h | 6 +- .../network_info_plus_windows_plugin.h | 4 +- .../windows/network_info.cpp | 4 +- .../network_info_plus_windows_plugin.cpp | 6 +- .../example/ios/Runner/AppDelegate.m | 3 +- .../example/ios/Runner/main.m | 7 +- .../package_info_plus/example/linux/main.cc | 2 +- .../example/linux/my_application.cc | 18 +- .../example/linux/my_application.h | 4 +- .../example/windows/runner/flutter_window.cpp | 10 +- .../example/windows/runner/flutter_window.h | 14 +- .../example/windows/runner/run_loop.cpp | 4 +- .../example/windows/runner/run_loop.h | 16 +- .../example/windows/runner/utils.h | 2 +- .../example/windows/runner/win32_window.cpp | 96 ++++----- .../example/windows/runner/win32_window.h | 14 +- .../ios/Classes/FLTPackageInfoPlusPlugin.m | 28 +-- .../macos/Classes/FLTPackageInfoPlusPlugin.m | 28 +-- .../example/ios/Runner/AppDelegate.m | 3 +- .../sensors_plus/example/ios/Runner/main.m | 7 +- .../ios/Classes/FLTSensorsPlusPlugin.m | 98 ++++++---- .../example/ios/Runner/AppDelegate.m | 3 +- .../share_plus/example/ios/Runner/main.m | 7 +- .../share_plus/example/linux/main.cc | 2 +- .../example/linux/my_application.cc | 14 +- .../share_plus/example/linux/my_application.h | 4 +- .../example/windows/runner/flutter_window.cpp | 10 +- .../example/windows/runner/flutter_window.h | 14 +- .../example/windows/runner/run_loop.cpp | 4 +- .../example/windows/runner/run_loop.h | 16 +- .../share_plus/example/windows/runner/utils.h | 2 +- .../example/windows/runner/win32_window.cpp | 96 ++++----- .../example/windows/runner/win32_window.h | 14 +- .../ios/Classes/FLTSharePlusPlugin.m | 183 ++++++++++-------- 106 files changed, 1059 insertions(+), 962 deletions(-) diff --git a/.editorconfig b/.editorconfig index 96eb00eff0..2d682b32e4 100644 --- a/.editorconfig +++ b/.editorconfig @@ -7,6 +7,10 @@ insert_final_newline = true trim_trailing_whitespace = true charset = utf-8 +[*.cpp] +indent_style = space +indent_size = 2 + [*.dart] indent_style = space indent_size = 2 @@ -16,10 +20,18 @@ indent_size = 2 indent_style = space indent_size = 4 +[*.h] +indent_style = space +indent_size = 2 + # Kotlin code style according to https://developer.android.com/kotlin/style-guide [*.{kt, kts}] indent_size = 4 max_line_length = 100 +[*.m] +indent_style = space +indent_size = 2 + [*.yml] indent_size = 2 diff --git a/.github/workflows/all_plugins.yaml b/.github/workflows/all_plugins.yaml index cc80d82473..a04ea44916 100644 --- a/.github/workflows/all_plugins.yaml +++ b/.github/workflows/all_plugins.yaml @@ -101,7 +101,7 @@ jobs: if: ${{ success() || failure() }} run: | melos exec -c 4 --ignore="*platform_interface*" --ignore="*web*" -- \ - find . -maxdepth 3 -name "*.h" -o -name "*.m" -print0 \| xargs -0 clang-format -i --style=Google --verbose + find . -maxdepth 3 -name "*.h" -o -name "*.m" -print0 \| xargs -0 clang-format -i --verbose ./.github/workflows/scripts/validate-formatting.sh - name: "Validate Java formatting" if: ${{ success() || failure() }} diff --git a/packages/android_alarm_manager_plus/ios/Classes/AndroidAlarmManagerPlusPlugin.m b/packages/android_alarm_manager_plus/ios/Classes/AndroidAlarmManagerPlusPlugin.m index affbc9e083..b3ed30b43e 100644 --- a/packages/android_alarm_manager_plus/ios/Classes/AndroidAlarmManagerPlusPlugin.m +++ b/packages/android_alarm_manager_plus/ios/Classes/AndroidAlarmManagerPlusPlugin.m @@ -5,16 +5,18 @@ #import "AndroidAlarmManagerPlusPlugin.h" @implementation FLTAndroidAlarmManagerPlusPlugin -+ (void)registerWithRegistrar:(NSObject*)registrar { - FlutterMethodChannel* channel = - [FlutterMethodChannel methodChannelWithName:@"dev.fluttercommunity.plus/android_alarm_manager" - binaryMessenger:[registrar messenger] - codec:[FlutterJSONMethodCodec sharedInstance]]; - FLTAndroidAlarmManagerPlusPlugin* instance = [[FLTAndroidAlarmManagerPlusPlugin alloc] init]; ++ (void)registerWithRegistrar:(NSObject *)registrar { + FlutterMethodChannel *channel = [FlutterMethodChannel + methodChannelWithName:@"dev.fluttercommunity.plus/android_alarm_manager" + binaryMessenger:[registrar messenger] + codec:[FlutterJSONMethodCodec sharedInstance]]; + FLTAndroidAlarmManagerPlusPlugin *instance = + [[FLTAndroidAlarmManagerPlusPlugin alloc] init]; [registrar addMethodCallDelegate:instance channel:channel]; } -- (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result { +- (void)handleMethodCall:(FlutterMethodCall *)call + result:(FlutterResult)result { result(FlutterMethodNotImplemented); } diff --git a/packages/android_intent_plus/example/ios/Runner/AppDelegate.m b/packages/android_intent_plus/example/ios/Runner/AppDelegate.m index f086757071..26c653a8ea 100644 --- a/packages/android_intent_plus/example/ios/Runner/AppDelegate.m +++ b/packages/android_intent_plus/example/ios/Runner/AppDelegate.m @@ -11,7 +11,8 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [GeneratedPluginRegistrant registerWithRegistry:self]; // Override point for customization after application launch. - return [super application:application didFinishLaunchingWithOptions:launchOptions]; + return [super application:application + didFinishLaunchingWithOptions:launchOptions]; } @end diff --git a/packages/android_intent_plus/example/ios/Runner/main.m b/packages/android_intent_plus/example/ios/Runner/main.m index bec320c0be..b7fe28c73a 100644 --- a/packages/android_intent_plus/example/ios/Runner/main.m +++ b/packages/android_intent_plus/example/ios/Runner/main.m @@ -2,12 +2,13 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#import "AppDelegate.h" #import #import -#import "AppDelegate.h" -int main(int argc, char* argv[]) { +int main(int argc, char *argv[]) { @autoreleasepool { - return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); + return UIApplicationMain(argc, argv, nil, + NSStringFromClass([AppDelegate class])); } } diff --git a/packages/battery_plus/battery_plus/example/linux/main.cc b/packages/battery_plus/battery_plus/example/linux/main.cc index 10835acb58..8bc1561588 100644 --- a/packages/battery_plus/battery_plus/example/linux/main.cc +++ b/packages/battery_plus/battery_plus/example/linux/main.cc @@ -1,6 +1,6 @@ #include "my_application.h" -int main(int argc, char** argv) { +int main(int argc, char **argv) { // Only X11 is currently supported. // Wayland support is being developed: // https://github.com/flutter/flutter/issues/57932. diff --git a/packages/battery_plus/battery_plus/example/linux/my_application.cc b/packages/battery_plus/battery_plus/example/linux/my_application.cc index 67ed0b9025..cef2f77145 100644 --- a/packages/battery_plus/battery_plus/example/linux/my_application.cc +++ b/packages/battery_plus/battery_plus/example/linux/my_application.cc @@ -11,10 +11,10 @@ struct _MyApplication { G_DEFINE_TYPE(MyApplication, my_application, GTK_TYPE_APPLICATION) // Implements GApplication::activate. -static void my_application_activate(GApplication* application) { - GtkWindow* window = +static void my_application_activate(GApplication *application) { + GtkWindow *window = GTK_WINDOW(gtk_application_window_new(GTK_APPLICATION(application))); - GtkHeaderBar* header_bar = GTK_HEADER_BAR(gtk_header_bar_new()); + GtkHeaderBar *header_bar = GTK_HEADER_BAR(gtk_header_bar_new()); gtk_widget_show(GTK_WIDGET(header_bar)); gtk_header_bar_set_title(header_bar, "example"); gtk_header_bar_set_show_close_button(header_bar, TRUE); @@ -24,7 +24,7 @@ static void my_application_activate(GApplication* application) { g_autoptr(FlDartProject) project = fl_dart_project_new(); - FlView* view = fl_view_new(project); + FlView *view = fl_view_new(project); gtk_widget_show(GTK_WIDGET(view)); gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(view)); @@ -33,13 +33,13 @@ static void my_application_activate(GApplication* application) { gtk_widget_grab_focus(GTK_WIDGET(view)); } -static void my_application_class_init(MyApplicationClass* klass) { +static void my_application_class_init(MyApplicationClass *klass) { G_APPLICATION_CLASS(klass)->activate = my_application_activate; } -static void my_application_init(MyApplication* self) {} +static void my_application_init(MyApplication *self) {} -MyApplication* my_application_new() { +MyApplication *my_application_new() { return MY_APPLICATION(g_object_new( my_application_get_type(), "application-id", APPLICATION_ID, nullptr)); } diff --git a/packages/battery_plus/battery_plus/example/linux/my_application.h b/packages/battery_plus/battery_plus/example/linux/my_application.h index 72271d5e41..3258a73cf4 100644 --- a/packages/battery_plus/battery_plus/example/linux/my_application.h +++ b/packages/battery_plus/battery_plus/example/linux/my_application.h @@ -13,6 +13,6 @@ G_DECLARE_FINAL_TYPE(MyApplication, my_application, MY, APPLICATION, * * Returns: a new #MyApplication. */ -MyApplication* my_application_new(); +MyApplication *my_application_new(); -#endif // FLUTTER_MY_APPLICATION_H_ +#endif // FLUTTER_MY_APPLICATION_H_ diff --git a/packages/battery_plus/battery_plus/example/windows/runner/flutter_window.cpp b/packages/battery_plus/battery_plus/example/windows/runner/flutter_window.cpp index c422723045..0f0105d995 100644 --- a/packages/battery_plus/battery_plus/example/windows/runner/flutter_window.cpp +++ b/packages/battery_plus/battery_plus/example/windows/runner/flutter_window.cpp @@ -4,8 +4,8 @@ #include "flutter/generated_plugin_registrant.h" -FlutterWindow::FlutterWindow(RunLoop* run_loop, - const flutter::DartProject& project) +FlutterWindow::FlutterWindow(RunLoop *run_loop, + const flutter::DartProject &project) : run_loop_(run_loop), project_(project) {} FlutterWindow::~FlutterWindow() {} @@ -55,9 +55,9 @@ FlutterWindow::MessageHandler(HWND hwnd, UINT const message, } switch (message) { - case WM_FONTCHANGE: - flutter_controller_->engine()->ReloadSystemFonts(); - break; + case WM_FONTCHANGE: + flutter_controller_->engine()->ReloadSystemFonts(); + break; } return Win32Window::MessageHandler(hwnd, message, wparam, lparam); diff --git a/packages/battery_plus/battery_plus/example/windows/runner/flutter_window.h b/packages/battery_plus/battery_plus/example/windows/runner/flutter_window.h index b663ddd501..69234d4f5e 100644 --- a/packages/battery_plus/battery_plus/example/windows/runner/flutter_window.h +++ b/packages/battery_plus/battery_plus/example/windows/runner/flutter_window.h @@ -11,23 +11,23 @@ // A window that does nothing but host a Flutter view. class FlutterWindow : public Win32Window { - public: +public: // Creates a new FlutterWindow driven by the |run_loop|, hosting a // Flutter view running |project|. - explicit FlutterWindow(RunLoop* run_loop, - const flutter::DartProject& project); + explicit FlutterWindow(RunLoop *run_loop, + const flutter::DartProject &project); virtual ~FlutterWindow(); - protected: +protected: // Win32Window: bool OnCreate() override; void OnDestroy() override; LRESULT MessageHandler(HWND window, UINT const message, WPARAM const wparam, LPARAM const lparam) noexcept override; - private: +private: // The run loop driving events for this window. - RunLoop* run_loop_; + RunLoop *run_loop_; // The project to run. flutter::DartProject project_; @@ -36,4 +36,4 @@ class FlutterWindow : public Win32Window { std::unique_ptr flutter_controller_; }; -#endif // RUNNER_FLUTTER_WINDOW_H_ +#endif // RUNNER_FLUTTER_WINDOW_H_ diff --git a/packages/battery_plus/battery_plus/example/windows/runner/run_loop.cpp b/packages/battery_plus/battery_plus/example/windows/runner/run_loop.cpp index 2d6636ab6b..31b89f6229 100644 --- a/packages/battery_plus/battery_plus/example/windows/runner/run_loop.cpp +++ b/packages/battery_plus/battery_plus/example/windows/runner/run_loop.cpp @@ -44,12 +44,12 @@ void RunLoop::Run() { } void RunLoop::RegisterFlutterInstance( - flutter::FlutterEngine* flutter_instance) { + flutter::FlutterEngine *flutter_instance) { flutter_instances_.insert(flutter_instance); } void RunLoop::UnregisterFlutterInstance( - flutter::FlutterEngine* flutter_instance) { + flutter::FlutterEngine *flutter_instance) { flutter_instances_.erase(flutter_instance); } diff --git a/packages/battery_plus/battery_plus/example/windows/runner/run_loop.h b/packages/battery_plus/battery_plus/example/windows/runner/run_loop.h index 5f2c4a9ad7..7fe1aaccc2 100644 --- a/packages/battery_plus/battery_plus/example/windows/runner/run_loop.h +++ b/packages/battery_plus/battery_plus/example/windows/runner/run_loop.h @@ -9,30 +9,30 @@ // A runloop that will service events for Flutter instances as well // as native messages. class RunLoop { - public: +public: RunLoop(); ~RunLoop(); // Prevent copying - RunLoop(RunLoop const&) = delete; - RunLoop& operator=(RunLoop const&) = delete; + RunLoop(RunLoop const &) = delete; + RunLoop &operator=(RunLoop const &) = delete; // Runs the run loop until the application quits. void Run(); // Registers the given Flutter instance for event servicing. - void RegisterFlutterInstance(flutter::FlutterEngine* flutter_instance); + void RegisterFlutterInstance(flutter::FlutterEngine *flutter_instance); // Unregisters the given Flutter instance from event servicing. - void UnregisterFlutterInstance(flutter::FlutterEngine* flutter_instance); + void UnregisterFlutterInstance(flutter::FlutterEngine *flutter_instance); - private: +private: using TimePoint = std::chrono::steady_clock::time_point; // Processes all currently pending messages for registered Flutter instances. TimePoint ProcessFlutterMessages(); - std::set flutter_instances_; + std::set flutter_instances_; }; -#endif // RUNNER_RUN_LOOP_H_ +#endif // RUNNER_RUN_LOOP_H_ diff --git a/packages/battery_plus/battery_plus/example/windows/runner/utils.h b/packages/battery_plus/battery_plus/example/windows/runner/utils.h index d792603bb1..7021e6d06d 100644 --- a/packages/battery_plus/battery_plus/example/windows/runner/utils.h +++ b/packages/battery_plus/battery_plus/example/windows/runner/utils.h @@ -5,4 +5,4 @@ // it for both the runner and the Flutter library. void CreateAndAttachConsole(); -#endif // RUNNER_UTILS_H_ +#endif // RUNNER_UTILS_H_ diff --git a/packages/battery_plus/battery_plus/example/windows/runner/win32_window.cpp b/packages/battery_plus/battery_plus/example/windows/runner/win32_window.cpp index c63ad013b0..9669d7fc6b 100644 --- a/packages/battery_plus/battery_plus/example/windows/runner/win32_window.cpp +++ b/packages/battery_plus/battery_plus/example/windows/runner/win32_window.cpp @@ -27,7 +27,7 @@ void EnableFullDpiSupportIfAvailable(HWND hwnd) { return; } auto enable_non_client_dpi_scaling = - reinterpret_cast( + reinterpret_cast( GetProcAddress(user32_module, "EnableNonClientDpiScaling")); if (enable_non_client_dpi_scaling != nullptr) { enable_non_client_dpi_scaling(hwnd); @@ -35,15 +35,15 @@ void EnableFullDpiSupportIfAvailable(HWND hwnd) { } } -} // namespace +} // namespace // Manages the Win32Window's window class registration. class WindowClassRegistrar { - public: +public: ~WindowClassRegistrar() = default; // Returns the singleton registar instance. - static WindowClassRegistrar* GetInstance() { + static WindowClassRegistrar *GetInstance() { if (!instance_) { instance_ = new WindowClassRegistrar(); } @@ -52,23 +52,23 @@ class WindowClassRegistrar { // Returns the name of the window class, registering the class if it hasn't // previously been registered. - const wchar_t* GetWindowClass(); + const wchar_t *GetWindowClass(); // Unregisters the window class. Should only be called if there are no // instances of the window. void UnregisterWindowClass(); - private: +private: WindowClassRegistrar() = default; - static WindowClassRegistrar* instance_; + static WindowClassRegistrar *instance_; bool class_registered_ = false; }; -WindowClassRegistrar* WindowClassRegistrar::instance_ = nullptr; +WindowClassRegistrar *WindowClassRegistrar::instance_ = nullptr; -const wchar_t* WindowClassRegistrar::GetWindowClass() { +const wchar_t *WindowClassRegistrar::GetWindowClass() { if (!class_registered_) { WNDCLASS window_class{}; window_class.hCursor = LoadCursor(nullptr, IDC_ARROW); @@ -100,11 +100,11 @@ Win32Window::~Win32Window() { Destroy(); } -bool Win32Window::CreateAndShow(const std::wstring& title, const Point& origin, - const Size& size) { +bool Win32Window::CreateAndShow(const std::wstring &title, const Point &origin, + const Size &size) { Destroy(); - const wchar_t* window_class = + const wchar_t *window_class = WindowClassRegistrar::GetInstance()->GetWindowClass(); const POINT target_point = {static_cast(origin.x), @@ -131,14 +131,14 @@ LRESULT CALLBACK Win32Window::WndProc(HWND const window, UINT const message, WPARAM const wparam, LPARAM const lparam) noexcept { if (message == WM_NCCREATE) { - auto window_struct = reinterpret_cast(lparam); + auto window_struct = reinterpret_cast(lparam); SetWindowLongPtr(window, GWLP_USERDATA, reinterpret_cast(window_struct->lpCreateParams)); - auto that = static_cast(window_struct->lpCreateParams); + auto that = static_cast(window_struct->lpCreateParams); EnableFullDpiSupportIfAvailable(window); that->window_handle_ = window; - } else if (Win32Window* that = GetThisFromHandle(window)) { + } else if (Win32Window *that = GetThisFromHandle(window)) { return that->MessageHandler(window, message, wparam, lparam); } @@ -149,38 +149,38 @@ LRESULT Win32Window::MessageHandler(HWND hwnd, UINT const message, WPARAM const wparam, LPARAM const lparam) noexcept { switch (message) { - case WM_DESTROY: - window_handle_ = nullptr; - Destroy(); - if (quit_on_close_) { - PostQuitMessage(0); - } - return 0; - - case WM_DPICHANGED: { - auto newRectSize = reinterpret_cast(lparam); - LONG newWidth = newRectSize->right - newRectSize->left; - LONG newHeight = newRectSize->bottom - newRectSize->top; - - SetWindowPos(hwnd, nullptr, newRectSize->left, newRectSize->top, newWidth, - newHeight, SWP_NOZORDER | SWP_NOACTIVATE); - - return 0; + case WM_DESTROY: + window_handle_ = nullptr; + Destroy(); + if (quit_on_close_) { + PostQuitMessage(0); + } + return 0; + + case WM_DPICHANGED: { + auto newRectSize = reinterpret_cast(lparam); + LONG newWidth = newRectSize->right - newRectSize->left; + LONG newHeight = newRectSize->bottom - newRectSize->top; + + SetWindowPos(hwnd, nullptr, newRectSize->left, newRectSize->top, newWidth, + newHeight, SWP_NOZORDER | SWP_NOACTIVATE); + + return 0; + } + case WM_SIZE: + RECT rect = GetClientArea(); + if (child_content_ != nullptr) { + // Size and position the child window. + MoveWindow(child_content_, rect.left, rect.top, rect.right - rect.left, + rect.bottom - rect.top, TRUE); + } + return 0; + + case WM_ACTIVATE: + if (child_content_ != nullptr) { + SetFocus(child_content_); } - case WM_SIZE: - RECT rect = GetClientArea(); - if (child_content_ != nullptr) { - // Size and position the child window. - MoveWindow(child_content_, rect.left, rect.top, rect.right - rect.left, - rect.bottom - rect.top, TRUE); - } - return 0; - - case WM_ACTIVATE: - if (child_content_ != nullptr) { - SetFocus(child_content_); - } - return 0; + return 0; } return DefWindowProc(window_handle_, message, wparam, lparam); @@ -198,8 +198,8 @@ void Win32Window::Destroy() { } } -Win32Window* Win32Window::GetThisFromHandle(HWND const window) noexcept { - return reinterpret_cast( +Win32Window *Win32Window::GetThisFromHandle(HWND const window) noexcept { + return reinterpret_cast( GetWindowLongPtr(window, GWLP_USERDATA)); } diff --git a/packages/battery_plus/battery_plus/example/windows/runner/win32_window.h b/packages/battery_plus/battery_plus/example/windows/runner/win32_window.h index 4ae64a12b4..7b518125bb 100644 --- a/packages/battery_plus/battery_plus/example/windows/runner/win32_window.h +++ b/packages/battery_plus/battery_plus/example/windows/runner/win32_window.h @@ -11,7 +11,7 @@ // inherited from by classes that wish to specialize with custom // rendering and input handling class Win32Window { - public: +public: struct Point { unsigned int x; unsigned int y; @@ -34,8 +34,8 @@ class Win32Window { // consistent size to will treat the width height passed in to this function // as logical pixels and scale to appropriate for the default monitor. Returns // true if the window was created successfully. - bool CreateAndShow(const std::wstring& title, const Point& origin, - const Size& size); + bool CreateAndShow(const std::wstring &title, const Point &origin, + const Size &size); // Release OS resources associated with window. void Destroy(); @@ -53,7 +53,7 @@ class Win32Window { // Return a RECT representing the bounds of the current client area. RECT GetClientArea(); - protected: +protected: // Processes and route salient window messages for mouse handling, // size change and DPI. Delegates handling of these to member overloads that // inheriting classes can handle. @@ -68,7 +68,7 @@ class Win32Window { // Called when Destroy is called. virtual void OnDestroy(); - private: +private: friend class WindowClassRegistrar; // OS callback called by message pump. Handles the WM_NCCREATE message which @@ -81,7 +81,7 @@ class Win32Window { LPARAM const lparam) noexcept; // Retrieves a class instance pointer for |window| - static Win32Window* GetThisFromHandle(HWND const window) noexcept; + static Win32Window *GetThisFromHandle(HWND const window) noexcept; bool quit_on_close_ = false; @@ -92,4 +92,4 @@ class Win32Window { HWND child_content_ = nullptr; }; -#endif // RUNNER_WIN32_WINDOW_H_ +#endif // RUNNER_WIN32_WINDOW_H_ diff --git a/packages/battery_plus/battery_plus/ios/Classes/FLTBatteryPlusPlugin.m b/packages/battery_plus/battery_plus/ios/Classes/FLTBatteryPlusPlugin.m index 47e35bd3cd..c15a50846b 100644 --- a/packages/battery_plus/battery_plus/ios/Classes/FLTBatteryPlusPlugin.m +++ b/packages/battery_plus/battery_plus/ios/Classes/FLTBatteryPlusPlugin.m @@ -11,21 +11,22 @@ @implementation FLTBatteryPlusPlugin { FlutterEventSink _eventSink; } -+ (void)registerWithRegistrar:(NSObject*)registrar { - FLTBatteryPlusPlugin* instance = [[FLTBatteryPlusPlugin alloc] init]; ++ (void)registerWithRegistrar:(NSObject *)registrar { + FLTBatteryPlusPlugin *instance = [[FLTBatteryPlusPlugin alloc] init]; - FlutterMethodChannel* channel = - [FlutterMethodChannel methodChannelWithName:@"dev.fluttercommunity.plus/battery" - binaryMessenger:[registrar messenger]]; + FlutterMethodChannel *channel = [FlutterMethodChannel + methodChannelWithName:@"dev.fluttercommunity.plus/battery" + binaryMessenger:[registrar messenger]]; [registrar addMethodCallDelegate:instance channel:channel]; - FlutterEventChannel* chargingChannel = - [FlutterEventChannel eventChannelWithName:@"dev.fluttercommunity.plus/charging" - binaryMessenger:[registrar messenger]]; + FlutterEventChannel *chargingChannel = [FlutterEventChannel + eventChannelWithName:@"dev.fluttercommunity.plus/charging" + binaryMessenger:[registrar messenger]]; [chargingChannel setStreamHandler:instance]; } -- (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result { +- (void)handleMethodCall:(FlutterMethodCall *)call + result:(FlutterResult)result { if ([@"getBatteryLevel" isEqualToString:call.method]) { int batteryLevel = [self getBatteryLevel]; if (batteryLevel == -1) { @@ -36,7 +37,7 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result { result(@(batteryLevel)); } } else if ([@"getBatteryState" isEqualToString:call.method]) { - NSString* state = [self getBatteryState]; + NSString *state = [self getBatteryState]; if (state) { result(state); } else { @@ -51,13 +52,14 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result { } } -- (void)onBatteryStateDidChange:(NSNotification*)notification { +- (void)onBatteryStateDidChange:(NSNotification *)notification { [self sendBatteryStateEvent]; } - (void)sendBatteryStateEvent { - if (!_eventSink) return; - NSString* state = [self getBatteryState]; + if (!_eventSink) + return; + NSString *state = [self getBatteryState]; if (state) { _eventSink(state); } else { @@ -67,24 +69,24 @@ - (void)sendBatteryStateEvent { } } -- (NSString*)getBatteryState { +- (NSString *)getBatteryState { UIDeviceBatteryState state = [[UIDevice currentDevice] batteryState]; switch (state) { - case UIDeviceBatteryStateUnknown: - return @"unknown"; - case UIDeviceBatteryStateFull: - return @"full"; - case UIDeviceBatteryStateCharging: - return @"charging"; - case UIDeviceBatteryStateUnplugged: - return @"discharging"; - default: - return nil; + case UIDeviceBatteryStateUnknown: + return @"unknown"; + case UIDeviceBatteryStateFull: + return @"full"; + case UIDeviceBatteryStateCharging: + return @"charging"; + case UIDeviceBatteryStateUnplugged: + return @"discharging"; + default: + return nil; } } - (int)getBatteryLevel { - UIDevice* device = UIDevice.currentDevice; + UIDevice *device = UIDevice.currentDevice; device.batteryMonitoringEnabled = YES; if (device.batteryState == UIDeviceBatteryStateUnknown) { return -1; @@ -95,18 +97,20 @@ - (int)getBatteryLevel { #pragma mark FlutterStreamHandler impl -- (FlutterError*)onListenWithArguments:(id)arguments eventSink:(FlutterEventSink)eventSink { +- (FlutterError *)onListenWithArguments:(id)arguments + eventSink:(FlutterEventSink)eventSink { _eventSink = eventSink; [[UIDevice currentDevice] setBatteryMonitoringEnabled:YES]; [self sendBatteryStateEvent]; - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(onBatteryStateDidChange:) - name:UIDeviceBatteryStateDidChangeNotification - object:nil]; + [[NSNotificationCenter defaultCenter] + addObserver:self + selector:@selector(onBatteryStateDidChange:) + name:UIDeviceBatteryStateDidChangeNotification + object:nil]; return nil; } -- (FlutterError*)onCancelWithArguments:(id)arguments { +- (FlutterError *)onCancelWithArguments:(id)arguments { [[NSNotificationCenter defaultCenter] removeObserver:self]; _eventSink = nil; return nil; diff --git a/packages/battery_plus/battery_plus_windows/windows/battery_plus_windows_plugin.cpp b/packages/battery_plus/battery_plus_windows/windows/battery_plus_windows_plugin.cpp index 2a00deecc4..8c368eff21 100644 --- a/packages/battery_plus/battery_plus_windows/windows/battery_plus_windows_plugin.cpp +++ b/packages/battery_plus/battery_plus_windows/windows/battery_plus_windows_plugin.cpp @@ -25,32 +25,32 @@ typedef flutter::StreamHandlerError FlStreamHandlerError; class BatteryPlusWindowsPlugin : public flutter::Plugin { - public: +public: static void RegisterWithRegistrar(flutter::PluginRegistrarWindows *registrar); BatteryPlusWindowsPlugin(flutter::PluginRegistrarWindows *registrar); ~BatteryPlusWindowsPlugin(); - private: +private: void HandleMethodCall(const FlMethodCall &method_call, std::unique_ptr result); }; class BatteryStatusStreamHandler : public FlStreamHandler { - public: +public: BatteryStatusStreamHandler(flutter::PluginRegistrarWindows *registrar); - protected: +protected: void AddStatusEvent(BatteryStatus status); - std::unique_ptr OnListenInternal( - const flutter::EncodableValue *arguments, - std::unique_ptr &&events) override; + std::unique_ptr + OnListenInternal(const flutter::EncodableValue *arguments, + std::unique_ptr &&events) override; - std::unique_ptr OnCancelInternal( - const flutter::EncodableValue *arguments) override; + std::unique_ptr + OnCancelInternal(const flutter::EncodableValue *arguments) override; - private: +private: int _delegate = -1; SystemBattery _battery; std::unique_ptr _events; @@ -164,7 +164,7 @@ void BatteryPlusWindowsPlugin::HandleMethodCall( } } -} // namespace +} // namespace void BatteryPlusWindowsPluginRegisterWithRegistrar( FlutterDesktopPluginRegistrarRef registrar) { diff --git a/packages/battery_plus/battery_plus_windows/windows/include/battery_plus_windows/battery_plus_windows_plugin.h b/packages/battery_plus/battery_plus_windows/windows/include/battery_plus_windows/battery_plus_windows_plugin.h index 0bdf64f2be..3616cbcbab 100644 --- a/packages/battery_plus/battery_plus_windows/windows/include/battery_plus_windows/battery_plus_windows_plugin.h +++ b/packages/battery_plus/battery_plus_windows/windows/include/battery_plus_windows/battery_plus_windows_plugin.h @@ -17,7 +17,7 @@ FLUTTER_PLUGIN_EXPORT void BatteryPlusWindowsPluginRegisterWithRegistrar( FlutterDesktopPluginRegistrarRef registrar); #if defined(__cplusplus) -} // extern "C" +} // extern "C" #endif -#endif // FLUTTER_PLUGIN_BATTERY_PLUS_WINDOWS_PLUGIN_H_ +#endif // FLUTTER_PLUGIN_BATTERY_PLUS_WINDOWS_PLUGIN_H_ diff --git a/packages/battery_plus/battery_plus_windows/windows/include/battery_plus_windows/system_battery.h b/packages/battery_plus/battery_plus_windows/windows/include/battery_plus_windows/system_battery.h index c34da3f8a8..9e58f0e21c 100644 --- a/packages/battery_plus/battery_plus_windows/windows/include/battery_plus_windows/system_battery.h +++ b/packages/battery_plus/battery_plus_windows/windows/include/battery_plus_windows/system_battery.h @@ -12,7 +12,7 @@ enum class BatteryStatus { Full, Charging, Discharging, Error, Unknown }; typedef std::function BatteryStatusCallback; class SystemBattery { - public: +public: SystemBattery(); ~SystemBattery(); @@ -29,9 +29,9 @@ class SystemBattery { void ProcessMsg(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam); bool StopListen(); - private: +private: HPOWERNOTIFY _notifier = nullptr; BatteryStatusCallback _callback = nullptr; }; -#endif // FLUTTER_PLUGIN_BATTERY_PLUS_SYSTEM_BATTERY_H_ +#endif // FLUTTER_PLUGIN_BATTERY_PLUS_SYSTEM_BATTERY_H_ diff --git a/packages/battery_plus/battery_plus_windows/windows/system_battery.cpp b/packages/battery_plus/battery_plus_windows/windows/system_battery.cpp index 32536e6513..767c4849bd 100644 --- a/packages/battery_plus/battery_plus_windows/windows/system_battery.cpp +++ b/packages/battery_plus/battery_plus_windows/windows/system_battery.cpp @@ -15,11 +15,11 @@ enum BatteryLevel { }; enum BatteryFlag { - High = 1, // the battery capacity is at more than 66 percent - Low = 2, // the battery capacity is at less than 33 percent - Critical = 4, // the battery capacity is at less than five percent + High = 1, // the battery capacity is at more than 66 percent + Low = 2, // the battery capacity is at less than 33 percent + Critical = 4, // the battery capacity is at less than five percent Charging = 8, - NoBattery = 128 // no system battery + NoBattery = 128 // no system battery }; bool GetBatteryStatus(LPSYSTEM_POWER_STATUS lpStatus) { @@ -30,7 +30,7 @@ bool IsValidBatteryStatus(LPSYSTEM_POWER_STATUS lpStatus) { return lpStatus->BatteryFlag != NoBattery && lpStatus->BatteryLifePercent != Unknown; } -} // namespace +} // namespace SystemBattery::SystemBattery() {} @@ -75,15 +75,15 @@ BatteryStatus SystemBattery::GetStatus() const { std::string SystemBattery::GetStatusString() const { switch (GetStatus()) { - case BatteryStatus::Charging: - return "charging"; - case BatteryStatus::Discharging: - return "discharging"; - case BatteryStatus::Full: - return "full"; - case BatteryStatus::Unknown: - default: - return "unknown"; + case BatteryStatus::Charging: + return "charging"; + case BatteryStatus::Discharging: + return "discharging"; + case BatteryStatus::Full: + return "full"; + case BatteryStatus::Unknown: + default: + return "unknown"; } } diff --git a/packages/connectivity_plus/connectivity_plus/example/linux/main.cc b/packages/connectivity_plus/connectivity_plus/example/linux/main.cc index 10835acb58..8bc1561588 100644 --- a/packages/connectivity_plus/connectivity_plus/example/linux/main.cc +++ b/packages/connectivity_plus/connectivity_plus/example/linux/main.cc @@ -1,6 +1,6 @@ #include "my_application.h" -int main(int argc, char** argv) { +int main(int argc, char **argv) { // Only X11 is currently supported. // Wayland support is being developed: // https://github.com/flutter/flutter/issues/57932. diff --git a/packages/connectivity_plus/connectivity_plus/example/linux/my_application.cc b/packages/connectivity_plus/connectivity_plus/example/linux/my_application.cc index 67ed0b9025..cef2f77145 100644 --- a/packages/connectivity_plus/connectivity_plus/example/linux/my_application.cc +++ b/packages/connectivity_plus/connectivity_plus/example/linux/my_application.cc @@ -11,10 +11,10 @@ struct _MyApplication { G_DEFINE_TYPE(MyApplication, my_application, GTK_TYPE_APPLICATION) // Implements GApplication::activate. -static void my_application_activate(GApplication* application) { - GtkWindow* window = +static void my_application_activate(GApplication *application) { + GtkWindow *window = GTK_WINDOW(gtk_application_window_new(GTK_APPLICATION(application))); - GtkHeaderBar* header_bar = GTK_HEADER_BAR(gtk_header_bar_new()); + GtkHeaderBar *header_bar = GTK_HEADER_BAR(gtk_header_bar_new()); gtk_widget_show(GTK_WIDGET(header_bar)); gtk_header_bar_set_title(header_bar, "example"); gtk_header_bar_set_show_close_button(header_bar, TRUE); @@ -24,7 +24,7 @@ static void my_application_activate(GApplication* application) { g_autoptr(FlDartProject) project = fl_dart_project_new(); - FlView* view = fl_view_new(project); + FlView *view = fl_view_new(project); gtk_widget_show(GTK_WIDGET(view)); gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(view)); @@ -33,13 +33,13 @@ static void my_application_activate(GApplication* application) { gtk_widget_grab_focus(GTK_WIDGET(view)); } -static void my_application_class_init(MyApplicationClass* klass) { +static void my_application_class_init(MyApplicationClass *klass) { G_APPLICATION_CLASS(klass)->activate = my_application_activate; } -static void my_application_init(MyApplication* self) {} +static void my_application_init(MyApplication *self) {} -MyApplication* my_application_new() { +MyApplication *my_application_new() { return MY_APPLICATION(g_object_new( my_application_get_type(), "application-id", APPLICATION_ID, nullptr)); } diff --git a/packages/connectivity_plus/connectivity_plus/example/linux/my_application.h b/packages/connectivity_plus/connectivity_plus/example/linux/my_application.h index 72271d5e41..3258a73cf4 100644 --- a/packages/connectivity_plus/connectivity_plus/example/linux/my_application.h +++ b/packages/connectivity_plus/connectivity_plus/example/linux/my_application.h @@ -13,6 +13,6 @@ G_DECLARE_FINAL_TYPE(MyApplication, my_application, MY, APPLICATION, * * Returns: a new #MyApplication. */ -MyApplication* my_application_new(); +MyApplication *my_application_new(); -#endif // FLUTTER_MY_APPLICATION_H_ +#endif // FLUTTER_MY_APPLICATION_H_ diff --git a/packages/connectivity_plus/connectivity_plus/example/windows/runner/flutter_window.cpp b/packages/connectivity_plus/connectivity_plus/example/windows/runner/flutter_window.cpp index c422723045..0f0105d995 100644 --- a/packages/connectivity_plus/connectivity_plus/example/windows/runner/flutter_window.cpp +++ b/packages/connectivity_plus/connectivity_plus/example/windows/runner/flutter_window.cpp @@ -4,8 +4,8 @@ #include "flutter/generated_plugin_registrant.h" -FlutterWindow::FlutterWindow(RunLoop* run_loop, - const flutter::DartProject& project) +FlutterWindow::FlutterWindow(RunLoop *run_loop, + const flutter::DartProject &project) : run_loop_(run_loop), project_(project) {} FlutterWindow::~FlutterWindow() {} @@ -55,9 +55,9 @@ FlutterWindow::MessageHandler(HWND hwnd, UINT const message, } switch (message) { - case WM_FONTCHANGE: - flutter_controller_->engine()->ReloadSystemFonts(); - break; + case WM_FONTCHANGE: + flutter_controller_->engine()->ReloadSystemFonts(); + break; } return Win32Window::MessageHandler(hwnd, message, wparam, lparam); diff --git a/packages/connectivity_plus/connectivity_plus/example/windows/runner/flutter_window.h b/packages/connectivity_plus/connectivity_plus/example/windows/runner/flutter_window.h index b663ddd501..69234d4f5e 100644 --- a/packages/connectivity_plus/connectivity_plus/example/windows/runner/flutter_window.h +++ b/packages/connectivity_plus/connectivity_plus/example/windows/runner/flutter_window.h @@ -11,23 +11,23 @@ // A window that does nothing but host a Flutter view. class FlutterWindow : public Win32Window { - public: +public: // Creates a new FlutterWindow driven by the |run_loop|, hosting a // Flutter view running |project|. - explicit FlutterWindow(RunLoop* run_loop, - const flutter::DartProject& project); + explicit FlutterWindow(RunLoop *run_loop, + const flutter::DartProject &project); virtual ~FlutterWindow(); - protected: +protected: // Win32Window: bool OnCreate() override; void OnDestroy() override; LRESULT MessageHandler(HWND window, UINT const message, WPARAM const wparam, LPARAM const lparam) noexcept override; - private: +private: // The run loop driving events for this window. - RunLoop* run_loop_; + RunLoop *run_loop_; // The project to run. flutter::DartProject project_; @@ -36,4 +36,4 @@ class FlutterWindow : public Win32Window { std::unique_ptr flutter_controller_; }; -#endif // RUNNER_FLUTTER_WINDOW_H_ +#endif // RUNNER_FLUTTER_WINDOW_H_ diff --git a/packages/connectivity_plus/connectivity_plus/example/windows/runner/run_loop.cpp b/packages/connectivity_plus/connectivity_plus/example/windows/runner/run_loop.cpp index 2d6636ab6b..31b89f6229 100644 --- a/packages/connectivity_plus/connectivity_plus/example/windows/runner/run_loop.cpp +++ b/packages/connectivity_plus/connectivity_plus/example/windows/runner/run_loop.cpp @@ -44,12 +44,12 @@ void RunLoop::Run() { } void RunLoop::RegisterFlutterInstance( - flutter::FlutterEngine* flutter_instance) { + flutter::FlutterEngine *flutter_instance) { flutter_instances_.insert(flutter_instance); } void RunLoop::UnregisterFlutterInstance( - flutter::FlutterEngine* flutter_instance) { + flutter::FlutterEngine *flutter_instance) { flutter_instances_.erase(flutter_instance); } diff --git a/packages/connectivity_plus/connectivity_plus/example/windows/runner/run_loop.h b/packages/connectivity_plus/connectivity_plus/example/windows/runner/run_loop.h index 5f2c4a9ad7..7fe1aaccc2 100644 --- a/packages/connectivity_plus/connectivity_plus/example/windows/runner/run_loop.h +++ b/packages/connectivity_plus/connectivity_plus/example/windows/runner/run_loop.h @@ -9,30 +9,30 @@ // A runloop that will service events for Flutter instances as well // as native messages. class RunLoop { - public: +public: RunLoop(); ~RunLoop(); // Prevent copying - RunLoop(RunLoop const&) = delete; - RunLoop& operator=(RunLoop const&) = delete; + RunLoop(RunLoop const &) = delete; + RunLoop &operator=(RunLoop const &) = delete; // Runs the run loop until the application quits. void Run(); // Registers the given Flutter instance for event servicing. - void RegisterFlutterInstance(flutter::FlutterEngine* flutter_instance); + void RegisterFlutterInstance(flutter::FlutterEngine *flutter_instance); // Unregisters the given Flutter instance from event servicing. - void UnregisterFlutterInstance(flutter::FlutterEngine* flutter_instance); + void UnregisterFlutterInstance(flutter::FlutterEngine *flutter_instance); - private: +private: using TimePoint = std::chrono::steady_clock::time_point; // Processes all currently pending messages for registered Flutter instances. TimePoint ProcessFlutterMessages(); - std::set flutter_instances_; + std::set flutter_instances_; }; -#endif // RUNNER_RUN_LOOP_H_ +#endif // RUNNER_RUN_LOOP_H_ diff --git a/packages/connectivity_plus/connectivity_plus/example/windows/runner/utils.cpp b/packages/connectivity_plus/connectivity_plus/example/windows/runner/utils.cpp index afa363b236..7758aabf38 100644 --- a/packages/connectivity_plus/connectivity_plus/example/windows/runner/utils.cpp +++ b/packages/connectivity_plus/connectivity_plus/example/windows/runner/utils.cpp @@ -9,7 +9,7 @@ void CreateAndAttachConsole() { if (::AllocConsole()) { - FILE* unused; + FILE *unused; if (freopen_s(&unused, "CONOUT$", "w", stdout)) { _dup2(_fileno(stdout), 1); } @@ -24,7 +24,7 @@ void CreateAndAttachConsole() { std::vector GetCommandLineArguments() { // Convert the UTF-16 command line arguments to UTF-8 for the Engine to use. int argc; - wchar_t** argv = ::CommandLineToArgvW(::GetCommandLineW(), &argc); + wchar_t **argv = ::CommandLineToArgvW(::GetCommandLineW(), &argc); if (argv == nullptr) { return std::vector(); } @@ -41,7 +41,7 @@ std::vector GetCommandLineArguments() { return command_line_arguments; } -std::string Utf8FromUtf16(const wchar_t* utf16_string) { +std::string Utf8FromUtf16(const wchar_t *utf16_string) { if (utf16_string == nullptr) { return std::string(); } diff --git a/packages/connectivity_plus/connectivity_plus/example/windows/runner/utils.h b/packages/connectivity_plus/connectivity_plus/example/windows/runner/utils.h index 3879d54755..ff43ce2ce5 100644 --- a/packages/connectivity_plus/connectivity_plus/example/windows/runner/utils.h +++ b/packages/connectivity_plus/connectivity_plus/example/windows/runner/utils.h @@ -10,10 +10,10 @@ void CreateAndAttachConsole(); // Takes a null-terminated wchar_t* encoded in UTF-16 and returns a std::string // encoded in UTF-8. Returns an empty std::string on failure. -std::string Utf8FromUtf16(const wchar_t* utf16_string); +std::string Utf8FromUtf16(const wchar_t *utf16_string); // Gets the command line arguments passed in as a std::vector, // encoded in UTF-8. Returns an empty std::vector on failure. std::vector GetCommandLineArguments(); -#endif // RUNNER_UTILS_H_ +#endif // RUNNER_UTILS_H_ diff --git a/packages/connectivity_plus/connectivity_plus/example/windows/runner/win32_window.cpp b/packages/connectivity_plus/connectivity_plus/example/windows/runner/win32_window.cpp index 44091b3f3c..90ff01e592 100644 --- a/packages/connectivity_plus/connectivity_plus/example/windows/runner/win32_window.cpp +++ b/packages/connectivity_plus/connectivity_plus/example/windows/runner/win32_window.cpp @@ -27,7 +27,7 @@ void EnableFullDpiSupportIfAvailable(HWND hwnd) { return; } auto enable_non_client_dpi_scaling = - reinterpret_cast( + reinterpret_cast( GetProcAddress(user32_module, "EnableNonClientDpiScaling")); if (enable_non_client_dpi_scaling != nullptr) { enable_non_client_dpi_scaling(hwnd); @@ -35,15 +35,15 @@ void EnableFullDpiSupportIfAvailable(HWND hwnd) { } } -} // namespace +} // namespace // Manages the Win32Window's window class registration. class WindowClassRegistrar { - public: +public: ~WindowClassRegistrar() = default; // Returns the singleton registar instance. - static WindowClassRegistrar* GetInstance() { + static WindowClassRegistrar *GetInstance() { if (!instance_) { instance_ = new WindowClassRegistrar(); } @@ -52,23 +52,23 @@ class WindowClassRegistrar { // Returns the name of the window class, registering the class if it hasn't // previously been registered. - const wchar_t* GetWindowClass(); + const wchar_t *GetWindowClass(); // Unregisters the window class. Should only be called if there are no // instances of the window. void UnregisterWindowClass(); - private: +private: WindowClassRegistrar() = default; - static WindowClassRegistrar* instance_; + static WindowClassRegistrar *instance_; bool class_registered_ = false; }; -WindowClassRegistrar* WindowClassRegistrar::instance_ = nullptr; +WindowClassRegistrar *WindowClassRegistrar::instance_ = nullptr; -const wchar_t* WindowClassRegistrar::GetWindowClass() { +const wchar_t *WindowClassRegistrar::GetWindowClass() { if (!class_registered_) { WNDCLASS window_class{}; window_class.hCursor = LoadCursor(nullptr, IDC_ARROW); @@ -100,11 +100,11 @@ Win32Window::~Win32Window() { Destroy(); } -bool Win32Window::CreateAndShow(const std::wstring& title, const Point& origin, - const Size& size) { +bool Win32Window::CreateAndShow(const std::wstring &title, const Point &origin, + const Size &size) { Destroy(); - const wchar_t* window_class = + const wchar_t *window_class = WindowClassRegistrar::GetInstance()->GetWindowClass(); const POINT target_point = {static_cast(origin.x), @@ -131,14 +131,14 @@ LRESULT CALLBACK Win32Window::WndProc(HWND const window, UINT const message, WPARAM const wparam, LPARAM const lparam) noexcept { if (message == WM_NCCREATE) { - auto window_struct = reinterpret_cast(lparam); + auto window_struct = reinterpret_cast(lparam); SetWindowLongPtr(window, GWLP_USERDATA, reinterpret_cast(window_struct->lpCreateParams)); - auto that = static_cast(window_struct->lpCreateParams); + auto that = static_cast(window_struct->lpCreateParams); EnableFullDpiSupportIfAvailable(window); that->window_handle_ = window; - } else if (Win32Window* that = GetThisFromHandle(window)) { + } else if (Win32Window *that = GetThisFromHandle(window)) { return that->MessageHandler(window, message, wparam, lparam); } @@ -149,39 +149,39 @@ LRESULT Win32Window::MessageHandler(HWND hwnd, UINT const message, WPARAM const wparam, LPARAM const lparam) noexcept { switch (message) { - case WM_DESTROY: - window_handle_ = nullptr; - Destroy(); - if (quit_on_close_) { - PostQuitMessage(0); - } - return 0; - - case WM_DPICHANGED: { - auto newRectSize = reinterpret_cast(lparam); - LONG newWidth = newRectSize->right - newRectSize->left; - LONG newHeight = newRectSize->bottom - newRectSize->top; - - SetWindowPos(hwnd, nullptr, newRectSize->left, newRectSize->top, newWidth, - newHeight, SWP_NOZORDER | SWP_NOACTIVATE); - - return 0; + case WM_DESTROY: + window_handle_ = nullptr; + Destroy(); + if (quit_on_close_) { + PostQuitMessage(0); } - case WM_SIZE: { - RECT rect = GetClientArea(); - if (child_content_ != nullptr) { - // Size and position the child window. - MoveWindow(child_content_, rect.left, rect.top, rect.right - rect.left, - rect.bottom - rect.top, TRUE); - } - return 0; + return 0; + + case WM_DPICHANGED: { + auto newRectSize = reinterpret_cast(lparam); + LONG newWidth = newRectSize->right - newRectSize->left; + LONG newHeight = newRectSize->bottom - newRectSize->top; + + SetWindowPos(hwnd, nullptr, newRectSize->left, newRectSize->top, newWidth, + newHeight, SWP_NOZORDER | SWP_NOACTIVATE); + + return 0; + } + case WM_SIZE: { + RECT rect = GetClientArea(); + if (child_content_ != nullptr) { + // Size and position the child window. + MoveWindow(child_content_, rect.left, rect.top, rect.right - rect.left, + rect.bottom - rect.top, TRUE); } + return 0; + } - case WM_ACTIVATE: - if (child_content_ != nullptr) { - SetFocus(child_content_); - } - return 0; + case WM_ACTIVATE: + if (child_content_ != nullptr) { + SetFocus(child_content_); + } + return 0; } return DefWindowProc(window_handle_, message, wparam, lparam); @@ -199,8 +199,8 @@ void Win32Window::Destroy() { } } -Win32Window* Win32Window::GetThisFromHandle(HWND const window) noexcept { - return reinterpret_cast( +Win32Window *Win32Window::GetThisFromHandle(HWND const window) noexcept { + return reinterpret_cast( GetWindowLongPtr(window, GWLP_USERDATA)); } diff --git a/packages/connectivity_plus/connectivity_plus/example/windows/runner/win32_window.h b/packages/connectivity_plus/connectivity_plus/example/windows/runner/win32_window.h index 4ae64a12b4..7b518125bb 100644 --- a/packages/connectivity_plus/connectivity_plus/example/windows/runner/win32_window.h +++ b/packages/connectivity_plus/connectivity_plus/example/windows/runner/win32_window.h @@ -11,7 +11,7 @@ // inherited from by classes that wish to specialize with custom // rendering and input handling class Win32Window { - public: +public: struct Point { unsigned int x; unsigned int y; @@ -34,8 +34,8 @@ class Win32Window { // consistent size to will treat the width height passed in to this function // as logical pixels and scale to appropriate for the default monitor. Returns // true if the window was created successfully. - bool CreateAndShow(const std::wstring& title, const Point& origin, - const Size& size); + bool CreateAndShow(const std::wstring &title, const Point &origin, + const Size &size); // Release OS resources associated with window. void Destroy(); @@ -53,7 +53,7 @@ class Win32Window { // Return a RECT representing the bounds of the current client area. RECT GetClientArea(); - protected: +protected: // Processes and route salient window messages for mouse handling, // size change and DPI. Delegates handling of these to member overloads that // inheriting classes can handle. @@ -68,7 +68,7 @@ class Win32Window { // Called when Destroy is called. virtual void OnDestroy(); - private: +private: friend class WindowClassRegistrar; // OS callback called by message pump. Handles the WM_NCCREATE message which @@ -81,7 +81,7 @@ class Win32Window { LPARAM const lparam) noexcept; // Retrieves a class instance pointer for |window| - static Win32Window* GetThisFromHandle(HWND const window) noexcept; + static Win32Window *GetThisFromHandle(HWND const window) noexcept; bool quit_on_close_ = false; @@ -92,4 +92,4 @@ class Win32Window { HWND child_content_ = nullptr; }; -#endif // RUNNER_WIN32_WINDOW_H_ +#endif // RUNNER_WIN32_WINDOW_H_ diff --git a/packages/connectivity_plus/connectivity_plus/ios/Classes/ConnectivityPlusPlugin.h b/packages/connectivity_plus/connectivity_plus/ios/Classes/ConnectivityPlusPlugin.h index fea9f3927e..e5d0ccbd1a 100644 --- a/packages/connectivity_plus/connectivity_plus/ios/Classes/ConnectivityPlusPlugin.h +++ b/packages/connectivity_plus/connectivity_plus/ios/Classes/ConnectivityPlusPlugin.h @@ -1,4 +1,4 @@ #import -@interface ConnectivityPlusPlugin : NSObject +@interface ConnectivityPlusPlugin : NSObject @end diff --git a/packages/connectivity_plus/connectivity_plus/ios/Classes/ConnectivityPlusPlugin.m b/packages/connectivity_plus/connectivity_plus/ios/Classes/ConnectivityPlusPlugin.m index 214775b304..43af3800bc 100644 --- a/packages/connectivity_plus/connectivity_plus/ios/Classes/ConnectivityPlusPlugin.m +++ b/packages/connectivity_plus/connectivity_plus/ios/Classes/ConnectivityPlusPlugin.m @@ -9,7 +9,7 @@ #endif @implementation ConnectivityPlusPlugin -+ (void)registerWithRegistrar:(NSObject*)registrar { ++ (void)registerWithRegistrar:(NSObject *)registrar { [SwiftConnectivityPlusPlugin registerWithRegistrar:registrar]; } @end diff --git a/packages/connectivity_plus/connectivity_plus_windows/windows/connectivity_plus_windows_plugin.cpp b/packages/connectivity_plus/connectivity_plus_windows/windows/connectivity_plus_windows_plugin.cpp index 2286f919e7..3b5d973b06 100644 --- a/packages/connectivity_plus/connectivity_plus_windows/windows/connectivity_plus_windows_plugin.cpp +++ b/packages/connectivity_plus/connectivity_plus_windows/windows/connectivity_plus_windows_plugin.cpp @@ -25,37 +25,37 @@ typedef flutter::StreamHandlerError FlStreamHandlerError; class ConnectivityPlusWindowsPlugin : public flutter::Plugin { - public: +public: ConnectivityPlusWindowsPlugin(); virtual ~ConnectivityPlusWindowsPlugin(); std::shared_ptr GetManager() const; - static void RegisterWithRegistrar(flutter::PluginRegistrarWindows* registrar); + static void RegisterWithRegistrar(flutter::PluginRegistrarWindows *registrar); - private: - void HandleMethodCall(const FlMethodCall& method_call, +private: + void HandleMethodCall(const FlMethodCall &method_call, std::unique_ptr result); std::shared_ptr manager; }; class ConnectivityStreamHandler : public FlStreamHandler { - public: +public: ConnectivityStreamHandler(std::shared_ptr manager); virtual ~ConnectivityStreamHandler(); - protected: +protected: void AddConnectivityEvent(); - std::unique_ptr OnListenInternal( - const flutter::EncodableValue* arguments, - std::unique_ptr&& sink) override; + std::unique_ptr + OnListenInternal(const flutter::EncodableValue *arguments, + std::unique_ptr &&sink) override; - std::unique_ptr OnCancelInternal( - const flutter::EncodableValue* arguments) override; + std::unique_ptr + OnCancelInternal(const flutter::EncodableValue *arguments) override; - private: +private: std::shared_ptr manager; std::unique_ptr sink; }; @@ -69,13 +69,13 @@ ConnectivityPlusWindowsPlugin::~ConnectivityPlusWindowsPlugin() { manager->Cleanup(); } -std::shared_ptr ConnectivityPlusWindowsPlugin::GetManager() - const { +std::shared_ptr +ConnectivityPlusWindowsPlugin::GetManager() const { return manager; } void ConnectivityPlusWindowsPlugin::RegisterWithRegistrar( - flutter::PluginRegistrarWindows* registrar) { + flutter::PluginRegistrarWindows *registrar) { auto plugin = std::make_unique(); auto methodChannel = @@ -84,7 +84,7 @@ void ConnectivityPlusWindowsPlugin::RegisterWithRegistrar( &flutter::StandardMethodCodec::GetInstance()); methodChannel->SetMethodCallHandler( - [plugin_pointer = plugin.get()](const auto& call, auto result) { + [plugin_pointer = plugin.get()](const auto &call, auto result) { plugin_pointer->HandleMethodCall(call, std::move(result)); }); @@ -100,18 +100,18 @@ void ConnectivityPlusWindowsPlugin::RegisterWithRegistrar( static std::string ConnectivityToString(ConnectivityType connectivityType) { switch (connectivityType) { - case ConnectivityType::WiFi: - return "wifi"; - case ConnectivityType::Ethernet: - return "ethernet"; - case ConnectivityType::None: - default: - return "none"; + case ConnectivityType::WiFi: + return "wifi"; + case ConnectivityType::Ethernet: + return "ethernet"; + case ConnectivityType::None: + default: + return "none"; } } void ConnectivityPlusWindowsPlugin::HandleMethodCall( - const flutter::MethodCall& method_call, + const flutter::MethodCall &method_call, std::unique_ptr> result) { if (method_call.method_name().compare("check") == 0) { std::string connectivity = @@ -136,8 +136,8 @@ void ConnectivityStreamHandler::AddConnectivityEvent() { std::unique_ptr ConnectivityStreamHandler::OnListenInternal( - const flutter::EncodableValue* arguments, - std::unique_ptr&& events) { + const flutter::EncodableValue *arguments, + std::unique_ptr &&events) { sink = std::move(events); auto callback = @@ -155,13 +155,13 @@ ConnectivityStreamHandler::OnListenInternal( std::unique_ptr ConnectivityStreamHandler::OnCancelInternal( - const flutter::EncodableValue* arguments) { + const flutter::EncodableValue *arguments) { manager->StopListen(); sink.reset(); return nullptr; } -} // namespace +} // namespace void ConnectivityPlusWindowsPluginRegisterWithRegistrar( FlutterDesktopPluginRegistrarRef registrar) { diff --git a/packages/connectivity_plus/connectivity_plus_windows/windows/include/connectivity_plus_windows/connectivity_plus_windows_plugin.h b/packages/connectivity_plus/connectivity_plus_windows/windows/include/connectivity_plus_windows/connectivity_plus_windows_plugin.h index 60ed256f70..9c6cdc778a 100644 --- a/packages/connectivity_plus/connectivity_plus_windows/windows/include/connectivity_plus_windows/connectivity_plus_windows_plugin.h +++ b/packages/connectivity_plus/connectivity_plus_windows/windows/include/connectivity_plus_windows/connectivity_plus_windows_plugin.h @@ -17,7 +17,7 @@ FLUTTER_PLUGIN_EXPORT void ConnectivityPlusWindowsPluginRegisterWithRegistrar( FlutterDesktopPluginRegistrarRef registrar); #if defined(__cplusplus) -} // extern "C" +} // extern "C" #endif -#endif // FLUTTER_PLUGIN_CONNECTIVITY_PLUS_WINDOWS_PLUGIN_H_ +#endif // FLUTTER_PLUGIN_CONNECTIVITY_PLUS_WINDOWS_PLUGIN_H_ diff --git a/packages/connectivity_plus/connectivity_plus_windows/windows/include/connectivity_plus_windows/network_manager.h b/packages/connectivity_plus/connectivity_plus_windows/windows/include/connectivity_plus_windows/network_manager.h index ea179b74a3..51a7e9b388 100644 --- a/packages/connectivity_plus/connectivity_plus_windows/windows/include/connectivity_plus_windows/network_manager.h +++ b/packages/connectivity_plus/connectivity_plus_windows/windows/include/connectivity_plus_windows/network_manager.h @@ -20,7 +20,7 @@ struct IUnknown; typedef std::function NetworkCallback; class NetworkManager { - public: +public: NetworkManager(); ~NetworkManager(); @@ -35,7 +35,7 @@ class NetworkManager { bool HasError() const; int GetError() const; - private: +private: std::vector GetConnectedAdapterIds() const; DWORD dwCookie = 0; @@ -46,4 +46,4 @@ class NetworkManager { NetworkListener *pListener = NULL; }; -#endif // NETWORK_MANAGER_H +#endif // NETWORK_MANAGER_H diff --git a/packages/connectivity_plus/connectivity_plus_windows/windows/network_manager.cpp b/packages/connectivity_plus/connectivity_plus_windows/windows/network_manager.cpp index 97054a4a44..fab46473c5 100644 --- a/packages/connectivity_plus/connectivity_plus_windows/windows/network_manager.cpp +++ b/packages/connectivity_plus/connectivity_plus_windows/windows/network_manager.cpp @@ -19,7 +19,7 @@ #include class NetworkListener final : public INetworkEvents { - public: +public: NetworkListener(NetworkCallback pCb) : pCallback(pCb) {} HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void **ppvObject) { @@ -69,7 +69,7 @@ class NetworkListener final : public INetworkEvents { pCallback(); } - private: +private: volatile LONG lRef = 1; NetworkCallback pCallback = nullptr; }; @@ -178,12 +178,12 @@ ConnectivityType NetworkManager::GetConnectivityType() const { if (std::find(adapterIds.begin(), adapterIds.end(), guid) != adapterIds.end()) { switch (addresses->IfType) { - case IF_TYPE_ETHERNET_CSMACD: - connectivities.insert(ConnectivityType::Ethernet); - break; - default: - connectivities.insert(ConnectivityType::WiFi); - break; + case IF_TYPE_ETHERNET_CSMACD: + connectivities.insert(ConnectivityType::Ethernet); + break; + default: + connectivities.insert(ConnectivityType::WiFi); + break; } } } diff --git a/packages/device_info_plus/device_info_plus/example/linux/main.cc b/packages/device_info_plus/device_info_plus/example/linux/main.cc index 10835acb58..8bc1561588 100644 --- a/packages/device_info_plus/device_info_plus/example/linux/main.cc +++ b/packages/device_info_plus/device_info_plus/example/linux/main.cc @@ -1,6 +1,6 @@ #include "my_application.h" -int main(int argc, char** argv) { +int main(int argc, char **argv) { // Only X11 is currently supported. // Wayland support is being developed: // https://github.com/flutter/flutter/issues/57932. diff --git a/packages/device_info_plus/device_info_plus/example/linux/my_application.cc b/packages/device_info_plus/device_info_plus/example/linux/my_application.cc index 67ed0b9025..cef2f77145 100644 --- a/packages/device_info_plus/device_info_plus/example/linux/my_application.cc +++ b/packages/device_info_plus/device_info_plus/example/linux/my_application.cc @@ -11,10 +11,10 @@ struct _MyApplication { G_DEFINE_TYPE(MyApplication, my_application, GTK_TYPE_APPLICATION) // Implements GApplication::activate. -static void my_application_activate(GApplication* application) { - GtkWindow* window = +static void my_application_activate(GApplication *application) { + GtkWindow *window = GTK_WINDOW(gtk_application_window_new(GTK_APPLICATION(application))); - GtkHeaderBar* header_bar = GTK_HEADER_BAR(gtk_header_bar_new()); + GtkHeaderBar *header_bar = GTK_HEADER_BAR(gtk_header_bar_new()); gtk_widget_show(GTK_WIDGET(header_bar)); gtk_header_bar_set_title(header_bar, "example"); gtk_header_bar_set_show_close_button(header_bar, TRUE); @@ -24,7 +24,7 @@ static void my_application_activate(GApplication* application) { g_autoptr(FlDartProject) project = fl_dart_project_new(); - FlView* view = fl_view_new(project); + FlView *view = fl_view_new(project); gtk_widget_show(GTK_WIDGET(view)); gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(view)); @@ -33,13 +33,13 @@ static void my_application_activate(GApplication* application) { gtk_widget_grab_focus(GTK_WIDGET(view)); } -static void my_application_class_init(MyApplicationClass* klass) { +static void my_application_class_init(MyApplicationClass *klass) { G_APPLICATION_CLASS(klass)->activate = my_application_activate; } -static void my_application_init(MyApplication* self) {} +static void my_application_init(MyApplication *self) {} -MyApplication* my_application_new() { +MyApplication *my_application_new() { return MY_APPLICATION(g_object_new( my_application_get_type(), "application-id", APPLICATION_ID, nullptr)); } diff --git a/packages/device_info_plus/device_info_plus/example/linux/my_application.h b/packages/device_info_plus/device_info_plus/example/linux/my_application.h index 72271d5e41..3258a73cf4 100644 --- a/packages/device_info_plus/device_info_plus/example/linux/my_application.h +++ b/packages/device_info_plus/device_info_plus/example/linux/my_application.h @@ -13,6 +13,6 @@ G_DECLARE_FINAL_TYPE(MyApplication, my_application, MY, APPLICATION, * * Returns: a new #MyApplication. */ -MyApplication* my_application_new(); +MyApplication *my_application_new(); -#endif // FLUTTER_MY_APPLICATION_H_ +#endif // FLUTTER_MY_APPLICATION_H_ diff --git a/packages/device_info_plus/device_info_plus/example/windows/runner/flutter_window.cpp b/packages/device_info_plus/device_info_plus/example/windows/runner/flutter_window.cpp index c422723045..0f0105d995 100644 --- a/packages/device_info_plus/device_info_plus/example/windows/runner/flutter_window.cpp +++ b/packages/device_info_plus/device_info_plus/example/windows/runner/flutter_window.cpp @@ -4,8 +4,8 @@ #include "flutter/generated_plugin_registrant.h" -FlutterWindow::FlutterWindow(RunLoop* run_loop, - const flutter::DartProject& project) +FlutterWindow::FlutterWindow(RunLoop *run_loop, + const flutter::DartProject &project) : run_loop_(run_loop), project_(project) {} FlutterWindow::~FlutterWindow() {} @@ -55,9 +55,9 @@ FlutterWindow::MessageHandler(HWND hwnd, UINT const message, } switch (message) { - case WM_FONTCHANGE: - flutter_controller_->engine()->ReloadSystemFonts(); - break; + case WM_FONTCHANGE: + flutter_controller_->engine()->ReloadSystemFonts(); + break; } return Win32Window::MessageHandler(hwnd, message, wparam, lparam); diff --git a/packages/device_info_plus/device_info_plus/example/windows/runner/flutter_window.h b/packages/device_info_plus/device_info_plus/example/windows/runner/flutter_window.h index b663ddd501..69234d4f5e 100644 --- a/packages/device_info_plus/device_info_plus/example/windows/runner/flutter_window.h +++ b/packages/device_info_plus/device_info_plus/example/windows/runner/flutter_window.h @@ -11,23 +11,23 @@ // A window that does nothing but host a Flutter view. class FlutterWindow : public Win32Window { - public: +public: // Creates a new FlutterWindow driven by the |run_loop|, hosting a // Flutter view running |project|. - explicit FlutterWindow(RunLoop* run_loop, - const flutter::DartProject& project); + explicit FlutterWindow(RunLoop *run_loop, + const flutter::DartProject &project); virtual ~FlutterWindow(); - protected: +protected: // Win32Window: bool OnCreate() override; void OnDestroy() override; LRESULT MessageHandler(HWND window, UINT const message, WPARAM const wparam, LPARAM const lparam) noexcept override; - private: +private: // The run loop driving events for this window. - RunLoop* run_loop_; + RunLoop *run_loop_; // The project to run. flutter::DartProject project_; @@ -36,4 +36,4 @@ class FlutterWindow : public Win32Window { std::unique_ptr flutter_controller_; }; -#endif // RUNNER_FLUTTER_WINDOW_H_ +#endif // RUNNER_FLUTTER_WINDOW_H_ diff --git a/packages/device_info_plus/device_info_plus/example/windows/runner/run_loop.cpp b/packages/device_info_plus/device_info_plus/example/windows/runner/run_loop.cpp index 2d6636ab6b..31b89f6229 100644 --- a/packages/device_info_plus/device_info_plus/example/windows/runner/run_loop.cpp +++ b/packages/device_info_plus/device_info_plus/example/windows/runner/run_loop.cpp @@ -44,12 +44,12 @@ void RunLoop::Run() { } void RunLoop::RegisterFlutterInstance( - flutter::FlutterEngine* flutter_instance) { + flutter::FlutterEngine *flutter_instance) { flutter_instances_.insert(flutter_instance); } void RunLoop::UnregisterFlutterInstance( - flutter::FlutterEngine* flutter_instance) { + flutter::FlutterEngine *flutter_instance) { flutter_instances_.erase(flutter_instance); } diff --git a/packages/device_info_plus/device_info_plus/example/windows/runner/run_loop.h b/packages/device_info_plus/device_info_plus/example/windows/runner/run_loop.h index 5f2c4a9ad7..7fe1aaccc2 100644 --- a/packages/device_info_plus/device_info_plus/example/windows/runner/run_loop.h +++ b/packages/device_info_plus/device_info_plus/example/windows/runner/run_loop.h @@ -9,30 +9,30 @@ // A runloop that will service events for Flutter instances as well // as native messages. class RunLoop { - public: +public: RunLoop(); ~RunLoop(); // Prevent copying - RunLoop(RunLoop const&) = delete; - RunLoop& operator=(RunLoop const&) = delete; + RunLoop(RunLoop const &) = delete; + RunLoop &operator=(RunLoop const &) = delete; // Runs the run loop until the application quits. void Run(); // Registers the given Flutter instance for event servicing. - void RegisterFlutterInstance(flutter::FlutterEngine* flutter_instance); + void RegisterFlutterInstance(flutter::FlutterEngine *flutter_instance); // Unregisters the given Flutter instance from event servicing. - void UnregisterFlutterInstance(flutter::FlutterEngine* flutter_instance); + void UnregisterFlutterInstance(flutter::FlutterEngine *flutter_instance); - private: +private: using TimePoint = std::chrono::steady_clock::time_point; // Processes all currently pending messages for registered Flutter instances. TimePoint ProcessFlutterMessages(); - std::set flutter_instances_; + std::set flutter_instances_; }; -#endif // RUNNER_RUN_LOOP_H_ +#endif // RUNNER_RUN_LOOP_H_ diff --git a/packages/device_info_plus/device_info_plus/example/windows/runner/utils.cpp b/packages/device_info_plus/device_info_plus/example/windows/runner/utils.cpp index afa363b236..7758aabf38 100644 --- a/packages/device_info_plus/device_info_plus/example/windows/runner/utils.cpp +++ b/packages/device_info_plus/device_info_plus/example/windows/runner/utils.cpp @@ -9,7 +9,7 @@ void CreateAndAttachConsole() { if (::AllocConsole()) { - FILE* unused; + FILE *unused; if (freopen_s(&unused, "CONOUT$", "w", stdout)) { _dup2(_fileno(stdout), 1); } @@ -24,7 +24,7 @@ void CreateAndAttachConsole() { std::vector GetCommandLineArguments() { // Convert the UTF-16 command line arguments to UTF-8 for the Engine to use. int argc; - wchar_t** argv = ::CommandLineToArgvW(::GetCommandLineW(), &argc); + wchar_t **argv = ::CommandLineToArgvW(::GetCommandLineW(), &argc); if (argv == nullptr) { return std::vector(); } @@ -41,7 +41,7 @@ std::vector GetCommandLineArguments() { return command_line_arguments; } -std::string Utf8FromUtf16(const wchar_t* utf16_string) { +std::string Utf8FromUtf16(const wchar_t *utf16_string) { if (utf16_string == nullptr) { return std::string(); } diff --git a/packages/device_info_plus/device_info_plus/example/windows/runner/utils.h b/packages/device_info_plus/device_info_plus/example/windows/runner/utils.h index 3879d54755..ff43ce2ce5 100644 --- a/packages/device_info_plus/device_info_plus/example/windows/runner/utils.h +++ b/packages/device_info_plus/device_info_plus/example/windows/runner/utils.h @@ -10,10 +10,10 @@ void CreateAndAttachConsole(); // Takes a null-terminated wchar_t* encoded in UTF-16 and returns a std::string // encoded in UTF-8. Returns an empty std::string on failure. -std::string Utf8FromUtf16(const wchar_t* utf16_string); +std::string Utf8FromUtf16(const wchar_t *utf16_string); // Gets the command line arguments passed in as a std::vector, // encoded in UTF-8. Returns an empty std::vector on failure. std::vector GetCommandLineArguments(); -#endif // RUNNER_UTILS_H_ +#endif // RUNNER_UTILS_H_ diff --git a/packages/device_info_plus/device_info_plus/example/windows/runner/win32_window.cpp b/packages/device_info_plus/device_info_plus/example/windows/runner/win32_window.cpp index 44091b3f3c..90ff01e592 100644 --- a/packages/device_info_plus/device_info_plus/example/windows/runner/win32_window.cpp +++ b/packages/device_info_plus/device_info_plus/example/windows/runner/win32_window.cpp @@ -27,7 +27,7 @@ void EnableFullDpiSupportIfAvailable(HWND hwnd) { return; } auto enable_non_client_dpi_scaling = - reinterpret_cast( + reinterpret_cast( GetProcAddress(user32_module, "EnableNonClientDpiScaling")); if (enable_non_client_dpi_scaling != nullptr) { enable_non_client_dpi_scaling(hwnd); @@ -35,15 +35,15 @@ void EnableFullDpiSupportIfAvailable(HWND hwnd) { } } -} // namespace +} // namespace // Manages the Win32Window's window class registration. class WindowClassRegistrar { - public: +public: ~WindowClassRegistrar() = default; // Returns the singleton registar instance. - static WindowClassRegistrar* GetInstance() { + static WindowClassRegistrar *GetInstance() { if (!instance_) { instance_ = new WindowClassRegistrar(); } @@ -52,23 +52,23 @@ class WindowClassRegistrar { // Returns the name of the window class, registering the class if it hasn't // previously been registered. - const wchar_t* GetWindowClass(); + const wchar_t *GetWindowClass(); // Unregisters the window class. Should only be called if there are no // instances of the window. void UnregisterWindowClass(); - private: +private: WindowClassRegistrar() = default; - static WindowClassRegistrar* instance_; + static WindowClassRegistrar *instance_; bool class_registered_ = false; }; -WindowClassRegistrar* WindowClassRegistrar::instance_ = nullptr; +WindowClassRegistrar *WindowClassRegistrar::instance_ = nullptr; -const wchar_t* WindowClassRegistrar::GetWindowClass() { +const wchar_t *WindowClassRegistrar::GetWindowClass() { if (!class_registered_) { WNDCLASS window_class{}; window_class.hCursor = LoadCursor(nullptr, IDC_ARROW); @@ -100,11 +100,11 @@ Win32Window::~Win32Window() { Destroy(); } -bool Win32Window::CreateAndShow(const std::wstring& title, const Point& origin, - const Size& size) { +bool Win32Window::CreateAndShow(const std::wstring &title, const Point &origin, + const Size &size) { Destroy(); - const wchar_t* window_class = + const wchar_t *window_class = WindowClassRegistrar::GetInstance()->GetWindowClass(); const POINT target_point = {static_cast(origin.x), @@ -131,14 +131,14 @@ LRESULT CALLBACK Win32Window::WndProc(HWND const window, UINT const message, WPARAM const wparam, LPARAM const lparam) noexcept { if (message == WM_NCCREATE) { - auto window_struct = reinterpret_cast(lparam); + auto window_struct = reinterpret_cast(lparam); SetWindowLongPtr(window, GWLP_USERDATA, reinterpret_cast(window_struct->lpCreateParams)); - auto that = static_cast(window_struct->lpCreateParams); + auto that = static_cast(window_struct->lpCreateParams); EnableFullDpiSupportIfAvailable(window); that->window_handle_ = window; - } else if (Win32Window* that = GetThisFromHandle(window)) { + } else if (Win32Window *that = GetThisFromHandle(window)) { return that->MessageHandler(window, message, wparam, lparam); } @@ -149,39 +149,39 @@ LRESULT Win32Window::MessageHandler(HWND hwnd, UINT const message, WPARAM const wparam, LPARAM const lparam) noexcept { switch (message) { - case WM_DESTROY: - window_handle_ = nullptr; - Destroy(); - if (quit_on_close_) { - PostQuitMessage(0); - } - return 0; - - case WM_DPICHANGED: { - auto newRectSize = reinterpret_cast(lparam); - LONG newWidth = newRectSize->right - newRectSize->left; - LONG newHeight = newRectSize->bottom - newRectSize->top; - - SetWindowPos(hwnd, nullptr, newRectSize->left, newRectSize->top, newWidth, - newHeight, SWP_NOZORDER | SWP_NOACTIVATE); - - return 0; + case WM_DESTROY: + window_handle_ = nullptr; + Destroy(); + if (quit_on_close_) { + PostQuitMessage(0); } - case WM_SIZE: { - RECT rect = GetClientArea(); - if (child_content_ != nullptr) { - // Size and position the child window. - MoveWindow(child_content_, rect.left, rect.top, rect.right - rect.left, - rect.bottom - rect.top, TRUE); - } - return 0; + return 0; + + case WM_DPICHANGED: { + auto newRectSize = reinterpret_cast(lparam); + LONG newWidth = newRectSize->right - newRectSize->left; + LONG newHeight = newRectSize->bottom - newRectSize->top; + + SetWindowPos(hwnd, nullptr, newRectSize->left, newRectSize->top, newWidth, + newHeight, SWP_NOZORDER | SWP_NOACTIVATE); + + return 0; + } + case WM_SIZE: { + RECT rect = GetClientArea(); + if (child_content_ != nullptr) { + // Size and position the child window. + MoveWindow(child_content_, rect.left, rect.top, rect.right - rect.left, + rect.bottom - rect.top, TRUE); } + return 0; + } - case WM_ACTIVATE: - if (child_content_ != nullptr) { - SetFocus(child_content_); - } - return 0; + case WM_ACTIVATE: + if (child_content_ != nullptr) { + SetFocus(child_content_); + } + return 0; } return DefWindowProc(window_handle_, message, wparam, lparam); @@ -199,8 +199,8 @@ void Win32Window::Destroy() { } } -Win32Window* Win32Window::GetThisFromHandle(HWND const window) noexcept { - return reinterpret_cast( +Win32Window *Win32Window::GetThisFromHandle(HWND const window) noexcept { + return reinterpret_cast( GetWindowLongPtr(window, GWLP_USERDATA)); } diff --git a/packages/device_info_plus/device_info_plus/example/windows/runner/win32_window.h b/packages/device_info_plus/device_info_plus/example/windows/runner/win32_window.h index 4ae64a12b4..7b518125bb 100644 --- a/packages/device_info_plus/device_info_plus/example/windows/runner/win32_window.h +++ b/packages/device_info_plus/device_info_plus/example/windows/runner/win32_window.h @@ -11,7 +11,7 @@ // inherited from by classes that wish to specialize with custom // rendering and input handling class Win32Window { - public: +public: struct Point { unsigned int x; unsigned int y; @@ -34,8 +34,8 @@ class Win32Window { // consistent size to will treat the width height passed in to this function // as logical pixels and scale to appropriate for the default monitor. Returns // true if the window was created successfully. - bool CreateAndShow(const std::wstring& title, const Point& origin, - const Size& size); + bool CreateAndShow(const std::wstring &title, const Point &origin, + const Size &size); // Release OS resources associated with window. void Destroy(); @@ -53,7 +53,7 @@ class Win32Window { // Return a RECT representing the bounds of the current client area. RECT GetClientArea(); - protected: +protected: // Processes and route salient window messages for mouse handling, // size change and DPI. Delegates handling of these to member overloads that // inheriting classes can handle. @@ -68,7 +68,7 @@ class Win32Window { // Called when Destroy is called. virtual void OnDestroy(); - private: +private: friend class WindowClassRegistrar; // OS callback called by message pump. Handles the WM_NCCREATE message which @@ -81,7 +81,7 @@ class Win32Window { LPARAM const lparam) noexcept; // Retrieves a class instance pointer for |window| - static Win32Window* GetThisFromHandle(HWND const window) noexcept; + static Win32Window *GetThisFromHandle(HWND const window) noexcept; bool quit_on_close_ = false; @@ -92,4 +92,4 @@ class Win32Window { HWND child_content_ = nullptr; }; -#endif // RUNNER_WIN32_WINDOW_H_ +#endif // RUNNER_WIN32_WINDOW_H_ diff --git a/packages/device_info_plus/device_info_plus/ios/Classes/FLTDeviceInfoPlusPlugin.m b/packages/device_info_plus/device_info_plus/ios/Classes/FLTDeviceInfoPlusPlugin.m index 619e4f0d20..700985610b 100644 --- a/packages/device_info_plus/device_info_plus/ios/Classes/FLTDeviceInfoPlusPlugin.m +++ b/packages/device_info_plus/device_info_plus/ios/Classes/FLTDeviceInfoPlusPlugin.m @@ -6,17 +6,18 @@ #import @implementation FLTDeviceInfoPlusPlugin -+ (void)registerWithRegistrar:(NSObject*)registrar { - FlutterMethodChannel* channel = - [FlutterMethodChannel methodChannelWithName:@"dev.fluttercommunity.plus/device_info" - binaryMessenger:[registrar messenger]]; - FLTDeviceInfoPlusPlugin* instance = [[FLTDeviceInfoPlusPlugin alloc] init]; ++ (void)registerWithRegistrar:(NSObject *)registrar { + FlutterMethodChannel *channel = [FlutterMethodChannel + methodChannelWithName:@"dev.fluttercommunity.plus/device_info" + binaryMessenger:[registrar messenger]]; + FLTDeviceInfoPlusPlugin *instance = [[FLTDeviceInfoPlusPlugin alloc] init]; [registrar addMethodCallDelegate:instance channel:channel]; } -- (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result { +- (void)handleMethodCall:(FlutterMethodCall *)call + result:(FlutterResult)result { if ([@"getIosDeviceInfo" isEqualToString:call.method]) { - UIDevice* device = [UIDevice currentDevice]; + UIDevice *device = [UIDevice currentDevice]; struct utsname un; uname(&un); @@ -26,7 +27,8 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result { @"systemVersion" : [device systemVersion], @"model" : [device model], @"localizedModel" : [device localizedModel], - @"identifierForVendor" : [[device identifierForVendor] UUIDString] ?: [NSNull null], + @"identifierForVendor" : [[device identifierForVendor] UUIDString] + ?: [NSNull null], @"isPhysicalDevice" : [self isDevicePhysical], @"utsname" : @{ @"sysname" : @(un.sysname), @@ -42,11 +44,11 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result { } // return value is false if code is run on a simulator -- (NSString*)isDevicePhysical { +- (NSString *)isDevicePhysical { #if TARGET_OS_SIMULATOR - NSString* isPhysicalDevice = @"false"; + NSString *isPhysicalDevice = @"false"; #else - NSString* isPhysicalDevice = @"true"; + NSString *isPhysicalDevice = @"true"; #endif return isPhysicalDevice; diff --git a/packages/network_info_plus/network_info_plus/example/ios/Runner/AppDelegate.m b/packages/network_info_plus/network_info_plus/example/ios/Runner/AppDelegate.m index f086757071..26c653a8ea 100644 --- a/packages/network_info_plus/network_info_plus/example/ios/Runner/AppDelegate.m +++ b/packages/network_info_plus/network_info_plus/example/ios/Runner/AppDelegate.m @@ -11,7 +11,8 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [GeneratedPluginRegistrant registerWithRegistry:self]; // Override point for customization after application launch. - return [super application:application didFinishLaunchingWithOptions:launchOptions]; + return [super application:application + didFinishLaunchingWithOptions:launchOptions]; } @end diff --git a/packages/network_info_plus/network_info_plus/example/ios/Runner/main.m b/packages/network_info_plus/network_info_plus/example/ios/Runner/main.m index bec320c0be..b7fe28c73a 100644 --- a/packages/network_info_plus/network_info_plus/example/ios/Runner/main.m +++ b/packages/network_info_plus/network_info_plus/example/ios/Runner/main.m @@ -2,12 +2,13 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#import "AppDelegate.h" #import #import -#import "AppDelegate.h" -int main(int argc, char* argv[]) { +int main(int argc, char *argv[]) { @autoreleasepool { - return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); + return UIApplicationMain(argc, argv, nil, + NSStringFromClass([AppDelegate class])); } } diff --git a/packages/network_info_plus/network_info_plus/example/linux/main.cc b/packages/network_info_plus/network_info_plus/example/linux/main.cc index 10835acb58..8bc1561588 100644 --- a/packages/network_info_plus/network_info_plus/example/linux/main.cc +++ b/packages/network_info_plus/network_info_plus/example/linux/main.cc @@ -1,6 +1,6 @@ #include "my_application.h" -int main(int argc, char** argv) { +int main(int argc, char **argv) { // Only X11 is currently supported. // Wayland support is being developed: // https://github.com/flutter/flutter/issues/57932. diff --git a/packages/network_info_plus/network_info_plus/example/linux/my_application.cc b/packages/network_info_plus/network_info_plus/example/linux/my_application.cc index 67ed0b9025..cef2f77145 100644 --- a/packages/network_info_plus/network_info_plus/example/linux/my_application.cc +++ b/packages/network_info_plus/network_info_plus/example/linux/my_application.cc @@ -11,10 +11,10 @@ struct _MyApplication { G_DEFINE_TYPE(MyApplication, my_application, GTK_TYPE_APPLICATION) // Implements GApplication::activate. -static void my_application_activate(GApplication* application) { - GtkWindow* window = +static void my_application_activate(GApplication *application) { + GtkWindow *window = GTK_WINDOW(gtk_application_window_new(GTK_APPLICATION(application))); - GtkHeaderBar* header_bar = GTK_HEADER_BAR(gtk_header_bar_new()); + GtkHeaderBar *header_bar = GTK_HEADER_BAR(gtk_header_bar_new()); gtk_widget_show(GTK_WIDGET(header_bar)); gtk_header_bar_set_title(header_bar, "example"); gtk_header_bar_set_show_close_button(header_bar, TRUE); @@ -24,7 +24,7 @@ static void my_application_activate(GApplication* application) { g_autoptr(FlDartProject) project = fl_dart_project_new(); - FlView* view = fl_view_new(project); + FlView *view = fl_view_new(project); gtk_widget_show(GTK_WIDGET(view)); gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(view)); @@ -33,13 +33,13 @@ static void my_application_activate(GApplication* application) { gtk_widget_grab_focus(GTK_WIDGET(view)); } -static void my_application_class_init(MyApplicationClass* klass) { +static void my_application_class_init(MyApplicationClass *klass) { G_APPLICATION_CLASS(klass)->activate = my_application_activate; } -static void my_application_init(MyApplication* self) {} +static void my_application_init(MyApplication *self) {} -MyApplication* my_application_new() { +MyApplication *my_application_new() { return MY_APPLICATION(g_object_new( my_application_get_type(), "application-id", APPLICATION_ID, nullptr)); } diff --git a/packages/network_info_plus/network_info_plus/example/linux/my_application.h b/packages/network_info_plus/network_info_plus/example/linux/my_application.h index 72271d5e41..3258a73cf4 100644 --- a/packages/network_info_plus/network_info_plus/example/linux/my_application.h +++ b/packages/network_info_plus/network_info_plus/example/linux/my_application.h @@ -13,6 +13,6 @@ G_DECLARE_FINAL_TYPE(MyApplication, my_application, MY, APPLICATION, * * Returns: a new #MyApplication. */ -MyApplication* my_application_new(); +MyApplication *my_application_new(); -#endif // FLUTTER_MY_APPLICATION_H_ +#endif // FLUTTER_MY_APPLICATION_H_ diff --git a/packages/network_info_plus/network_info_plus/example/windows/runner/flutter_window.cpp b/packages/network_info_plus/network_info_plus/example/windows/runner/flutter_window.cpp index c422723045..0f0105d995 100644 --- a/packages/network_info_plus/network_info_plus/example/windows/runner/flutter_window.cpp +++ b/packages/network_info_plus/network_info_plus/example/windows/runner/flutter_window.cpp @@ -4,8 +4,8 @@ #include "flutter/generated_plugin_registrant.h" -FlutterWindow::FlutterWindow(RunLoop* run_loop, - const flutter::DartProject& project) +FlutterWindow::FlutterWindow(RunLoop *run_loop, + const flutter::DartProject &project) : run_loop_(run_loop), project_(project) {} FlutterWindow::~FlutterWindow() {} @@ -55,9 +55,9 @@ FlutterWindow::MessageHandler(HWND hwnd, UINT const message, } switch (message) { - case WM_FONTCHANGE: - flutter_controller_->engine()->ReloadSystemFonts(); - break; + case WM_FONTCHANGE: + flutter_controller_->engine()->ReloadSystemFonts(); + break; } return Win32Window::MessageHandler(hwnd, message, wparam, lparam); diff --git a/packages/network_info_plus/network_info_plus/example/windows/runner/flutter_window.h b/packages/network_info_plus/network_info_plus/example/windows/runner/flutter_window.h index b663ddd501..69234d4f5e 100644 --- a/packages/network_info_plus/network_info_plus/example/windows/runner/flutter_window.h +++ b/packages/network_info_plus/network_info_plus/example/windows/runner/flutter_window.h @@ -11,23 +11,23 @@ // A window that does nothing but host a Flutter view. class FlutterWindow : public Win32Window { - public: +public: // Creates a new FlutterWindow driven by the |run_loop|, hosting a // Flutter view running |project|. - explicit FlutterWindow(RunLoop* run_loop, - const flutter::DartProject& project); + explicit FlutterWindow(RunLoop *run_loop, + const flutter::DartProject &project); virtual ~FlutterWindow(); - protected: +protected: // Win32Window: bool OnCreate() override; void OnDestroy() override; LRESULT MessageHandler(HWND window, UINT const message, WPARAM const wparam, LPARAM const lparam) noexcept override; - private: +private: // The run loop driving events for this window. - RunLoop* run_loop_; + RunLoop *run_loop_; // The project to run. flutter::DartProject project_; @@ -36,4 +36,4 @@ class FlutterWindow : public Win32Window { std::unique_ptr flutter_controller_; }; -#endif // RUNNER_FLUTTER_WINDOW_H_ +#endif // RUNNER_FLUTTER_WINDOW_H_ diff --git a/packages/network_info_plus/network_info_plus/example/windows/runner/run_loop.cpp b/packages/network_info_plus/network_info_plus/example/windows/runner/run_loop.cpp index 2d6636ab6b..31b89f6229 100644 --- a/packages/network_info_plus/network_info_plus/example/windows/runner/run_loop.cpp +++ b/packages/network_info_plus/network_info_plus/example/windows/runner/run_loop.cpp @@ -44,12 +44,12 @@ void RunLoop::Run() { } void RunLoop::RegisterFlutterInstance( - flutter::FlutterEngine* flutter_instance) { + flutter::FlutterEngine *flutter_instance) { flutter_instances_.insert(flutter_instance); } void RunLoop::UnregisterFlutterInstance( - flutter::FlutterEngine* flutter_instance) { + flutter::FlutterEngine *flutter_instance) { flutter_instances_.erase(flutter_instance); } diff --git a/packages/network_info_plus/network_info_plus/example/windows/runner/run_loop.h b/packages/network_info_plus/network_info_plus/example/windows/runner/run_loop.h index 5f2c4a9ad7..7fe1aaccc2 100644 --- a/packages/network_info_plus/network_info_plus/example/windows/runner/run_loop.h +++ b/packages/network_info_plus/network_info_plus/example/windows/runner/run_loop.h @@ -9,30 +9,30 @@ // A runloop that will service events for Flutter instances as well // as native messages. class RunLoop { - public: +public: RunLoop(); ~RunLoop(); // Prevent copying - RunLoop(RunLoop const&) = delete; - RunLoop& operator=(RunLoop const&) = delete; + RunLoop(RunLoop const &) = delete; + RunLoop &operator=(RunLoop const &) = delete; // Runs the run loop until the application quits. void Run(); // Registers the given Flutter instance for event servicing. - void RegisterFlutterInstance(flutter::FlutterEngine* flutter_instance); + void RegisterFlutterInstance(flutter::FlutterEngine *flutter_instance); // Unregisters the given Flutter instance from event servicing. - void UnregisterFlutterInstance(flutter::FlutterEngine* flutter_instance); + void UnregisterFlutterInstance(flutter::FlutterEngine *flutter_instance); - private: +private: using TimePoint = std::chrono::steady_clock::time_point; // Processes all currently pending messages for registered Flutter instances. TimePoint ProcessFlutterMessages(); - std::set flutter_instances_; + std::set flutter_instances_; }; -#endif // RUNNER_RUN_LOOP_H_ +#endif // RUNNER_RUN_LOOP_H_ diff --git a/packages/network_info_plus/network_info_plus/example/windows/runner/utils.cpp b/packages/network_info_plus/network_info_plus/example/windows/runner/utils.cpp index afa363b236..7758aabf38 100644 --- a/packages/network_info_plus/network_info_plus/example/windows/runner/utils.cpp +++ b/packages/network_info_plus/network_info_plus/example/windows/runner/utils.cpp @@ -9,7 +9,7 @@ void CreateAndAttachConsole() { if (::AllocConsole()) { - FILE* unused; + FILE *unused; if (freopen_s(&unused, "CONOUT$", "w", stdout)) { _dup2(_fileno(stdout), 1); } @@ -24,7 +24,7 @@ void CreateAndAttachConsole() { std::vector GetCommandLineArguments() { // Convert the UTF-16 command line arguments to UTF-8 for the Engine to use. int argc; - wchar_t** argv = ::CommandLineToArgvW(::GetCommandLineW(), &argc); + wchar_t **argv = ::CommandLineToArgvW(::GetCommandLineW(), &argc); if (argv == nullptr) { return std::vector(); } @@ -41,7 +41,7 @@ std::vector GetCommandLineArguments() { return command_line_arguments; } -std::string Utf8FromUtf16(const wchar_t* utf16_string) { +std::string Utf8FromUtf16(const wchar_t *utf16_string) { if (utf16_string == nullptr) { return std::string(); } diff --git a/packages/network_info_plus/network_info_plus/example/windows/runner/utils.h b/packages/network_info_plus/network_info_plus/example/windows/runner/utils.h index 3879d54755..ff43ce2ce5 100644 --- a/packages/network_info_plus/network_info_plus/example/windows/runner/utils.h +++ b/packages/network_info_plus/network_info_plus/example/windows/runner/utils.h @@ -10,10 +10,10 @@ void CreateAndAttachConsole(); // Takes a null-terminated wchar_t* encoded in UTF-16 and returns a std::string // encoded in UTF-8. Returns an empty std::string on failure. -std::string Utf8FromUtf16(const wchar_t* utf16_string); +std::string Utf8FromUtf16(const wchar_t *utf16_string); // Gets the command line arguments passed in as a std::vector, // encoded in UTF-8. Returns an empty std::vector on failure. std::vector GetCommandLineArguments(); -#endif // RUNNER_UTILS_H_ +#endif // RUNNER_UTILS_H_ diff --git a/packages/network_info_plus/network_info_plus/example/windows/runner/win32_window.cpp b/packages/network_info_plus/network_info_plus/example/windows/runner/win32_window.cpp index 44091b3f3c..90ff01e592 100644 --- a/packages/network_info_plus/network_info_plus/example/windows/runner/win32_window.cpp +++ b/packages/network_info_plus/network_info_plus/example/windows/runner/win32_window.cpp @@ -27,7 +27,7 @@ void EnableFullDpiSupportIfAvailable(HWND hwnd) { return; } auto enable_non_client_dpi_scaling = - reinterpret_cast( + reinterpret_cast( GetProcAddress(user32_module, "EnableNonClientDpiScaling")); if (enable_non_client_dpi_scaling != nullptr) { enable_non_client_dpi_scaling(hwnd); @@ -35,15 +35,15 @@ void EnableFullDpiSupportIfAvailable(HWND hwnd) { } } -} // namespace +} // namespace // Manages the Win32Window's window class registration. class WindowClassRegistrar { - public: +public: ~WindowClassRegistrar() = default; // Returns the singleton registar instance. - static WindowClassRegistrar* GetInstance() { + static WindowClassRegistrar *GetInstance() { if (!instance_) { instance_ = new WindowClassRegistrar(); } @@ -52,23 +52,23 @@ class WindowClassRegistrar { // Returns the name of the window class, registering the class if it hasn't // previously been registered. - const wchar_t* GetWindowClass(); + const wchar_t *GetWindowClass(); // Unregisters the window class. Should only be called if there are no // instances of the window. void UnregisterWindowClass(); - private: +private: WindowClassRegistrar() = default; - static WindowClassRegistrar* instance_; + static WindowClassRegistrar *instance_; bool class_registered_ = false; }; -WindowClassRegistrar* WindowClassRegistrar::instance_ = nullptr; +WindowClassRegistrar *WindowClassRegistrar::instance_ = nullptr; -const wchar_t* WindowClassRegistrar::GetWindowClass() { +const wchar_t *WindowClassRegistrar::GetWindowClass() { if (!class_registered_) { WNDCLASS window_class{}; window_class.hCursor = LoadCursor(nullptr, IDC_ARROW); @@ -100,11 +100,11 @@ Win32Window::~Win32Window() { Destroy(); } -bool Win32Window::CreateAndShow(const std::wstring& title, const Point& origin, - const Size& size) { +bool Win32Window::CreateAndShow(const std::wstring &title, const Point &origin, + const Size &size) { Destroy(); - const wchar_t* window_class = + const wchar_t *window_class = WindowClassRegistrar::GetInstance()->GetWindowClass(); const POINT target_point = {static_cast(origin.x), @@ -131,14 +131,14 @@ LRESULT CALLBACK Win32Window::WndProc(HWND const window, UINT const message, WPARAM const wparam, LPARAM const lparam) noexcept { if (message == WM_NCCREATE) { - auto window_struct = reinterpret_cast(lparam); + auto window_struct = reinterpret_cast(lparam); SetWindowLongPtr(window, GWLP_USERDATA, reinterpret_cast(window_struct->lpCreateParams)); - auto that = static_cast(window_struct->lpCreateParams); + auto that = static_cast(window_struct->lpCreateParams); EnableFullDpiSupportIfAvailable(window); that->window_handle_ = window; - } else if (Win32Window* that = GetThisFromHandle(window)) { + } else if (Win32Window *that = GetThisFromHandle(window)) { return that->MessageHandler(window, message, wparam, lparam); } @@ -149,39 +149,39 @@ LRESULT Win32Window::MessageHandler(HWND hwnd, UINT const message, WPARAM const wparam, LPARAM const lparam) noexcept { switch (message) { - case WM_DESTROY: - window_handle_ = nullptr; - Destroy(); - if (quit_on_close_) { - PostQuitMessage(0); - } - return 0; - - case WM_DPICHANGED: { - auto newRectSize = reinterpret_cast(lparam); - LONG newWidth = newRectSize->right - newRectSize->left; - LONG newHeight = newRectSize->bottom - newRectSize->top; - - SetWindowPos(hwnd, nullptr, newRectSize->left, newRectSize->top, newWidth, - newHeight, SWP_NOZORDER | SWP_NOACTIVATE); - - return 0; + case WM_DESTROY: + window_handle_ = nullptr; + Destroy(); + if (quit_on_close_) { + PostQuitMessage(0); } - case WM_SIZE: { - RECT rect = GetClientArea(); - if (child_content_ != nullptr) { - // Size and position the child window. - MoveWindow(child_content_, rect.left, rect.top, rect.right - rect.left, - rect.bottom - rect.top, TRUE); - } - return 0; + return 0; + + case WM_DPICHANGED: { + auto newRectSize = reinterpret_cast(lparam); + LONG newWidth = newRectSize->right - newRectSize->left; + LONG newHeight = newRectSize->bottom - newRectSize->top; + + SetWindowPos(hwnd, nullptr, newRectSize->left, newRectSize->top, newWidth, + newHeight, SWP_NOZORDER | SWP_NOACTIVATE); + + return 0; + } + case WM_SIZE: { + RECT rect = GetClientArea(); + if (child_content_ != nullptr) { + // Size and position the child window. + MoveWindow(child_content_, rect.left, rect.top, rect.right - rect.left, + rect.bottom - rect.top, TRUE); } + return 0; + } - case WM_ACTIVATE: - if (child_content_ != nullptr) { - SetFocus(child_content_); - } - return 0; + case WM_ACTIVATE: + if (child_content_ != nullptr) { + SetFocus(child_content_); + } + return 0; } return DefWindowProc(window_handle_, message, wparam, lparam); @@ -199,8 +199,8 @@ void Win32Window::Destroy() { } } -Win32Window* Win32Window::GetThisFromHandle(HWND const window) noexcept { - return reinterpret_cast( +Win32Window *Win32Window::GetThisFromHandle(HWND const window) noexcept { + return reinterpret_cast( GetWindowLongPtr(window, GWLP_USERDATA)); } diff --git a/packages/network_info_plus/network_info_plus/example/windows/runner/win32_window.h b/packages/network_info_plus/network_info_plus/example/windows/runner/win32_window.h index 4ae64a12b4..7b518125bb 100644 --- a/packages/network_info_plus/network_info_plus/example/windows/runner/win32_window.h +++ b/packages/network_info_plus/network_info_plus/example/windows/runner/win32_window.h @@ -11,7 +11,7 @@ // inherited from by classes that wish to specialize with custom // rendering and input handling class Win32Window { - public: +public: struct Point { unsigned int x; unsigned int y; @@ -34,8 +34,8 @@ class Win32Window { // consistent size to will treat the width height passed in to this function // as logical pixels and scale to appropriate for the default monitor. Returns // true if the window was created successfully. - bool CreateAndShow(const std::wstring& title, const Point& origin, - const Size& size); + bool CreateAndShow(const std::wstring &title, const Point &origin, + const Size &size); // Release OS resources associated with window. void Destroy(); @@ -53,7 +53,7 @@ class Win32Window { // Return a RECT representing the bounds of the current client area. RECT GetClientArea(); - protected: +protected: // Processes and route salient window messages for mouse handling, // size change and DPI. Delegates handling of these to member overloads that // inheriting classes can handle. @@ -68,7 +68,7 @@ class Win32Window { // Called when Destroy is called. virtual void OnDestroy(); - private: +private: friend class WindowClassRegistrar; // OS callback called by message pump. Handles the WM_NCCREATE message which @@ -81,7 +81,7 @@ class Win32Window { LPARAM const lparam) noexcept; // Retrieves a class instance pointer for |window| - static Win32Window* GetThisFromHandle(HWND const window) noexcept; + static Win32Window *GetThisFromHandle(HWND const window) noexcept; bool quit_on_close_ = false; @@ -92,4 +92,4 @@ class Win32Window { HWND child_content_ = nullptr; }; -#endif // RUNNER_WIN32_WINDOW_H_ +#endif // RUNNER_WIN32_WINDOW_H_ diff --git a/packages/network_info_plus/network_info_plus/ios/Classes/FLTCaptiveNetworkInfoProvider.h b/packages/network_info_plus/network_info_plus/ios/Classes/FLTCaptiveNetworkInfoProvider.h index fa46e4e1f2..9053b6b396 100644 --- a/packages/network_info_plus/network_info_plus/ios/Classes/FLTCaptiveNetworkInfoProvider.h +++ b/packages/network_info_plus/network_info_plus/ios/Classes/FLTCaptiveNetworkInfoProvider.h @@ -1,5 +1,5 @@ -#import #import "FLTNetworkInfoProvider.h" +#import @interface FLTCaptiveNetworkInfoProvider : NSObject @end diff --git a/packages/network_info_plus/network_info_plus/ios/Classes/FLTCaptiveNetworkInfoProvider.m b/packages/network_info_plus/network_info_plus/ios/Classes/FLTCaptiveNetworkInfoProvider.m index 485d668a25..d9d61d742a 100644 --- a/packages/network_info_plus/network_info_plus/ios/Classes/FLTCaptiveNetworkInfoProvider.m +++ b/packages/network_info_plus/network_info_plus/ios/Classes/FLTCaptiveNetworkInfoProvider.m @@ -3,16 +3,19 @@ @implementation FLTCaptiveNetworkInfoProvider -- (void)fetchNetworkInfoWithCompletionHandler:(void (^)(FLTNetworkInfo *network))completionHandler { +- (void)fetchNetworkInfoWithCompletionHandler: + (void (^)(FLTNetworkInfo *network))completionHandler { dispatch_async(dispatch_get_main_queue(), ^{ NSArray *interfaceNames = (__bridge_transfer id)CNCopySupportedInterfaces(); for (NSString *interfaceName in interfaceNames) { NSDictionary *networkInfo = - (__bridge_transfer id)CNCopyCurrentNetworkInfo((__bridge CFStringRef)interfaceName); + (__bridge_transfer id)CNCopyCurrentNetworkInfo( + (__bridge CFStringRef)interfaceName); if (networkInfo) { NSString *ssid = networkInfo[(NSString *)kCNNetworkInfoKeySSID]; NSString *bssid = networkInfo[(NSString *)kCNNetworkInfoKeyBSSID]; - completionHandler([[FLTNetworkInfo alloc] initWithSSID:ssid BSSID:bssid]); + completionHandler([[FLTNetworkInfo alloc] initWithSSID:ssid + BSSID:bssid]); return; } } diff --git a/packages/network_info_plus/network_info_plus/ios/Classes/FLTHotspotNetworkInfoProvider.h b/packages/network_info_plus/network_info_plus/ios/Classes/FLTHotspotNetworkInfoProvider.h index c23e67e344..bdcdef68a1 100644 --- a/packages/network_info_plus/network_info_plus/ios/Classes/FLTHotspotNetworkInfoProvider.h +++ b/packages/network_info_plus/network_info_plus/ios/Classes/FLTHotspotNetworkInfoProvider.h @@ -1,5 +1,5 @@ -#import #import "FLTNetworkInfoProvider.h" +#import @interface FLTHotspotNetworkInfoProvider : NSObject @end diff --git a/packages/network_info_plus/network_info_plus/ios/Classes/FLTHotspotNetworkInfoProvider.m b/packages/network_info_plus/network_info_plus/ios/Classes/FLTHotspotNetworkInfoProvider.m index 495a072001..a617223792 100644 --- a/packages/network_info_plus/network_info_plus/ios/Classes/FLTHotspotNetworkInfoProvider.m +++ b/packages/network_info_plus/network_info_plus/ios/Classes/FLTHotspotNetworkInfoProvider.m @@ -3,12 +3,15 @@ @implementation FLTHotspotNetworkInfoProvider -- (void)fetchNetworkInfoWithCompletionHandler:(void (^)(FLTNetworkInfo *network))completionHandler +- (void)fetchNetworkInfoWithCompletionHandler: + (void (^)(FLTNetworkInfo *network))completionHandler API_AVAILABLE(ios(14)) { - [NEHotspotNetwork fetchCurrentWithCompletionHandler:^(NEHotspotNetwork *network) { + [NEHotspotNetwork fetchCurrentWithCompletionHandler:^( + NEHotspotNetwork *network) { dispatch_async(dispatch_get_main_queue(), ^{ if (network) { - completionHandler([[FLTNetworkInfo alloc] initWithSSID:network.SSID BSSID:network.BSSID]); + completionHandler([[FLTNetworkInfo alloc] initWithSSID:network.SSID + BSSID:network.BSSID]); return; } completionHandler(nil); diff --git a/packages/network_info_plus/network_info_plus/ios/Classes/FLTNetworkInfoLocationPlusHandler.h b/packages/network_info_plus/network_info_plus/ios/Classes/FLTNetworkInfoLocationPlusHandler.h index 516a9bab85..9beac1bc07 100644 --- a/packages/network_info_plus/network_info_plus/ios/Classes/FLTNetworkInfoLocationPlusHandler.h +++ b/packages/network_info_plus/network_info_plus/ios/Classes/FLTNetworkInfoLocationPlusHandler.h @@ -16,7 +16,8 @@ typedef void (^FLTNetworkInfoLocationPlusCompletion)(CLAuthorizationStatus); - (void)requestLocationAuthorization:(BOOL)always completion: - (_Nonnull FLTNetworkInfoLocationPlusCompletion)completionHnadler; + (_Nonnull FLTNetworkInfoLocationPlusCompletion) + completionHnadler; @end diff --git a/packages/network_info_plus/network_info_plus/ios/Classes/FLTNetworkInfoLocationPlusHandler.m b/packages/network_info_plus/network_info_plus/ios/Classes/FLTNetworkInfoLocationPlusHandler.m index 6fca387640..2c276f657b 100644 --- a/packages/network_info_plus/network_info_plus/ios/Classes/FLTNetworkInfoLocationPlusHandler.m +++ b/packages/network_info_plus/network_info_plus/ios/Classes/FLTNetworkInfoLocationPlusHandler.m @@ -18,7 +18,8 @@ + (CLAuthorizationStatus)locationAuthorizationStatus { } - (void)requestLocationAuthorization:(BOOL)always - completion:(FLTNetworkInfoLocationPlusCompletion)completionHandler { + completion:(FLTNetworkInfoLocationPlusCompletion) + completionHandler { CLAuthorizationStatus status = CLLocationManager.authorizationStatus; if (status != kCLAuthorizationStatusAuthorizedWhenInUse && always) { completionHandler(kCLAuthorizationStatusDenied); diff --git a/packages/network_info_plus/network_info_plus/ios/Classes/FLTNetworkInfoPlusPlugin.m b/packages/network_info_plus/network_info_plus/ios/Classes/FLTNetworkInfoPlusPlugin.m index 2dfc8bce82..d6f9c6be23 100644 --- a/packages/network_info_plus/network_info_plus/ios/Classes/FLTNetworkInfoPlusPlugin.m +++ b/packages/network_info_plus/network_info_plus/ios/Classes/FLTNetworkInfoPlusPlugin.m @@ -4,7 +4,6 @@ #import "FLTNetworkInfoPlusPlugin.h" -#import #import "FLTCaptiveNetworkInfoProvider.h" #import "FLTHotspotNetworkInfoProvider.h" #import "FLTNetworkInfo.h" @@ -12,6 +11,7 @@ #import "FLTNetworkInfoProvider.h" #import "SystemConfiguration/CaptiveNetwork.h" #import "getgateway.h" +#import #include @@ -20,33 +20,35 @@ @interface FLTNetworkInfoPlusPlugin () -@property(strong, nonatomic) FLTNetworkInfoLocationPlusHandler* locationHandler; +@property(strong, nonatomic) FLTNetworkInfoLocationPlusHandler *locationHandler; @property(strong, nonatomic) id networkInfoProvider; -- (instancetype)initWithNetworkInfoProvider:(id)networkInfoProvider; +- (instancetype)initWithNetworkInfoProvider: + (id)networkInfoProvider; @end @implementation FLTNetworkInfoPlusPlugin { } -+ (void)registerWithRegistrar:(NSObject*)registrar { ++ (void)registerWithRegistrar:(NSObject *)registrar { id networkInfoProvider; if (@available(iOS 14, *)) { networkInfoProvider = [[FLTHotspotNetworkInfoProvider alloc] init]; } else { networkInfoProvider = [[FLTCaptiveNetworkInfoProvider alloc] init]; } - FLTNetworkInfoPlusPlugin* instance = - [[FLTNetworkInfoPlusPlugin alloc] initWithNetworkInfoProvider:networkInfoProvider]; + FLTNetworkInfoPlusPlugin *instance = [[FLTNetworkInfoPlusPlugin alloc] + initWithNetworkInfoProvider:networkInfoProvider]; - FlutterMethodChannel* channel = - [FlutterMethodChannel methodChannelWithName:@"dev.fluttercommunity.plus/network_info" - binaryMessenger:[registrar messenger]]; + FlutterMethodChannel *channel = [FlutterMethodChannel + methodChannelWithName:@"dev.fluttercommunity.plus/network_info" + binaryMessenger:[registrar messenger]]; [registrar addMethodCallDelegate:instance channel:channel]; } -- (instancetype)initWithNetworkInfoProvider:(id)networkInfoProvider { +- (instancetype)initWithNetworkInfoProvider: + (id)networkInfoProvider { if ((self = [super init])) { self.networkInfoProvider = networkInfoProvider; } @@ -55,7 +57,7 @@ - (instancetype)initWithNetworkInfoProvider:(id)networkI #pragma mark - Callbacks -- (NSString*)getGatewayIP { +- (NSString *)getGatewayIP { struct in_addr gatewayAddr; int gatewayAdressResult = getDefaultGateway(&(gatewayAddr.s_addr)); if (gatewayAdressResult >= 0) { @@ -65,74 +67,78 @@ - (NSString*)getGatewayIP { } } -- (NSString*)getWifiIP { - __block NSString* addr = nil; +- (NSString *)getWifiIP { + __block NSString *addr = nil; [self enumerateWifiAddresses:AF_INET - usingBlock:^(struct ifaddrs* ifaddr) { + usingBlock:^(struct ifaddrs *ifaddr) { addr = [self descriptionForAddress:ifaddr->ifa_addr]; }]; return addr; } -- (NSString*)getWifiIPv6 { - __block NSString* addr = nil; +- (NSString *)getWifiIPv6 { + __block NSString *addr = nil; [self enumerateWifiAddresses:AF_INET6 - usingBlock:^(struct ifaddrs* ifaddr) { + usingBlock:^(struct ifaddrs *ifaddr) { addr = [self descriptionForAddress:ifaddr->ifa_addr]; }]; return addr; } -- (NSString*)getWifiSubmask { - __block NSString* addr = nil; +- (NSString *)getWifiSubmask { + __block NSString *addr = nil; [self enumerateWifiAddresses:AF_INET - usingBlock:^(struct ifaddrs* ifaddr) { + usingBlock:^(struct ifaddrs *ifaddr) { addr = [self descriptionForAddress:ifaddr->ifa_netmask]; }]; return addr; } -- (NSString*)getWifiBroadcast { - __block NSString* addr = nil; +- (NSString *)getWifiBroadcast { + __block NSString *addr = nil; [self enumerateWifiAddresses:AF_INET - usingBlock:^(struct ifaddrs* ifaddr) { + usingBlock:^(struct ifaddrs *ifaddr) { addr = [self descriptionForAddress:ifaddr->ifa_dstaddr]; }]; return addr; } -- (NSString*)convertCLAuthorizationStatusToString:(CLAuthorizationStatus)status { +- (NSString *)convertCLAuthorizationStatusToString: + (CLAuthorizationStatus)status { switch (status) { - case kCLAuthorizationStatusNotDetermined: { - return @"notDetermined"; - } - case kCLAuthorizationStatusRestricted: { - return @"restricted"; - } - case kCLAuthorizationStatusDenied: { - return @"denied"; - } - case kCLAuthorizationStatusAuthorizedAlways: { - return @"authorizedAlways"; - } - case kCLAuthorizationStatusAuthorizedWhenInUse: { - return @"authorizedWhenInUse"; - } - default: { - return @"unknown"; - } + case kCLAuthorizationStatusNotDetermined: { + return @"notDetermined"; + } + case kCLAuthorizationStatusRestricted: { + return @"restricted"; + } + case kCLAuthorizationStatusDenied: { + return @"denied"; + } + case kCLAuthorizationStatusAuthorizedAlways: { + return @"authorizedAlways"; + } + case kCLAuthorizationStatusAuthorizedWhenInUse: { + return @"authorizedWhenInUse"; + } + default: { + return @"unknown"; + } } } -- (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result { +- (void)handleMethodCall:(FlutterMethodCall *)call + result:(FlutterResult)result { if ([call.method isEqualToString:@"wifiName"]) { - [self.networkInfoProvider fetchNetworkInfoWithCompletionHandler:^(FLTNetworkInfo* networkInfo) { - result(networkInfo.SSID); - }]; + [self.networkInfoProvider + fetchNetworkInfoWithCompletionHandler:^(FLTNetworkInfo *networkInfo) { + result(networkInfo.SSID); + }]; } else if ([call.method isEqualToString:@"wifiBSSID"]) { - [self.networkInfoProvider fetchNetworkInfoWithCompletionHandler:^(FLTNetworkInfo* networkInfo) { - result(networkInfo.BSSID); - }]; + [self.networkInfoProvider + fetchNetworkInfoWithCompletionHandler:^(FLTNetworkInfo *networkInfo) { + result(networkInfo.BSSID); + }]; } else if ([call.method isEqualToString:@"wifiIPAddress"]) { result([self getWifiIP]); } else if ([call.method isEqualToString:@"wifiIPv6Address"]) { @@ -144,23 +150,26 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result { } else if ([call.method isEqualToString:@"wifiGatewayAddress"]) { result([self getGatewayIP]); } else if ([call.method isEqualToString:@"getLocationServiceAuthorization"]) { - result([self convertCLAuthorizationStatusToString:[FLTNetworkInfoLocationPlusHandler - locationAuthorizationStatus]]); - } else if ([call.method isEqualToString:@"requestLocationServiceAuthorization"]) { - NSArray* arguments = call.arguments; + result([self + convertCLAuthorizationStatusToString:[FLTNetworkInfoLocationPlusHandler + locationAuthorizationStatus]]); + } else if ([call.method + isEqualToString:@"requestLocationServiceAuthorization"]) { + NSArray *arguments = call.arguments; BOOL always = [arguments.firstObject boolValue]; __weak typeof(self) weakSelf = self; [self.locationHandler requestLocationAuthorization:always completion:^(CLAuthorizationStatus status) { - result([weakSelf convertCLAuthorizationStatusToString:status]); + result([weakSelf + convertCLAuthorizationStatusToString:status]); }]; } else { result(FlutterMethodNotImplemented); } } -- (FLTNetworkInfoLocationPlusHandler*)locationHandler { +- (FLTNetworkInfoLocationPlusHandler *)locationHandler { if (!_locationHandler) { _locationHandler = [FLTNetworkInfoLocationPlusHandler new]; } @@ -169,9 +178,10 @@ - (FLTNetworkInfoLocationPlusHandler*)locationHandler { #pragma mark - Utils -- (void)enumerateWifiAddresses:(NSInteger)family usingBlock:(void (^)(struct ifaddrs*))block { - struct ifaddrs* interfaces = NULL; - struct ifaddrs* temp_addr = NULL; +- (void)enumerateWifiAddresses:(NSInteger)family + usingBlock:(void (^)(struct ifaddrs *))block { + struct ifaddrs *interfaces = NULL; + struct ifaddrs *temp_addr = NULL; int success = 0; // retrieve the current interfaces - returns 0 on success @@ -182,7 +192,8 @@ - (void)enumerateWifiAddresses:(NSInteger)family usingBlock:(void (^)(struct ifa while (temp_addr != NULL) { if (temp_addr->ifa_addr->sa_family == family) { // en0 is the wifi connection on iOS - if ([[NSString stringWithUTF8String:temp_addr->ifa_name] isEqualToString:@"en0"]) { + if ([[NSString stringWithUTF8String:temp_addr->ifa_name] + isEqualToString:@"en0"]) { block(temp_addr); } } @@ -195,9 +206,10 @@ - (void)enumerateWifiAddresses:(NSInteger)family usingBlock:(void (^)(struct ifa freeifaddrs(interfaces); } -- (NSString*)descriptionForAddress:(struct sockaddr*)addr { +- (NSString *)descriptionForAddress:(struct sockaddr *)addr { char hostname[NI_MAXHOST]; - getnameinfo(addr, addr->sa_len, hostname, NI_MAXHOST, NULL, 0, NI_NUMERICHOST); + getnameinfo(addr, addr->sa_len, hostname, NI_MAXHOST, NULL, 0, + NI_NUMERICHOST); return [NSString stringWithUTF8String:hostname]; } diff --git a/packages/network_info_plus/network_info_plus/ios/Classes/FLTNetworkInfoProvider.h b/packages/network_info_plus/network_info_plus/ios/Classes/FLTNetworkInfoProvider.h index 1bdfcc18e5..024fe2ef71 100644 --- a/packages/network_info_plus/network_info_plus/ios/Classes/FLTNetworkInfoProvider.h +++ b/packages/network_info_plus/network_info_plus/ios/Classes/FLTNetworkInfoProvider.h @@ -1,5 +1,5 @@ -#import #import "FLTNetworkInfo.h" +#import @protocol FLTNetworkInfoProvider diff --git a/packages/network_info_plus/network_info_plus/ios/Classes/getgateway.h b/packages/network_info_plus/network_info_plus/ios/Classes/getgateway.h index d11675a886..b1fec6dd3f 100644 --- a/packages/network_info_plus/network_info_plus/ios/Classes/getgateway.h +++ b/packages/network_info_plus/network_info_plus/ios/Classes/getgateway.h @@ -8,6 +8,6 @@ #ifndef getgateway_h #define getgateway_h -int getDefaultGateway(in_addr_t* addr); +int getDefaultGateway(in_addr_t *addr); #endif /* getgateway_h */ diff --git a/packages/network_info_plus/network_info_plus/ios/Classes/route.h b/packages/network_info_plus/network_info_plus/ios/Classes/route.h index 48882bed2d..55a555a377 100644 --- a/packages/network_info_plus/network_info_plus/ios/Classes/route.h +++ b/packages/network_info_plus/network_info_plus/ios/Classes/route.h @@ -336,83 +336,85 @@ typedef struct ctrace { extern void ctrace_record(ctrace_t *); -#define RT_LOCK_ASSERT_HELD(_rt) \ +#define RT_LOCK_ASSERT_HELD(_rt) \ lck_mtx_assert(&(_rt)->rt_lock, LCK_MTX_ASSERT_OWNED) -#define RT_LOCK_ASSERT_NOTHELD(_rt) \ +#define RT_LOCK_ASSERT_NOTHELD(_rt) \ lck_mtx_assert(&(_rt)->rt_lock, LCK_MTX_ASSERT_NOTOWNED) -#define RT_LOCK(_rt) \ - do { \ - if (!rte_debug) \ - lck_mtx_lock(&(_rt)->rt_lock); \ - else \ - rt_lock(_rt, FALSE); \ +#define RT_LOCK(_rt) \ + do { \ + if (!rte_debug) \ + lck_mtx_lock(&(_rt)->rt_lock); \ + else \ + rt_lock(_rt, FALSE); \ } while (0) -#define RT_LOCK_SPIN(_rt) \ - do { \ - if (!rte_debug) \ - lck_mtx_lock_spin(&(_rt)->rt_lock); \ - else \ - rt_lock(_rt, TRUE); \ +#define RT_LOCK_SPIN(_rt) \ + do { \ + if (!rte_debug) \ + lck_mtx_lock_spin(&(_rt)->rt_lock); \ + else \ + rt_lock(_rt, TRUE); \ } while (0) -#define RT_CONVERT_LOCK(_rt) \ - do { \ - RT_LOCK_ASSERT_HELD(_rt); \ - lck_mtx_convert_spin(&(_rt)->rt_lock); \ +#define RT_CONVERT_LOCK(_rt) \ + do { \ + RT_LOCK_ASSERT_HELD(_rt); \ + lck_mtx_convert_spin(&(_rt)->rt_lock); \ } while (0) -#define RT_UNLOCK(_rt) \ - do { \ - if (!rte_debug) \ - lck_mtx_unlock(&(_rt)->rt_lock); \ - else \ - rt_unlock(_rt); \ +#define RT_UNLOCK(_rt) \ + do { \ + if (!rte_debug) \ + lck_mtx_unlock(&(_rt)->rt_lock); \ + else \ + rt_unlock(_rt); \ } while (0) -#define RT_ADDREF_LOCKED(_rt) \ - do { \ - if (!rte_debug) { \ - RT_LOCK_ASSERT_HELD(_rt); \ - if (++(_rt)->rt_refcnt == 0) panic("RT_ADDREF(%p) bad refcnt\n", _rt); \ - } else { \ - rtref(_rt); \ - } \ +#define RT_ADDREF_LOCKED(_rt) \ + do { \ + if (!rte_debug) { \ + RT_LOCK_ASSERT_HELD(_rt); \ + if (++(_rt)->rt_refcnt == 0) \ + panic("RT_ADDREF(%p) bad refcnt\n", _rt); \ + } else { \ + rtref(_rt); \ + } \ } while (0) /* * Spin variant mutex is used here; caller is responsible for * converting any previously-held similar lock to full mutex. */ -#define RT_ADDREF(_rt) \ - do { \ - RT_LOCK_SPIN(_rt); \ - RT_ADDREF_LOCKED(_rt); \ - RT_UNLOCK(_rt); \ +#define RT_ADDREF(_rt) \ + do { \ + RT_LOCK_SPIN(_rt); \ + RT_ADDREF_LOCKED(_rt); \ + RT_UNLOCK(_rt); \ } while (0) -#define RT_REMREF_LOCKED(_rt) \ - do { \ - if (!rte_debug) { \ - RT_LOCK_ASSERT_HELD(_rt); \ - if ((_rt)->rt_refcnt == 0) panic("RT_REMREF(%p) bad refcnt\n", _rt); \ - --(_rt)->rt_refcnt; \ - } else { \ - (void)rtunref(_rt); \ - } \ +#define RT_REMREF_LOCKED(_rt) \ + do { \ + if (!rte_debug) { \ + RT_LOCK_ASSERT_HELD(_rt); \ + if ((_rt)->rt_refcnt == 0) \ + panic("RT_REMREF(%p) bad refcnt\n", _rt); \ + --(_rt)->rt_refcnt; \ + } else { \ + (void)rtunref(_rt); \ + } \ } while (0) /* * Spin variant mutex is used here; caller is responsible for * converting any previously-held similar lock to full mutex. */ -#define RT_REMREF(_rt) \ - do { \ - RT_LOCK_SPIN(_rt); \ - RT_REMREF_LOCKED(_rt); \ - RT_UNLOCK(_rt); \ +#define RT_REMREF(_rt) \ + do { \ + RT_LOCK_SPIN(_rt); \ + RT_REMREF_LOCKED(_rt); \ + RT_UNLOCK(_rt); \ } while (0) #define RTFREE(_rt) rtfree(_rt) diff --git a/packages/network_info_plus/network_info_plus_windows/windows/include/network_info_plus_windows/network_info.h b/packages/network_info_plus/network_info_plus_windows/windows/include/network_info_plus_windows/network_info.h index ce2d6e8116..0f3bfecfd1 100644 --- a/packages/network_info_plus/network_info_plus_windows/windows/include/network_info_plus_windows/network_info.h +++ b/packages/network_info_plus/network_info_plus_windows/windows/include/network_info_plus_windows/network_info.h @@ -15,7 +15,7 @@ typedef std::function WlanQuery; class NetworkInfo { - public: +public: NetworkInfo(); ~NetworkInfo(); @@ -27,7 +27,7 @@ class NetworkInfo { std::string GetWifiBssid() const; std::string GetWifiIpAddress() const; - private: +private: void Init(); void Cleanup(); std::string Query(WlanQuery query); @@ -36,4 +36,4 @@ class NetworkInfo { HANDLE _hClient = NULL; }; -#endif // FLUTTER_PLUGIN_NETWORK_INFO_PLUS_NETWORK_INFO_H_ +#endif // FLUTTER_PLUGIN_NETWORK_INFO_PLUS_NETWORK_INFO_H_ diff --git a/packages/network_info_plus/network_info_plus_windows/windows/include/network_info_plus_windows/network_info_plus_windows_plugin.h b/packages/network_info_plus/network_info_plus_windows/windows/include/network_info_plus_windows/network_info_plus_windows_plugin.h index d816b910fb..f6c2ff6c77 100644 --- a/packages/network_info_plus/network_info_plus_windows/windows/include/network_info_plus_windows/network_info_plus_windows_plugin.h +++ b/packages/network_info_plus/network_info_plus_windows/windows/include/network_info_plus_windows/network_info_plus_windows_plugin.h @@ -17,7 +17,7 @@ FLUTTER_PLUGIN_EXPORT void NetworkInfoPlusWindowsPluginRegisterWithRegistrar( FlutterDesktopPluginRegistrarRef registrar); #if defined(__cplusplus) -} // extern "C" +} // extern "C" #endif -#endif // FLUTTER_PLUGIN_NETWORK_INFO_PLUS_WINDOWS_PLUGIN_H_ +#endif // FLUTTER_PLUGIN_NETWORK_INFO_PLUS_WINDOWS_PLUGIN_H_ diff --git a/packages/network_info_plus/network_info_plus_windows/windows/network_info.cpp b/packages/network_info_plus/network_info_plus_windows/windows/network_info.cpp index 56d3404115..64367e53e0 100644 --- a/packages/network_info_plus/network_info_plus_windows/windows/network_info.cpp +++ b/packages/network_info_plus/network_info_plus_windows/windows/network_info.cpp @@ -54,8 +54,8 @@ static std::string FormatIpAddress(PIP_ADAPTER_ADDRESSES pIpAdapterAddress) { return std::string(inet_ntop(AF_INET, &(sa_in->sin_addr), buffer, 64)); } -static std::string GetAdapterAddress( - LPGUID pGuid, PIP_ADAPTER_ADDRESSES pIpAdapterAddresses) { +static std::string +GetAdapterAddress(LPGUID pGuid, PIP_ADAPTER_ADDRESSES pIpAdapterAddresses) { IF_LUID ifLuid; if (ConvertInterfaceGuidToLuid(pGuid, &ifLuid) != NO_ERROR) { return ""; diff --git a/packages/network_info_plus/network_info_plus_windows/windows/network_info_plus_windows_plugin.cpp b/packages/network_info_plus/network_info_plus_windows/windows/network_info_plus_windows_plugin.cpp index fbd38cbe5f..bbdab37067 100644 --- a/packages/network_info_plus/network_info_plus_windows/windows/network_info_plus_windows_plugin.cpp +++ b/packages/network_info_plus/network_info_plus_windows/windows/network_info_plus_windows_plugin.cpp @@ -10,14 +10,14 @@ namespace { class NetworkInfoPlusWindowsPlugin : public flutter::Plugin { - public: +public: static void RegisterWithRegistrar(flutter::PluginRegistrarWindows *registrar); NetworkInfoPlusWindowsPlugin(); virtual ~NetworkInfoPlusWindowsPlugin(); - private: +private: void HandleMethodCall( const flutter::MethodCall &method_call, std::unique_ptr> result); @@ -75,7 +75,7 @@ void NetworkInfoPlusWindowsPlugin::HandleMethodResult( } } -} // namespace +} // namespace void NetworkInfoPlusWindowsPluginRegisterWithRegistrar( FlutterDesktopPluginRegistrarRef registrar) { diff --git a/packages/package_info_plus/package_info_plus/example/ios/Runner/AppDelegate.m b/packages/package_info_plus/package_info_plus/example/ios/Runner/AppDelegate.m index f086757071..26c653a8ea 100644 --- a/packages/package_info_plus/package_info_plus/example/ios/Runner/AppDelegate.m +++ b/packages/package_info_plus/package_info_plus/example/ios/Runner/AppDelegate.m @@ -11,7 +11,8 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [GeneratedPluginRegistrant registerWithRegistry:self]; // Override point for customization after application launch. - return [super application:application didFinishLaunchingWithOptions:launchOptions]; + return [super application:application + didFinishLaunchingWithOptions:launchOptions]; } @end diff --git a/packages/package_info_plus/package_info_plus/example/ios/Runner/main.m b/packages/package_info_plus/package_info_plus/example/ios/Runner/main.m index bec320c0be..b7fe28c73a 100644 --- a/packages/package_info_plus/package_info_plus/example/ios/Runner/main.m +++ b/packages/package_info_plus/package_info_plus/example/ios/Runner/main.m @@ -2,12 +2,13 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#import "AppDelegate.h" #import #import -#import "AppDelegate.h" -int main(int argc, char* argv[]) { +int main(int argc, char *argv[]) { @autoreleasepool { - return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); + return UIApplicationMain(argc, argv, nil, + NSStringFromClass([AppDelegate class])); } } diff --git a/packages/package_info_plus/package_info_plus/example/linux/main.cc b/packages/package_info_plus/package_info_plus/example/linux/main.cc index e7c5c54370..26cd225d93 100644 --- a/packages/package_info_plus/package_info_plus/example/linux/main.cc +++ b/packages/package_info_plus/package_info_plus/example/linux/main.cc @@ -1,6 +1,6 @@ #include "my_application.h" -int main(int argc, char** argv) { +int main(int argc, char **argv) { g_autoptr(MyApplication) app = my_application_new(); return g_application_run(G_APPLICATION(app), argc, argv); } diff --git a/packages/package_info_plus/package_info_plus/example/linux/my_application.cc b/packages/package_info_plus/package_info_plus/example/linux/my_application.cc index d99ca6c35e..8f6e1346a5 100644 --- a/packages/package_info_plus/package_info_plus/example/linux/my_application.cc +++ b/packages/package_info_plus/package_info_plus/example/linux/my_application.cc @@ -14,8 +14,8 @@ struct _MyApplication { G_DEFINE_TYPE(MyApplication, my_application, GTK_TYPE_APPLICATION) // Implements GApplication::activate. -static void my_application_activate(GApplication* application) { - GtkWindow* window = +static void my_application_activate(GApplication *application) { + GtkWindow *window = GTK_WINDOW(gtk_application_window_new(GTK_APPLICATION(application))); // Use a header bar when running in GNOME as this is the common style used @@ -27,16 +27,16 @@ static void my_application_activate(GApplication* application) { // if future cases occur). gboolean use_header_bar = TRUE; #ifdef GDK_WINDOWING_X11 - GdkScreen* screen = gtk_window_get_screen(window); + GdkScreen *screen = gtk_window_get_screen(window); if (GDK_IS_X11_SCREEN(screen)) { - const gchar* wm_name = gdk_x11_screen_get_window_manager_name(screen); + const gchar *wm_name = gdk_x11_screen_get_window_manager_name(screen); if (g_strcmp0(wm_name, "GNOME Shell") != 0) { use_header_bar = FALSE; } } #endif if (use_header_bar) { - GtkHeaderBar* header_bar = GTK_HEADER_BAR(gtk_header_bar_new()); + GtkHeaderBar *header_bar = GTK_HEADER_BAR(gtk_header_bar_new()); gtk_widget_show(GTK_WIDGET(header_bar)); gtk_header_bar_set_title(header_bar, "example"); gtk_header_bar_set_show_close_button(header_bar, TRUE); @@ -50,7 +50,7 @@ static void my_application_activate(GApplication* application) { g_autoptr(FlDartProject) project = fl_dart_project_new(); - FlView* view = fl_view_new(project); + FlView *view = fl_view_new(project); gtk_widget_show(GTK_WIDGET(view)); gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(view)); @@ -59,13 +59,13 @@ static void my_application_activate(GApplication* application) { gtk_widget_grab_focus(GTK_WIDGET(view)); } -static void my_application_class_init(MyApplicationClass* klass) { +static void my_application_class_init(MyApplicationClass *klass) { G_APPLICATION_CLASS(klass)->activate = my_application_activate; } -static void my_application_init(MyApplication* self) {} +static void my_application_init(MyApplication *self) {} -MyApplication* my_application_new() { +MyApplication *my_application_new() { return MY_APPLICATION(g_object_new( my_application_get_type(), "application-id", APPLICATION_ID, nullptr)); } diff --git a/packages/package_info_plus/package_info_plus/example/linux/my_application.h b/packages/package_info_plus/package_info_plus/example/linux/my_application.h index 72271d5e41..3258a73cf4 100644 --- a/packages/package_info_plus/package_info_plus/example/linux/my_application.h +++ b/packages/package_info_plus/package_info_plus/example/linux/my_application.h @@ -13,6 +13,6 @@ G_DECLARE_FINAL_TYPE(MyApplication, my_application, MY, APPLICATION, * * Returns: a new #MyApplication. */ -MyApplication* my_application_new(); +MyApplication *my_application_new(); -#endif // FLUTTER_MY_APPLICATION_H_ +#endif // FLUTTER_MY_APPLICATION_H_ diff --git a/packages/package_info_plus/package_info_plus/example/windows/runner/flutter_window.cpp b/packages/package_info_plus/package_info_plus/example/windows/runner/flutter_window.cpp index c422723045..0f0105d995 100644 --- a/packages/package_info_plus/package_info_plus/example/windows/runner/flutter_window.cpp +++ b/packages/package_info_plus/package_info_plus/example/windows/runner/flutter_window.cpp @@ -4,8 +4,8 @@ #include "flutter/generated_plugin_registrant.h" -FlutterWindow::FlutterWindow(RunLoop* run_loop, - const flutter::DartProject& project) +FlutterWindow::FlutterWindow(RunLoop *run_loop, + const flutter::DartProject &project) : run_loop_(run_loop), project_(project) {} FlutterWindow::~FlutterWindow() {} @@ -55,9 +55,9 @@ FlutterWindow::MessageHandler(HWND hwnd, UINT const message, } switch (message) { - case WM_FONTCHANGE: - flutter_controller_->engine()->ReloadSystemFonts(); - break; + case WM_FONTCHANGE: + flutter_controller_->engine()->ReloadSystemFonts(); + break; } return Win32Window::MessageHandler(hwnd, message, wparam, lparam); diff --git a/packages/package_info_plus/package_info_plus/example/windows/runner/flutter_window.h b/packages/package_info_plus/package_info_plus/example/windows/runner/flutter_window.h index b663ddd501..69234d4f5e 100644 --- a/packages/package_info_plus/package_info_plus/example/windows/runner/flutter_window.h +++ b/packages/package_info_plus/package_info_plus/example/windows/runner/flutter_window.h @@ -11,23 +11,23 @@ // A window that does nothing but host a Flutter view. class FlutterWindow : public Win32Window { - public: +public: // Creates a new FlutterWindow driven by the |run_loop|, hosting a // Flutter view running |project|. - explicit FlutterWindow(RunLoop* run_loop, - const flutter::DartProject& project); + explicit FlutterWindow(RunLoop *run_loop, + const flutter::DartProject &project); virtual ~FlutterWindow(); - protected: +protected: // Win32Window: bool OnCreate() override; void OnDestroy() override; LRESULT MessageHandler(HWND window, UINT const message, WPARAM const wparam, LPARAM const lparam) noexcept override; - private: +private: // The run loop driving events for this window. - RunLoop* run_loop_; + RunLoop *run_loop_; // The project to run. flutter::DartProject project_; @@ -36,4 +36,4 @@ class FlutterWindow : public Win32Window { std::unique_ptr flutter_controller_; }; -#endif // RUNNER_FLUTTER_WINDOW_H_ +#endif // RUNNER_FLUTTER_WINDOW_H_ diff --git a/packages/package_info_plus/package_info_plus/example/windows/runner/run_loop.cpp b/packages/package_info_plus/package_info_plus/example/windows/runner/run_loop.cpp index 2d6636ab6b..31b89f6229 100644 --- a/packages/package_info_plus/package_info_plus/example/windows/runner/run_loop.cpp +++ b/packages/package_info_plus/package_info_plus/example/windows/runner/run_loop.cpp @@ -44,12 +44,12 @@ void RunLoop::Run() { } void RunLoop::RegisterFlutterInstance( - flutter::FlutterEngine* flutter_instance) { + flutter::FlutterEngine *flutter_instance) { flutter_instances_.insert(flutter_instance); } void RunLoop::UnregisterFlutterInstance( - flutter::FlutterEngine* flutter_instance) { + flutter::FlutterEngine *flutter_instance) { flutter_instances_.erase(flutter_instance); } diff --git a/packages/package_info_plus/package_info_plus/example/windows/runner/run_loop.h b/packages/package_info_plus/package_info_plus/example/windows/runner/run_loop.h index 5f2c4a9ad7..7fe1aaccc2 100644 --- a/packages/package_info_plus/package_info_plus/example/windows/runner/run_loop.h +++ b/packages/package_info_plus/package_info_plus/example/windows/runner/run_loop.h @@ -9,30 +9,30 @@ // A runloop that will service events for Flutter instances as well // as native messages. class RunLoop { - public: +public: RunLoop(); ~RunLoop(); // Prevent copying - RunLoop(RunLoop const&) = delete; - RunLoop& operator=(RunLoop const&) = delete; + RunLoop(RunLoop const &) = delete; + RunLoop &operator=(RunLoop const &) = delete; // Runs the run loop until the application quits. void Run(); // Registers the given Flutter instance for event servicing. - void RegisterFlutterInstance(flutter::FlutterEngine* flutter_instance); + void RegisterFlutterInstance(flutter::FlutterEngine *flutter_instance); // Unregisters the given Flutter instance from event servicing. - void UnregisterFlutterInstance(flutter::FlutterEngine* flutter_instance); + void UnregisterFlutterInstance(flutter::FlutterEngine *flutter_instance); - private: +private: using TimePoint = std::chrono::steady_clock::time_point; // Processes all currently pending messages for registered Flutter instances. TimePoint ProcessFlutterMessages(); - std::set flutter_instances_; + std::set flutter_instances_; }; -#endif // RUNNER_RUN_LOOP_H_ +#endif // RUNNER_RUN_LOOP_H_ diff --git a/packages/package_info_plus/package_info_plus/example/windows/runner/utils.h b/packages/package_info_plus/package_info_plus/example/windows/runner/utils.h index d792603bb1..7021e6d06d 100644 --- a/packages/package_info_plus/package_info_plus/example/windows/runner/utils.h +++ b/packages/package_info_plus/package_info_plus/example/windows/runner/utils.h @@ -5,4 +5,4 @@ // it for both the runner and the Flutter library. void CreateAndAttachConsole(); -#endif // RUNNER_UTILS_H_ +#endif // RUNNER_UTILS_H_ diff --git a/packages/package_info_plus/package_info_plus/example/windows/runner/win32_window.cpp b/packages/package_info_plus/package_info_plus/example/windows/runner/win32_window.cpp index c63ad013b0..9669d7fc6b 100644 --- a/packages/package_info_plus/package_info_plus/example/windows/runner/win32_window.cpp +++ b/packages/package_info_plus/package_info_plus/example/windows/runner/win32_window.cpp @@ -27,7 +27,7 @@ void EnableFullDpiSupportIfAvailable(HWND hwnd) { return; } auto enable_non_client_dpi_scaling = - reinterpret_cast( + reinterpret_cast( GetProcAddress(user32_module, "EnableNonClientDpiScaling")); if (enable_non_client_dpi_scaling != nullptr) { enable_non_client_dpi_scaling(hwnd); @@ -35,15 +35,15 @@ void EnableFullDpiSupportIfAvailable(HWND hwnd) { } } -} // namespace +} // namespace // Manages the Win32Window's window class registration. class WindowClassRegistrar { - public: +public: ~WindowClassRegistrar() = default; // Returns the singleton registar instance. - static WindowClassRegistrar* GetInstance() { + static WindowClassRegistrar *GetInstance() { if (!instance_) { instance_ = new WindowClassRegistrar(); } @@ -52,23 +52,23 @@ class WindowClassRegistrar { // Returns the name of the window class, registering the class if it hasn't // previously been registered. - const wchar_t* GetWindowClass(); + const wchar_t *GetWindowClass(); // Unregisters the window class. Should only be called if there are no // instances of the window. void UnregisterWindowClass(); - private: +private: WindowClassRegistrar() = default; - static WindowClassRegistrar* instance_; + static WindowClassRegistrar *instance_; bool class_registered_ = false; }; -WindowClassRegistrar* WindowClassRegistrar::instance_ = nullptr; +WindowClassRegistrar *WindowClassRegistrar::instance_ = nullptr; -const wchar_t* WindowClassRegistrar::GetWindowClass() { +const wchar_t *WindowClassRegistrar::GetWindowClass() { if (!class_registered_) { WNDCLASS window_class{}; window_class.hCursor = LoadCursor(nullptr, IDC_ARROW); @@ -100,11 +100,11 @@ Win32Window::~Win32Window() { Destroy(); } -bool Win32Window::CreateAndShow(const std::wstring& title, const Point& origin, - const Size& size) { +bool Win32Window::CreateAndShow(const std::wstring &title, const Point &origin, + const Size &size) { Destroy(); - const wchar_t* window_class = + const wchar_t *window_class = WindowClassRegistrar::GetInstance()->GetWindowClass(); const POINT target_point = {static_cast(origin.x), @@ -131,14 +131,14 @@ LRESULT CALLBACK Win32Window::WndProc(HWND const window, UINT const message, WPARAM const wparam, LPARAM const lparam) noexcept { if (message == WM_NCCREATE) { - auto window_struct = reinterpret_cast(lparam); + auto window_struct = reinterpret_cast(lparam); SetWindowLongPtr(window, GWLP_USERDATA, reinterpret_cast(window_struct->lpCreateParams)); - auto that = static_cast(window_struct->lpCreateParams); + auto that = static_cast(window_struct->lpCreateParams); EnableFullDpiSupportIfAvailable(window); that->window_handle_ = window; - } else if (Win32Window* that = GetThisFromHandle(window)) { + } else if (Win32Window *that = GetThisFromHandle(window)) { return that->MessageHandler(window, message, wparam, lparam); } @@ -149,38 +149,38 @@ LRESULT Win32Window::MessageHandler(HWND hwnd, UINT const message, WPARAM const wparam, LPARAM const lparam) noexcept { switch (message) { - case WM_DESTROY: - window_handle_ = nullptr; - Destroy(); - if (quit_on_close_) { - PostQuitMessage(0); - } - return 0; - - case WM_DPICHANGED: { - auto newRectSize = reinterpret_cast(lparam); - LONG newWidth = newRectSize->right - newRectSize->left; - LONG newHeight = newRectSize->bottom - newRectSize->top; - - SetWindowPos(hwnd, nullptr, newRectSize->left, newRectSize->top, newWidth, - newHeight, SWP_NOZORDER | SWP_NOACTIVATE); - - return 0; + case WM_DESTROY: + window_handle_ = nullptr; + Destroy(); + if (quit_on_close_) { + PostQuitMessage(0); + } + return 0; + + case WM_DPICHANGED: { + auto newRectSize = reinterpret_cast(lparam); + LONG newWidth = newRectSize->right - newRectSize->left; + LONG newHeight = newRectSize->bottom - newRectSize->top; + + SetWindowPos(hwnd, nullptr, newRectSize->left, newRectSize->top, newWidth, + newHeight, SWP_NOZORDER | SWP_NOACTIVATE); + + return 0; + } + case WM_SIZE: + RECT rect = GetClientArea(); + if (child_content_ != nullptr) { + // Size and position the child window. + MoveWindow(child_content_, rect.left, rect.top, rect.right - rect.left, + rect.bottom - rect.top, TRUE); + } + return 0; + + case WM_ACTIVATE: + if (child_content_ != nullptr) { + SetFocus(child_content_); } - case WM_SIZE: - RECT rect = GetClientArea(); - if (child_content_ != nullptr) { - // Size and position the child window. - MoveWindow(child_content_, rect.left, rect.top, rect.right - rect.left, - rect.bottom - rect.top, TRUE); - } - return 0; - - case WM_ACTIVATE: - if (child_content_ != nullptr) { - SetFocus(child_content_); - } - return 0; + return 0; } return DefWindowProc(window_handle_, message, wparam, lparam); @@ -198,8 +198,8 @@ void Win32Window::Destroy() { } } -Win32Window* Win32Window::GetThisFromHandle(HWND const window) noexcept { - return reinterpret_cast( +Win32Window *Win32Window::GetThisFromHandle(HWND const window) noexcept { + return reinterpret_cast( GetWindowLongPtr(window, GWLP_USERDATA)); } diff --git a/packages/package_info_plus/package_info_plus/example/windows/runner/win32_window.h b/packages/package_info_plus/package_info_plus/example/windows/runner/win32_window.h index 4ae64a12b4..7b518125bb 100644 --- a/packages/package_info_plus/package_info_plus/example/windows/runner/win32_window.h +++ b/packages/package_info_plus/package_info_plus/example/windows/runner/win32_window.h @@ -11,7 +11,7 @@ // inherited from by classes that wish to specialize with custom // rendering and input handling class Win32Window { - public: +public: struct Point { unsigned int x; unsigned int y; @@ -34,8 +34,8 @@ class Win32Window { // consistent size to will treat the width height passed in to this function // as logical pixels and scale to appropriate for the default monitor. Returns // true if the window was created successfully. - bool CreateAndShow(const std::wstring& title, const Point& origin, - const Size& size); + bool CreateAndShow(const std::wstring &title, const Point &origin, + const Size &size); // Release OS resources associated with window. void Destroy(); @@ -53,7 +53,7 @@ class Win32Window { // Return a RECT representing the bounds of the current client area. RECT GetClientArea(); - protected: +protected: // Processes and route salient window messages for mouse handling, // size change and DPI. Delegates handling of these to member overloads that // inheriting classes can handle. @@ -68,7 +68,7 @@ class Win32Window { // Called when Destroy is called. virtual void OnDestroy(); - private: +private: friend class WindowClassRegistrar; // OS callback called by message pump. Handles the WM_NCCREATE message which @@ -81,7 +81,7 @@ class Win32Window { LPARAM const lparam) noexcept; // Retrieves a class instance pointer for |window| - static Win32Window* GetThisFromHandle(HWND const window) noexcept; + static Win32Window *GetThisFromHandle(HWND const window) noexcept; bool quit_on_close_ = false; @@ -92,4 +92,4 @@ class Win32Window { HWND child_content_ = nullptr; }; -#endif // RUNNER_WIN32_WINDOW_H_ +#endif // RUNNER_WIN32_WINDOW_H_ diff --git a/packages/package_info_plus/package_info_plus/ios/Classes/FLTPackageInfoPlusPlugin.m b/packages/package_info_plus/package_info_plus/ios/Classes/FLTPackageInfoPlusPlugin.m index 33c99253f4..0a5f279436 100644 --- a/packages/package_info_plus/package_info_plus/ios/Classes/FLTPackageInfoPlusPlugin.m +++ b/packages/package_info_plus/package_info_plus/ios/Classes/FLTPackageInfoPlusPlugin.m @@ -5,23 +5,29 @@ #import "FLTPackageInfoPlusPlugin.h" @implementation FLTPackageInfoPlusPlugin -+ (void)registerWithRegistrar:(NSObject*)registrar { - FlutterMethodChannel* channel = - [FlutterMethodChannel methodChannelWithName:@"dev.fluttercommunity.plus/package_info" - binaryMessenger:[registrar messenger]]; - FLTPackageInfoPlusPlugin* instance = [[FLTPackageInfoPlusPlugin alloc] init]; ++ (void)registerWithRegistrar:(NSObject *)registrar { + FlutterMethodChannel *channel = [FlutterMethodChannel + methodChannelWithName:@"dev.fluttercommunity.plus/package_info" + binaryMessenger:[registrar messenger]]; + FLTPackageInfoPlusPlugin *instance = [[FLTPackageInfoPlusPlugin alloc] init]; [registrar addMethodCallDelegate:instance channel:channel]; } -- (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result { +- (void)handleMethodCall:(FlutterMethodCall *)call + result:(FlutterResult)result { if ([call.method isEqualToString:@"getAll"]) { result(@{ - @"appName" : [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleDisplayName"] - ?: [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleName"] ?: [NSNull null], - @"packageName" : [[NSBundle mainBundle] bundleIdentifier] ?: [NSNull null], - @"version" : [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"] + @"appName" : [[NSBundle mainBundle] + objectForInfoDictionaryKey:@"CFBundleDisplayName"] + ?: [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleName"] + ?: [NSNull null], + @"packageName" : [[NSBundle mainBundle] bundleIdentifier] ?: [NSNull null], - @"buildNumber" : [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"] + @"version" : [[NSBundle mainBundle] + objectForInfoDictionaryKey:@"CFBundleShortVersionString"] + ?: [NSNull null], + @"buildNumber" : [[NSBundle mainBundle] + objectForInfoDictionaryKey:@"CFBundleVersion"] ?: [NSNull null], }); } else { diff --git a/packages/package_info_plus/package_info_plus_macos/macos/Classes/FLTPackageInfoPlusPlugin.m b/packages/package_info_plus/package_info_plus_macos/macos/Classes/FLTPackageInfoPlusPlugin.m index 33c99253f4..0a5f279436 100644 --- a/packages/package_info_plus/package_info_plus_macos/macos/Classes/FLTPackageInfoPlusPlugin.m +++ b/packages/package_info_plus/package_info_plus_macos/macos/Classes/FLTPackageInfoPlusPlugin.m @@ -5,23 +5,29 @@ #import "FLTPackageInfoPlusPlugin.h" @implementation FLTPackageInfoPlusPlugin -+ (void)registerWithRegistrar:(NSObject*)registrar { - FlutterMethodChannel* channel = - [FlutterMethodChannel methodChannelWithName:@"dev.fluttercommunity.plus/package_info" - binaryMessenger:[registrar messenger]]; - FLTPackageInfoPlusPlugin* instance = [[FLTPackageInfoPlusPlugin alloc] init]; ++ (void)registerWithRegistrar:(NSObject *)registrar { + FlutterMethodChannel *channel = [FlutterMethodChannel + methodChannelWithName:@"dev.fluttercommunity.plus/package_info" + binaryMessenger:[registrar messenger]]; + FLTPackageInfoPlusPlugin *instance = [[FLTPackageInfoPlusPlugin alloc] init]; [registrar addMethodCallDelegate:instance channel:channel]; } -- (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result { +- (void)handleMethodCall:(FlutterMethodCall *)call + result:(FlutterResult)result { if ([call.method isEqualToString:@"getAll"]) { result(@{ - @"appName" : [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleDisplayName"] - ?: [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleName"] ?: [NSNull null], - @"packageName" : [[NSBundle mainBundle] bundleIdentifier] ?: [NSNull null], - @"version" : [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"] + @"appName" : [[NSBundle mainBundle] + objectForInfoDictionaryKey:@"CFBundleDisplayName"] + ?: [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleName"] + ?: [NSNull null], + @"packageName" : [[NSBundle mainBundle] bundleIdentifier] ?: [NSNull null], - @"buildNumber" : [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"] + @"version" : [[NSBundle mainBundle] + objectForInfoDictionaryKey:@"CFBundleShortVersionString"] + ?: [NSNull null], + @"buildNumber" : [[NSBundle mainBundle] + objectForInfoDictionaryKey:@"CFBundleVersion"] ?: [NSNull null], }); } else { diff --git a/packages/sensors_plus/sensors_plus/example/ios/Runner/AppDelegate.m b/packages/sensors_plus/sensors_plus/example/ios/Runner/AppDelegate.m index 59a72e90be..352291d2f0 100644 --- a/packages/sensors_plus/sensors_plus/example/ios/Runner/AppDelegate.m +++ b/packages/sensors_plus/sensors_plus/example/ios/Runner/AppDelegate.m @@ -7,7 +7,8 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [GeneratedPluginRegistrant registerWithRegistry:self]; // Override point for customization after application launch. - return [super application:application didFinishLaunchingWithOptions:launchOptions]; + return [super application:application + didFinishLaunchingWithOptions:launchOptions]; } @end diff --git a/packages/sensors_plus/sensors_plus/example/ios/Runner/main.m b/packages/sensors_plus/sensors_plus/example/ios/Runner/main.m index dff6597e45..5b8c35f9d3 100644 --- a/packages/sensors_plus/sensors_plus/example/ios/Runner/main.m +++ b/packages/sensors_plus/sensors_plus/example/ios/Runner/main.m @@ -1,9 +1,10 @@ +#import "AppDelegate.h" #import #import -#import "AppDelegate.h" -int main(int argc, char* argv[]) { +int main(int argc, char *argv[]) { @autoreleasepool { - return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); + return UIApplicationMain(argc, argv, nil, + NSStringFromClass([AppDelegate class])); } } diff --git a/packages/sensors_plus/sensors_plus/ios/Classes/FLTSensorsPlusPlugin.m b/packages/sensors_plus/sensors_plus/ios/Classes/FLTSensorsPlusPlugin.m index 85f2ca6b76..ef785ff2a5 100644 --- a/packages/sensors_plus/sensors_plus/ios/Classes/FLTSensorsPlusPlugin.m +++ b/packages/sensors_plus/sensors_plus/ios/Classes/FLTSensorsPlusPlugin.m @@ -7,40 +7,40 @@ @implementation FLTSensorsPlusPlugin -+ (void)registerWithRegistrar:(NSObject*)registrar { - FLTAccelerometerStreamHandlerPlus* accelerometerStreamHandler = ++ (void)registerWithRegistrar:(NSObject *)registrar { + FLTAccelerometerStreamHandlerPlus *accelerometerStreamHandler = [[FLTAccelerometerStreamHandlerPlus alloc] init]; - FlutterEventChannel* accelerometerChannel = - [FlutterEventChannel eventChannelWithName:@"dev.fluttercommunity.plus/sensors/accelerometer" - binaryMessenger:[registrar messenger]]; + FlutterEventChannel *accelerometerChannel = [FlutterEventChannel + eventChannelWithName:@"dev.fluttercommunity.plus/sensors/accelerometer" + binaryMessenger:[registrar messenger]]; [accelerometerChannel setStreamHandler:accelerometerStreamHandler]; - FLTUserAccelStreamHandlerPlus* userAccelerometerStreamHandler = + FLTUserAccelStreamHandlerPlus *userAccelerometerStreamHandler = [[FLTUserAccelStreamHandlerPlus alloc] init]; - FlutterEventChannel* userAccelerometerChannel = - [FlutterEventChannel eventChannelWithName:@"dev.fluttercommunity.plus/sensors/user_accel" - binaryMessenger:[registrar messenger]]; + FlutterEventChannel *userAccelerometerChannel = [FlutterEventChannel + eventChannelWithName:@"dev.fluttercommunity.plus/sensors/user_accel" + binaryMessenger:[registrar messenger]]; [userAccelerometerChannel setStreamHandler:userAccelerometerStreamHandler]; - FLTGyroscopeStreamHandlerPlus* gyroscopeStreamHandler = + FLTGyroscopeStreamHandlerPlus *gyroscopeStreamHandler = [[FLTGyroscopeStreamHandlerPlus alloc] init]; - FlutterEventChannel* gyroscopeChannel = - [FlutterEventChannel eventChannelWithName:@"dev.fluttercommunity.plus/sensors/gyroscope" - binaryMessenger:[registrar messenger]]; + FlutterEventChannel *gyroscopeChannel = [FlutterEventChannel + eventChannelWithName:@"dev.fluttercommunity.plus/sensors/gyroscope" + binaryMessenger:[registrar messenger]]; [gyroscopeChannel setStreamHandler:gyroscopeStreamHandler]; - FLTMagnetometerStreamHandlerPlus* magnetometerStreamHandler = + FLTMagnetometerStreamHandlerPlus *magnetometerStreamHandler = [[FLTMagnetometerStreamHandlerPlus alloc] init]; - FlutterEventChannel* magnetometerChannel = - [FlutterEventChannel eventChannelWithName:@"dev.fluttercommunity.plus/sensors/magnetometer" - binaryMessenger:[registrar messenger]]; + FlutterEventChannel *magnetometerChannel = [FlutterEventChannel + eventChannelWithName:@"dev.fluttercommunity.plus/sensors/magnetometer" + binaryMessenger:[registrar messenger]]; [magnetometerChannel setStreamHandler:magnetometerStreamHandler]; } @end const double GRAVITY = 9.8; -CMMotionManager* _motionManager; +CMMotionManager *_motionManager; void _initMotionManager() { if (!_motionManager) { @@ -48,8 +48,9 @@ void _initMotionManager() { } } -static void sendTriplet(Float64 x, Float64 y, Float64 z, FlutterEventSink sink) { - NSMutableData* event = [NSMutableData dataWithCapacity:3 * sizeof(Float64)]; +static void sendTriplet(Float64 x, Float64 y, Float64 z, + FlutterEventSink sink) { + NSMutableData *event = [NSMutableData dataWithCapacity:3 * sizeof(Float64)]; [event appendBytes:&x length:sizeof(Float64)]; [event appendBytes:&y length:sizeof(Float64)]; [event appendBytes:&z length:sizeof(Float64)]; @@ -58,21 +59,25 @@ static void sendTriplet(Float64 x, Float64 y, Float64 z, FlutterEventSink sink) @implementation FLTAccelerometerStreamHandlerPlus -- (FlutterError*)onListenWithArguments:(id)arguments eventSink:(FlutterEventSink)eventSink { +- (FlutterError *)onListenWithArguments:(id)arguments + eventSink:(FlutterEventSink)eventSink { _initMotionManager(); [_motionManager startAccelerometerUpdatesToQueue:[[NSOperationQueue alloc] init] - withHandler:^(CMAccelerometerData* accelerometerData, NSError* error) { - CMAcceleration acceleration = accelerometerData.acceleration; + withHandler:^(CMAccelerometerData *accelerometerData, + NSError *error) { + CMAcceleration acceleration = + accelerometerData.acceleration; // Multiply by gravity, and adjust sign values to // align with Android. - sendTriplet(-acceleration.x * GRAVITY, -acceleration.y * GRAVITY, + sendTriplet(-acceleration.x * GRAVITY, + -acceleration.y * GRAVITY, -acceleration.z * GRAVITY, eventSink); }]; return nil; } -- (FlutterError*)onCancelWithArguments:(id)arguments { +- (FlutterError *)onCancelWithArguments:(id)arguments { [_motionManager stopAccelerometerUpdates]; return nil; } @@ -81,20 +86,23 @@ - (FlutterError*)onCancelWithArguments:(id)arguments { @implementation FLTUserAccelStreamHandlerPlus -- (FlutterError*)onListenWithArguments:(id)arguments eventSink:(FlutterEventSink)eventSink { +- (FlutterError *)onListenWithArguments:(id)arguments + eventSink:(FlutterEventSink)eventSink { _initMotionManager(); [_motionManager startDeviceMotionUpdatesToQueue:[[NSOperationQueue alloc] init] - withHandler:^(CMDeviceMotion* data, NSError* error) { + withHandler:^(CMDeviceMotion *data, NSError *error) { CMAcceleration acceleration = data.userAcceleration; - // Multiply by gravity, and adjust sign values to align with Android. - sendTriplet(-acceleration.x * GRAVITY, -acceleration.y * GRAVITY, + // Multiply by gravity, and adjust sign values to + // align with Android. + sendTriplet(-acceleration.x * GRAVITY, + -acceleration.y * GRAVITY, -acceleration.z * GRAVITY, eventSink); }]; return nil; } -- (FlutterError*)onCancelWithArguments:(id)arguments { +- (FlutterError *)onCancelWithArguments:(id)arguments { [_motionManager stopDeviceMotionUpdates]; return nil; } @@ -103,18 +111,20 @@ - (FlutterError*)onCancelWithArguments:(id)arguments { @implementation FLTGyroscopeStreamHandlerPlus -- (FlutterError*)onListenWithArguments:(id)arguments eventSink:(FlutterEventSink)eventSink { +- (FlutterError *)onListenWithArguments:(id)arguments + eventSink:(FlutterEventSink)eventSink { _initMotionManager(); [_motionManager startGyroUpdatesToQueue:[[NSOperationQueue alloc] init] - withHandler:^(CMGyroData* gyroData, NSError* error) { + withHandler:^(CMGyroData *gyroData, NSError *error) { CMRotationRate rotationRate = gyroData.rotationRate; - sendTriplet(rotationRate.x, rotationRate.y, rotationRate.z, eventSink); + sendTriplet(rotationRate.x, rotationRate.y, rotationRate.z, + eventSink); }]; return nil; } -- (FlutterError*)onCancelWithArguments:(id)arguments { +- (FlutterError *)onCancelWithArguments:(id)arguments { [_motionManager stopGyroUpdates]; return nil; } @@ -123,18 +133,22 @@ - (FlutterError*)onCancelWithArguments:(id)arguments { @implementation FLTMagnetometerStreamHandlerPlus -- (FlutterError*)onListenWithArguments:(id)arguments eventSink:(FlutterEventSink)eventSink { +- (FlutterError *)onListenWithArguments:(id)arguments + eventSink:(FlutterEventSink)eventSink { _initMotionManager(); - [_motionManager startMagnetometerUpdatesToQueue:[[NSOperationQueue alloc] init] - withHandler:^(CMMagnetometerData* magData, NSError* error) { - CMMagneticField magneticField = magData.magneticField; - sendTriplet(magneticField.x, magneticField.y, - magneticField.z, eventSink); - }]; + [_motionManager + startMagnetometerUpdatesToQueue:[[NSOperationQueue alloc] init] + withHandler:^(CMMagnetometerData *magData, + NSError *error) { + CMMagneticField magneticField = + magData.magneticField; + sendTriplet(magneticField.x, magneticField.y, + magneticField.z, eventSink); + }]; return nil; } -- (FlutterError*)onCancelWithArguments:(id)arguments { +- (FlutterError *)onCancelWithArguments:(id)arguments { [_motionManager stopMagnetometerUpdates]; return nil; } diff --git a/packages/share_plus/share_plus/example/ios/Runner/AppDelegate.m b/packages/share_plus/share_plus/example/ios/Runner/AppDelegate.m index a4b51c88eb..d46e7886e7 100644 --- a/packages/share_plus/share_plus/example/ios/Runner/AppDelegate.m +++ b/packages/share_plus/share_plus/example/ios/Runner/AppDelegate.m @@ -10,7 +10,8 @@ @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [GeneratedPluginRegistrant registerWithRegistry:self]; - return [super application:application didFinishLaunchingWithOptions:launchOptions]; + return [super application:application + didFinishLaunchingWithOptions:launchOptions]; } @end diff --git a/packages/share_plus/share_plus/example/ios/Runner/main.m b/packages/share_plus/share_plus/example/ios/Runner/main.m index bec320c0be..b7fe28c73a 100644 --- a/packages/share_plus/share_plus/example/ios/Runner/main.m +++ b/packages/share_plus/share_plus/example/ios/Runner/main.m @@ -2,12 +2,13 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#import "AppDelegate.h" #import #import -#import "AppDelegate.h" -int main(int argc, char* argv[]) { +int main(int argc, char *argv[]) { @autoreleasepool { - return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); + return UIApplicationMain(argc, argv, nil, + NSStringFromClass([AppDelegate class])); } } diff --git a/packages/share_plus/share_plus/example/linux/main.cc b/packages/share_plus/share_plus/example/linux/main.cc index 10835acb58..8bc1561588 100644 --- a/packages/share_plus/share_plus/example/linux/main.cc +++ b/packages/share_plus/share_plus/example/linux/main.cc @@ -1,6 +1,6 @@ #include "my_application.h" -int main(int argc, char** argv) { +int main(int argc, char **argv) { // Only X11 is currently supported. // Wayland support is being developed: // https://github.com/flutter/flutter/issues/57932. diff --git a/packages/share_plus/share_plus/example/linux/my_application.cc b/packages/share_plus/share_plus/example/linux/my_application.cc index 67ed0b9025..cef2f77145 100644 --- a/packages/share_plus/share_plus/example/linux/my_application.cc +++ b/packages/share_plus/share_plus/example/linux/my_application.cc @@ -11,10 +11,10 @@ struct _MyApplication { G_DEFINE_TYPE(MyApplication, my_application, GTK_TYPE_APPLICATION) // Implements GApplication::activate. -static void my_application_activate(GApplication* application) { - GtkWindow* window = +static void my_application_activate(GApplication *application) { + GtkWindow *window = GTK_WINDOW(gtk_application_window_new(GTK_APPLICATION(application))); - GtkHeaderBar* header_bar = GTK_HEADER_BAR(gtk_header_bar_new()); + GtkHeaderBar *header_bar = GTK_HEADER_BAR(gtk_header_bar_new()); gtk_widget_show(GTK_WIDGET(header_bar)); gtk_header_bar_set_title(header_bar, "example"); gtk_header_bar_set_show_close_button(header_bar, TRUE); @@ -24,7 +24,7 @@ static void my_application_activate(GApplication* application) { g_autoptr(FlDartProject) project = fl_dart_project_new(); - FlView* view = fl_view_new(project); + FlView *view = fl_view_new(project); gtk_widget_show(GTK_WIDGET(view)); gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(view)); @@ -33,13 +33,13 @@ static void my_application_activate(GApplication* application) { gtk_widget_grab_focus(GTK_WIDGET(view)); } -static void my_application_class_init(MyApplicationClass* klass) { +static void my_application_class_init(MyApplicationClass *klass) { G_APPLICATION_CLASS(klass)->activate = my_application_activate; } -static void my_application_init(MyApplication* self) {} +static void my_application_init(MyApplication *self) {} -MyApplication* my_application_new() { +MyApplication *my_application_new() { return MY_APPLICATION(g_object_new( my_application_get_type(), "application-id", APPLICATION_ID, nullptr)); } diff --git a/packages/share_plus/share_plus/example/linux/my_application.h b/packages/share_plus/share_plus/example/linux/my_application.h index 72271d5e41..3258a73cf4 100644 --- a/packages/share_plus/share_plus/example/linux/my_application.h +++ b/packages/share_plus/share_plus/example/linux/my_application.h @@ -13,6 +13,6 @@ G_DECLARE_FINAL_TYPE(MyApplication, my_application, MY, APPLICATION, * * Returns: a new #MyApplication. */ -MyApplication* my_application_new(); +MyApplication *my_application_new(); -#endif // FLUTTER_MY_APPLICATION_H_ +#endif // FLUTTER_MY_APPLICATION_H_ diff --git a/packages/share_plus/share_plus/example/windows/runner/flutter_window.cpp b/packages/share_plus/share_plus/example/windows/runner/flutter_window.cpp index c422723045..0f0105d995 100644 --- a/packages/share_plus/share_plus/example/windows/runner/flutter_window.cpp +++ b/packages/share_plus/share_plus/example/windows/runner/flutter_window.cpp @@ -4,8 +4,8 @@ #include "flutter/generated_plugin_registrant.h" -FlutterWindow::FlutterWindow(RunLoop* run_loop, - const flutter::DartProject& project) +FlutterWindow::FlutterWindow(RunLoop *run_loop, + const flutter::DartProject &project) : run_loop_(run_loop), project_(project) {} FlutterWindow::~FlutterWindow() {} @@ -55,9 +55,9 @@ FlutterWindow::MessageHandler(HWND hwnd, UINT const message, } switch (message) { - case WM_FONTCHANGE: - flutter_controller_->engine()->ReloadSystemFonts(); - break; + case WM_FONTCHANGE: + flutter_controller_->engine()->ReloadSystemFonts(); + break; } return Win32Window::MessageHandler(hwnd, message, wparam, lparam); diff --git a/packages/share_plus/share_plus/example/windows/runner/flutter_window.h b/packages/share_plus/share_plus/example/windows/runner/flutter_window.h index b663ddd501..69234d4f5e 100644 --- a/packages/share_plus/share_plus/example/windows/runner/flutter_window.h +++ b/packages/share_plus/share_plus/example/windows/runner/flutter_window.h @@ -11,23 +11,23 @@ // A window that does nothing but host a Flutter view. class FlutterWindow : public Win32Window { - public: +public: // Creates a new FlutterWindow driven by the |run_loop|, hosting a // Flutter view running |project|. - explicit FlutterWindow(RunLoop* run_loop, - const flutter::DartProject& project); + explicit FlutterWindow(RunLoop *run_loop, + const flutter::DartProject &project); virtual ~FlutterWindow(); - protected: +protected: // Win32Window: bool OnCreate() override; void OnDestroy() override; LRESULT MessageHandler(HWND window, UINT const message, WPARAM const wparam, LPARAM const lparam) noexcept override; - private: +private: // The run loop driving events for this window. - RunLoop* run_loop_; + RunLoop *run_loop_; // The project to run. flutter::DartProject project_; @@ -36,4 +36,4 @@ class FlutterWindow : public Win32Window { std::unique_ptr flutter_controller_; }; -#endif // RUNNER_FLUTTER_WINDOW_H_ +#endif // RUNNER_FLUTTER_WINDOW_H_ diff --git a/packages/share_plus/share_plus/example/windows/runner/run_loop.cpp b/packages/share_plus/share_plus/example/windows/runner/run_loop.cpp index 2d6636ab6b..31b89f6229 100644 --- a/packages/share_plus/share_plus/example/windows/runner/run_loop.cpp +++ b/packages/share_plus/share_plus/example/windows/runner/run_loop.cpp @@ -44,12 +44,12 @@ void RunLoop::Run() { } void RunLoop::RegisterFlutterInstance( - flutter::FlutterEngine* flutter_instance) { + flutter::FlutterEngine *flutter_instance) { flutter_instances_.insert(flutter_instance); } void RunLoop::UnregisterFlutterInstance( - flutter::FlutterEngine* flutter_instance) { + flutter::FlutterEngine *flutter_instance) { flutter_instances_.erase(flutter_instance); } diff --git a/packages/share_plus/share_plus/example/windows/runner/run_loop.h b/packages/share_plus/share_plus/example/windows/runner/run_loop.h index 5f2c4a9ad7..7fe1aaccc2 100644 --- a/packages/share_plus/share_plus/example/windows/runner/run_loop.h +++ b/packages/share_plus/share_plus/example/windows/runner/run_loop.h @@ -9,30 +9,30 @@ // A runloop that will service events for Flutter instances as well // as native messages. class RunLoop { - public: +public: RunLoop(); ~RunLoop(); // Prevent copying - RunLoop(RunLoop const&) = delete; - RunLoop& operator=(RunLoop const&) = delete; + RunLoop(RunLoop const &) = delete; + RunLoop &operator=(RunLoop const &) = delete; // Runs the run loop until the application quits. void Run(); // Registers the given Flutter instance for event servicing. - void RegisterFlutterInstance(flutter::FlutterEngine* flutter_instance); + void RegisterFlutterInstance(flutter::FlutterEngine *flutter_instance); // Unregisters the given Flutter instance from event servicing. - void UnregisterFlutterInstance(flutter::FlutterEngine* flutter_instance); + void UnregisterFlutterInstance(flutter::FlutterEngine *flutter_instance); - private: +private: using TimePoint = std::chrono::steady_clock::time_point; // Processes all currently pending messages for registered Flutter instances. TimePoint ProcessFlutterMessages(); - std::set flutter_instances_; + std::set flutter_instances_; }; -#endif // RUNNER_RUN_LOOP_H_ +#endif // RUNNER_RUN_LOOP_H_ diff --git a/packages/share_plus/share_plus/example/windows/runner/utils.h b/packages/share_plus/share_plus/example/windows/runner/utils.h index d792603bb1..7021e6d06d 100644 --- a/packages/share_plus/share_plus/example/windows/runner/utils.h +++ b/packages/share_plus/share_plus/example/windows/runner/utils.h @@ -5,4 +5,4 @@ // it for both the runner and the Flutter library. void CreateAndAttachConsole(); -#endif // RUNNER_UTILS_H_ +#endif // RUNNER_UTILS_H_ diff --git a/packages/share_plus/share_plus/example/windows/runner/win32_window.cpp b/packages/share_plus/share_plus/example/windows/runner/win32_window.cpp index c63ad013b0..9669d7fc6b 100644 --- a/packages/share_plus/share_plus/example/windows/runner/win32_window.cpp +++ b/packages/share_plus/share_plus/example/windows/runner/win32_window.cpp @@ -27,7 +27,7 @@ void EnableFullDpiSupportIfAvailable(HWND hwnd) { return; } auto enable_non_client_dpi_scaling = - reinterpret_cast( + reinterpret_cast( GetProcAddress(user32_module, "EnableNonClientDpiScaling")); if (enable_non_client_dpi_scaling != nullptr) { enable_non_client_dpi_scaling(hwnd); @@ -35,15 +35,15 @@ void EnableFullDpiSupportIfAvailable(HWND hwnd) { } } -} // namespace +} // namespace // Manages the Win32Window's window class registration. class WindowClassRegistrar { - public: +public: ~WindowClassRegistrar() = default; // Returns the singleton registar instance. - static WindowClassRegistrar* GetInstance() { + static WindowClassRegistrar *GetInstance() { if (!instance_) { instance_ = new WindowClassRegistrar(); } @@ -52,23 +52,23 @@ class WindowClassRegistrar { // Returns the name of the window class, registering the class if it hasn't // previously been registered. - const wchar_t* GetWindowClass(); + const wchar_t *GetWindowClass(); // Unregisters the window class. Should only be called if there are no // instances of the window. void UnregisterWindowClass(); - private: +private: WindowClassRegistrar() = default; - static WindowClassRegistrar* instance_; + static WindowClassRegistrar *instance_; bool class_registered_ = false; }; -WindowClassRegistrar* WindowClassRegistrar::instance_ = nullptr; +WindowClassRegistrar *WindowClassRegistrar::instance_ = nullptr; -const wchar_t* WindowClassRegistrar::GetWindowClass() { +const wchar_t *WindowClassRegistrar::GetWindowClass() { if (!class_registered_) { WNDCLASS window_class{}; window_class.hCursor = LoadCursor(nullptr, IDC_ARROW); @@ -100,11 +100,11 @@ Win32Window::~Win32Window() { Destroy(); } -bool Win32Window::CreateAndShow(const std::wstring& title, const Point& origin, - const Size& size) { +bool Win32Window::CreateAndShow(const std::wstring &title, const Point &origin, + const Size &size) { Destroy(); - const wchar_t* window_class = + const wchar_t *window_class = WindowClassRegistrar::GetInstance()->GetWindowClass(); const POINT target_point = {static_cast(origin.x), @@ -131,14 +131,14 @@ LRESULT CALLBACK Win32Window::WndProc(HWND const window, UINT const message, WPARAM const wparam, LPARAM const lparam) noexcept { if (message == WM_NCCREATE) { - auto window_struct = reinterpret_cast(lparam); + auto window_struct = reinterpret_cast(lparam); SetWindowLongPtr(window, GWLP_USERDATA, reinterpret_cast(window_struct->lpCreateParams)); - auto that = static_cast(window_struct->lpCreateParams); + auto that = static_cast(window_struct->lpCreateParams); EnableFullDpiSupportIfAvailable(window); that->window_handle_ = window; - } else if (Win32Window* that = GetThisFromHandle(window)) { + } else if (Win32Window *that = GetThisFromHandle(window)) { return that->MessageHandler(window, message, wparam, lparam); } @@ -149,38 +149,38 @@ LRESULT Win32Window::MessageHandler(HWND hwnd, UINT const message, WPARAM const wparam, LPARAM const lparam) noexcept { switch (message) { - case WM_DESTROY: - window_handle_ = nullptr; - Destroy(); - if (quit_on_close_) { - PostQuitMessage(0); - } - return 0; - - case WM_DPICHANGED: { - auto newRectSize = reinterpret_cast(lparam); - LONG newWidth = newRectSize->right - newRectSize->left; - LONG newHeight = newRectSize->bottom - newRectSize->top; - - SetWindowPos(hwnd, nullptr, newRectSize->left, newRectSize->top, newWidth, - newHeight, SWP_NOZORDER | SWP_NOACTIVATE); - - return 0; + case WM_DESTROY: + window_handle_ = nullptr; + Destroy(); + if (quit_on_close_) { + PostQuitMessage(0); + } + return 0; + + case WM_DPICHANGED: { + auto newRectSize = reinterpret_cast(lparam); + LONG newWidth = newRectSize->right - newRectSize->left; + LONG newHeight = newRectSize->bottom - newRectSize->top; + + SetWindowPos(hwnd, nullptr, newRectSize->left, newRectSize->top, newWidth, + newHeight, SWP_NOZORDER | SWP_NOACTIVATE); + + return 0; + } + case WM_SIZE: + RECT rect = GetClientArea(); + if (child_content_ != nullptr) { + // Size and position the child window. + MoveWindow(child_content_, rect.left, rect.top, rect.right - rect.left, + rect.bottom - rect.top, TRUE); + } + return 0; + + case WM_ACTIVATE: + if (child_content_ != nullptr) { + SetFocus(child_content_); } - case WM_SIZE: - RECT rect = GetClientArea(); - if (child_content_ != nullptr) { - // Size and position the child window. - MoveWindow(child_content_, rect.left, rect.top, rect.right - rect.left, - rect.bottom - rect.top, TRUE); - } - return 0; - - case WM_ACTIVATE: - if (child_content_ != nullptr) { - SetFocus(child_content_); - } - return 0; + return 0; } return DefWindowProc(window_handle_, message, wparam, lparam); @@ -198,8 +198,8 @@ void Win32Window::Destroy() { } } -Win32Window* Win32Window::GetThisFromHandle(HWND const window) noexcept { - return reinterpret_cast( +Win32Window *Win32Window::GetThisFromHandle(HWND const window) noexcept { + return reinterpret_cast( GetWindowLongPtr(window, GWLP_USERDATA)); } diff --git a/packages/share_plus/share_plus/example/windows/runner/win32_window.h b/packages/share_plus/share_plus/example/windows/runner/win32_window.h index 4ae64a12b4..7b518125bb 100644 --- a/packages/share_plus/share_plus/example/windows/runner/win32_window.h +++ b/packages/share_plus/share_plus/example/windows/runner/win32_window.h @@ -11,7 +11,7 @@ // inherited from by classes that wish to specialize with custom // rendering and input handling class Win32Window { - public: +public: struct Point { unsigned int x; unsigned int y; @@ -34,8 +34,8 @@ class Win32Window { // consistent size to will treat the width height passed in to this function // as logical pixels and scale to appropriate for the default monitor. Returns // true if the window was created successfully. - bool CreateAndShow(const std::wstring& title, const Point& origin, - const Size& size); + bool CreateAndShow(const std::wstring &title, const Point &origin, + const Size &size); // Release OS resources associated with window. void Destroy(); @@ -53,7 +53,7 @@ class Win32Window { // Return a RECT representing the bounds of the current client area. RECT GetClientArea(); - protected: +protected: // Processes and route salient window messages for mouse handling, // size change and DPI. Delegates handling of these to member overloads that // inheriting classes can handle. @@ -68,7 +68,7 @@ class Win32Window { // Called when Destroy is called. virtual void OnDestroy(); - private: +private: friend class WindowClassRegistrar; // OS callback called by message pump. Handles the WM_NCCREATE message which @@ -81,7 +81,7 @@ class Win32Window { LPARAM const lparam) noexcept; // Retrieves a class instance pointer for |window| - static Win32Window* GetThisFromHandle(HWND const window) noexcept; + static Win32Window *GetThisFromHandle(HWND const window) noexcept; bool quit_on_close_ = false; @@ -92,4 +92,4 @@ class Win32Window { HWND child_content_ = nullptr; }; -#endif // RUNNER_WIN32_WINDOW_H_ +#endif // RUNNER_WIN32_WINDOW_H_ diff --git a/packages/share_plus/share_plus/ios/Classes/FLTSharePlusPlugin.m b/packages/share_plus/share_plus/ios/Classes/FLTSharePlusPlugin.m index 97bd0ef7e4..1ff0130bdb 100644 --- a/packages/share_plus/share_plus/ios/Classes/FLTSharePlusPlugin.m +++ b/packages/share_plus/share_plus/ios/Classes/FLTSharePlusPlugin.m @@ -11,9 +11,11 @@ return [UIApplication sharedApplication].keyWindow.rootViewController; } -static UIViewController *TopViewControllerForViewController(UIViewController *viewController) { +static UIViewController * +TopViewControllerForViewController(UIViewController *viewController) { if (viewController.presentedViewController) { - return TopViewControllerForViewController(viewController.presentedViewController); + return TopViewControllerForViewController( + viewController.presentedViewController); } if ([viewController isKindOfClass:[UINavigationController class]]) { return TopViewControllerForViewController( @@ -43,8 +45,8 @@ - (id)initWithResult:(FlutterResult)result { return self; } -// We use dealloc as the share-sheet might disappear (e.g. iCloud photo album creation) -// and could then reappear if the user cancels +// We use dealloc as the share-sheet might disappear (e.g. iCloud photo album +// creation) and could then reappear if the user cancels - (void)dealloc { if (self.completed) { self.result(self.activityType); @@ -71,11 +73,13 @@ @interface SharePlusData : NSObject @property(readonly, nonatomic, copy) NSString *path; @property(readonly, nonatomic, copy) NSString *mimeType; -- (instancetype)initWithSubject:(NSString *)subject text:(NSString *)text NS_DESIGNATED_INITIALIZER; +- (instancetype)initWithSubject:(NSString *)subject + text:(NSString *)text NS_DESIGNATED_INITIALIZER; - (instancetype)initWithFile:(NSString *)path mimeType:(NSString *)mimeType NS_DESIGNATED_INITIALIZER; -- (instancetype)init __attribute__((unavailable("Use initWithSubject:text: instead"))); +- (instancetype)init + __attribute__((unavailable("Use initWithSubject:text: instead"))); @end @@ -104,7 +108,8 @@ - (instancetype)initWithFile:(NSString *)path mimeType:(NSString *)mimeType { return self; } -- (id)activityViewControllerPlaceholderItem:(UIActivityViewController *)activityViewController { +- (id)activityViewControllerPlaceholderItem: + (UIActivityViewController *)activityViewController { return @""; } @@ -123,12 +128,14 @@ - (id)activityViewController:(UIActivityViewController *)activityViewController } } -- (NSString *)activityViewController:(UIActivityViewController *)activityViewController +- (NSString *)activityViewController: + (UIActivityViewController *)activityViewController subjectForActivityType:(UIActivityType)activityType { return _subject; } -- (UIImage *)activityViewController:(UIActivityViewController *)activityViewController +- (UIImage *)activityViewController: + (UIActivityViewController *)activityViewController thumbnailImageForActivityType:(UIActivityType)activityType suggestedSize:(CGSize)suggestedSize { if (!_path || !_mimeType || ![_mimeType hasPrefix:@"image/"]) { @@ -168,77 +175,81 @@ + (void)registerWithRegistrar:(NSObject *)registrar { [FlutterMethodChannel methodChannelWithName:PLATFORM_CHANNEL binaryMessenger:registrar.messenger]; - [shareChannel setMethodCallHandler:^(FlutterMethodCall *call, FlutterResult result) { - BOOL withResult = [call.method hasSuffix:@"WithResult"]; - NSDictionary *arguments = [call arguments]; - NSNumber *originX = arguments[@"originX"]; - NSNumber *originY = arguments[@"originY"]; - NSNumber *originWidth = arguments[@"originWidth"]; - NSNumber *originHeight = arguments[@"originHeight"]; - - CGRect originRect = CGRectZero; - if (originX && originY && originWidth && originHeight) { - originRect = CGRectMake([originX doubleValue], [originY doubleValue], - [originWidth doubleValue], [originHeight doubleValue]); - } + [shareChannel + setMethodCallHandler:^(FlutterMethodCall *call, FlutterResult result) { + BOOL withResult = [call.method hasSuffix:@"WithResult"]; + NSDictionary *arguments = [call arguments]; + NSNumber *originX = arguments[@"originX"]; + NSNumber *originY = arguments[@"originY"]; + NSNumber *originWidth = arguments[@"originWidth"]; + NSNumber *originHeight = arguments[@"originHeight"]; + + CGRect originRect = CGRectZero; + if (originX && originY && originWidth && originHeight) { + originRect = + CGRectMake([originX doubleValue], [originY doubleValue], + [originWidth doubleValue], [originHeight doubleValue]); + } - if ([@"share" isEqualToString:call.method] || - [@"shareWithResult" isEqualToString:call.method]) { - NSString *shareText = arguments[@"text"]; - NSString *shareSubject = arguments[@"subject"]; - - if (shareText.length == 0) { - result([FlutterError errorWithCode:@"error" - message:@"Non-empty text expected" - details:nil]); - return; - } - - UIViewController *topViewController = - TopViewControllerForViewController(RootViewController()); - [self shareText:shareText - subject:shareSubject - withController:topViewController - atSource:originRect - toResult:withResult ? result : nil]; - if (!withResult) result(nil); - } else if ([@"shareFiles" isEqualToString:call.method] || - [@"shareFilesWithResult" isEqualToString:call.method]) { - NSArray *paths = arguments[@"paths"]; - NSArray *mimeTypes = arguments[@"mimeTypes"]; - NSString *subject = arguments[@"subject"]; - NSString *text = arguments[@"text"]; - - if (paths.count == 0) { - result([FlutterError errorWithCode:@"error" - message:@"Non-empty paths expected" - details:nil]); - return; - } - - for (NSString *path in paths) { - if (path.length == 0) { - result([FlutterError errorWithCode:@"error" - message:@"Each path must not be empty" - details:nil]); - return; + if ([@"share" isEqualToString:call.method] || + [@"shareWithResult" isEqualToString:call.method]) { + NSString *shareText = arguments[@"text"]; + NSString *shareSubject = arguments[@"subject"]; + + if (shareText.length == 0) { + result([FlutterError errorWithCode:@"error" + message:@"Non-empty text expected" + details:nil]); + return; + } + + UIViewController *topViewController = + TopViewControllerForViewController(RootViewController()); + [self shareText:shareText + subject:shareSubject + withController:topViewController + atSource:originRect + toResult:withResult ? result : nil]; + if (!withResult) + result(nil); + } else if ([@"shareFiles" isEqualToString:call.method] || + [@"shareFilesWithResult" isEqualToString:call.method]) { + NSArray *paths = arguments[@"paths"]; + NSArray *mimeTypes = arguments[@"mimeTypes"]; + NSString *subject = arguments[@"subject"]; + NSString *text = arguments[@"text"]; + + if (paths.count == 0) { + result([FlutterError errorWithCode:@"error" + message:@"Non-empty paths expected" + details:nil]); + return; + } + + for (NSString *path in paths) { + if (path.length == 0) { + result([FlutterError errorWithCode:@"error" + message:@"Each path must not be empty" + details:nil]); + return; + } + } + + UIViewController *topViewController = + TopViewControllerForViewController(RootViewController()); + [self shareFiles:paths + withMimeType:mimeTypes + withSubject:subject + withText:text + withController:topViewController + atSource:originRect + toResult:withResult ? result : nil]; + if (!withResult) + result(nil); + } else { + result(FlutterMethodNotImplemented); } - } - - UIViewController *topViewController = - TopViewControllerForViewController(RootViewController()); - [self shareFiles:paths - withMimeType:mimeTypes - withSubject:subject - withText:text - withController:topViewController - atSource:originRect - toResult:withResult ? result : nil]; - if (!withResult) result(nil); - } else { - result(FlutterMethodNotImplemented); - } - }]; + }]; } + (void)share:(NSArray *)shareItems @@ -249,11 +260,14 @@ + (void)share:(NSArray *)shareItems UIActivityViewSuccessController *activityViewController = [[UIActivityViewSuccessController alloc] initWithActivityItems:shareItems applicationActivities:nil]; + // Force subject when sharing a raw url or files if (![subject isKindOfClass:[NSNull class]]) { [activityViewController setValue:subject forKey:@"subject"]; } - activityViewController.popoverPresentationController.sourceView = controller.view; + + activityViewController.popoverPresentationController.sourceView = + controller.view; if (!CGRectIsEmpty(origin)) { activityViewController.popoverPresentationController.sourceRect = origin; } @@ -268,7 +282,9 @@ + (void)share:(NSArray *)shareItems companion.completed = completed; }; } - [controller presentViewController:activityViewController animated:YES completion:nil]; + [controller presentViewController:activityViewController + animated:YES + completion:nil]; } + (void)shareText:(NSString *)shareText @@ -280,7 +296,6 @@ + (void)shareText:(NSString *)shareText if (data == nil) { data = [[SharePlusData alloc] initWithSubject:subject text:shareText]; } - [self share:@[ data ] withSubject:subject withController:controller @@ -319,7 +334,11 @@ + (void)shareFiles:(NSArray *)paths } } - [self share:items withSubject:subject withController:controller atSource:origin toResult:result]; + [self share:items + withSubject:subject + withController:controller + atSource:origin + toResult:result]; } @end