diff --git a/packages/package_info_plus/package_info_plus_aurora/.gitignore b/packages/package_info_plus/package_info_plus_aurora/.gitignore new file mode 100644 index 0000000..96486fd --- /dev/null +++ b/packages/package_info_plus/package_info_plus_aurora/.gitignore @@ -0,0 +1,30 @@ +# Miscellaneous +*.class +*.log +*.pyc +*.swp +.DS_Store +.atom/ +.buildlog/ +.history +.svn/ +migrate_working_dir/ + +# IntelliJ related +*.iml +*.ipr +*.iws +.idea/ + +# The .vscode folder contains launch configuration and tasks you configure in +# VS Code which you may wish to be included in version control, so this line +# is commented out by default. +#.vscode/ + +# Flutter/Dart/Pub related +# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock. +/pubspec.lock +**/doc/api/ +.dart_tool/ +.packages +build/ diff --git a/packages/package_info_plus/package_info_plus_aurora/README.md b/packages/package_info_plus/package_info_plus_aurora/README.md new file mode 100644 index 0000000..c4f2f56 --- /dev/null +++ b/packages/package_info_plus/package_info_plus_aurora/README.md @@ -0,0 +1,28 @@ +# package_info_plus_aurora + +The Aurora implementation of [`package_info_plus`](https://pub.dev/packages/package_info_plus). + +## Usage + +This package is not an _endorsed_ implementation of `package_info_plus`. +Therefore, you have to include `package_info_plus_aurora` alongside `package_info_plus` as dependencies in your `pubspec.yaml` file. + +**pubspec.yaml** + +```yaml +dependencies: + package_info_plus: 4.0.0 + package_info_plus_aurora: + path: # path to folder with plugin +``` + +***.dart** + +```dart +import 'package:package_info_plus/package_info_plus.dart'; + +PackageInfo packageInfo = await PackageInfo.fromPlatform(); + +String appName = packageInfo.appName; +String packageName = packageInfo.packageName; +``` diff --git a/packages/package_info_plus/package_info_plus_aurora/analysis_options.yaml b/packages/package_info_plus/package_info_plus_aurora/analysis_options.yaml new file mode 100644 index 0000000..566c597 --- /dev/null +++ b/packages/package_info_plus/package_info_plus_aurora/analysis_options.yaml @@ -0,0 +1,4 @@ +# Copyright (c) 2023. Open Mobile Platform LLC. +# License: Proprietary. + +include: package:flutter_lints/flutter.yaml diff --git a/packages/package_info_plus/package_info_plus_aurora/aurora/CMakeLists.txt b/packages/package_info_plus/package_info_plus_aurora/aurora/CMakeLists.txt new file mode 100644 index 0000000..b0d31a5 --- /dev/null +++ b/packages/package_info_plus/package_info_plus_aurora/aurora/CMakeLists.txt @@ -0,0 +1,26 @@ +# Copyright (c) 2023. Open Mobile Platform LLC. +# License: Proprietary. + +cmake_minimum_required(VERSION 3.10) + +set(PROJECT_NAME package_info_plus_aurora) +set(PLUGIN_NAME package_info_plus_aurora_platform_plugin) + +project(${PROJECT_NAME} LANGUAGES CXX) + +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +set(CMAKE_CXX_FLAGS "-Wall -Wextra -Wno-psabi") +set(CMAKE_CXX_FLAGS_RELEASE "-O3") + +find_package(PkgConfig REQUIRED) +pkg_check_modules(FlutterEmbedder REQUIRED IMPORTED_TARGET flutter-embedder) + +add_library(${PLUGIN_NAME} SHARED package_info_plus_aurora_plugin.cpp) + +set_target_properties(${PLUGIN_NAME} PROPERTIES CXX_VISIBILITY_PRESET hidden) +target_link_libraries(${PLUGIN_NAME} PRIVATE PkgConfig::FlutterEmbedder) + +target_include_directories(${PLUGIN_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include) +target_compile_definitions(${PLUGIN_NAME} PRIVATE PLUGIN_IMPL) diff --git a/packages/package_info_plus/package_info_plus_aurora/aurora/include/package_info_plus_aurora/package_info_plus_aurora_plugin.h b/packages/package_info_plus/package_info_plus_aurora/aurora/include/package_info_plus_aurora/package_info_plus_aurora_plugin.h new file mode 100644 index 0000000..3d9703b --- /dev/null +++ b/packages/package_info_plus/package_info_plus_aurora/aurora/include/package_info_plus_aurora/package_info_plus_aurora_plugin.h @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2023. Open Mobile Platform LLC. + * License: Proprietary. + */ +#ifndef FLUTTER_PLUGIN_PACKAGE_INFO_PLUS_AURORA_PLUGIN_H +#define FLUTTER_PLUGIN_PACKAGE_INFO_PLUS_AURORA_PLUGIN_H + +#include + +#ifdef PLUGIN_IMPL +#define PLUGIN_EXPORT __attribute__((visibility("default"))) +#else +#define PLUGIN_EXPORT +#endif + +class PLUGIN_EXPORT PackageInfoPlusAuroraPlugin final : public PluginInterface +{ +public: + void RegisterWithRegistrar(PluginRegistrar ®istrar) override; + +private: + void onMethodCall(const MethodCall &call); + void onGetApplicationOrg(const MethodCall &call); + void onGetApplicationName(const MethodCall &call); + void unimplemented(const MethodCall &call); +}; + +#endif /* FLUTTER_PLUGIN_PACKAGE_INFO_PLUS_AURORA_PLUGIN_H */ diff --git a/packages/package_info_plus/package_info_plus_aurora/aurora/package_info_plus_aurora_plugin.cpp b/packages/package_info_plus/package_info_plus_aurora/aurora/package_info_plus_aurora_plugin.cpp new file mode 100644 index 0000000..4d8a580 --- /dev/null +++ b/packages/package_info_plus/package_info_plus_aurora/aurora/package_info_plus_aurora_plugin.cpp @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2023. Open Mobile Platform LLC. + * License: Proprietary. + */ +#include +#include +#include +#include + +void PackageInfoPlusAuroraPlugin::RegisterWithRegistrar(PluginRegistrar ®istrar) +{ + registrar.RegisterMethodChannel("package_info_plus_aurora", + MethodCodecType::Standard, + [this](const MethodCall &call) { this->onMethodCall(call); }); +} + +void PackageInfoPlusAuroraPlugin::onMethodCall(const MethodCall &call) +{ + const auto &method = call.GetMethod(); + + if (method == "getApplicationOrg") { + onGetApplicationOrg(call); + return; + } + + if (method == "getApplicationName") { + onGetApplicationName(call); + return; + } + + unimplemented(call); +} + +void PackageInfoPlusAuroraPlugin::onGetApplicationOrg(const MethodCall &call) +{ + call.SendSuccessResponse(Application::GetID().orgname); +} + +void PackageInfoPlusAuroraPlugin::onGetApplicationName(const MethodCall &call) +{ + call.SendSuccessResponse(Application::GetID().appname); +} + +void PackageInfoPlusAuroraPlugin::unimplemented(const MethodCall &call) +{ + call.SendSuccessResponse(nullptr); +} diff --git a/packages/package_info_plus/package_info_plus_aurora/data/preview.png b/packages/package_info_plus/package_info_plus_aurora/data/preview.png new file mode 100644 index 0000000..e70f4b1 Binary files /dev/null and b/packages/package_info_plus/package_info_plus_aurora/data/preview.png differ diff --git a/packages/package_info_plus/package_info_plus_aurora/example/.gitignore b/packages/package_info_plus/package_info_plus_aurora/example/.gitignore new file mode 100644 index 0000000..3db3823 --- /dev/null +++ b/packages/package_info_plus/package_info_plus_aurora/example/.gitignore @@ -0,0 +1,47 @@ +# Miscellaneous +*.class +*.log +*.pyc +*.swp +.DS_Store +.atom/ +.buildlog/ +.history +.svn/ +migrate_working_dir/ + +# IntelliJ related +*.iml +*.ipr +*.iws +.idea/ + +# The .vscode folder contains launch configuration and tasks you configure in +# VS Code which you may wish to be included in version control, so this line +# is commented out by default. +#.vscode/ + +# Flutter/Dart/Pub related +**/doc/api/ +**/ios/Flutter/.last_build_id +.dart_tool/ +.flutter-plugins +.flutter-plugins-dependencies +.packages +.pub-cache/ +.pub/ +/build/ + +# Symbolication related +app.*.symbols + +# Obfuscation related +app.*.map.json + +# Android Studio will place build artifacts here +/android/app/debug +/android/app/profile +/android/app/release + +# Aurora generated +/aurora/flutter diff --git a/packages/package_info_plus/package_info_plus_aurora/example/README.md b/packages/package_info_plus/package_info_plus_aurora/example/README.md new file mode 100644 index 0000000..c7ef8e1 --- /dev/null +++ b/packages/package_info_plus/package_info_plus_aurora/example/README.md @@ -0,0 +1,21 @@ +# package_info_plus_aurora_example + +Demonstrates how to use the package_info_plus_aurora plugin. + +## Build + +```shell +# Add an alias if it doesn't already exist +alias flutter-aurora=$HOME/.local/opt/flutter-sdk/bin/flutter +# Get dependencies +flutter-aurora pub get +# Run build +flutter-aurora build aurora --release # [--release|--debug|--profile] +``` + +You can collect, sign, run an example on the device with a script located in the `script/build_example.sh` +More information in `build_example.sh`. + +### Preview example + +![preview.png](../data/preview.png) diff --git a/packages/package_info_plus/package_info_plus_aurora/example/analysis_options.yaml b/packages/package_info_plus/package_info_plus_aurora/example/analysis_options.yaml new file mode 100644 index 0000000..566c597 --- /dev/null +++ b/packages/package_info_plus/package_info_plus_aurora/example/analysis_options.yaml @@ -0,0 +1,4 @@ +# Copyright (c) 2023. Open Mobile Platform LLC. +# License: Proprietary. + +include: package:flutter_lints/flutter.yaml diff --git a/packages/package_info_plus/package_info_plus_aurora/example/aurora/.gitignore b/packages/package_info_plus/package_info_plus_aurora/example/aurora/.gitignore new file mode 100644 index 0000000..d3896c9 --- /dev/null +++ b/packages/package_info_plus/package_info_plus_aurora/example/aurora/.gitignore @@ -0,0 +1 @@ +flutter/ephemeral diff --git a/packages/package_info_plus/package_info_plus_aurora/example/aurora/CMakeLists.txt b/packages/package_info_plus/package_info_plus_aurora/example/aurora/CMakeLists.txt new file mode 100644 index 0000000..c75fffe --- /dev/null +++ b/packages/package_info_plus/package_info_plus_aurora/example/aurora/CMakeLists.txt @@ -0,0 +1,50 @@ +# Copyright (c) 2023. Open Mobile Platform LLC. +# License: Proprietary. + +cmake_minimum_required(VERSION 3.10) +project(com.example.package_info_plus_aurora_example LANGUAGES CXX) + +include(GNUInstallDirs) + +set(BINARY_NAME ${CMAKE_PROJECT_NAME}) +set(FLUTTER_DIR ${CMAKE_CURRENT_SOURCE_DIR}/flutter) + +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +set(CMAKE_CXX_FLAGS "-Wall -Wextra") +set(CMAKE_CXX_FLAGS_RELEASE "-O3") + +set(CMAKE_SKIP_RPATH OFF) +set(CMAKE_INSTALL_RPATH "\$ORIGIN/../share/${BINARY_NAME}/lib") + +find_package(PkgConfig REQUIRED) +pkg_check_modules(FlutterEmbedder REQUIRED IMPORTED_TARGET flutter-embedder) + +add_executable(${BINARY_NAME} main.cpp ${FLUTTER_DIR}/generated_plugin_registrant.cpp) +target_link_libraries(${BINARY_NAME} PRIVATE PkgConfig::FlutterEmbedder) +target_include_directories(${BINARY_NAME} PRIVATE ${FLUTTER_DIR}) + +include(flutter/generated_plugins.cmake) + +set(PACKAGE_INSTALL_DIR ${CMAKE_INSTALL_DATADIR}/${BINARY_NAME}) +set(DESKTOP_INSTALL_DIR ${CMAKE_INSTALL_DATADIR}/applications) +set(ICONS_INSTALL_ROOT_DIR ${CMAKE_INSTALL_DATADIR}/icons/hicolor) + +add_custom_command(TARGET ${BINARY_NAME} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy + ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/libflutter-embedder.so + ${PROJECT_BINARY_DIR}/bundle/lib/libflutter-embedder.so) + +install(FILES ${PROJECT_BINARY_DIR}/bundle/icudtl.dat DESTINATION ${PACKAGE_INSTALL_DIR}) +install(DIRECTORY ${PROJECT_BINARY_DIR}/bundle/flutter_assets DESTINATION ${PACKAGE_INSTALL_DIR}) +install(DIRECTORY ${PROJECT_BINARY_DIR}/bundle/lib DESTINATION ${PACKAGE_INSTALL_DIR}) + +install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) +install(FILES desktop/${BINARY_NAME}.desktop DESTINATION ${DESKTOP_INSTALL_DIR}) + +foreach(ICONS_SIZE 86x86 108x108 128x128 172x172) + install(FILES icons/${ICONS_SIZE}.png + RENAME ${BINARY_NAME}.png + DESTINATION ${ICONS_INSTALL_ROOT_DIR}/${ICONS_SIZE}/apps/) +endforeach(ICONS_SIZE) diff --git a/packages/package_info_plus/package_info_plus_aurora/example/aurora/desktop/com.example.package_info_plus_aurora_example.desktop b/packages/package_info_plus/package_info_plus_aurora/example/aurora/desktop/com.example.package_info_plus_aurora_example.desktop new file mode 100644 index 0000000..1e01856 --- /dev/null +++ b/packages/package_info_plus/package_info_plus_aurora/example/aurora/desktop/com.example.package_info_plus_aurora_example.desktop @@ -0,0 +1,12 @@ +[Desktop Entry] +Type=Application +Name=Example Info Plus +Comment=Demonstrates how to use the package_info_plus_aurora plugin. +Icon=com.example.package_info_plus_aurora_example +Exec=/usr/bin/com.example.package_info_plus_aurora_example +X-Nemo-Application-Type=silica-qt5 + +[X-Application] +Permissions= +OrganizationName=com.example +ApplicationName=package_info_plus_aurora_example diff --git a/packages/package_info_plus/package_info_plus_aurora/example/aurora/icons/108x108.png b/packages/package_info_plus/package_info_plus_aurora/example/aurora/icons/108x108.png new file mode 100644 index 0000000..984893d Binary files /dev/null and b/packages/package_info_plus/package_info_plus_aurora/example/aurora/icons/108x108.png differ diff --git a/packages/package_info_plus/package_info_plus_aurora/example/aurora/icons/128x128.png b/packages/package_info_plus/package_info_plus_aurora/example/aurora/icons/128x128.png new file mode 100644 index 0000000..2d552ef Binary files /dev/null and b/packages/package_info_plus/package_info_plus_aurora/example/aurora/icons/128x128.png differ diff --git a/packages/package_info_plus/package_info_plus_aurora/example/aurora/icons/172x172.png b/packages/package_info_plus/package_info_plus_aurora/example/aurora/icons/172x172.png new file mode 100644 index 0000000..9dc271b Binary files /dev/null and b/packages/package_info_plus/package_info_plus_aurora/example/aurora/icons/172x172.png differ diff --git a/packages/package_info_plus/package_info_plus_aurora/example/aurora/icons/86x86.png b/packages/package_info_plus/package_info_plus_aurora/example/aurora/icons/86x86.png new file mode 100644 index 0000000..5923bb1 Binary files /dev/null and b/packages/package_info_plus/package_info_plus_aurora/example/aurora/icons/86x86.png differ diff --git a/packages/package_info_plus/package_info_plus_aurora/example/aurora/main.cpp b/packages/package_info_plus/package_info_plus_aurora/example/aurora/main.cpp new file mode 100644 index 0000000..83f2ca8 --- /dev/null +++ b/packages/package_info_plus/package_info_plus_aurora/example/aurora/main.cpp @@ -0,0 +1,13 @@ +/* + * Copyright (c) 2023. Open Mobile Platform LLC. + * License: Proprietary. + */ +#include +#include "generated_plugin_registrant.h" + +int main(int argc, char *argv[]) { + Application::Initialize(argc, argv); + RegisterPlugins(); + Application::Launch(); + return 0; +} diff --git a/packages/package_info_plus/package_info_plus_aurora/example/aurora/rpm/com.example.package_info_plus_aurora_example.spec b/packages/package_info_plus/package_info_plus_aurora/example/aurora/rpm/com.example.package_info_plus_aurora_example.spec new file mode 100644 index 0000000..6a0c214 --- /dev/null +++ b/packages/package_info_plus/package_info_plus_aurora/example/aurora/rpm/com.example.package_info_plus_aurora_example.spec @@ -0,0 +1,31 @@ +%global __provides_exclude_from ^%{_datadir}/%{name}/lib/.*$ +%global __requires_exclude ^lib(dconf|flutter-embedder|maliit-glib|appmanifest-.+|.+_platform_plugin)\\.so.*$ + +Name: com.example.package_info_plus_aurora_example +Summary: Demonstrates how to use the package_info_plus_aurora plugin. +Version: 0.1.0 +Release: 1 +License: Proprietary +Source0: %{name}-%{version}.tar.zst + +BuildRequires: cmake +BuildRequires: pkgconfig(flutter-embedder) + +%description +%{summary}. + +%prep +%autosetup + +%build +%cmake -DCMAKE_BUILD_TYPE=%{_flutter_build_type} +%make_build + +%install +%make_install + +%files +%{_bindir}/%{name} +%{_datadir}/%{name}/* +%{_datadir}/applications/%{name}.desktop +%{_datadir}/icons/hicolor/*/apps/%{name}.png diff --git a/packages/package_info_plus/package_info_plus_aurora/example/lib/main.dart b/packages/package_info_plus/package_info_plus_aurora/example/lib/main.dart new file mode 100644 index 0000000..230fa54 --- /dev/null +++ b/packages/package_info_plus/package_info_plus_aurora/example/lib/main.dart @@ -0,0 +1,143 @@ +/* + * Copyright (c) 2023. Open Mobile Platform LLC. + * License: Proprietary. + */ +import 'package:flutter/material.dart'; +import 'dart:async'; + +import 'package:package_info_plus/package_info_plus.dart'; + +void main() { + runApp(const MyApp()); +} + +class MyApp extends StatefulWidget { + const MyApp({super.key}); + + @override + State createState() => _MyAppState(); +} + +class _MyAppState extends State { + String? _error; + String? _appName; + String? _packageName; + + @override + void initState() { + super.initState(); + initPlatformState(); + } + + Future initPlatformState() async { + try { + PackageInfo packageInfo = await PackageInfo.fromPlatform(); + + String appName = packageInfo.appName; + String packageName = packageInfo.packageName; + + // Update state variable + setState(() { + _appName = appName; + _packageName = packageName; + }); + } on Exception catch (e) { + setState(() { + _error = e.toString(); + }); + } + } + + @override + Widget build(BuildContext context) { + const textStyleWhite = TextStyle(fontSize: 18, color: Colors.white); + const textStyleTitle = TextStyle(fontSize: 20, color: Colors.black); + const textStylePath = TextStyle(fontSize: 18, color: Colors.black54); + + const spaceMedium = SizedBox(height: 20); + const spaceSmall = SizedBox(height: 10); + + return MaterialApp( + home: Scaffold( + appBar: AppBar( + title: const Text('Example package_info_plus'), + ), + body: Stack( + children: [ + // Error message + Visibility( + visible: _error != null, + child: Center( + child: Padding( + padding: const EdgeInsets.all(16), + child: Container( + padding: const EdgeInsets.all(20), + decoration: const BoxDecoration( + color: Colors.redAccent, + borderRadius: BorderRadius.all(Radius.circular(10.0)), + ), + child: Text( + _error ?? '', + style: textStyleWhite, + ), + ), + ), + ), + ), + // List directories path + Visibility( + visible: _error == null, + child: SingleChildScrollView( + child: Padding( + padding: const EdgeInsets.all(16), + child: Center( + child: Column( + children: [ + // Info + Container( + padding: const EdgeInsets.all(20), + decoration: const BoxDecoration( + color: Colors.green, + borderRadius: + BorderRadius.all(Radius.circular(10.0)), + ), + child: const Text( + 'Demo application demonstration implementation of package_info_plus', + style: textStyleWhite, + textAlign: TextAlign.center, + ), + ), + const SizedBox(height: 30), + + const Text( + 'Application Name', + style: textStyleTitle, + ), + spaceSmall, + Text( + _appName ?? 'Not found.', + style: textStylePath, + ), + + spaceMedium, + const Text( + 'Package Name', + style: textStyleTitle, + ), + spaceSmall, + Text( + _packageName ?? 'Not found.', + style: textStylePath, + ), + ], + ), + ), + ), + ), + ), + ], + ), + ), + ); + } +} diff --git a/packages/package_info_plus/package_info_plus_aurora/example/pubspec.lock b/packages/package_info_plus/package_info_plus_aurora/example/pubspec.lock new file mode 100644 index 0000000..910942c --- /dev/null +++ b/packages/package_info_plus/package_info_plus_aurora/example/pubspec.lock @@ -0,0 +1,236 @@ +# Generated by pub +# See https://dart.dev/tools/pub/glossary#lockfile +packages: + async: + dependency: transitive + description: + name: async + url: "https://pub.dartlang.org" + source: hosted + version: "2.9.0" + boolean_selector: + dependency: transitive + description: + name: boolean_selector + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.0" + characters: + dependency: transitive + description: + name: characters + url: "https://pub.dartlang.org" + source: hosted + version: "1.2.1" + clock: + dependency: transitive + description: + name: clock + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.1" + collection: + dependency: transitive + description: + name: collection + url: "https://pub.dartlang.org" + source: hosted + version: "1.16.0" + cupertino_icons: + dependency: "direct main" + description: + name: cupertino_icons + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.5" + fake_async: + dependency: transitive + description: + name: fake_async + url: "https://pub.dartlang.org" + source: hosted + version: "1.3.1" + ffi: + dependency: transitive + description: + name: ffi + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.2" + flutter: + dependency: "direct main" + description: flutter + source: sdk + version: "0.0.0" + flutter_lints: + dependency: "direct dev" + description: + name: flutter_lints + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.1" + flutter_test: + dependency: "direct dev" + description: flutter + source: sdk + version: "0.0.0" + flutter_web_plugins: + dependency: transitive + description: flutter + source: sdk + version: "0.0.0" + http: + dependency: transitive + description: + name: http + url: "https://pub.dartlang.org" + source: hosted + version: "0.13.5" + http_parser: + dependency: transitive + description: + name: http_parser + url: "https://pub.dartlang.org" + source: hosted + version: "4.0.2" + js: + dependency: transitive + description: + name: js + url: "https://pub.dartlang.org" + source: hosted + version: "0.6.4" + lints: + dependency: transitive + description: + name: lints + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.1" + matcher: + dependency: transitive + description: + name: matcher + url: "https://pub.dartlang.org" + source: hosted + version: "0.12.12" + material_color_utilities: + dependency: transitive + description: + name: material_color_utilities + url: "https://pub.dartlang.org" + source: hosted + version: "0.1.5" + meta: + dependency: transitive + description: + name: meta + url: "https://pub.dartlang.org" + source: hosted + version: "1.8.0" + package_info_plus: + dependency: "direct main" + description: + name: package_info_plus + url: "https://pub.dartlang.org" + source: hosted + version: "4.0.2" + package_info_plus_aurora: + dependency: "direct main" + description: + path: ".." + relative: true + source: path + version: "0.0.1" + package_info_plus_platform_interface: + dependency: transitive + description: + name: package_info_plus_platform_interface + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.1" + path: + dependency: transitive + description: + name: path + url: "https://pub.dartlang.org" + source: hosted + version: "1.8.2" + plugin_platform_interface: + dependency: transitive + description: + name: plugin_platform_interface + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.4" + sky_engine: + dependency: transitive + description: flutter + source: sdk + version: "0.0.99" + source_span: + dependency: transitive + description: + name: source_span + url: "https://pub.dartlang.org" + source: hosted + version: "1.9.0" + stack_trace: + dependency: transitive + description: + name: stack_trace + url: "https://pub.dartlang.org" + source: hosted + version: "1.10.0" + stream_channel: + dependency: transitive + description: + name: stream_channel + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.0" + string_scanner: + dependency: transitive + description: + name: string_scanner + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.1" + term_glyph: + dependency: transitive + description: + name: term_glyph + url: "https://pub.dartlang.org" + source: hosted + version: "1.2.1" + test_api: + dependency: transitive + description: + name: test_api + url: "https://pub.dartlang.org" + source: hosted + version: "0.4.12" + typed_data: + dependency: transitive + description: + name: typed_data + url: "https://pub.dartlang.org" + source: hosted + version: "1.3.2" + vector_math: + dependency: transitive + description: + name: vector_math + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.2" + win32: + dependency: transitive + description: + name: win32 + url: "https://pub.dartlang.org" + source: hosted + version: "4.1.4" +sdks: + dart: ">=2.18.6 <3.0.0" + flutter: ">=3.3.0" diff --git a/packages/package_info_plus/package_info_plus_aurora/example/pubspec.yaml b/packages/package_info_plus/package_info_plus_aurora/example/pubspec.yaml new file mode 100644 index 0000000..5b48f42 --- /dev/null +++ b/packages/package_info_plus/package_info_plus_aurora/example/pubspec.yaml @@ -0,0 +1,26 @@ +# Copyright (c) 2023. Open Mobile Platform LLC. +# License: Proprietary. + +name: package_info_plus_aurora_example +description: Demonstrates how to use the package_info_plus_aurora plugin. + +publish_to: 'none' + +environment: + sdk: '>=2.18.6 <3.0.0' + +dependencies: + flutter: + sdk: flutter + package_info_plus: ^4.0.0 + package_info_plus_aurora: + path: ../ + cupertino_icons: ^1.0.2 + +dev_dependencies: + flutter_test: + sdk: flutter + flutter_lints: ^2.0.0 + +flutter: + uses-material-design: true diff --git a/packages/package_info_plus/package_info_plus_aurora/lib/package_info_plus_aurora.dart b/packages/package_info_plus/package_info_plus_aurora/lib/package_info_plus_aurora.dart new file mode 100644 index 0000000..36fb258 --- /dev/null +++ b/packages/package_info_plus/package_info_plus_aurora/lib/package_info_plus_aurora.dart @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2023. Open Mobile Platform LLC. + * License: Proprietary. + */ +import 'dart:io'; +import 'package:flutter/widgets.dart'; +import 'package_info_plus_aurora_platform_interface.dart'; +import 'package:package_info_plus_platform_interface/package_info_platform_interface.dart'; +import 'package:package_info_plus_platform_interface/package_info_data.dart'; + +class PackageInfoPlusAurora extends PackageInfoPlatform { + /// Register this dart class as the platform implementation for aurora + static void registerWith() { + PackageInfoPlatform.instance = PackageInfoPlusAurora(); + } + + final _platform = PackageInfoPlusAuroraPlatform.instance; + + @override + Future getAll() async { + final versionJson = await _getVersionJson(); + return PackageInfoData( + appName: versionJson['app_name'] ?? '', + packageName: versionJson['package_name'] ?? '', + version: versionJson['version'] ?? '', + buildNumber: versionJson['build_number'] ?? '', + buildSignature: '', + ); + } + + Future> _getVersionJson() async { + try { + // Get package from aurora platform + final org = await _platform.getApplicationOrg(); + final name = await _platform.getApplicationName(); + final packageName = '$org.$name'; + + // Get application name + final desktop = + (await File('/usr/share/applications/$packageName.desktop') + .readAsLines()) + .where((element) => element.contains('Name=')); + + // @todo + // Get application versions + // rpm -q --queryformat %{VERSION} + // not working even with Compatibility permission + + return { + 'app_name': desktop.isNotEmpty ? desktop.first.substring(5) : null, + 'package_name': packageName, + 'version': '', + 'build_number': '', + }; + } catch (e) { + debugPrint(e.toString()); + return {}; + } + } +} diff --git a/packages/package_info_plus/package_info_plus_aurora/lib/package_info_plus_aurora_method_channel.dart b/packages/package_info_plus/package_info_plus_aurora/lib/package_info_plus_aurora_method_channel.dart new file mode 100644 index 0000000..90ae4e4 --- /dev/null +++ b/packages/package_info_plus/package_info_plus_aurora/lib/package_info_plus_aurora_method_channel.dart @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2023. Open Mobile Platform LLC. + * License: Proprietary. + */ +import 'package:flutter/foundation.dart'; +import 'package:flutter/services.dart'; + +import 'package_info_plus_aurora_platform_interface.dart'; + +/// An implementation of [PackageInfoPlusAuroraPlatform] that uses method channels. +class MethodChannelPackageInfoPlusAurora extends PackageInfoPlusAuroraPlatform { + /// The method channel used to interact with the native platform. + @visibleForTesting + final methodChannel = const MethodChannel('package_info_plus_aurora'); + + @override + Future getApplicationOrg() async { + return await methodChannel.invokeMethod('getApplicationOrg'); + } + + @override + Future getApplicationName() async { + return await methodChannel.invokeMethod('getApplicationName'); + } +} diff --git a/packages/package_info_plus/package_info_plus_aurora/lib/package_info_plus_aurora_platform_interface.dart b/packages/package_info_plus/package_info_plus_aurora/lib/package_info_plus_aurora_platform_interface.dart new file mode 100644 index 0000000..e8b2230 --- /dev/null +++ b/packages/package_info_plus/package_info_plus_aurora/lib/package_info_plus_aurora_platform_interface.dart @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2023. Open Mobile Platform LLC. + * License: Proprietary. + */ +import 'package:plugin_platform_interface/plugin_platform_interface.dart'; + +import 'package_info_plus_aurora_method_channel.dart'; + +abstract class PackageInfoPlusAuroraPlatform extends PlatformInterface { + /// Constructs a PackageInfoPlusAuroraPlatform. + PackageInfoPlusAuroraPlatform() : super(token: _token); + + static final Object _token = Object(); + + static PackageInfoPlusAuroraPlatform _instance = + MethodChannelPackageInfoPlusAurora(); + + /// The default instance of [PackageInfoPlusAuroraPlatform] to use. + /// + /// Defaults to [MethodChannelPackageInfoPlusAurora]. + static PackageInfoPlusAuroraPlatform get instance => _instance; + + /// Platform-specific implementations should set this with their own + /// platform-specific class that extends [PackageInfoPlusAuroraPlatform] when + /// they register themselves. + static set instance(PackageInfoPlusAuroraPlatform instance) { + PlatformInterface.verifyToken(instance, _token); + _instance = instance; + } + + Future getApplicationOrg() { + throw UnimplementedError('getApplicationOrg() has not been implemented.'); + } + + Future getApplicationName() { + throw UnimplementedError('getApplicationName() has not been implemented.'); + } +} diff --git a/packages/package_info_plus/package_info_plus_aurora/pubspec.yaml b/packages/package_info_plus/package_info_plus_aurora/pubspec.yaml new file mode 100644 index 0000000..ede11bc --- /dev/null +++ b/packages/package_info_plus/package_info_plus_aurora/pubspec.yaml @@ -0,0 +1,28 @@ +# Copyright (c) 2023. Open Mobile Platform LLC. +# License: Proprietary. + +name: package_info_plus_aurora +description: A new Flutter plugin project. +version: 0.0.1 + +environment: + sdk: '>=2.18.6 <3.0.0' + flutter: ">=2.5.0" + +dependencies: + flutter: + sdk: flutter + plugin_platform_interface: ^2.0.2 + package_info_plus_platform_interface: ^2.0.1 + +dev_dependencies: + flutter_test: + sdk: flutter + flutter_lints: ^2.0.0 + +flutter: + plugin: + platforms: + aurora: + pluginClass: PackageInfoPlusAuroraPlugin + dartPluginClass: PackageInfoPlusAurora diff --git a/packages/package_info_plus/package_info_plus_aurora/test/package_info_plus_aurora_method_channel_test.dart b/packages/package_info_plus/package_info_plus_aurora/test/package_info_plus_aurora_method_channel_test.dart new file mode 100644 index 0000000..b70772b --- /dev/null +++ b/packages/package_info_plus/package_info_plus_aurora/test/package_info_plus_aurora_method_channel_test.dart @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2023. Open Mobile Platform LLC. + * License: Proprietary. + */ +import 'package:flutter/services.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:package_info_plus_aurora/package_info_plus_aurora_method_channel.dart'; + +void main() { + MethodChannelPackageInfoPlusAurora platform = + MethodChannelPackageInfoPlusAurora(); + const MethodChannel channel = MethodChannel('package_info_plus_aurora'); + + TestWidgetsFlutterBinding.ensureInitialized(); + + setUp(() { + channel.setMockMethodCallHandler((MethodCall methodCall) async { + switch (methodCall.method) { + case 'getApplicationOrg': + return 'com.example'; + case 'getApplicationName': + return 'path_provider_aurora'; + } + return ''; + }); + }); + + tearDown(() { + channel.setMockMethodCallHandler(null); + }); + + test('onGetApplicationOrg', () async { + expect(await platform.getApplicationOrg(), 'com.example'); + }); + + test('onGetApplicationName', () async { + expect(await platform.getApplicationName(), 'path_provider_aurora'); + }); +}