├── .clang-format
├── .gitignore
├── .gitmodules
├── .idea
├── libraries
│ └── Dart_SDK.xml
├── modules.xml
├── runConfigurations
│ └── example_lib_main_dart.xml
└── workspace.xml
├── .metadata
├── CHANGELOG.md
├── COPYRIGHT
├── LICENSE
├── README.md
├── dart_discord_rpc.iml
├── example
├── .gitignore
├── .metadata
├── README.md
├── lib
│ └── main.dart
├── linux
│ ├── .gitignore
│ ├── CMakeLists.txt
│ ├── flutter
│ │ ├── CMakeLists.txt
│ │ ├── generated_plugin_registrant.cc
│ │ ├── generated_plugin_registrant.h
│ │ └── generated_plugins.cmake
│ ├── main.cc
│ ├── my_application.cc
│ └── my_application.h
├── pubspec.lock
├── pubspec.yaml
└── windows
│ ├── .gitignore
│ ├── CMakeLists.txt
│ ├── flutter
│ ├── CMakeLists.txt
│ ├── generated_plugin_registrant.cc
│ ├── generated_plugin_registrant.h
│ └── generated_plugins.cmake
│ └── runner
│ ├── CMakeLists.txt
│ ├── Runner.rc
│ ├── flutter_window.cpp
│ ├── flutter_window.h
│ ├── main.cpp
│ ├── resource.h
│ ├── resources
│ └── app_icon.ico
│ ├── runner.exe.manifest
│ ├── utils.cpp
│ ├── utils.h
│ ├── win32_window.cpp
│ └── win32_window.h
├── headers
├── discord_register.h
└── discord_rpc.h
├── image.png
├── lib
├── dart_discord_rpc.dart
├── dart_discord_rpc_native.dart
├── dart_discord_rpc_stub.dart
├── generated
│ └── bindings.dart
└── model
│ └── discord_presence.dart
├── linux
├── CMakeLists.txt
├── bin
│ └── libdiscord-rpc.so
├── dart_discord_rpc_plugin.cc
└── include
│ └── dart_discord_rpc
│ └── dart_discord_rpc_plugin.h
├── pubspec.lock
├── pubspec.yaml
└── windows
├── .gitignore
├── CMakeLists.txt
├── bin
└── discord-rpc.dll
├── dart_discord_rpc_plugin.cpp
└── include
└── dart_discord_rpc
└── dart_discord_rpc_plugin.h
/.clang-format:
--------------------------------------------------------------------------------
1 | BasedOnStyle: Google
2 | DerivePointerAlignment: false
3 | PointerAlignment: Left
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Operating system specific ignores.
2 | .DS_Store
3 |
4 | # Files and directories created by pub.
5 | .dart_tool/
6 | .packages
7 | .pub/
8 |
9 | # Conventional directory for build outputs.
10 | build/
11 |
--------------------------------------------------------------------------------
/.gitmodules:
--------------------------------------------------------------------------------
1 | [submodule "cxx/include/dart_api"]
2 | path = cxx/include/dart_api
3 | url = https://github.com/alexmercerind/dart_api.git
--------------------------------------------------------------------------------
/.idea/libraries/Dart_SDK.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.idea/runConfigurations/example_lib_main_dart.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/workspace.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/.metadata:
--------------------------------------------------------------------------------
1 | # This file tracks properties of this Flutter project.
2 | # Used by Flutter tool to assess capabilities and perform upgrades etc.
3 | #
4 | # This file should be version controlled and should not be manually edited.
5 |
6 | version:
7 | revision: 02c026b03cd31dd3f867e5faeb7e104cce174c5f
8 | channel: stable
9 |
10 | project_type: plugin
11 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | ## 0.0.1
2 |
3 | - Initial version.
4 | - Add Windows support.
5 | - Add `DiscordRPC`, `DiscordPresence` along with many other classes.
6 | - Add `Stream` based event handling.
7 |
8 | ## 0.0.2
9 |
10 | - Update README.
11 |
12 | ## 0.0.3
13 |
14 | - Unify dart_discord_rpc and dart_discord_rpc_ffi.
15 | - Use stub for unsupported platforms.
16 |
--------------------------------------------------------------------------------
/COPYRIGHT:
--------------------------------------------------------------------------------
1 | Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
2 | Upstream-Name: dart_discord_rpc
3 | Upstream-Contact: Hitesh Kumar Saini
4 | Source: https://github.com/alexmercerind/dart_discord_rpc/
5 |
6 | Files: *
7 | Copyright: 2021-2022 Hitesh Kumar Saini
8 | Comment: dart_discord_rpc
9 | License: Expat
10 |
11 | Files: linux/bin/*
12 | Copyright: 2017 Discord, Inc.
13 | Comment: Discord RPC Libraries
14 | License: Expat
15 |
16 | License: Expat
17 | Permission is hereby granted, free of charge, to any person obtaining
18 | a copy of this software and associated documentation files (the
19 | "Software"), to deal in the Software without restriction, including
20 | without limitation the rights to use, copy, modify, merge, publish,
21 | distribute, sublicense, and/or sell copies of the Software, and to
22 | permit persons to whom the Software is furnished to do so, subject to
23 | the following conditions:
24 | .
25 | The above copyright notice and this permission notice shall be
26 | included in all copies or substantial portions of the Software.
27 | .
28 | THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,
29 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
30 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
31 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
32 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
33 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
34 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2021 Hitesh Kumar Saini
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining a copy
4 | of this software and associated documentation files (the "Software"), to deal
5 | in the Software without restriction, including without limitation the rights
6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 | copies of the Software, and to permit persons to whom the Software is
8 | furnished to do so, subject to the following conditions:
9 |
10 | The above copyright notice and this permission notice shall be included in all
11 | copies or substantial portions of the Software.
12 |
13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19 | SOFTWARE.
20 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 | Discord Rich Presence for Flutter & Dart apps & games.
3 |
4 |
5 |
6 |
7 |
8 | ## Install
9 |
10 | **Flutter**
11 |
12 | `flutter pub add dart_discord_rpc`
13 |
14 | **Dart CLI**
15 |
16 | `dart pub add dart_discord_rpc`
17 |
18 | ## Documentation
19 |
20 | For integrating Discord Rich Presence into your application or game, you must create an application at [Discord Developer Portal](https://discord.com/developers/applications).
21 |
22 | **Initialize the plugin.**
23 |
24 | ```dart
25 | void main() {
26 | DiscordRPC.initialize();
27 | runApp(MyApp());
28 | }
29 | ```
30 |
31 | **Instantiate class.**
32 |
33 | ```dart
34 | DiscordRPC rpc = DiscordRPC(
35 | applicationId: 'APPLICATION_ID',
36 | );
37 | ```
38 |
39 | **Set or change the user presence.**
40 |
41 | ```dart
42 | rpc.start(autoRegister: true);
43 | rpc.updatePresence(
44 | DiscordPresence(
45 | state: 'Discord Rich Presence from Dart. 🎯',
46 | details: 'github.com/alexmercerind/dart_discord_rpc',
47 | startTimeStamp: DateTime.now().millisecondsSinceEpoch,
48 | largeImageKey: 'large_image',
49 | largeImageText: 'This text describes the large image.',
50 | smallImageKey: 'small_image',
51 | smallImageText: 'This text describes the small image.',
52 | ),
53 | );
54 | ```
55 |
56 | **Clear the user presence.**
57 |
58 | ```dart
59 | rpc.clearPresence();
60 | ```
61 |
62 | **Listen to the events.**
63 |
64 | ```dart
65 | rpc.events.listen((event) {
66 | if (event is DiscordReady) {
67 | event.user;
68 | }
69 | if (event is DiscordErrored) {
70 | event.errorCode;
71 | event.message;
72 | }
73 | if (event is DiscordJoinGame) {
74 | event.joinSecret;
75 | }
76 | // Other events.
77 | });
78 | ```
79 |
80 | There are other features for you to checkout.
81 |
82 | ## Support
83 |
84 | Consider supporting the project by starring the repository or buying me a coffee.
85 |
86 |
87 |
88 | ## License
89 |
90 | Copyright (c) 2021 Hitesh Kumar Saini
91 |
92 | MIT. Contributions welcomed.
93 |
94 | See [COPYRIGHT](https://github.com/alexmercerind/dart_discord_rpc/blob/master/COPYRIGHT) for comprehensive licensing information.
95 |
96 | ## Platforms
97 |
98 | Supported
99 |
100 | - Windows
101 | - Linux
102 |
--------------------------------------------------------------------------------
/dart_discord_rpc.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/example/.gitignore:
--------------------------------------------------------------------------------
1 | # Miscellaneous
2 | *.class
3 | *.log
4 | *.pyc
5 | *.swp
6 | .DS_Store
7 | .atom/
8 | .buildlog/
9 | .history
10 | .svn/
11 |
12 | # IntelliJ related
13 | *.iml
14 | *.ipr
15 | *.iws
16 | .idea/
17 |
18 | # The .vscode folder contains launch configuration and tasks you configure in
19 | # VS Code which you may wish to be included in version control, so this line
20 | # is commented out by default.
21 | #.vscode/
22 |
23 | # Flutter/Dart/Pub related
24 | **/doc/api/
25 | **/ios/Flutter/.last_build_id
26 | .dart_tool/
27 | .flutter-plugins
28 | .flutter-plugins-dependencies
29 | .packages
30 | .pub-cache/
31 | .pub/
32 | /build/
33 |
34 | # Web related
35 | lib/generated_plugin_registrant.dart
36 |
37 | # Symbolication related
38 | app.*.symbols
39 |
40 | # Obfuscation related
41 | app.*.map.json
42 |
43 | # Android Studio will place build artifacts here
44 | /android/app/debug
45 | /android/app/profile
46 | /android/app/release
47 |
--------------------------------------------------------------------------------
/example/.metadata:
--------------------------------------------------------------------------------
1 | # This file tracks properties of this Flutter project.
2 | # Used by Flutter tool to assess capabilities and perform upgrades etc.
3 | #
4 | # This file should be version controlled and should not be manually edited.
5 |
6 | version:
7 | revision: 02c026b03cd31dd3f867e5faeb7e104cce174c5f
8 | channel: stable
9 |
10 | project_type: app
11 |
--------------------------------------------------------------------------------
/example/README.md:
--------------------------------------------------------------------------------
1 | # dart_discord_rpc_example
2 |
3 | Demonstrates how to use the dart_discord_rpc plugin.
4 |
5 | ## Getting Started
6 |
7 | This project is a starting point for a Flutter application.
8 |
9 | A few resources to get you started if this is your first Flutter project:
10 |
11 | - [Lab: Write your first Flutter app](https://flutter.dev/docs/get-started/codelab)
12 | - [Cookbook: Useful Flutter samples](https://flutter.dev/docs/cookbook)
13 |
14 | For help getting started with Flutter, view our
15 | [online documentation](https://flutter.dev/docs), which offers tutorials,
16 | samples, guidance on mobile development, and a full API reference.
17 |
--------------------------------------------------------------------------------
/example/lib/main.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter/material.dart';
2 | import 'package:dart_discord_rpc/dart_discord_rpc.dart';
3 |
4 | void main() {
5 | DiscordRPC.initialize();
6 | runApp(MyApp());
7 | }
8 |
9 | class MyApp extends StatefulWidget {
10 | @override
11 | _MyAppState createState() => _MyAppState();
12 | }
13 |
14 | class _MyAppState extends State {
15 | DiscordRPC discord = DiscordRPC(
16 | applicationId: '877853131025809438',
17 | );
18 |
19 | @override
20 | void initState() {
21 | super.initState();
22 | discord.start(autoRegister: true);
23 | discord.updatePresence(
24 | DiscordPresence(
25 | state: 'Discord Rich Presence from Dart. 🎯',
26 | details: 'github.com/alexmercerind/dart_discord_rpc',
27 | startTimeStamp: DateTime.now().millisecondsSinceEpoch,
28 | largeImageKey: 'large_image',
29 | largeImageText: 'This text describes the large image.',
30 | smallImageKey: 'small_image',
31 | smallImageText: 'This text describes the small image.',
32 | ),
33 | );
34 | }
35 |
36 | @override
37 | Widget build(BuildContext context) {
38 | return MaterialApp(
39 | home: Scaffold(
40 | appBar: AppBar(
41 | title: const Text('dart_discord_rpc'),
42 | ),
43 | body: Center(
44 | child: Text('Open Discord to see the plugin working.'),
45 | ),
46 | ),
47 | );
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/example/linux/.gitignore:
--------------------------------------------------------------------------------
1 | flutter/ephemeral
2 |
--------------------------------------------------------------------------------
/example/linux/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.10)
2 | project(runner LANGUAGES CXX)
3 |
4 | set(BINARY_NAME "dart_discord_rpc_example")
5 | set(APPLICATION_ID "com.alexmercerind.dart_discord_rpc")
6 |
7 | cmake_policy(SET CMP0063 NEW)
8 |
9 | set(CMAKE_INSTALL_RPATH "$ORIGIN/lib")
10 |
11 | # Root filesystem for cross-building.
12 | if(FLUTTER_TARGET_PLATFORM_SYSROOT)
13 | set(CMAKE_SYSROOT ${FLUTTER_TARGET_PLATFORM_SYSROOT})
14 | set(CMAKE_FIND_ROOT_PATH ${CMAKE_SYSROOT})
15 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
16 | set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
17 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
18 | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
19 | endif()
20 |
21 | # Configure build options.
22 | if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
23 | set(CMAKE_BUILD_TYPE "Debug" CACHE
24 | STRING "Flutter build mode" FORCE)
25 | set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
26 | "Debug" "Profile" "Release")
27 | endif()
28 |
29 | # Compilation settings that should be applied to most targets.
30 | function(APPLY_STANDARD_SETTINGS TARGET)
31 | target_compile_features(${TARGET} PUBLIC cxx_std_14)
32 | target_compile_options(${TARGET} PRIVATE -Wall -Werror)
33 | target_compile_options(${TARGET} PRIVATE "$<$>:-O3>")
34 | target_compile_definitions(${TARGET} PRIVATE "$<$>:NDEBUG>")
35 | endfunction()
36 |
37 | set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter")
38 |
39 | # Flutter library and tool build rules.
40 | add_subdirectory(${FLUTTER_MANAGED_DIR})
41 |
42 | # System-level dependencies.
43 | find_package(PkgConfig REQUIRED)
44 | pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0)
45 |
46 | add_definitions(-DAPPLICATION_ID="${APPLICATION_ID}")
47 |
48 | # Application build
49 | add_executable(${BINARY_NAME}
50 | "main.cc"
51 | "my_application.cc"
52 | "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc"
53 | )
54 | apply_standard_settings(${BINARY_NAME})
55 | target_link_libraries(${BINARY_NAME} PRIVATE flutter)
56 | target_link_libraries(${BINARY_NAME} PRIVATE PkgConfig::GTK)
57 | add_dependencies(${BINARY_NAME} flutter_assemble)
58 | # Only the install-generated bundle's copy of the executable will launch
59 | # correctly, since the resources must in the right relative locations. To avoid
60 | # people trying to run the unbundled copy, put it in a subdirectory instead of
61 | # the default top-level location.
62 | set_target_properties(${BINARY_NAME}
63 | PROPERTIES
64 | RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/intermediates_do_not_run"
65 | )
66 |
67 | # Generated plugin build rules, which manage building the plugins and adding
68 | # them to the application.
69 | include(flutter/generated_plugins.cmake)
70 |
71 |
72 | # === Installation ===
73 | # By default, "installing" just makes a relocatable bundle in the build
74 | # directory.
75 | set(BUILD_BUNDLE_DIR "${PROJECT_BINARY_DIR}/bundle")
76 | if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
77 | set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE)
78 | endif()
79 |
80 | # Start with a clean build bundle directory every time.
81 | install(CODE "
82 | file(REMOVE_RECURSE \"${BUILD_BUNDLE_DIR}/\")
83 | " COMPONENT Runtime)
84 |
85 | set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data")
86 | set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib")
87 |
88 | install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}"
89 | COMPONENT Runtime)
90 |
91 | install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}"
92 | COMPONENT Runtime)
93 |
94 | install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
95 | COMPONENT Runtime)
96 |
97 | if(PLUGIN_BUNDLED_LIBRARIES)
98 | install(FILES "${PLUGIN_BUNDLED_LIBRARIES}"
99 | DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
100 | COMPONENT Runtime)
101 | endif()
102 |
103 | # Fully re-copy the assets directory on each build to avoid having stale files
104 | # from a previous install.
105 | set(FLUTTER_ASSET_DIR_NAME "flutter_assets")
106 | install(CODE "
107 | file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\")
108 | " COMPONENT Runtime)
109 | install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}"
110 | DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime)
111 |
112 | # Install the AOT library on non-Debug builds only.
113 | if(NOT CMAKE_BUILD_TYPE MATCHES "Debug")
114 | install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
115 | COMPONENT Runtime)
116 | endif()
117 |
--------------------------------------------------------------------------------
/example/linux/flutter/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.10)
2 |
3 | set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral")
4 |
5 | # Configuration provided via flutter tool.
6 | include(${EPHEMERAL_DIR}/generated_config.cmake)
7 |
8 | # TODO: Move the rest of this into files in ephemeral. See
9 | # https://github.com/flutter/flutter/issues/57146.
10 |
11 | # Serves the same purpose as list(TRANSFORM ... PREPEND ...),
12 | # which isn't available in 3.10.
13 | function(list_prepend LIST_NAME PREFIX)
14 | set(NEW_LIST "")
15 | foreach(element ${${LIST_NAME}})
16 | list(APPEND NEW_LIST "${PREFIX}${element}")
17 | endforeach(element)
18 | set(${LIST_NAME} "${NEW_LIST}" PARENT_SCOPE)
19 | endfunction()
20 |
21 | # === Flutter Library ===
22 | # System-level dependencies.
23 | find_package(PkgConfig REQUIRED)
24 | pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0)
25 | pkg_check_modules(GLIB REQUIRED IMPORTED_TARGET glib-2.0)
26 | pkg_check_modules(GIO REQUIRED IMPORTED_TARGET gio-2.0)
27 |
28 | set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/libflutter_linux_gtk.so")
29 |
30 | # Published to parent scope for install step.
31 | set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE)
32 | set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE)
33 | set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE)
34 | set(AOT_LIBRARY "${PROJECT_DIR}/build/lib/libapp.so" PARENT_SCOPE)
35 |
36 | list(APPEND FLUTTER_LIBRARY_HEADERS
37 | "fl_basic_message_channel.h"
38 | "fl_binary_codec.h"
39 | "fl_binary_messenger.h"
40 | "fl_dart_project.h"
41 | "fl_engine.h"
42 | "fl_json_message_codec.h"
43 | "fl_json_method_codec.h"
44 | "fl_message_codec.h"
45 | "fl_method_call.h"
46 | "fl_method_channel.h"
47 | "fl_method_codec.h"
48 | "fl_method_response.h"
49 | "fl_plugin_registrar.h"
50 | "fl_plugin_registry.h"
51 | "fl_standard_message_codec.h"
52 | "fl_standard_method_codec.h"
53 | "fl_string_codec.h"
54 | "fl_value.h"
55 | "fl_view.h"
56 | "flutter_linux.h"
57 | )
58 | list_prepend(FLUTTER_LIBRARY_HEADERS "${EPHEMERAL_DIR}/flutter_linux/")
59 | add_library(flutter INTERFACE)
60 | target_include_directories(flutter INTERFACE
61 | "${EPHEMERAL_DIR}"
62 | )
63 | target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}")
64 | target_link_libraries(flutter INTERFACE
65 | PkgConfig::GTK
66 | PkgConfig::GLIB
67 | PkgConfig::GIO
68 | )
69 | add_dependencies(flutter flutter_assemble)
70 |
71 | # === Flutter tool backend ===
72 | # _phony_ is a non-existent file to force this command to run every time,
73 | # since currently there's no way to get a full input/output list from the
74 | # flutter tool.
75 | add_custom_command(
76 | OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS}
77 | ${CMAKE_CURRENT_BINARY_DIR}/_phony_
78 | COMMAND ${CMAKE_COMMAND} -E env
79 | ${FLUTTER_TOOL_ENVIRONMENT}
80 | "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.sh"
81 | ${FLUTTER_TARGET_PLATFORM} ${CMAKE_BUILD_TYPE}
82 | VERBATIM
83 | )
84 | add_custom_target(flutter_assemble DEPENDS
85 | "${FLUTTER_LIBRARY}"
86 | ${FLUTTER_LIBRARY_HEADERS}
87 | )
88 |
--------------------------------------------------------------------------------
/example/linux/flutter/generated_plugin_registrant.cc:
--------------------------------------------------------------------------------
1 | //
2 | // Generated file. Do not edit.
3 | //
4 |
5 | // clang-format off
6 |
7 | #include "generated_plugin_registrant.h"
8 |
9 | #include
10 |
11 | void fl_register_plugins(FlPluginRegistry* registry) {
12 | g_autoptr(FlPluginRegistrar) dart_discord_rpc_registrar =
13 | fl_plugin_registry_get_registrar_for_plugin(registry, "DartDiscordRpcPlugin");
14 | dart_discord_rpc_plugin_register_with_registrar(dart_discord_rpc_registrar);
15 | }
16 |
--------------------------------------------------------------------------------
/example/linux/flutter/generated_plugin_registrant.h:
--------------------------------------------------------------------------------
1 | //
2 | // Generated file. Do not edit.
3 | //
4 |
5 | // clang-format off
6 |
7 | #ifndef GENERATED_PLUGIN_REGISTRANT_
8 | #define GENERATED_PLUGIN_REGISTRANT_
9 |
10 | #include
11 |
12 | // Registers Flutter plugins.
13 | void fl_register_plugins(FlPluginRegistry* registry);
14 |
15 | #endif // GENERATED_PLUGIN_REGISTRANT_
16 |
--------------------------------------------------------------------------------
/example/linux/flutter/generated_plugins.cmake:
--------------------------------------------------------------------------------
1 | #
2 | # Generated file, do not edit.
3 | #
4 |
5 | list(APPEND FLUTTER_PLUGIN_LIST
6 | dart_discord_rpc
7 | )
8 |
9 | list(APPEND FLUTTER_FFI_PLUGIN_LIST
10 | )
11 |
12 | set(PLUGIN_BUNDLED_LIBRARIES)
13 |
14 | foreach(plugin ${FLUTTER_PLUGIN_LIST})
15 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${plugin}/linux plugins/${plugin})
16 | target_link_libraries(${BINARY_NAME} PRIVATE ${plugin}_plugin)
17 | list(APPEND PLUGIN_BUNDLED_LIBRARIES $)
18 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries})
19 | endforeach(plugin)
20 |
21 | foreach(ffi_plugin ${FLUTTER_FFI_PLUGIN_LIST})
22 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${ffi_plugin}/linux plugins/${ffi_plugin})
23 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${ffi_plugin}_bundled_libraries})
24 | endforeach(ffi_plugin)
25 |
--------------------------------------------------------------------------------
/example/linux/main.cc:
--------------------------------------------------------------------------------
1 | #include "my_application.h"
2 |
3 | int main(int argc, char** argv) {
4 | g_autoptr(MyApplication) app = my_application_new();
5 | return g_application_run(G_APPLICATION(app), argc, argv);
6 | }
7 |
--------------------------------------------------------------------------------
/example/linux/my_application.cc:
--------------------------------------------------------------------------------
1 | #include "my_application.h"
2 |
3 | #include
4 | #ifdef GDK_WINDOWING_X11
5 | #include
6 | #endif
7 |
8 | #include "flutter/generated_plugin_registrant.h"
9 |
10 | struct _MyApplication {
11 | GtkApplication parent_instance;
12 | char** dart_entrypoint_arguments;
13 | };
14 |
15 | G_DEFINE_TYPE(MyApplication, my_application, GTK_TYPE_APPLICATION)
16 |
17 | // Implements GApplication::activate.
18 | static void my_application_activate(GApplication* application) {
19 | MyApplication* self = MY_APPLICATION(application);
20 | GtkWindow* window =
21 | GTK_WINDOW(gtk_application_window_new(GTK_APPLICATION(application)));
22 |
23 | // Use a header bar when running in GNOME as this is the common style used
24 | // by applications and is the setup most users will be using (e.g. Ubuntu
25 | // desktop).
26 | // If running on X and not using GNOME then just use a traditional title bar
27 | // in case the window manager does more exotic layout, e.g. tiling.
28 | // If running on Wayland assume the header bar will work (may need changing
29 | // if future cases occur).
30 | gboolean use_header_bar = TRUE;
31 | #ifdef GDK_WINDOWING_X11
32 | GdkScreen *screen = gtk_window_get_screen(window);
33 | if (GDK_IS_X11_SCREEN(screen)) {
34 | const gchar* wm_name = gdk_x11_screen_get_window_manager_name(screen);
35 | if (g_strcmp0(wm_name, "GNOME Shell") != 0) {
36 | use_header_bar = FALSE;
37 | }
38 | }
39 | #endif
40 | if (use_header_bar) {
41 | GtkHeaderBar *header_bar = GTK_HEADER_BAR(gtk_header_bar_new());
42 | gtk_widget_show(GTK_WIDGET(header_bar));
43 | gtk_header_bar_set_title(header_bar, "dart_discord_rpc_example");
44 | gtk_header_bar_set_show_close_button(header_bar, TRUE);
45 | gtk_window_set_titlebar(window, GTK_WIDGET(header_bar));
46 | }
47 | else {
48 | gtk_window_set_title(window, "dart_discord_rpc_example");
49 | }
50 |
51 | gtk_window_set_default_size(window, 1280, 720);
52 | gtk_widget_show(GTK_WIDGET(window));
53 |
54 | g_autoptr(FlDartProject) project = fl_dart_project_new();
55 | fl_dart_project_set_dart_entrypoint_arguments(project, self->dart_entrypoint_arguments);
56 |
57 | FlView* view = fl_view_new(project);
58 | gtk_widget_show(GTK_WIDGET(view));
59 | gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(view));
60 |
61 | fl_register_plugins(FL_PLUGIN_REGISTRY(view));
62 |
63 | gtk_widget_grab_focus(GTK_WIDGET(view));
64 | }
65 |
66 | // Implements GApplication::local_command_line.
67 | static gboolean my_application_local_command_line(GApplication* application, gchar ***arguments, int *exit_status) {
68 | MyApplication* self = MY_APPLICATION(application);
69 | // Strip out the first argument as it is the binary name.
70 | self->dart_entrypoint_arguments = g_strdupv(*arguments + 1);
71 |
72 | g_autoptr(GError) error = nullptr;
73 | if (!g_application_register(application, nullptr, &error)) {
74 | g_warning("Failed to register: %s", error->message);
75 | *exit_status = 1;
76 | return TRUE;
77 | }
78 |
79 | g_application_activate(application);
80 | *exit_status = 0;
81 |
82 | return TRUE;
83 | }
84 |
85 | // Implements GObject::dispose.
86 | static void my_application_dispose(GObject *object) {
87 | MyApplication* self = MY_APPLICATION(object);
88 | g_clear_pointer(&self->dart_entrypoint_arguments, g_strfreev);
89 | G_OBJECT_CLASS(my_application_parent_class)->dispose(object);
90 | }
91 |
92 | static void my_application_class_init(MyApplicationClass* klass) {
93 | G_APPLICATION_CLASS(klass)->activate = my_application_activate;
94 | G_APPLICATION_CLASS(klass)->local_command_line = my_application_local_command_line;
95 | G_OBJECT_CLASS(klass)->dispose = my_application_dispose;
96 | }
97 |
98 | static void my_application_init(MyApplication* self) {}
99 |
100 | MyApplication* my_application_new() {
101 | return MY_APPLICATION(g_object_new(my_application_get_type(),
102 | "application-id", APPLICATION_ID,
103 | "flags", G_APPLICATION_NON_UNIQUE,
104 | nullptr));
105 | }
106 |
--------------------------------------------------------------------------------
/example/linux/my_application.h:
--------------------------------------------------------------------------------
1 | #ifndef FLUTTER_MY_APPLICATION_H_
2 | #define FLUTTER_MY_APPLICATION_H_
3 |
4 | #include
5 |
6 | G_DECLARE_FINAL_TYPE(MyApplication, my_application, MY, APPLICATION,
7 | GtkApplication)
8 |
9 | /**
10 | * my_application_new:
11 | *
12 | * Creates a new Flutter-based application.
13 | *
14 | * Returns: a new #MyApplication.
15 | */
16 | MyApplication* my_application_new();
17 |
18 | #endif // FLUTTER_MY_APPLICATION_H_
19 |
--------------------------------------------------------------------------------
/example/pubspec.lock:
--------------------------------------------------------------------------------
1 | # Generated by pub
2 | # See https://dart.dev/tools/pub/glossary#lockfile
3 | packages:
4 | async:
5 | dependency: transitive
6 | description:
7 | name: async
8 | sha256: bfe67ef28df125b7dddcea62755991f807aa39a2492a23e1550161692950bbe0
9 | url: "https://pub.dev"
10 | source: hosted
11 | version: "2.10.0"
12 | boolean_selector:
13 | dependency: transitive
14 | description:
15 | name: boolean_selector
16 | sha256: "6cfb5af12253eaf2b368f07bacc5a80d1301a071c73360d746b7f2e32d762c66"
17 | url: "https://pub.dev"
18 | source: hosted
19 | version: "2.1.1"
20 | characters:
21 | dependency: transitive
22 | description:
23 | name: characters
24 | sha256: e6a326c8af69605aec75ed6c187d06b349707a27fbff8222ca9cc2cff167975c
25 | url: "https://pub.dev"
26 | source: hosted
27 | version: "1.2.1"
28 | clock:
29 | dependency: transitive
30 | description:
31 | name: clock
32 | sha256: cb6d7f03e1de671e34607e909a7213e31d7752be4fb66a86d29fe1eb14bfb5cf
33 | url: "https://pub.dev"
34 | source: hosted
35 | version: "1.1.1"
36 | collection:
37 | dependency: transitive
38 | description:
39 | name: collection
40 | sha256: cfc915e6923fe5ce6e153b0723c753045de46de1b4d63771530504004a45fae0
41 | url: "https://pub.dev"
42 | source: hosted
43 | version: "1.17.0"
44 | cupertino_icons:
45 | dependency: "direct main"
46 | description:
47 | name: cupertino_icons
48 | sha256: "486b7bc707424572cdf7bd7e812a0c146de3fd47ecadf070254cc60383f21dd8"
49 | url: "https://pub.dev"
50 | source: hosted
51 | version: "1.0.3"
52 | dart_discord_rpc:
53 | dependency: "direct main"
54 | description:
55 | path: ".."
56 | relative: true
57 | source: path
58 | version: "0.0.3"
59 | fake_async:
60 | dependency: transitive
61 | description:
62 | name: fake_async
63 | sha256: "511392330127add0b769b75a987850d136345d9227c6b94c96a04cf4a391bf78"
64 | url: "https://pub.dev"
65 | source: hosted
66 | version: "1.3.1"
67 | ffi:
68 | dependency: transitive
69 | description:
70 | name: ffi
71 | sha256: a38574032c5f1dd06c4aee541789906c12ccaab8ba01446e800d9c5b79c4a978
72 | url: "https://pub.dev"
73 | source: hosted
74 | version: "2.0.1"
75 | flutter:
76 | dependency: "direct main"
77 | description: flutter
78 | source: sdk
79 | version: "0.0.0"
80 | flutter_test:
81 | dependency: "direct dev"
82 | description: flutter
83 | source: sdk
84 | version: "0.0.0"
85 | js:
86 | dependency: transitive
87 | description:
88 | name: js
89 | sha256: "5528c2f391ededb7775ec1daa69e65a2d61276f7552de2b5f7b8d34ee9fd4ab7"
90 | url: "https://pub.dev"
91 | source: hosted
92 | version: "0.6.5"
93 | matcher:
94 | dependency: transitive
95 | description:
96 | name: matcher
97 | sha256: "16db949ceee371e9b99d22f88fa3a73c4e59fd0afed0bd25fc336eb76c198b72"
98 | url: "https://pub.dev"
99 | source: hosted
100 | version: "0.12.13"
101 | material_color_utilities:
102 | dependency: transitive
103 | description:
104 | name: material_color_utilities
105 | sha256: d92141dc6fe1dad30722f9aa826c7fbc896d021d792f80678280601aff8cf724
106 | url: "https://pub.dev"
107 | source: hosted
108 | version: "0.2.0"
109 | meta:
110 | dependency: transitive
111 | description:
112 | name: meta
113 | sha256: "6c268b42ed578a53088d834796959e4a1814b5e9e164f147f580a386e5decf42"
114 | url: "https://pub.dev"
115 | source: hosted
116 | version: "1.8.0"
117 | path:
118 | dependency: transitive
119 | description:
120 | name: path
121 | sha256: db9d4f58c908a4ba5953fcee2ae317c94889433e5024c27ce74a37f94267945b
122 | url: "https://pub.dev"
123 | source: hosted
124 | version: "1.8.2"
125 | sky_engine:
126 | dependency: transitive
127 | description: flutter
128 | source: sdk
129 | version: "0.0.99"
130 | source_span:
131 | dependency: transitive
132 | description:
133 | name: source_span
134 | sha256: dd904f795d4b4f3b870833847c461801f6750a9fa8e61ea5ac53f9422b31f250
135 | url: "https://pub.dev"
136 | source: hosted
137 | version: "1.9.1"
138 | stack_trace:
139 | dependency: transitive
140 | description:
141 | name: stack_trace
142 | sha256: c3c7d8edb15bee7f0f74debd4b9c5f3c2ea86766fe4178eb2a18eb30a0bdaed5
143 | url: "https://pub.dev"
144 | source: hosted
145 | version: "1.11.0"
146 | stream_channel:
147 | dependency: transitive
148 | description:
149 | name: stream_channel
150 | sha256: "83615bee9045c1d322bbbd1ba209b7a749c2cbcdcb3fdd1df8eb488b3279c1c8"
151 | url: "https://pub.dev"
152 | source: hosted
153 | version: "2.1.1"
154 | string_scanner:
155 | dependency: transitive
156 | description:
157 | name: string_scanner
158 | sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde"
159 | url: "https://pub.dev"
160 | source: hosted
161 | version: "1.2.0"
162 | term_glyph:
163 | dependency: transitive
164 | description:
165 | name: term_glyph
166 | sha256: a29248a84fbb7c79282b40b8c72a1209db169a2e0542bce341da992fe1bc7e84
167 | url: "https://pub.dev"
168 | source: hosted
169 | version: "1.2.1"
170 | test_api:
171 | dependency: transitive
172 | description:
173 | name: test_api
174 | sha256: ad540f65f92caa91bf21dfc8ffb8c589d6e4dc0c2267818b4cc2792857706206
175 | url: "https://pub.dev"
176 | source: hosted
177 | version: "0.4.16"
178 | vector_math:
179 | dependency: transitive
180 | description:
181 | name: vector_math
182 | sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803"
183 | url: "https://pub.dev"
184 | source: hosted
185 | version: "2.1.4"
186 | sdks:
187 | dart: ">=2.18.0 <3.0.0"
188 |
--------------------------------------------------------------------------------
/example/pubspec.yaml:
--------------------------------------------------------------------------------
1 | name: dart_discord_rpc_example
2 | description: Demonstrates how to use the dart_discord_rpc plugin.
3 |
4 | # The following line prevents the package from being accidentally published to
5 | # pub.dev using `pub publish`. This is preferred for private packages.
6 | publish_to: "none" # Remove this line if you wish to publish to pub.dev
7 |
8 | environment:
9 | sdk: ">=2.12.0 <3.0.0"
10 |
11 | dependencies:
12 | flutter:
13 | sdk: flutter
14 |
15 | dart_discord_rpc:
16 | # When depending on this package from a real application you should use:
17 | # dart_discord_rpc: ^x.y.z
18 | # See https://dart.dev/tools/pub/dependencies#version-constraints
19 | # The example app is bundled with the plugin so we use a path dependency on
20 | # the parent directory to use the current plugin's version.
21 | path: ../
22 |
23 | # The following adds the Cupertino Icons font to your application.
24 | # Use with the CupertinoIcons class for iOS style icons.
25 | cupertino_icons: ^1.0.2
26 |
27 | dev_dependencies:
28 | flutter_test:
29 | sdk: flutter
30 |
31 | # For information on the generic Dart part of this file, see the
32 | # following page: https://dart.dev/tools/pub/pubspec
33 |
34 | # The following section is specific to Flutter.
35 | flutter:
36 | # The following line ensures that the Material Icons font is
37 | # included with your application, so that you can use the icons in
38 | # the material Icons class.
39 | uses-material-design: true
40 |
41 | # To add assets to your application, add an assets section, like this:
42 | # assets:
43 | # - images/a_dot_burr.jpeg
44 | # - images/a_dot_ham.jpeg
45 |
46 | # An image asset can refer to one or more resolution-specific "variants", see
47 | # https://flutter.dev/assets-and-images/#resolution-aware.
48 |
49 | # For details regarding adding assets from package dependencies, see
50 | # https://flutter.dev/assets-and-images/#from-packages
51 |
52 | # To add custom fonts to your application, add a fonts section here,
53 | # in this "flutter" section. Each entry in this list should have a
54 | # "family" key with the font family name, and a "fonts" key with a
55 | # list giving the asset and other descriptors for the font. For
56 | # example:
57 | # fonts:
58 | # - family: Schyler
59 | # fonts:
60 | # - asset: fonts/Schyler-Regular.ttf
61 | # - asset: fonts/Schyler-Italic.ttf
62 | # style: italic
63 | # - family: Trajan Pro
64 | # fonts:
65 | # - asset: fonts/TrajanPro.ttf
66 | # - asset: fonts/TrajanPro_Bold.ttf
67 | # weight: 700
68 | #
69 | # For details regarding fonts from package dependencies,
70 | # see https://flutter.dev/custom-fonts/#from-packages
71 |
--------------------------------------------------------------------------------
/example/windows/.gitignore:
--------------------------------------------------------------------------------
1 | flutter/ephemeral/
2 |
3 | # Visual Studio user-specific files.
4 | *.suo
5 | *.user
6 | *.userosscache
7 | *.sln.docstates
8 |
9 | # Visual Studio build-related files.
10 | x64/
11 | x86/
12 |
13 | # Visual Studio cache files
14 | # files ending in .cache can be ignored
15 | *.[Cc]ache
16 | # but keep track of directories ending in .cache
17 | !*.[Cc]ache/
18 |
--------------------------------------------------------------------------------
/example/windows/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.15)
2 | project(dart_discord_rpc_example LANGUAGES CXX)
3 |
4 | set(BINARY_NAME "dart_discord_rpc_example")
5 |
6 | cmake_policy(SET CMP0063 NEW)
7 |
8 | set(CMAKE_INSTALL_RPATH "$ORIGIN/lib")
9 |
10 | # Configure build options.
11 | get_property(IS_MULTICONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
12 | if(IS_MULTICONFIG)
13 | set(CMAKE_CONFIGURATION_TYPES "Debug;Profile;Release"
14 | CACHE STRING "" FORCE)
15 | else()
16 | if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
17 | set(CMAKE_BUILD_TYPE "Debug" CACHE
18 | STRING "Flutter build mode" FORCE)
19 | set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
20 | "Debug" "Profile" "Release")
21 | endif()
22 | endif()
23 |
24 | set(CMAKE_EXE_LINKER_FLAGS_PROFILE "${CMAKE_EXE_LINKER_FLAGS_RELEASE}")
25 | set(CMAKE_SHARED_LINKER_FLAGS_PROFILE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE}")
26 | set(CMAKE_C_FLAGS_PROFILE "${CMAKE_C_FLAGS_RELEASE}")
27 | set(CMAKE_CXX_FLAGS_PROFILE "${CMAKE_CXX_FLAGS_RELEASE}")
28 |
29 | # Use Unicode for all projects.
30 | add_definitions(-DUNICODE -D_UNICODE)
31 |
32 | # Compilation settings that should be applied to most targets.
33 | function(APPLY_STANDARD_SETTINGS TARGET)
34 | target_compile_features(${TARGET} PUBLIC cxx_std_17)
35 | target_compile_options(${TARGET} PRIVATE /W4 /WX /wd"4100")
36 | target_compile_options(${TARGET} PRIVATE /EHsc)
37 | target_compile_definitions(${TARGET} PRIVATE "_HAS_EXCEPTIONS=0")
38 | target_compile_definitions(${TARGET} PRIVATE "$<$:_DEBUG>")
39 | endfunction()
40 |
41 | set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter")
42 |
43 | # Flutter library and tool build rules.
44 | add_subdirectory(${FLUTTER_MANAGED_DIR})
45 |
46 | # Application build
47 | add_subdirectory("runner")
48 |
49 | # Generated plugin build rules, which manage building the plugins and adding
50 | # them to the application.
51 | include(flutter/generated_plugins.cmake)
52 |
53 |
54 | # === Installation ===
55 | # Support files are copied into place next to the executable, so that it can
56 | # run in place. This is done instead of making a separate bundle (as on Linux)
57 | # so that building and running from within Visual Studio will work.
58 | set(BUILD_BUNDLE_DIR "$")
59 | # Make the "install" step default, as it's required to run.
60 | set(CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD 1)
61 | if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
62 | set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE)
63 | endif()
64 |
65 | set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data")
66 | set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}")
67 |
68 | install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}"
69 | COMPONENT Runtime)
70 |
71 | install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}"
72 | COMPONENT Runtime)
73 |
74 | install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
75 | COMPONENT Runtime)
76 |
77 | if(PLUGIN_BUNDLED_LIBRARIES)
78 | install(FILES "${PLUGIN_BUNDLED_LIBRARIES}"
79 | DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
80 | COMPONENT Runtime)
81 | endif()
82 |
83 | # Fully re-copy the assets directory on each build to avoid having stale files
84 | # from a previous install.
85 | set(FLUTTER_ASSET_DIR_NAME "flutter_assets")
86 | install(CODE "
87 | file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\")
88 | " COMPONENT Runtime)
89 | install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}"
90 | DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime)
91 |
92 | # Install the AOT library on non-Debug builds only.
93 | install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}"
94 | CONFIGURATIONS Profile;Release
95 | COMPONENT Runtime)
96 |
--------------------------------------------------------------------------------
/example/windows/flutter/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.15)
2 |
3 | set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral")
4 |
5 | # Configuration provided via flutter tool.
6 | include(${EPHEMERAL_DIR}/generated_config.cmake)
7 |
8 | # TODO: Move the rest of this into files in ephemeral. See
9 | # https://github.com/flutter/flutter/issues/57146.
10 | set(WRAPPER_ROOT "${EPHEMERAL_DIR}/cpp_client_wrapper")
11 |
12 | # === Flutter Library ===
13 | set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/flutter_windows.dll")
14 |
15 | # Published to parent scope for install step.
16 | set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE)
17 | set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE)
18 | set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE)
19 | set(AOT_LIBRARY "${PROJECT_DIR}/build/windows/app.so" PARENT_SCOPE)
20 |
21 | list(APPEND FLUTTER_LIBRARY_HEADERS
22 | "flutter_export.h"
23 | "flutter_windows.h"
24 | "flutter_messenger.h"
25 | "flutter_plugin_registrar.h"
26 | "flutter_texture_registrar.h"
27 | )
28 | list(TRANSFORM FLUTTER_LIBRARY_HEADERS PREPEND "${EPHEMERAL_DIR}/")
29 | add_library(flutter INTERFACE)
30 | target_include_directories(flutter INTERFACE
31 | "${EPHEMERAL_DIR}"
32 | )
33 | target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}.lib")
34 | add_dependencies(flutter flutter_assemble)
35 |
36 | # === Wrapper ===
37 | list(APPEND CPP_WRAPPER_SOURCES_CORE
38 | "core_implementations.cc"
39 | "standard_codec.cc"
40 | )
41 | list(TRANSFORM CPP_WRAPPER_SOURCES_CORE PREPEND "${WRAPPER_ROOT}/")
42 | list(APPEND CPP_WRAPPER_SOURCES_PLUGIN
43 | "plugin_registrar.cc"
44 | )
45 | list(TRANSFORM CPP_WRAPPER_SOURCES_PLUGIN PREPEND "${WRAPPER_ROOT}/")
46 | list(APPEND CPP_WRAPPER_SOURCES_APP
47 | "flutter_engine.cc"
48 | "flutter_view_controller.cc"
49 | )
50 | list(TRANSFORM CPP_WRAPPER_SOURCES_APP PREPEND "${WRAPPER_ROOT}/")
51 |
52 | # Wrapper sources needed for a plugin.
53 | add_library(flutter_wrapper_plugin STATIC
54 | ${CPP_WRAPPER_SOURCES_CORE}
55 | ${CPP_WRAPPER_SOURCES_PLUGIN}
56 | )
57 | apply_standard_settings(flutter_wrapper_plugin)
58 | set_target_properties(flutter_wrapper_plugin PROPERTIES
59 | POSITION_INDEPENDENT_CODE ON)
60 | set_target_properties(flutter_wrapper_plugin PROPERTIES
61 | CXX_VISIBILITY_PRESET hidden)
62 | target_link_libraries(flutter_wrapper_plugin PUBLIC flutter)
63 | target_include_directories(flutter_wrapper_plugin PUBLIC
64 | "${WRAPPER_ROOT}/include"
65 | )
66 | add_dependencies(flutter_wrapper_plugin flutter_assemble)
67 |
68 | # Wrapper sources needed for the runner.
69 | add_library(flutter_wrapper_app STATIC
70 | ${CPP_WRAPPER_SOURCES_CORE}
71 | ${CPP_WRAPPER_SOURCES_APP}
72 | )
73 | apply_standard_settings(flutter_wrapper_app)
74 | target_link_libraries(flutter_wrapper_app PUBLIC flutter)
75 | target_include_directories(flutter_wrapper_app PUBLIC
76 | "${WRAPPER_ROOT}/include"
77 | )
78 | add_dependencies(flutter_wrapper_app flutter_assemble)
79 |
80 | # === Flutter tool backend ===
81 | # _phony_ is a non-existent file to force this command to run every time,
82 | # since currently there's no way to get a full input/output list from the
83 | # flutter tool.
84 | set(PHONY_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/_phony_")
85 | set_source_files_properties("${PHONY_OUTPUT}" PROPERTIES SYMBOLIC TRUE)
86 | add_custom_command(
87 | OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS}
88 | ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_PLUGIN}
89 | ${CPP_WRAPPER_SOURCES_APP}
90 | ${PHONY_OUTPUT}
91 | COMMAND ${CMAKE_COMMAND} -E env
92 | ${FLUTTER_TOOL_ENVIRONMENT}
93 | "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.bat"
94 | windows-x64 $
95 | VERBATIM
96 | )
97 | add_custom_target(flutter_assemble DEPENDS
98 | "${FLUTTER_LIBRARY}"
99 | ${FLUTTER_LIBRARY_HEADERS}
100 | ${CPP_WRAPPER_SOURCES_CORE}
101 | ${CPP_WRAPPER_SOURCES_PLUGIN}
102 | ${CPP_WRAPPER_SOURCES_APP}
103 | )
104 |
--------------------------------------------------------------------------------
/example/windows/flutter/generated_plugin_registrant.cc:
--------------------------------------------------------------------------------
1 | //
2 | // Generated file. Do not edit.
3 | //
4 |
5 | // clang-format off
6 |
7 | #include "generated_plugin_registrant.h"
8 |
9 | #include
10 |
11 | void RegisterPlugins(flutter::PluginRegistry* registry) {
12 | DartDiscordRpcPluginRegisterWithRegistrar(
13 | registry->GetRegistrarForPlugin("DartDiscordRpcPlugin"));
14 | }
15 |
--------------------------------------------------------------------------------
/example/windows/flutter/generated_plugin_registrant.h:
--------------------------------------------------------------------------------
1 | //
2 | // Generated file. Do not edit.
3 | //
4 |
5 | // clang-format off
6 |
7 | #ifndef GENERATED_PLUGIN_REGISTRANT_
8 | #define GENERATED_PLUGIN_REGISTRANT_
9 |
10 | #include
11 |
12 | // Registers Flutter plugins.
13 | void RegisterPlugins(flutter::PluginRegistry* registry);
14 |
15 | #endif // GENERATED_PLUGIN_REGISTRANT_
16 |
--------------------------------------------------------------------------------
/example/windows/flutter/generated_plugins.cmake:
--------------------------------------------------------------------------------
1 | #
2 | # Generated file, do not edit.
3 | #
4 |
5 | list(APPEND FLUTTER_PLUGIN_LIST
6 | dart_discord_rpc
7 | )
8 |
9 | list(APPEND FLUTTER_FFI_PLUGIN_LIST
10 | )
11 |
12 | set(PLUGIN_BUNDLED_LIBRARIES)
13 |
14 | foreach(plugin ${FLUTTER_PLUGIN_LIST})
15 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${plugin}/windows plugins/${plugin})
16 | target_link_libraries(${BINARY_NAME} PRIVATE ${plugin}_plugin)
17 | list(APPEND PLUGIN_BUNDLED_LIBRARIES $)
18 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries})
19 | endforeach(plugin)
20 |
21 | foreach(ffi_plugin ${FLUTTER_FFI_PLUGIN_LIST})
22 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${ffi_plugin}/windows plugins/${ffi_plugin})
23 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${ffi_plugin}_bundled_libraries})
24 | endforeach(ffi_plugin)
25 |
--------------------------------------------------------------------------------
/example/windows/runner/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.15)
2 | project(runner LANGUAGES CXX)
3 |
4 | add_executable(${BINARY_NAME} WIN32
5 | "flutter_window.cpp"
6 | "main.cpp"
7 | "utils.cpp"
8 | "win32_window.cpp"
9 | "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc"
10 | "Runner.rc"
11 | "runner.exe.manifest"
12 | )
13 | apply_standard_settings(${BINARY_NAME})
14 | target_compile_definitions(${BINARY_NAME} PRIVATE "NOMINMAX")
15 | target_link_libraries(${BINARY_NAME} PRIVATE flutter flutter_wrapper_app)
16 | target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}")
17 | add_dependencies(${BINARY_NAME} flutter_assemble)
18 |
--------------------------------------------------------------------------------
/example/windows/runner/Runner.rc:
--------------------------------------------------------------------------------
1 | // Microsoft Visual C++ generated resource script.
2 | //
3 | #pragma code_page(65001)
4 | #include "resource.h"
5 |
6 | #define APSTUDIO_READONLY_SYMBOLS
7 | /////////////////////////////////////////////////////////////////////////////
8 | //
9 | // Generated from the TEXTINCLUDE 2 resource.
10 | //
11 | #include "winres.h"
12 |
13 | /////////////////////////////////////////////////////////////////////////////
14 | #undef APSTUDIO_READONLY_SYMBOLS
15 |
16 | /////////////////////////////////////////////////////////////////////////////
17 | // English (United States) resources
18 |
19 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
20 | LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
21 |
22 | #ifdef APSTUDIO_INVOKED
23 | /////////////////////////////////////////////////////////////////////////////
24 | //
25 | // TEXTINCLUDE
26 | //
27 |
28 | 1 TEXTINCLUDE
29 | BEGIN
30 | "resource.h\0"
31 | END
32 |
33 | 2 TEXTINCLUDE
34 | BEGIN
35 | "#include ""winres.h""\r\n"
36 | "\0"
37 | END
38 |
39 | 3 TEXTINCLUDE
40 | BEGIN
41 | "\r\n"
42 | "\0"
43 | END
44 |
45 | #endif // APSTUDIO_INVOKED
46 |
47 |
48 | /////////////////////////////////////////////////////////////////////////////
49 | //
50 | // Icon
51 | //
52 |
53 | // Icon with lowest ID value placed first to ensure application icon
54 | // remains consistent on all systems.
55 | IDI_APP_ICON ICON "resources\\app_icon.ico"
56 |
57 |
58 | /////////////////////////////////////////////////////////////////////////////
59 | //
60 | // Version
61 | //
62 |
63 | #ifdef FLUTTER_BUILD_NUMBER
64 | #define VERSION_AS_NUMBER FLUTTER_BUILD_NUMBER
65 | #else
66 | #define VERSION_AS_NUMBER 1,0,0
67 | #endif
68 |
69 | #ifdef FLUTTER_BUILD_NAME
70 | #define VERSION_AS_STRING #FLUTTER_BUILD_NAME
71 | #else
72 | #define VERSION_AS_STRING "1.0.0"
73 | #endif
74 |
75 | VS_VERSION_INFO VERSIONINFO
76 | FILEVERSION VERSION_AS_NUMBER
77 | PRODUCTVERSION VERSION_AS_NUMBER
78 | FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
79 | #ifdef _DEBUG
80 | FILEFLAGS VS_FF_DEBUG
81 | #else
82 | FILEFLAGS 0x0L
83 | #endif
84 | FILEOS VOS__WINDOWS32
85 | FILETYPE VFT_APP
86 | FILESUBTYPE 0x0L
87 | BEGIN
88 | BLOCK "StringFileInfo"
89 | BEGIN
90 | BLOCK "040904e4"
91 | BEGIN
92 | VALUE "CompanyName", "com.alexmercerind" "\0"
93 | VALUE "FileDescription", "Demonstrates how to use the dart_discord_rpc plugin." "\0"
94 | VALUE "FileVersion", VERSION_AS_STRING "\0"
95 | VALUE "InternalName", "dart_discord_rpc_example" "\0"
96 | VALUE "LegalCopyright", "Copyright (C) 2021 com.alexmercerind. All rights reserved." "\0"
97 | VALUE "OriginalFilename", "dart_discord_rpc_example.exe" "\0"
98 | VALUE "ProductName", "dart_discord_rpc_example" "\0"
99 | VALUE "ProductVersion", VERSION_AS_STRING "\0"
100 | END
101 | END
102 | BLOCK "VarFileInfo"
103 | BEGIN
104 | VALUE "Translation", 0x409, 1252
105 | END
106 | END
107 |
108 | #endif // English (United States) resources
109 | /////////////////////////////////////////////////////////////////////////////
110 |
111 |
112 |
113 | #ifndef APSTUDIO_INVOKED
114 | /////////////////////////////////////////////////////////////////////////////
115 | //
116 | // Generated from the TEXTINCLUDE 3 resource.
117 | //
118 |
119 |
120 | /////////////////////////////////////////////////////////////////////////////
121 | #endif // not APSTUDIO_INVOKED
122 |
--------------------------------------------------------------------------------
/example/windows/runner/flutter_window.cpp:
--------------------------------------------------------------------------------
1 | #include "flutter_window.h"
2 |
3 | #include
4 |
5 | #include "flutter/generated_plugin_registrant.h"
6 |
7 | FlutterWindow::FlutterWindow(const flutter::DartProject& project)
8 | : project_(project) {}
9 |
10 | FlutterWindow::~FlutterWindow() {}
11 |
12 | bool FlutterWindow::OnCreate() {
13 | if (!Win32Window::OnCreate()) {
14 | return false;
15 | }
16 |
17 | RECT frame = GetClientArea();
18 |
19 | // The size here must match the window dimensions to avoid unnecessary surface
20 | // creation / destruction in the startup path.
21 | flutter_controller_ = std::make_unique(
22 | frame.right - frame.left, frame.bottom - frame.top, project_);
23 | // Ensure that basic setup of the controller was successful.
24 | if (!flutter_controller_->engine() || !flutter_controller_->view()) {
25 | return false;
26 | }
27 | RegisterPlugins(flutter_controller_->engine());
28 | SetChildContent(flutter_controller_->view()->GetNativeWindow());
29 | return true;
30 | }
31 |
32 | void FlutterWindow::OnDestroy() {
33 | if (flutter_controller_) {
34 | flutter_controller_ = nullptr;
35 | }
36 |
37 | Win32Window::OnDestroy();
38 | }
39 |
40 | LRESULT
41 | FlutterWindow::MessageHandler(HWND hwnd, UINT const message,
42 | WPARAM const wparam,
43 | LPARAM const lparam) noexcept {
44 | // Give Flutter, including plugins, an opportunity to handle window messages.
45 | if (flutter_controller_) {
46 | std::optional result =
47 | flutter_controller_->HandleTopLevelWindowProc(hwnd, message, wparam,
48 | lparam);
49 | if (result) {
50 | return *result;
51 | }
52 | }
53 |
54 | switch (message) {
55 | case WM_FONTCHANGE:
56 | flutter_controller_->engine()->ReloadSystemFonts();
57 | break;
58 | }
59 |
60 | return Win32Window::MessageHandler(hwnd, message, wparam, lparam);
61 | }
62 |
--------------------------------------------------------------------------------
/example/windows/runner/flutter_window.h:
--------------------------------------------------------------------------------
1 | #ifndef RUNNER_FLUTTER_WINDOW_H_
2 | #define RUNNER_FLUTTER_WINDOW_H_
3 |
4 | #include
5 | #include
6 |
7 | #include
8 |
9 | #include "win32_window.h"
10 |
11 | // A window that does nothing but host a Flutter view.
12 | class FlutterWindow : public Win32Window {
13 | public:
14 | explicit FlutterWindow(const flutter::DartProject& project);
15 | virtual ~FlutterWindow();
16 |
17 | protected:
18 | // Win32Window:
19 | bool OnCreate() override;
20 | void OnDestroy() override;
21 | LRESULT MessageHandler(HWND window, UINT const message, WPARAM const wparam,
22 | LPARAM const lparam) noexcept override;
23 |
24 | private:
25 | // The project to run.
26 | flutter::DartProject project_;
27 |
28 | // The Flutter instance hosted by this window.
29 | std::unique_ptr flutter_controller_;
30 | };
31 |
32 | #endif // RUNNER_FLUTTER_WINDOW_H_
33 |
--------------------------------------------------------------------------------
/example/windows/runner/main.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 |
5 | #include "flutter_window.h"
6 | #include "utils.h"
7 |
8 | int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev,
9 | _In_ wchar_t* command_line, _In_ int show_command) {
10 | if (!::AttachConsole(ATTACH_PARENT_PROCESS) && ::IsDebuggerPresent()) {
11 | CreateAndAttachConsole();
12 | }
13 | ::CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED);
14 | flutter::DartProject project(L"data");
15 | std::vector command_line_arguments = GetCommandLineArguments();
16 | project.set_dart_entrypoint_arguments(std::move(command_line_arguments));
17 | FlutterWindow window(project);
18 | Win32Window::Point origin(10, 10);
19 | Win32Window::Size size(1280, 720);
20 | if (!window.CreateAndShow(L"dart_discord_rpc_example", origin, size)) {
21 | return EXIT_FAILURE;
22 | }
23 | window.SetQuitOnClose(true);
24 | MSG msg;
25 | while (GetMessage(&msg, nullptr, 0, 0)) {
26 | TranslateMessage(&msg);
27 | DispatchMessage(&msg);
28 | }
29 | ::CoUninitialize();
30 | return EXIT_SUCCESS;
31 | }
32 |
--------------------------------------------------------------------------------
/example/windows/runner/resource.h:
--------------------------------------------------------------------------------
1 | //{{NO_DEPENDENCIES}}
2 | // Microsoft Visual C++ generated include file.
3 | // Used by Runner.rc
4 | //
5 | #define IDI_APP_ICON 101
6 |
7 | // Next default values for new objects
8 | //
9 | #ifdef APSTUDIO_INVOKED
10 | #ifndef APSTUDIO_READONLY_SYMBOLS
11 | #define _APS_NEXT_RESOURCE_VALUE 102
12 | #define _APS_NEXT_COMMAND_VALUE 40001
13 | #define _APS_NEXT_CONTROL_VALUE 1001
14 | #define _APS_NEXT_SYMED_VALUE 101
15 | #endif
16 | #endif
17 |
--------------------------------------------------------------------------------
/example/windows/runner/resources/app_icon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alexmercerind/dart_discord_rpc/1eeb6360342327f86b36642412e915fe714641fc/example/windows/runner/resources/app_icon.ico
--------------------------------------------------------------------------------
/example/windows/runner/runner.exe.manifest:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | PerMonitorV2
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/example/windows/runner/utils.cpp:
--------------------------------------------------------------------------------
1 | #include "utils.h"
2 |
3 | #include
4 | #include
5 | #include
6 | #include
7 |
8 | #include
9 |
10 | void CreateAndAttachConsole() {
11 | if (::AllocConsole()) {
12 | FILE *unused;
13 | if (freopen_s(&unused, "CONOUT$", "w", stdout)) {
14 | _dup2(_fileno(stdout), 1);
15 | }
16 | if (freopen_s(&unused, "CONOUT$", "w", stderr)) {
17 | _dup2(_fileno(stdout), 2);
18 | }
19 | std::ios::sync_with_stdio();
20 | FlutterDesktopResyncOutputStreams();
21 | }
22 | }
23 |
24 | std::vector GetCommandLineArguments() {
25 | // Convert the UTF-16 command line arguments to UTF-8 for the Engine to use.
26 | int argc;
27 | wchar_t** argv = ::CommandLineToArgvW(::GetCommandLineW(), &argc);
28 | if (argv == nullptr) {
29 | return std::vector();
30 | }
31 |
32 | std::vector command_line_arguments;
33 |
34 | // Skip the first argument as it's the binary name.
35 | for (int i = 1; i < argc; i++) {
36 | command_line_arguments.push_back(Utf8FromUtf16(argv[i]));
37 | }
38 |
39 | ::LocalFree(argv);
40 |
41 | return command_line_arguments;
42 | }
43 |
44 | std::string Utf8FromUtf16(const wchar_t* utf16_string) {
45 | if (utf16_string == nullptr) {
46 | return std::string();
47 | }
48 | int target_length = ::WideCharToMultiByte(
49 | CP_UTF8, WC_ERR_INVALID_CHARS, utf16_string,
50 | -1, nullptr, 0, nullptr, nullptr);
51 | if (target_length == 0) {
52 | return std::string();
53 | }
54 | std::string utf8_string;
55 | utf8_string.resize(target_length);
56 | int converted_length = ::WideCharToMultiByte(
57 | CP_UTF8, WC_ERR_INVALID_CHARS, utf16_string,
58 | -1, utf8_string.data(),
59 | target_length, nullptr, nullptr);
60 | if (converted_length == 0) {
61 | return std::string();
62 | }
63 | return utf8_string;
64 | }
65 |
--------------------------------------------------------------------------------
/example/windows/runner/utils.h:
--------------------------------------------------------------------------------
1 | #ifndef RUNNER_UTILS_H_
2 | #define RUNNER_UTILS_H_
3 |
4 | #include
5 | #include
6 |
7 | // Creates a console for the process, and redirects stdout and stderr to
8 | // it for both the runner and the Flutter library.
9 | void CreateAndAttachConsole();
10 |
11 | // Takes a null-terminated wchar_t* encoded in UTF-16 and returns a std::string
12 | // encoded in UTF-8. Returns an empty std::string on failure.
13 | std::string Utf8FromUtf16(const wchar_t* utf16_string);
14 |
15 | // Gets the command line arguments passed in as a std::vector,
16 | // encoded in UTF-8. Returns an empty std::vector on failure.
17 | std::vector GetCommandLineArguments();
18 |
19 | #endif // RUNNER_UTILS_H_
20 |
--------------------------------------------------------------------------------
/example/windows/runner/win32_window.cpp:
--------------------------------------------------------------------------------
1 | #include "win32_window.h"
2 |
3 | #include
4 |
5 | #include "resource.h"
6 |
7 | namespace {
8 |
9 | constexpr const wchar_t kWindowClassName[] = L"FLUTTER_RUNNER_WIN32_WINDOW";
10 |
11 | // The number of Win32Window objects that currently exist.
12 | static int g_active_window_count = 0;
13 |
14 | using EnableNonClientDpiScaling = BOOL __stdcall(HWND hwnd);
15 |
16 | // Scale helper to convert logical scaler values to physical using passed in
17 | // scale factor
18 | int Scale(int source, double scale_factor) {
19 | return static_cast(source * scale_factor);
20 | }
21 |
22 | // Dynamically loads the |EnableNonClientDpiScaling| from the User32 module.
23 | // This API is only needed for PerMonitor V1 awareness mode.
24 | void EnableFullDpiSupportIfAvailable(HWND hwnd) {
25 | HMODULE user32_module = LoadLibraryA("User32.dll");
26 | if (!user32_module) {
27 | return;
28 | }
29 | auto enable_non_client_dpi_scaling =
30 | reinterpret_cast(
31 | GetProcAddress(user32_module, "EnableNonClientDpiScaling"));
32 | if (enable_non_client_dpi_scaling != nullptr) {
33 | enable_non_client_dpi_scaling(hwnd);
34 | FreeLibrary(user32_module);
35 | }
36 | }
37 |
38 | } // namespace
39 |
40 | // Manages the Win32Window's window class registration.
41 | class WindowClassRegistrar {
42 | public:
43 | ~WindowClassRegistrar() = default;
44 |
45 | // Returns the singleton registar instance.
46 | static WindowClassRegistrar* GetInstance() {
47 | if (!instance_) {
48 | instance_ = new WindowClassRegistrar();
49 | }
50 | return instance_;
51 | }
52 |
53 | // Returns the name of the window class, registering the class if it hasn't
54 | // previously been registered.
55 | const wchar_t* GetWindowClass();
56 |
57 | // Unregisters the window class. Should only be called if there are no
58 | // instances of the window.
59 | void UnregisterWindowClass();
60 |
61 | private:
62 | WindowClassRegistrar() = default;
63 |
64 | static WindowClassRegistrar* instance_;
65 |
66 | bool class_registered_ = false;
67 | };
68 |
69 | WindowClassRegistrar* WindowClassRegistrar::instance_ = nullptr;
70 |
71 | const wchar_t* WindowClassRegistrar::GetWindowClass() {
72 | if (!class_registered_) {
73 | WNDCLASS window_class{};
74 | window_class.hCursor = LoadCursor(nullptr, IDC_ARROW);
75 | window_class.lpszClassName = kWindowClassName;
76 | window_class.style = CS_HREDRAW | CS_VREDRAW;
77 | window_class.cbClsExtra = 0;
78 | window_class.cbWndExtra = 0;
79 | window_class.hInstance = GetModuleHandle(nullptr);
80 | window_class.hIcon =
81 | LoadIcon(window_class.hInstance, MAKEINTRESOURCE(IDI_APP_ICON));
82 | window_class.hbrBackground = 0;
83 | window_class.lpszMenuName = nullptr;
84 | window_class.lpfnWndProc = Win32Window::WndProc;
85 | RegisterClass(&window_class);
86 | class_registered_ = true;
87 | }
88 | return kWindowClassName;
89 | }
90 |
91 | void WindowClassRegistrar::UnregisterWindowClass() {
92 | UnregisterClass(kWindowClassName, nullptr);
93 | class_registered_ = false;
94 | }
95 |
96 | Win32Window::Win32Window() {
97 | ++g_active_window_count;
98 | }
99 |
100 | Win32Window::~Win32Window() {
101 | --g_active_window_count;
102 | Destroy();
103 | }
104 |
105 | bool Win32Window::CreateAndShow(const std::wstring& title,
106 | const Point& origin,
107 | const Size& size) {
108 | Destroy();
109 |
110 | const wchar_t* window_class =
111 | WindowClassRegistrar::GetInstance()->GetWindowClass();
112 |
113 | const POINT target_point = {static_cast(origin.x),
114 | static_cast(origin.y)};
115 | HMONITOR monitor = MonitorFromPoint(target_point, MONITOR_DEFAULTTONEAREST);
116 | UINT dpi = FlutterDesktopGetDpiForMonitor(monitor);
117 | double scale_factor = dpi / 96.0;
118 |
119 | HWND window = CreateWindow(
120 | window_class, title.c_str(), WS_OVERLAPPEDWINDOW | WS_VISIBLE,
121 | Scale(origin.x, scale_factor), Scale(origin.y, scale_factor),
122 | Scale(size.width, scale_factor), Scale(size.height, scale_factor),
123 | nullptr, nullptr, GetModuleHandle(nullptr), this);
124 |
125 | if (!window) {
126 | return false;
127 | }
128 |
129 | return OnCreate();
130 | }
131 |
132 | // static
133 | LRESULT CALLBACK Win32Window::WndProc(HWND const window,
134 | UINT const message,
135 | WPARAM const wparam,
136 | LPARAM const lparam) noexcept {
137 | if (message == WM_NCCREATE) {
138 | auto window_struct = reinterpret_cast(lparam);
139 | SetWindowLongPtr(window, GWLP_USERDATA,
140 | reinterpret_cast(window_struct->lpCreateParams));
141 |
142 | auto that = static_cast(window_struct->lpCreateParams);
143 | EnableFullDpiSupportIfAvailable(window);
144 | that->window_handle_ = window;
145 | } else if (Win32Window* that = GetThisFromHandle(window)) {
146 | return that->MessageHandler(window, message, wparam, lparam);
147 | }
148 |
149 | return DefWindowProc(window, message, wparam, lparam);
150 | }
151 |
152 | LRESULT
153 | Win32Window::MessageHandler(HWND hwnd,
154 | UINT const message,
155 | WPARAM const wparam,
156 | LPARAM const lparam) noexcept {
157 | switch (message) {
158 | case WM_DESTROY:
159 | window_handle_ = nullptr;
160 | Destroy();
161 | if (quit_on_close_) {
162 | PostQuitMessage(0);
163 | }
164 | return 0;
165 |
166 | case WM_DPICHANGED: {
167 | auto newRectSize = reinterpret_cast(lparam);
168 | LONG newWidth = newRectSize->right - newRectSize->left;
169 | LONG newHeight = newRectSize->bottom - newRectSize->top;
170 |
171 | SetWindowPos(hwnd, nullptr, newRectSize->left, newRectSize->top, newWidth,
172 | newHeight, SWP_NOZORDER | SWP_NOACTIVATE);
173 |
174 | return 0;
175 | }
176 | case WM_SIZE: {
177 | RECT rect = GetClientArea();
178 | if (child_content_ != nullptr) {
179 | // Size and position the child window.
180 | MoveWindow(child_content_, rect.left, rect.top, rect.right - rect.left,
181 | rect.bottom - rect.top, TRUE);
182 | }
183 | return 0;
184 | }
185 |
186 | case WM_ACTIVATE:
187 | if (child_content_ != nullptr) {
188 | SetFocus(child_content_);
189 | }
190 | return 0;
191 | }
192 |
193 | return DefWindowProc(window_handle_, message, wparam, lparam);
194 | }
195 |
196 | void Win32Window::Destroy() {
197 | OnDestroy();
198 |
199 | if (window_handle_) {
200 | DestroyWindow(window_handle_);
201 | window_handle_ = nullptr;
202 | }
203 | if (g_active_window_count == 0) {
204 | WindowClassRegistrar::GetInstance()->UnregisterWindowClass();
205 | }
206 | }
207 |
208 | Win32Window* Win32Window::GetThisFromHandle(HWND const window) noexcept {
209 | return reinterpret_cast(
210 | GetWindowLongPtr(window, GWLP_USERDATA));
211 | }
212 |
213 | void Win32Window::SetChildContent(HWND content) {
214 | child_content_ = content;
215 | SetParent(content, window_handle_);
216 | RECT frame = GetClientArea();
217 |
218 | MoveWindow(content, frame.left, frame.top, frame.right - frame.left,
219 | frame.bottom - frame.top, true);
220 |
221 | SetFocus(child_content_);
222 | }
223 |
224 | RECT Win32Window::GetClientArea() {
225 | RECT frame;
226 | GetClientRect(window_handle_, &frame);
227 | return frame;
228 | }
229 |
230 | HWND Win32Window::GetHandle() {
231 | return window_handle_;
232 | }
233 |
234 | void Win32Window::SetQuitOnClose(bool quit_on_close) {
235 | quit_on_close_ = quit_on_close;
236 | }
237 |
238 | bool Win32Window::OnCreate() {
239 | // No-op; provided for subclasses.
240 | return true;
241 | }
242 |
243 | void Win32Window::OnDestroy() {
244 | // No-op; provided for subclasses.
245 | }
246 |
--------------------------------------------------------------------------------
/example/windows/runner/win32_window.h:
--------------------------------------------------------------------------------
1 | #ifndef RUNNER_WIN32_WINDOW_H_
2 | #define RUNNER_WIN32_WINDOW_H_
3 |
4 | #include
5 |
6 | #include
7 | #include
8 | #include
9 |
10 | // A class abstraction for a high DPI-aware Win32 Window. Intended to be
11 | // inherited from by classes that wish to specialize with custom
12 | // rendering and input handling
13 | class Win32Window {
14 | public:
15 | struct Point {
16 | unsigned int x;
17 | unsigned int y;
18 | Point(unsigned int x, unsigned int y) : x(x), y(y) {}
19 | };
20 |
21 | struct Size {
22 | unsigned int width;
23 | unsigned int height;
24 | Size(unsigned int width, unsigned int height)
25 | : width(width), height(height) {}
26 | };
27 |
28 | Win32Window();
29 | virtual ~Win32Window();
30 |
31 | // Creates and shows a win32 window with |title| and position and size using
32 | // |origin| and |size|. New windows are created on the default monitor. Window
33 | // sizes are specified to the OS in physical pixels, hence to ensure a
34 | // consistent size to will treat the width height passed in to this function
35 | // as logical pixels and scale to appropriate for the default monitor. Returns
36 | // true if the window was created successfully.
37 | bool CreateAndShow(const std::wstring& title,
38 | const Point& origin,
39 | const Size& size);
40 |
41 | // Release OS resources associated with window.
42 | void Destroy();
43 |
44 | // Inserts |content| into the window tree.
45 | void SetChildContent(HWND content);
46 |
47 | // Returns the backing Window handle to enable clients to set icon and other
48 | // window properties. Returns nullptr if the window has been destroyed.
49 | HWND GetHandle();
50 |
51 | // If true, closing this window will quit the application.
52 | void SetQuitOnClose(bool quit_on_close);
53 |
54 | // Return a RECT representing the bounds of the current client area.
55 | RECT GetClientArea();
56 |
57 | protected:
58 | // Processes and route salient window messages for mouse handling,
59 | // size change and DPI. Delegates handling of these to member overloads that
60 | // inheriting classes can handle.
61 | virtual LRESULT MessageHandler(HWND window,
62 | UINT const message,
63 | WPARAM const wparam,
64 | LPARAM const lparam) noexcept;
65 |
66 | // Called when CreateAndShow is called, allowing subclass window-related
67 | // setup. Subclasses should return false if setup fails.
68 | virtual bool OnCreate();
69 |
70 | // Called when Destroy is called.
71 | virtual void OnDestroy();
72 |
73 | private:
74 | friend class WindowClassRegistrar;
75 |
76 | // OS callback called by message pump. Handles the WM_NCCREATE message which
77 | // is passed when the non-client area is being created and enables automatic
78 | // non-client DPI scaling so that the non-client area automatically
79 | // responsponds to changes in DPI. All other messages are handled by
80 | // MessageHandler.
81 | static LRESULT CALLBACK WndProc(HWND const window,
82 | UINT const message,
83 | WPARAM const wparam,
84 | LPARAM const lparam) noexcept;
85 |
86 | // Retrieves a class instance pointer for |window|
87 | static Win32Window* GetThisFromHandle(HWND const window) noexcept;
88 |
89 | bool quit_on_close_ = false;
90 |
91 | // window handle for top level window.
92 | HWND window_handle_ = nullptr;
93 |
94 | // window handle for hosted content.
95 | HWND child_content_ = nullptr;
96 | };
97 |
98 | #endif // RUNNER_WIN32_WINDOW_H_
99 |
--------------------------------------------------------------------------------
/headers/discord_register.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #if defined(DISCORD_DYNAMIC_LIB)
4 | #if defined(_WIN32)
5 | #if defined(DISCORD_BUILDING_SDK)
6 | #define DISCORD_EXPORT __declspec(dllexport)
7 | #else
8 | #define DISCORD_EXPORT __declspec(dllimport)
9 | #endif
10 | #else
11 | #define DISCORD_EXPORT __attribute__((visibility("default")))
12 | #endif
13 | #else
14 | #define DISCORD_EXPORT
15 | #endif
16 |
17 | #ifdef __cplusplus
18 | extern "C" {
19 | #endif
20 |
21 | DISCORD_EXPORT void Discord_Register(const char* applicationId,
22 | const char* command);
23 | DISCORD_EXPORT void Discord_RegisterSteamGame(const char* applicationId,
24 | const char* steamId);
25 |
26 | #ifdef __cplusplus
27 | }
28 | #endif
29 |
--------------------------------------------------------------------------------
/headers/discord_rpc.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include
3 |
4 | // clang-format off
5 |
6 | #if defined(DISCORD_DYNAMIC_LIB)
7 | # if defined(_WIN32)
8 | # if defined(DISCORD_BUILDING_SDK)
9 | # define DISCORD_EXPORT __declspec(dllexport)
10 | # else
11 | # define DISCORD_EXPORT __declspec(dllimport)
12 | # endif
13 | # else
14 | # define DISCORD_EXPORT __attribute__((visibility("default")))
15 | # endif
16 | #else
17 | # define DISCORD_EXPORT
18 | #endif
19 |
20 | // clang-format on
21 |
22 | #ifdef __cplusplus
23 | extern "C" {
24 | #endif
25 |
26 | typedef struct DiscordRichPresence {
27 | const char* state; /* max 128 bytes */
28 | const char* details; /* max 128 bytes */
29 | int64_t startTimestamp;
30 | int64_t endTimestamp;
31 | const char* largeImageKey; /* max 32 bytes */
32 | const char* largeImageText; /* max 128 bytes */
33 | const char* smallImageKey; /* max 32 bytes */
34 | const char* smallImageText; /* max 128 bytes */
35 | const char* partyId; /* max 128 bytes */
36 | int partySize;
37 | int partyMax;
38 | const char* matchSecret; /* max 128 bytes */
39 | const char* joinSecret; /* max 128 bytes */
40 | const char* spectateSecret; /* max 128 bytes */
41 | int8_t instance;
42 | } DiscordRichPresence;
43 |
44 | typedef struct DiscordUser {
45 | const char* userId;
46 | const char* username;
47 | const char* discriminator;
48 | const char* avatar;
49 | } DiscordUser;
50 |
51 | typedef struct DiscordEventHandlers {
52 | void (*ready)(const DiscordUser* request);
53 | void (*disconnected)(int errorCode, const char* message);
54 | void (*errored)(int errorCode, const char* message);
55 | void (*joinGame)(const char* joinSecret);
56 | void (*spectateGame)(const char* spectateSecret);
57 | void (*joinRequest)(const DiscordUser* request);
58 | } DiscordEventHandlers;
59 |
60 | #define DISCORD_REPLY_NO 0
61 | #define DISCORD_REPLY_YES 1
62 | #define DISCORD_REPLY_IGNORE 2
63 |
64 | DISCORD_EXPORT void Discord_Initialize(const char* applicationId,
65 | DiscordEventHandlers* handlers,
66 | int autoRegister,
67 | const char* optionalSteamId);
68 | DISCORD_EXPORT void Discord_Shutdown(void);
69 |
70 | /* checks for incoming messages, dispatches callbacks */
71 | DISCORD_EXPORT void Discord_RunCallbacks(void);
72 |
73 | /* If you disable the lib starting its own io thread, you'll need to call this
74 | * from your own */
75 | #ifdef DISCORD_DISABLE_IO_THREAD
76 | DISCORD_EXPORT void Discord_UpdateConnection(void);
77 | #endif
78 |
79 | DISCORD_EXPORT void Discord_UpdatePresence(const DiscordRichPresence* presence);
80 | DISCORD_EXPORT void Discord_ClearPresence(void);
81 |
82 | DISCORD_EXPORT void Discord_Respond(const char* userid,
83 | /* DISCORD_REPLY_ */ int reply);
84 |
85 | DISCORD_EXPORT void Discord_UpdateHandlers(DiscordEventHandlers* handlers);
86 |
87 | #ifdef __cplusplus
88 | } /* extern "C" */
89 | #endif
90 |
--------------------------------------------------------------------------------
/image.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alexmercerind/dart_discord_rpc/1eeb6360342327f86b36642412e915fe714641fc/image.png
--------------------------------------------------------------------------------
/lib/dart_discord_rpc.dart:
--------------------------------------------------------------------------------
1 | // Model does not depend on native libraries, so it can be exported as-is.
2 | export 'model/discord_presence.dart';
3 |
4 | // Use stub if native Discord RPC is not supported.
5 | export 'dart_discord_rpc_stub.dart'
6 | if (dart.library.io) 'dart_discord_rpc_native.dart';
7 |
--------------------------------------------------------------------------------
/lib/dart_discord_rpc_native.dart:
--------------------------------------------------------------------------------
1 | import 'dart:io';
2 | import 'dart:ffi';
3 | import 'package:ffi/ffi.dart';
4 | import 'package:path/path.dart';
5 | import 'model/discord_presence.dart';
6 | import 'generated/bindings.dart' as bindings;
7 |
8 | DynamicLibrary? _dynamicLibrary;
9 |
10 | /// ## Discord Rich Presence for Dart & Flutter.
11 | ///
12 | /// For integrating Discord Rich Presence into your application or game, you must create an
13 | /// application at [Discord Developer Portal](https://discord.com/developers/applications).
14 | ///
15 | /// Initialize the plugin.
16 | /// ```dart
17 | /// void main() {
18 | /// DiscordRPC.initialize();
19 | /// runApp(MyApp());
20 | /// }
21 | /// ```
22 | ///
23 | /// Example
24 | ///
25 | /// ```dart
26 | /// var rpc = DiscordRPC(
27 | /// applicationId: '877853131025809438',
28 | /// );
29 | /// rpc.start(autoRegister: true);
30 | /// rpc.updatePresence(
31 | /// DiscordPresence(
32 | /// state: 'Discord Rich Presence from Dart. 🎯',
33 | /// details: 'github.com/alexmercerind/dart_discord_rpc',
34 | /// startTimeStamp: DateTime.now().millisecondsSinceEpoch,
35 | /// largeImageKey: 'large_image',
36 | /// largeImageText: 'This text describes the large image.',
37 | /// smallImageKey: 'small_image',
38 | /// smallImageText: 'This text describes the small image.',
39 | /// ),
40 | /// );
41 | /// ```
42 | ///
43 | class DiscordRPC {
44 | /// ID of your application at Discord Developer Portal.
45 | final String applicationId;
46 |
47 | /// Steam ID.
48 | final String? steamId;
49 |
50 | late bindings.DiscordRPC _bindings;
51 |
52 | DiscordRPC({required this.applicationId, this.steamId}) {
53 | final library = _dynamicLibrary;
54 | if (library == null) {
55 | throw Exception(
56 | "Discord RPC has not been initialized! Please run 'DiscordRPC.initialize()'.",
57 | );
58 | }
59 | _bindings = bindings.DiscordRPC(library);
60 | }
61 |
62 | /// Registers the rich presence client.
63 | void register(String command) {
64 | _bindings.Discord_Register(
65 | applicationId.toNativeUtf8().cast(),
66 | command.toNativeUtf8().cast(),
67 | );
68 | }
69 |
70 | /// Registers the steam game.
71 | void registerSteamGame() {
72 | _bindings.Discord_RegisterSteamGame(
73 | applicationId.toNativeUtf8().cast(),
74 | (steamId ?? '').toNativeUtf8().cast(),
75 | );
76 | }
77 |
78 | /// Starts the Discord Rich Presence.
79 | void start({bool autoRegister = false}) {
80 | _bindings.Discord_Initialize(
81 | applicationId.toNativeUtf8().cast(),
82 | calloc(),
83 | autoRegister == false ? 0 : 1,
84 | (steamId ?? '').toNativeUtf8().cast(),
85 | );
86 | }
87 |
88 | /// Updates the presence of the [DiscordUser], takes [DiscordPresence] as argument.
89 | /// Describing current user presence inside the application or game.
90 | ///
91 | /// For showing the user's start time from present, you must pass [DiscordPresence.startTimeStamp] as `DateTime.now().millisecondsSinceEpoch`.
92 | ///
93 | void updatePresence(DiscordPresence presence) {
94 | var presencePtr = calloc();
95 | presencePtr.ref.state = (presence.state ?? '').toNativeUtf8().cast();
96 | presencePtr.ref.details =
97 | (presence.details ?? '').toNativeUtf8().cast();
98 | presencePtr.ref.startTimestamp = presence.startTimeStamp ?? 0;
99 | presencePtr.ref.endTimestamp = presence.endTimeStamp ?? 0;
100 | presencePtr.ref.largeImageKey =
101 | (presence.largeImageKey ?? '').toNativeUtf8().cast();
102 | presencePtr.ref.largeImageText =
103 | (presence.largeImageText ?? '').toNativeUtf8().cast();
104 | presencePtr.ref.smallImageKey =
105 | (presence.smallImageKey ?? '').toNativeUtf8().cast();
106 | presencePtr.ref.smallImageText =
107 | (presence.smallImageText ?? '').toNativeUtf8().cast();
108 | presencePtr.ref.partySize = presence.partySize ?? 0;
109 | presencePtr.ref.matchSecret =
110 | (presence.matchSecret ?? '').toNativeUtf8().cast();
111 | presencePtr.ref.joinSecret =
112 | (presence.joinSecret ?? '').toNativeUtf8().cast();
113 | presencePtr.ref.spectateSecret =
114 | (presence.spectateSecret ?? '').toNativeUtf8().cast();
115 | presencePtr.ref.instance = presence.instance ?? 0;
116 | _bindings.Discord_UpdatePresence(presencePtr);
117 | calloc.free(presencePtr);
118 | }
119 |
120 | /// Shuts down the Discord RPC.
121 | void shutDown() {
122 | _bindings.Discord_Shutdown();
123 | }
124 |
125 | /// Clears the previously set [DiscordPresence] for the user.
126 | void clearPresence() {
127 | _bindings.Discord_ClearPresence();
128 | }
129 |
130 | /// Responds to the user.
131 | void respond(String userId, int reply) {
132 | _bindings.Discord_Respond(
133 | userId.toNativeUtf8().cast(),
134 | reply,
135 | );
136 | }
137 |
138 | /// Initializes the plugin.
139 | ///
140 | /// ```dart
141 | /// void main() {
142 | /// DiscordRPC.initialize();
143 | /// runApp(MyApp());
144 | /// }
145 | /// ```
146 | ///
147 | static void initialize() {
148 | if (_dynamicLibrary != null) {
149 | throw Exception("DiscordRPC has already been initialized.");
150 | }
151 | if (Platform.isLinux) {
152 | _dynamicLibrary = DynamicLibrary.open(
153 | join(
154 | dirname(Platform.resolvedExecutable),
155 | 'lib',
156 | 'libdiscord-rpc.so',
157 | ),
158 | );
159 | } else if (Platform.isWindows) {
160 | _dynamicLibrary = DynamicLibrary.open(
161 | join(
162 | dirname(Platform.resolvedExecutable),
163 | 'discord-rpc.dll',
164 | ),
165 | );
166 | } else {
167 | throw Exception(
168 | "Unsupported DiscordRPC platform: '${Platform.operatingSystem}'.",
169 | );
170 | }
171 | }
172 | }
173 |
--------------------------------------------------------------------------------
/lib/dart_discord_rpc_stub.dart:
--------------------------------------------------------------------------------
1 | import 'model/discord_presence.dart';
2 |
3 | // Stub implementation for unsupported platforms.
4 | // This prevents errors when compiling for web.
5 | class DiscordRPC {
6 | DiscordRPC({
7 | required String applicationId,
8 | String? steamId,
9 | });
10 |
11 | void register(String command) {}
12 | void registerSteamGame() {}
13 | void start({bool autoRegister = false}) {}
14 | void updatePresence(DiscordPresence presence) {}
15 | void shutDown() {}
16 | void clearPresence() {}
17 | void respond(String userId, int reply) {}
18 | static void initialize() {}
19 | }
20 |
--------------------------------------------------------------------------------
/lib/generated/bindings.dart:
--------------------------------------------------------------------------------
1 | // AUTO GENERATED FILE, DO NOT EDIT.
2 | //
3 | // Generated by `package:ffigen`.
4 | // ignore_for_file: type=lint
5 | import 'dart:ffi' as ffi;
6 |
7 | /// Dart bindings to Discord RPC client.
8 | class DiscordRPC {
9 | /// Holds the symbol lookup function.
10 | final ffi.Pointer Function(String symbolName)
11 | _lookup;
12 |
13 | /// The symbols are looked up in [dynamicLibrary].
14 | DiscordRPC(ffi.DynamicLibrary dynamicLibrary)
15 | : _lookup = dynamicLibrary.lookup;
16 |
17 | /// The symbols are looked up with [lookup].
18 | DiscordRPC.fromLookup(
19 | ffi.Pointer Function(String symbolName)
20 | lookup)
21 | : _lookup = lookup;
22 |
23 | void Discord_Register(
24 | ffi.Pointer applicationId,
25 | ffi.Pointer command,
26 | ) {
27 | return _Discord_Register(
28 | applicationId,
29 | command,
30 | );
31 | }
32 |
33 | late final _Discord_RegisterPtr = _lookup<
34 | ffi.NativeFunction<
35 | ffi.Void Function(ffi.Pointer,
36 | ffi.Pointer)>>('Discord_Register');
37 | late final _Discord_Register = _Discord_RegisterPtr.asFunction<
38 | void Function(ffi.Pointer, ffi.Pointer)>();
39 |
40 | void Discord_RegisterSteamGame(
41 | ffi.Pointer applicationId,
42 | ffi.Pointer steamId,
43 | ) {
44 | return _Discord_RegisterSteamGame(
45 | applicationId,
46 | steamId,
47 | );
48 | }
49 |
50 | late final _Discord_RegisterSteamGamePtr = _lookup<
51 | ffi.NativeFunction<
52 | ffi.Void Function(ffi.Pointer,
53 | ffi.Pointer)>>('Discord_RegisterSteamGame');
54 | late final _Discord_RegisterSteamGame =
55 | _Discord_RegisterSteamGamePtr.asFunction<
56 | void Function(ffi.Pointer, ffi.Pointer)>();
57 |
58 | void __va_start(
59 | ffi.Pointer arg0,
60 | ) {
61 | return ___va_start(
62 | arg0,
63 | );
64 | }
65 |
66 | late final ___va_startPtr =
67 | _lookup)>>(
68 | '__va_start');
69 | late final ___va_start =
70 | ___va_startPtr.asFunction)>();
71 |
72 | void __security_init_cookie() {
73 | return ___security_init_cookie();
74 | }
75 |
76 | late final ___security_init_cookiePtr =
77 | _lookup>(
78 | '__security_init_cookie');
79 | late final ___security_init_cookie =
80 | ___security_init_cookiePtr.asFunction();
81 |
82 | void __security_check_cookie(
83 | int _StackCookie,
84 | ) {
85 | return ___security_check_cookie(
86 | _StackCookie,
87 | );
88 | }
89 |
90 | late final ___security_check_cookiePtr =
91 | _lookup>(
92 | '__security_check_cookie');
93 | late final ___security_check_cookie =
94 | ___security_check_cookiePtr.asFunction();
95 |
96 | void __report_gsfailure(
97 | int _StackCookie,
98 | ) {
99 | return ___report_gsfailure(
100 | _StackCookie,
101 | );
102 | }
103 |
104 | late final ___report_gsfailurePtr =
105 | _lookup>(
106 | '__report_gsfailure');
107 | late final ___report_gsfailure =
108 | ___report_gsfailurePtr.asFunction();
109 |
110 | late final ffi.Pointer ___security_cookie =
111 | _lookup('__security_cookie');
112 |
113 | int get __security_cookie => ___security_cookie.value;
114 |
115 | set __security_cookie(int value) => ___security_cookie.value = value;
116 |
117 | void Discord_Initialize(
118 | ffi.Pointer applicationId,
119 | ffi.Pointer handlers,
120 | int autoRegister,
121 | ffi.Pointer optionalSteamId,
122 | ) {
123 | return _Discord_Initialize(
124 | applicationId,
125 | handlers,
126 | autoRegister,
127 | optionalSteamId,
128 | );
129 | }
130 |
131 | late final _Discord_InitializePtr = _lookup<
132 | ffi.NativeFunction<
133 | ffi.Void Function(
134 | ffi.Pointer,
135 | ffi.Pointer,
136 | ffi.Int,
137 | ffi.Pointer)>>('Discord_Initialize');
138 | late final _Discord_Initialize = _Discord_InitializePtr.asFunction<
139 | void Function(ffi.Pointer, ffi.Pointer,
140 | int, ffi.Pointer)>();
141 |
142 | void Discord_Shutdown() {
143 | return _Discord_Shutdown();
144 | }
145 |
146 | late final _Discord_ShutdownPtr =
147 | _lookup>('Discord_Shutdown');
148 | late final _Discord_Shutdown =
149 | _Discord_ShutdownPtr.asFunction();
150 |
151 | void Discord_RunCallbacks() {
152 | return _Discord_RunCallbacks();
153 | }
154 |
155 | late final _Discord_RunCallbacksPtr =
156 | _lookup>('Discord_RunCallbacks');
157 | late final _Discord_RunCallbacks =
158 | _Discord_RunCallbacksPtr.asFunction();
159 |
160 | void Discord_UpdatePresence(
161 | ffi.Pointer presence,
162 | ) {
163 | return _Discord_UpdatePresence(
164 | presence,
165 | );
166 | }
167 |
168 | late final _Discord_UpdatePresencePtr = _lookup<
169 | ffi.NativeFunction<
170 | ffi.Void Function(
171 | ffi.Pointer)>>('Discord_UpdatePresence');
172 | late final _Discord_UpdatePresence = _Discord_UpdatePresencePtr.asFunction<
173 | void Function(ffi.Pointer)>();
174 |
175 | void Discord_ClearPresence() {
176 | return _Discord_ClearPresence();
177 | }
178 |
179 | late final _Discord_ClearPresencePtr =
180 | _lookup>('Discord_ClearPresence');
181 | late final _Discord_ClearPresence =
182 | _Discord_ClearPresencePtr.asFunction();
183 |
184 | void Discord_Respond(
185 | ffi.Pointer userid,
186 | int reply,
187 | ) {
188 | return _Discord_Respond(
189 | userid,
190 | reply,
191 | );
192 | }
193 |
194 | late final _Discord_RespondPtr = _lookup<
195 | ffi.NativeFunction<
196 | ffi.Void Function(
197 | ffi.Pointer, ffi.Int)>>('Discord_Respond');
198 | late final _Discord_Respond = _Discord_RespondPtr.asFunction<
199 | void Function(ffi.Pointer, int)>();
200 |
201 | void Discord_UpdateHandlers(
202 | ffi.Pointer handlers,
203 | ) {
204 | return _Discord_UpdateHandlers(
205 | handlers,
206 | );
207 | }
208 |
209 | late final _Discord_UpdateHandlersPtr = _lookup<
210 | ffi.NativeFunction<
211 | ffi.Void Function(
212 | ffi.Pointer)>>('Discord_UpdateHandlers');
213 | late final _Discord_UpdateHandlers = _Discord_UpdateHandlersPtr.asFunction<
214 | void Function(ffi.Pointer)>();
215 | }
216 |
217 | typedef va_list = ffi.Pointer;
218 |
219 | class DiscordRichPresence extends ffi.Struct {
220 | external ffi.Pointer state;
221 |
222 | external ffi.Pointer details;
223 |
224 | @ffi.Int64()
225 | external int startTimestamp;
226 |
227 | @ffi.Int64()
228 | external int endTimestamp;
229 |
230 | external ffi.Pointer largeImageKey;
231 |
232 | external ffi.Pointer largeImageText;
233 |
234 | external ffi.Pointer smallImageKey;
235 |
236 | external ffi.Pointer smallImageText;
237 |
238 | external ffi.Pointer partyId;
239 |
240 | @ffi.Int()
241 | external int partySize;
242 |
243 | @ffi.Int()
244 | external int partyMax;
245 |
246 | external ffi.Pointer matchSecret;
247 |
248 | external ffi.Pointer joinSecret;
249 |
250 | external ffi.Pointer spectateSecret;
251 |
252 | @ffi.Int8()
253 | external int instance;
254 | }
255 |
256 | class DiscordUser extends ffi.Struct {
257 | external ffi.Pointer userId;
258 |
259 | external ffi.Pointer username;
260 |
261 | external ffi.Pointer discriminator;
262 |
263 | external ffi.Pointer avatar;
264 | }
265 |
266 | class DiscordEventHandlers extends ffi.Struct {
267 | external ffi.Pointer<
268 | ffi.NativeFunction<
269 | ffi.Void Function(ffi.Pointer request)>> ready;
270 |
271 | external ffi.Pointer<
272 | ffi.NativeFunction<
273 | ffi.Void Function(
274 | ffi.Int errorCode, ffi.Pointer message)>> disconnected;
275 |
276 | external ffi.Pointer<
277 | ffi.NativeFunction<
278 | ffi.Void Function(
279 | ffi.Int errorCode, ffi.Pointer message)>> errored;
280 |
281 | external ffi.Pointer<
282 | ffi.NativeFunction<
283 | ffi.Void Function(ffi.Pointer joinSecret)>> joinGame;
284 |
285 | external ffi.Pointer<
286 | ffi.NativeFunction<
287 | ffi.Void Function(ffi.Pointer spectateSecret)>>
288 | spectateGame;
289 |
290 | external ffi.Pointer<
291 | ffi.NativeFunction<
292 | ffi.Void Function(ffi.Pointer request)>> joinRequest;
293 | }
294 |
295 | const int _VCRT_COMPILER_PREPROCESSOR = 1;
296 |
297 | const int _SAL_VERSION = 20;
298 |
299 | const int __SAL_H_VERSION = 180000000;
300 |
301 | const int _USE_DECLSPECS_FOR_SAL = 0;
302 |
303 | const int _USE_ATTRIBUTES_FOR_SAL = 0;
304 |
305 | const int _CRT_PACKING = 8;
306 |
307 | const int _VCRUNTIME_DISABLED_WARNINGS = 4514;
308 |
309 | const int _HAS_EXCEPTIONS = 1;
310 |
311 | const int _WCHAR_T_DEFINED = 1;
312 |
313 | const int NULL = 0;
314 |
315 | const int _HAS_CXX17 = 0;
316 |
317 | const int _HAS_CXX20 = 0;
318 |
319 | const int _HAS_CXX23 = 0;
320 |
321 | const int _HAS_NODISCARD = 1;
322 |
323 | const int INT8_MIN = -128;
324 |
325 | const int INT16_MIN = -32768;
326 |
327 | const int INT32_MIN = -2147483648;
328 |
329 | const int INT64_MIN = -9223372036854775808;
330 |
331 | const int INT8_MAX = 127;
332 |
333 | const int INT16_MAX = 32767;
334 |
335 | const int INT32_MAX = 2147483647;
336 |
337 | const int INT64_MAX = 9223372036854775807;
338 |
339 | const int UINT8_MAX = 255;
340 |
341 | const int UINT16_MAX = 65535;
342 |
343 | const int UINT32_MAX = 4294967295;
344 |
345 | const int UINT64_MAX = -1;
346 |
347 | const int INT_LEAST8_MIN = -128;
348 |
349 | const int INT_LEAST16_MIN = -32768;
350 |
351 | const int INT_LEAST32_MIN = -2147483648;
352 |
353 | const int INT_LEAST64_MIN = -9223372036854775808;
354 |
355 | const int INT_LEAST8_MAX = 127;
356 |
357 | const int INT_LEAST16_MAX = 32767;
358 |
359 | const int INT_LEAST32_MAX = 2147483647;
360 |
361 | const int INT_LEAST64_MAX = 9223372036854775807;
362 |
363 | const int UINT_LEAST8_MAX = 255;
364 |
365 | const int UINT_LEAST16_MAX = 65535;
366 |
367 | const int UINT_LEAST32_MAX = 4294967295;
368 |
369 | const int UINT_LEAST64_MAX = -1;
370 |
371 | const int INT_FAST8_MIN = -128;
372 |
373 | const int INT_FAST16_MIN = -2147483648;
374 |
375 | const int INT_FAST32_MIN = -2147483648;
376 |
377 | const int INT_FAST64_MIN = -9223372036854775808;
378 |
379 | const int INT_FAST8_MAX = 127;
380 |
381 | const int INT_FAST16_MAX = 2147483647;
382 |
383 | const int INT_FAST32_MAX = 2147483647;
384 |
385 | const int INT_FAST64_MAX = 9223372036854775807;
386 |
387 | const int UINT_FAST8_MAX = 255;
388 |
389 | const int UINT_FAST16_MAX = 4294967295;
390 |
391 | const int UINT_FAST32_MAX = 4294967295;
392 |
393 | const int UINT_FAST64_MAX = -1;
394 |
395 | const int INTPTR_MIN = -9223372036854775808;
396 |
397 | const int INTPTR_MAX = 9223372036854775807;
398 |
399 | const int UINTPTR_MAX = -1;
400 |
401 | const int INTMAX_MIN = -9223372036854775808;
402 |
403 | const int INTMAX_MAX = 9223372036854775807;
404 |
405 | const int UINTMAX_MAX = -1;
406 |
407 | const int PTRDIFF_MIN = -9223372036854775808;
408 |
409 | const int PTRDIFF_MAX = 9223372036854775807;
410 |
411 | const int SIZE_MAX = -1;
412 |
413 | const int SIG_ATOMIC_MIN = -2147483648;
414 |
415 | const int SIG_ATOMIC_MAX = 2147483647;
416 |
417 | const int WCHAR_MIN = 0;
418 |
419 | const int WCHAR_MAX = 65535;
420 |
421 | const int WINT_MIN = 0;
422 |
423 | const int WINT_MAX = 65535;
424 |
425 | const int DISCORD_REPLY_NO = 0;
426 |
427 | const int DISCORD_REPLY_YES = 1;
428 |
429 | const int DISCORD_REPLY_IGNORE = 2;
430 |
--------------------------------------------------------------------------------
/lib/model/discord_presence.dart:
--------------------------------------------------------------------------------
1 | /// Declares the presence of the user.
2 | /// To update the [DiscordUser] presence, pass the object of this class to [DiscordRPC.updatePresence].
3 | ///
4 | /// For showing the user's start time from present, you must pass [DiscordPresence.startTimeStamp] as `DateTime.now().millisecondsSinceEpoch`.
5 | class DiscordPresence {
6 | /// State of the current presence.
7 | final String? state;
8 |
9 | /// Details about current presence.
10 | final String? details;
11 |
12 | /// Start time stamp. Used to show how much time has passed.
13 | final int? startTimeStamp;
14 |
15 | /// End time stamp. Used to show how much time is left.
16 | final int? endTimeStamp;
17 |
18 | /// Key of the large image from Discord Developer Portal, to show inside Discord Rich Presence.
19 | final String? largeImageKey;
20 |
21 | /// String describing the large image.
22 | final String? largeImageText;
23 |
24 | /// Key of the small image from Discord Developer Portal, to show inside Discord Rich Presence.
25 | final String? smallImageKey;
26 |
27 | /// String describing the small image.
28 | final String? smallImageText;
29 |
30 | /// Party ID.
31 | final String? partyId;
32 |
33 | /// Size of the party.
34 | final int? partySize;
35 |
36 | /// Maximum size of the party.
37 | final int? partySizeMax;
38 |
39 | /// Match secret.
40 | final String? matchSecret;
41 |
42 | /// Join secret.
43 | final String? joinSecret;
44 |
45 | /// Spectate secret.
46 | final String? spectateSecret;
47 |
48 | /// Instance.
49 | final int? instance;
50 |
51 | DiscordPresence(
52 | {this.state,
53 | this.details,
54 | this.startTimeStamp,
55 | this.endTimeStamp,
56 | this.largeImageKey,
57 | this.largeImageText,
58 | this.smallImageKey,
59 | this.smallImageText,
60 | this.partyId,
61 | this.partySize,
62 | this.partySizeMax,
63 | this.matchSecret,
64 | this.joinSecret,
65 | this.spectateSecret,
66 | this.instance});
67 | }
68 |
--------------------------------------------------------------------------------
/linux/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.10)
2 | set(PROJECT_NAME dart_discord_rpc)
3 | project(${PROJECT_NAME} LANGUAGES CXX)
4 |
5 | set(PLUGIN_NAME dart_discord_rpc_plugin)
6 |
7 | add_library(${PLUGIN_NAME} SHARED
8 | dart_discord_rpc_plugin.cc
9 | )
10 | apply_standard_settings(${PLUGIN_NAME})
11 | set_target_properties(${PLUGIN_NAME} PROPERTIES
12 | CXX_VISIBILITY_PRESET hidden)
13 | target_compile_definitions(${PLUGIN_NAME} PRIVATE FLUTTER_PLUGIN_IMPL)
14 | target_include_directories(${PLUGIN_NAME} INTERFACE
15 | ${CMAKE_CURRENT_SOURCE_DIR}/include)
16 | target_link_libraries(${PLUGIN_NAME} PRIVATE flutter)
17 | target_link_libraries(${PLUGIN_NAME} PRIVATE PkgConfig::GTK)
18 |
19 | set(dart_discord_rpc_bundled_libraries
20 | ${CMAKE_CURRENT_SOURCE_DIR}/bin/libdiscord-rpc.so
21 | PARENT_SCOPE
22 | )
23 |
--------------------------------------------------------------------------------
/linux/bin/libdiscord-rpc.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alexmercerind/dart_discord_rpc/1eeb6360342327f86b36642412e915fe714641fc/linux/bin/libdiscord-rpc.so
--------------------------------------------------------------------------------
/linux/dart_discord_rpc_plugin.cc:
--------------------------------------------------------------------------------
1 | #include "include/dart_discord_rpc/dart_discord_rpc_plugin.h"
2 |
3 | #include
4 | #include
5 | #include
6 |
7 | #include
8 |
9 | #define DART_DISCORD_RPC_PLUGIN(obj) \
10 | (G_TYPE_CHECK_INSTANCE_CAST((obj), dart_discord_rpc_plugin_get_type(), \
11 | DartDiscordRpcPlugin))
12 |
13 | struct _DartDiscordRpcPlugin {
14 | GObject parent_instance;
15 | };
16 |
17 | G_DEFINE_TYPE(DartDiscordRpcPlugin, dart_discord_rpc_plugin,
18 | g_object_get_type())
19 |
20 | static void dart_discord_rpc_plugin_handle_method_call(
21 | DartDiscordRpcPlugin* self, FlMethodCall* method_call) {
22 | fl_method_call_respond(
23 | method_call, FL_METHOD_RESPONSE(fl_method_not_implemented_response_new()),
24 | nullptr);
25 | }
26 |
27 | static void dart_discord_rpc_plugin_dispose(GObject* object) {
28 | G_OBJECT_CLASS(dart_discord_rpc_plugin_parent_class)->dispose(object);
29 | }
30 |
31 | static void dart_discord_rpc_plugin_class_init(
32 | DartDiscordRpcPluginClass* klass) {
33 | G_OBJECT_CLASS(klass)->dispose = dart_discord_rpc_plugin_dispose;
34 | }
35 |
36 | static void dart_discord_rpc_plugin_init(DartDiscordRpcPlugin* self) {}
37 |
38 | static void method_call_cb(FlMethodChannel* channel, FlMethodCall* method_call,
39 | gpointer user_data) {
40 | DartDiscordRpcPlugin* plugin = DART_DISCORD_RPC_PLUGIN(user_data);
41 | dart_discord_rpc_plugin_handle_method_call(plugin, method_call);
42 | }
43 |
44 | void dart_discord_rpc_plugin_register_with_registrar(
45 | FlPluginRegistrar* registrar) {
46 | DartDiscordRpcPlugin* plugin = DART_DISCORD_RPC_PLUGIN(
47 | g_object_new(dart_discord_rpc_plugin_get_type(), nullptr));
48 |
49 | g_autoptr(FlStandardMethodCodec) codec = fl_standard_method_codec_new();
50 | g_autoptr(FlMethodChannel) channel =
51 | fl_method_channel_new(fl_plugin_registrar_get_messenger(registrar),
52 | "dart_discord_rpc", FL_METHOD_CODEC(codec));
53 | fl_method_channel_set_method_call_handler(
54 | channel, method_call_cb, g_object_ref(plugin), g_object_unref);
55 |
56 | g_object_unref(plugin);
57 | }
58 |
--------------------------------------------------------------------------------
/linux/include/dart_discord_rpc/dart_discord_rpc_plugin.h:
--------------------------------------------------------------------------------
1 | #ifndef FLUTTER_PLUGIN_DART_DISCORD_RPC_PLUGIN_H_
2 | #define FLUTTER_PLUGIN_DART_DISCORD_RPC_PLUGIN_H_
3 |
4 | #include
5 |
6 | G_BEGIN_DECLS
7 |
8 | #ifdef FLUTTER_PLUGIN_IMPL
9 | #define FLUTTER_PLUGIN_EXPORT __attribute__((visibility("default")))
10 | #else
11 | #define FLUTTER_PLUGIN_EXPORT
12 | #endif
13 |
14 | typedef struct _DartDiscordRpcPlugin DartDiscordRpcPlugin;
15 | typedef struct {
16 | GObjectClass parent_class;
17 | } DartDiscordRpcPluginClass;
18 |
19 | FLUTTER_PLUGIN_EXPORT GType dart_discord_rpc_plugin_get_type();
20 |
21 | FLUTTER_PLUGIN_EXPORT void dart_discord_rpc_plugin_register_with_registrar(
22 | FlPluginRegistrar* registrar);
23 |
24 | G_END_DECLS
25 |
26 | #endif // FLUTTER_PLUGIN_DART_DISCORD_RPC_PLUGIN_H_
27 |
--------------------------------------------------------------------------------
/pubspec.lock:
--------------------------------------------------------------------------------
1 | # Generated by pub
2 | # See https://dart.dev/tools/pub/glossary#lockfile
3 | packages:
4 | args:
5 | dependency: transitive
6 | description:
7 | name: args
8 | sha256: "4cab82a83ffef80b262ddedf47a0a8e56ee6fbf7fe21e6e768b02792034dd440"
9 | url: "https://pub.dev"
10 | source: hosted
11 | version: "2.4.0"
12 | async:
13 | dependency: transitive
14 | description:
15 | name: async
16 | sha256: "947bfcf187f74dbc5e146c9eb9c0f10c9f8b30743e341481c1e2ed3ecc18c20c"
17 | url: "https://pub.dev"
18 | source: hosted
19 | version: "2.11.0"
20 | boolean_selector:
21 | dependency: transitive
22 | description:
23 | name: boolean_selector
24 | sha256: "6cfb5af12253eaf2b368f07bacc5a80d1301a071c73360d746b7f2e32d762c66"
25 | url: "https://pub.dev"
26 | source: hosted
27 | version: "2.1.1"
28 | cli_util:
29 | dependency: transitive
30 | description:
31 | name: cli_util
32 | sha256: b8db3080e59b2503ca9e7922c3df2072cf13992354d5e944074ffa836fba43b7
33 | url: "https://pub.dev"
34 | source: hosted
35 | version: "0.4.0"
36 | collection:
37 | dependency: transitive
38 | description:
39 | name: collection
40 | sha256: "4a07be6cb69c84d677a6c3096fcf960cc3285a8330b4603e0d463d15d9bd934c"
41 | url: "https://pub.dev"
42 | source: hosted
43 | version: "1.17.1"
44 | ffi:
45 | dependency: "direct main"
46 | description:
47 | name: ffi
48 | sha256: a38574032c5f1dd06c4aee541789906c12ccaab8ba01446e800d9c5b79c4a978
49 | url: "https://pub.dev"
50 | source: hosted
51 | version: "2.0.1"
52 | ffigen:
53 | dependency: "direct dev"
54 | description:
55 | name: ffigen
56 | sha256: "94587f4c9699a4d0a25da95dc0b41903ddc69201d9bac3ca128ade8e67d56015"
57 | url: "https://pub.dev"
58 | source: hosted
59 | version: "7.2.10"
60 | file:
61 | dependency: transitive
62 | description:
63 | name: file
64 | sha256: "1b92bec4fc2a72f59a8e15af5f52cd441e4a7860b49499d69dfa817af20e925d"
65 | url: "https://pub.dev"
66 | source: hosted
67 | version: "6.1.4"
68 | glob:
69 | dependency: transitive
70 | description:
71 | name: glob
72 | sha256: "4515b5b6ddb505ebdd242a5f2cc5d22d3d6a80013789debfbda7777f47ea308c"
73 | url: "https://pub.dev"
74 | source: hosted
75 | version: "2.1.1"
76 | logging:
77 | dependency: transitive
78 | description:
79 | name: logging
80 | sha256: "04094f2eb032cbb06c6f6e8d3607edcfcb0455e2bb6cbc010cb01171dcb64e6d"
81 | url: "https://pub.dev"
82 | source: hosted
83 | version: "1.1.1"
84 | matcher:
85 | dependency: transitive
86 | description:
87 | name: matcher
88 | sha256: "6501fbd55da300384b768785b83e5ce66991266cec21af89ab9ae7f5ce1c4cbb"
89 | url: "https://pub.dev"
90 | source: hosted
91 | version: "0.12.15"
92 | meta:
93 | dependency: transitive
94 | description:
95 | name: meta
96 | sha256: "3c74dbf8763d36539f114c799d8a2d87343b5067e9d796ca22b5eb8437090ee3"
97 | url: "https://pub.dev"
98 | source: hosted
99 | version: "1.9.1"
100 | package_config:
101 | dependency: transitive
102 | description:
103 | name: package_config
104 | sha256: "1c5b77ccc91e4823a5af61ee74e6b972db1ef98c2ff5a18d3161c982a55448bd"
105 | url: "https://pub.dev"
106 | source: hosted
107 | version: "2.1.0"
108 | path:
109 | dependency: "direct main"
110 | description:
111 | name: path
112 | sha256: "8829d8a55c13fc0e37127c29fedf290c102f4e40ae94ada574091fe0ff96c917"
113 | url: "https://pub.dev"
114 | source: hosted
115 | version: "1.8.3"
116 | quiver:
117 | dependency: transitive
118 | description:
119 | name: quiver
120 | sha256: b1c1ac5ce6688d77f65f3375a9abb9319b3cb32486bdc7a1e0fdf004d7ba4e47
121 | url: "https://pub.dev"
122 | source: hosted
123 | version: "3.2.1"
124 | source_span:
125 | dependency: transitive
126 | description:
127 | name: source_span
128 | sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c"
129 | url: "https://pub.dev"
130 | source: hosted
131 | version: "1.10.0"
132 | stack_trace:
133 | dependency: transitive
134 | description:
135 | name: stack_trace
136 | sha256: c3c7d8edb15bee7f0f74debd4b9c5f3c2ea86766fe4178eb2a18eb30a0bdaed5
137 | url: "https://pub.dev"
138 | source: hosted
139 | version: "1.11.0"
140 | stream_channel:
141 | dependency: transitive
142 | description:
143 | name: stream_channel
144 | sha256: "83615bee9045c1d322bbbd1ba209b7a749c2cbcdcb3fdd1df8eb488b3279c1c8"
145 | url: "https://pub.dev"
146 | source: hosted
147 | version: "2.1.1"
148 | string_scanner:
149 | dependency: transitive
150 | description:
151 | name: string_scanner
152 | sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde"
153 | url: "https://pub.dev"
154 | source: hosted
155 | version: "1.2.0"
156 | term_glyph:
157 | dependency: transitive
158 | description:
159 | name: term_glyph
160 | sha256: a29248a84fbb7c79282b40b8c72a1209db169a2e0542bce341da992fe1bc7e84
161 | url: "https://pub.dev"
162 | source: hosted
163 | version: "1.2.1"
164 | test_api:
165 | dependency: transitive
166 | description:
167 | name: test_api
168 | sha256: eb6ac1540b26de412b3403a163d919ba86f6a973fe6cc50ae3541b80092fdcfb
169 | url: "https://pub.dev"
170 | source: hosted
171 | version: "0.5.1"
172 | yaml:
173 | dependency: transitive
174 | description:
175 | name: yaml
176 | sha256: "23812a9b125b48d4007117254bca50abb6c712352927eece9e155207b1db2370"
177 | url: "https://pub.dev"
178 | source: hosted
179 | version: "3.1.1"
180 | yaml_edit:
181 | dependency: transitive
182 | description:
183 | name: yaml_edit
184 | sha256: "0b968021754d8fbd3e9c83563b538ee417d88b2cc587606da5615546b7ee033b"
185 | url: "https://pub.dev"
186 | source: hosted
187 | version: "2.1.0"
188 | sdks:
189 | dart: ">=2.19.0 <3.0.0"
190 |
--------------------------------------------------------------------------------
/pubspec.yaml:
--------------------------------------------------------------------------------
1 | name: dart_discord_rpc
2 | description: Discord Rich Presence for Flutter & Dart apps & games.
3 | version: 0.0.3
4 | repository: https://github.com/alexmercerind/dart_discord_rpc
5 | homepage: https://github.com/alexmercerind/dart_discord_rpc
6 |
7 | environment:
8 | sdk: ">=2.13.0 <3.0.0"
9 |
10 | dependencies:
11 | ffi: ^2.0.1
12 | path: ^1.8.2
13 |
14 | dev_dependencies:
15 | ffigen: ^7.2.10
16 |
17 | flutter:
18 | plugin:
19 | platforms:
20 | linux:
21 | pluginClass: DartDiscordRpcPlugin
22 | windows:
23 | pluginClass: DartDiscordRpcPlugin
24 |
25 | ffigen:
26 | output: "lib/generated/bindings.dart"
27 | dart-bool: true
28 | headers:
29 | entry-points:
30 | - "headers/discord_register.h"
31 | - "headers/discord_rpc.h"
32 | name: "DiscordRPC"
33 | description: "Dart bindings to Discord RPC client."
34 |
--------------------------------------------------------------------------------
/windows/.gitignore:
--------------------------------------------------------------------------------
1 | flutter/
2 |
3 | # Visual Studio user-specific files.
4 | *.suo
5 | *.user
6 | *.userosscache
7 | *.sln.docstates
8 |
9 | # Visual Studio build-related files.
10 | x64/
11 | x86/
12 |
13 | # Visual Studio cache files
14 | # files ending in .cache can be ignored
15 | *.[Cc]ache
16 | # but keep track of directories ending in .cache
17 | !*.[Cc]ache/
18 |
--------------------------------------------------------------------------------
/windows/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.15)
2 | set(PROJECT_NAME dart_discord_rpc)
3 | project(${PROJECT_NAME} LANGUAGES CXX)
4 |
5 | set(PLUGIN_NAME dart_discord_rpc_plugin)
6 |
7 | add_library(
8 | ${PLUGIN_NAME} SHARED
9 | dart_discord_rpc_plugin.cpp
10 | )
11 | apply_standard_settings(${PLUGIN_NAME})
12 | set_target_properties(${PLUGIN_NAME} PROPERTIES
13 | CXX_VISIBILITY_PRESET hidden)
14 | target_compile_definitions(${PLUGIN_NAME} PRIVATE FLUTTER_PLUGIN_IMPL)
15 | target_include_directories(${PLUGIN_NAME} INTERFACE
16 | ${CMAKE_CURRENT_SOURCE_DIR}/include)
17 | target_link_libraries(${PLUGIN_NAME} PRIVATE flutter flutter_wrapper_plugin)
18 |
19 | set(dart_discord_rpc_bundled_libraries
20 | ${CMAKE_CURRENT_SOURCE_DIR}/bin/discord-rpc.dll
21 | PARENT_SCOPE
22 | )
23 |
--------------------------------------------------------------------------------
/windows/bin/discord-rpc.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alexmercerind/dart_discord_rpc/1eeb6360342327f86b36642412e915fe714641fc/windows/bin/discord-rpc.dll
--------------------------------------------------------------------------------
/windows/dart_discord_rpc_plugin.cpp:
--------------------------------------------------------------------------------
1 | #include "include/dart_discord_rpc/dart_discord_rpc_plugin.h"
2 | #include
3 | #include
4 | #include
5 |
6 | namespace {
7 |
8 | class DartDiscordRpcPlugin : public flutter::Plugin {
9 | public:
10 | static void RegisterWithRegistrar(flutter::PluginRegistrarWindows* registrar);
11 |
12 | DartDiscordRpcPlugin();
13 |
14 | virtual ~DartDiscordRpcPlugin();
15 |
16 | private:
17 | void HandleMethodCall(
18 | const flutter::MethodCall& method_call,
19 | std::unique_ptr> result);
20 | };
21 |
22 | void DartDiscordRpcPlugin::RegisterWithRegistrar(
23 | flutter::PluginRegistrarWindows* registrar) {
24 | auto channel =
25 | std::make_unique>(
26 | registrar->messenger(), "dart_discord_rpc",
27 | &flutter::StandardMethodCodec::GetInstance());
28 |
29 | auto plugin = std::make_unique();
30 |
31 | channel->SetMethodCallHandler([plugin_pointer = plugin.get()](
32 | const auto& call, auto result) {
33 | plugin_pointer->HandleMethodCall(call, std::move(result));
34 | });
35 |
36 | registrar->AddPlugin(std::move(plugin));
37 | }
38 |
39 | DartDiscordRpcPlugin::DartDiscordRpcPlugin() {}
40 |
41 | DartDiscordRpcPlugin::~DartDiscordRpcPlugin() {}
42 |
43 | void DartDiscordRpcPlugin::HandleMethodCall(
44 | const flutter::MethodCall& method_call,
45 | std::unique_ptr> result) {
46 | result->NotImplemented();
47 | }
48 | }
49 |
50 | void DartDiscordRpcPluginRegisterWithRegistrar(
51 | FlutterDesktopPluginRegistrarRef registrar) {
52 | DartDiscordRpcPlugin::RegisterWithRegistrar(
53 | flutter::PluginRegistrarManager::GetInstance()
54 | ->GetRegistrar(registrar));
55 | }
56 |
--------------------------------------------------------------------------------
/windows/include/dart_discord_rpc/dart_discord_rpc_plugin.h:
--------------------------------------------------------------------------------
1 | #ifndef FLUTTER_PLUGIN_DART_DISCORD_RPC_PLUGIN_H_
2 | #define FLUTTER_PLUGIN_DART_DISCORD_RPC_PLUGIN_H_
3 |
4 | #include
5 |
6 | #ifdef FLUTTER_PLUGIN_IMPL
7 | #define FLUTTER_PLUGIN_EXPORT __declspec(dllexport)
8 | #else
9 | #define FLUTTER_PLUGIN_EXPORT __declspec(dllimport)
10 | #endif
11 |
12 | #if defined(__cplusplus)
13 | extern "C" {
14 | #endif
15 |
16 | FLUTTER_PLUGIN_EXPORT void DartDiscordRpcPluginRegisterWithRegistrar(
17 | FlutterDesktopPluginRegistrarRef registrar);
18 |
19 | #if defined(__cplusplus)
20 | } // extern "C"
21 | #endif
22 |
23 | #endif // FLUTTER_PLUGIN_DART_DISCORD_RPC_PLUGIN_H_
24 |
--------------------------------------------------------------------------------