Skip to content

Commit 43f0ad6

Browse files
feat: update desktop example setup
1 parent 754e250 commit 43f0ad6

20 files changed

+254
-52
lines changed

example/.metadata

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ migration:
1515
- platform: root
1616
create_revision: 35c388afb57ef061d06a39b537336c87e0e3d1b1
1717
base_revision: 35c388afb57ef061d06a39b537336c87e0e3d1b1
18-
- platform: web
18+
- platform: macos
1919
create_revision: 35c388afb57ef061d06a39b537336c87e0e3d1b1
2020
base_revision: 35c388afb57ef061d06a39b537336c87e0e3d1b1
2121

example/linux/CMakeLists.txt

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# Project-level configuration.
2-
cmake_minimum_required(VERSION 3.10)
2+
cmake_minimum_required(VERSION 3.13)
33
project(runner LANGUAGES CXX)
44

55
# The name of the executable created for the application. Change this to change
66
# the on-disk name of your application.
77
set(BINARY_NAME "example")
88
# The unique GTK application identifier for this application. See:
99
# https://wiki.gnome.org/HowDoI/ChooseApplicationID
10-
set(APPLICATION_ID "dev.danvickmiller.flutterformbuilder.example")
10+
set(APPLICATION_ID "com.flutterformbuilderecosystem.example")
1111

1212
# Explicitly opt in to modern CMake behaviors to avoid warnings with recent
1313
# versions of CMake.
@@ -54,25 +54,8 @@ add_subdirectory(${FLUTTER_MANAGED_DIR})
5454
find_package(PkgConfig REQUIRED)
5555
pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0)
5656

57-
add_definitions(-DAPPLICATION_ID="${APPLICATION_ID}")
58-
59-
# Define the application target. To change its name, change BINARY_NAME above,
60-
# not the value here, or `flutter run` will no longer work.
61-
#
62-
# Any new source files that you add to the application should be added here.
63-
add_executable(${BINARY_NAME}
64-
"main.cc"
65-
"my_application.cc"
66-
"${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc"
67-
)
68-
69-
# Apply the standard set of build settings. This can be removed for applications
70-
# that need different build settings.
71-
apply_standard_settings(${BINARY_NAME})
72-
73-
# Add dependency libraries. Add any application-specific dependencies here.
74-
target_link_libraries(${BINARY_NAME} PRIVATE flutter)
75-
target_link_libraries(${BINARY_NAME} PRIVATE PkgConfig::GTK)
57+
# Application build; see runner/CMakeLists.txt.
58+
add_subdirectory("runner")
7659

7760
# Run the Flutter tool portions of the build. This must not be removed.
7861
add_dependencies(${BINARY_NAME} flutter_assemble)
@@ -86,6 +69,7 @@ set_target_properties(${BINARY_NAME}
8669
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/intermediates_do_not_run"
8770
)
8871

72+
8973
# Generated plugin build rules, which manage building the plugins and adding
9074
# them to the application.
9175
include(flutter/generated_plugins.cmake)
@@ -122,6 +106,12 @@ foreach(bundled_library ${PLUGIN_BUNDLED_LIBRARIES})
122106
COMPONENT Runtime)
123107
endforeach(bundled_library)
124108

109+
# Copy the native assets provided by the build.dart from all packages.
110+
set(NATIVE_ASSETS_DIR "${PROJECT_BUILD_DIR}native_assets/linux/")
111+
install(DIRECTORY "${NATIVE_ASSETS_DIR}"
112+
DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
113+
COMPONENT Runtime)
114+
125115
# Fully re-copy the assets directory on each build to avoid having stale files
126116
# from a previous install.
127117
set(FLUTTER_ASSET_DIR_NAME "flutter_assets")

example/linux/runner/CMakeLists.txt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
cmake_minimum_required(VERSION 3.13)
2+
project(runner LANGUAGES CXX)
3+
4+
# Define the application target. To change its name, change BINARY_NAME in the
5+
# top-level CMakeLists.txt, not the value here, or `flutter run` will no longer
6+
# work.
7+
#
8+
# Any new source files that you add to the application should be added here.
9+
add_executable(${BINARY_NAME}
10+
"main.cc"
11+
"my_application.cc"
12+
"${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc"
13+
)
14+
15+
# Apply the standard set of build settings. This can be removed for applications
16+
# that need different build settings.
17+
apply_standard_settings(${BINARY_NAME})
18+
19+
# Add preprocessor definitions for the application ID.
20+
add_definitions(-DAPPLICATION_ID="${APPLICATION_ID}")
21+
22+
# Add dependency libraries. Add any application-specific dependencies here.
23+
target_link_libraries(${BINARY_NAME} PRIVATE flutter)
24+
target_link_libraries(${BINARY_NAME} PRIVATE PkgConfig::GTK)
25+
26+
target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}")
File renamed without changes.

example/linux/my_application.cc renamed to example/linux/runner/my_application.cc

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,24 @@ static gboolean my_application_local_command_line(GApplication* application, gch
8181
return TRUE;
8282
}
8383

84+
// Implements GApplication::startup.
85+
static void my_application_startup(GApplication* application) {
86+
//MyApplication* self = MY_APPLICATION(object);
87+
88+
// Perform any actions required at application startup.
89+
90+
G_APPLICATION_CLASS(my_application_parent_class)->startup(application);
91+
}
92+
93+
// Implements GApplication::shutdown.
94+
static void my_application_shutdown(GApplication* application) {
95+
//MyApplication* self = MY_APPLICATION(object);
96+
97+
// Perform any actions required at application shutdown.
98+
99+
G_APPLICATION_CLASS(my_application_parent_class)->shutdown(application);
100+
}
101+
84102
// Implements GObject::dispose.
85103
static void my_application_dispose(GObject* object) {
86104
MyApplication* self = MY_APPLICATION(object);
@@ -91,12 +109,20 @@ static void my_application_dispose(GObject* object) {
91109
static void my_application_class_init(MyApplicationClass* klass) {
92110
G_APPLICATION_CLASS(klass)->activate = my_application_activate;
93111
G_APPLICATION_CLASS(klass)->local_command_line = my_application_local_command_line;
112+
G_APPLICATION_CLASS(klass)->startup = my_application_startup;
113+
G_APPLICATION_CLASS(klass)->shutdown = my_application_shutdown;
94114
G_OBJECT_CLASS(klass)->dispose = my_application_dispose;
95115
}
96116

97117
static void my_application_init(MyApplication* self) {}
98118

99119
MyApplication* my_application_new() {
120+
// Set the program name to the application ID, which helps various systems
121+
// like GTK and desktop environments map this running application to its
122+
// corresponding .desktop file. This ensures better integration by allowing
123+
// the application to be recognized beyond its binary name.
124+
g_set_prgname(APPLICATION_ID);
125+
100126
return MY_APPLICATION(g_object_new(my_application_get_type(),
101127
"application-id", APPLICATION_ID,
102128
"flags", G_APPLICATION_NON_UNIQUE,

0 commit comments

Comments
 (0)