From e500291bc6f639c5220346c069943d515476adb3 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 1 Mar 2026 05:52:11 +0000 Subject: [PATCH 1/3] Initial plan From ee87f7fab4277ba44de1c1aac8d955ea61576a46 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 1 Mar 2026 05:56:22 +0000 Subject: [PATCH 2/3] Add autostart_example and autostart_c_example Co-authored-by: lijy91 <3889523+lijy91@users.noreply.github.com> --- CMakeLists.txt | 2 + _codeql_detected_source_root | 1 + examples/autostart_c_example/CMakeLists.txt | 15 +++ examples/autostart_c_example/main.c | 107 ++++++++++++++++++++ examples/autostart_example/CMakeLists.txt | 16 +++ examples/autostart_example/main.cpp | 89 ++++++++++++++++ 6 files changed, 230 insertions(+) create mode 120000 _codeql_detected_source_root create mode 100644 examples/autostart_c_example/CMakeLists.txt create mode 100644 examples/autostart_c_example/main.c create mode 100644 examples/autostart_example/CMakeLists.txt create mode 100644 examples/autostart_example/main.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index a954e2b..4a14471 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,6 +10,8 @@ add_subdirectory(src) # Add example programs subdirectory add_subdirectory(examples/application_example) add_subdirectory(examples/application_c_example) +add_subdirectory(examples/autostart_example) +add_subdirectory(examples/autostart_c_example) add_subdirectory(examples/display_example) add_subdirectory(examples/display_c_example) add_subdirectory(examples/id_allocator_example) diff --git a/_codeql_detected_source_root b/_codeql_detected_source_root new file mode 120000 index 0000000..945c9b4 --- /dev/null +++ b/_codeql_detected_source_root @@ -0,0 +1 @@ +. \ No newline at end of file diff --git a/examples/autostart_c_example/CMakeLists.txt b/examples/autostart_c_example/CMakeLists.txt new file mode 100644 index 0000000..b3f7b9f --- /dev/null +++ b/examples/autostart_c_example/CMakeLists.txt @@ -0,0 +1,15 @@ +cmake_minimum_required(VERSION 3.10) + +project(autostart_c_example) + +set(CMAKE_C_STANDARD 11) +set(CMAKE_C_STANDARD_REQUIRED ON) + +# Add executable +add_executable(autostart_c_example main.c) + +# Link with the native API library +target_link_libraries(autostart_c_example nativeapi) + +# Set include directories +target_include_directories(autostart_c_example PRIVATE ../../include) diff --git a/examples/autostart_c_example/main.c b/examples/autostart_c_example/main.c new file mode 100644 index 0000000..f9a32d7 --- /dev/null +++ b/examples/autostart_c_example/main.c @@ -0,0 +1,107 @@ +#include +#include +#include + +int main(void) { + printf("AutoStart C API Example\n"); + printf("=======================\n\n"); + + /* Check if auto-start is supported on this platform */ + if (!native_autostart_is_supported()) { + printf("AutoStart is not supported on this platform.\n"); + return 0; + } + + printf("AutoStart is supported on this platform.\n\n"); + + /* Create an AutoStart manager with a custom identifier and display name */ + native_autostart_t autostart = + native_autostart_create_with_id_and_name("com.example.myapp.c", "My C Example App"); + if (!autostart) { + printf("Failed to create AutoStart instance.\n"); + return 1; + } + + /* Display current configuration */ + char* id = native_autostart_get_id(autostart); + char* display_name = native_autostart_get_display_name(autostart); + char* executable = native_autostart_get_executable_path(autostart); + + printf("AutoStart configuration:\n"); + printf(" ID: %s\n", id ? id : "(null)"); + printf(" Display name: %s\n", display_name ? display_name : "(null)"); + printf(" Executable: %s\n\n", executable ? executable : "(null)"); + + free_c_str(id); + free_c_str(display_name); + + /* Set a custom program path and arguments */ + const char* arguments[] = {"--minimized", "--autostart"}; + native_autostart_set_program(autostart, executable ? executable : "", arguments, 2); + free_c_str(executable); + + /* Retrieve and display the updated executable path */ + char* exec_path = native_autostart_get_executable_path(autostart); + printf("After SetProgram:\n"); + printf(" Executable: %s\n", exec_path ? exec_path : "(null)"); + printf(" Arguments: --minimized --autostart\n\n"); + free_c_str(exec_path); + + /* Check current state before enabling */ + printf("Is enabled (before Enable): %s\n", + native_autostart_is_enabled(autostart) ? "yes" : "no"); + + /* Enable auto-start */ + printf("Enabling auto-start...\n"); + if (native_autostart_enable(autostart)) { + printf("Auto-start enabled successfully.\n"); + } else { + printf("Failed to enable auto-start.\n"); + native_autostart_destroy(autostart); + return 1; + } + + /* Verify it is now enabled */ + printf("Is enabled (after Enable): %s\n\n", + native_autostart_is_enabled(autostart) ? "yes" : "no"); + + /* Update the display name and re-enable to update the stored entry */ + native_autostart_set_display_name(autostart, "My C Example App (Updated)"); + char* updated_name = native_autostart_get_display_name(autostart); + printf("Updated display name to: %s\n", updated_name ? updated_name : "(null)"); + free_c_str(updated_name); + native_autostart_enable(autostart); + + /* Disable auto-start */ + printf("\nDisabling auto-start...\n"); + if (native_autostart_disable(autostart)) { + printf("Auto-start disabled successfully.\n"); + } else { + printf("Failed to disable auto-start.\n"); + native_autostart_destroy(autostart); + return 1; + } + + /* Verify it is now disabled */ + printf("Is enabled (after Disable): %s\n\n", + native_autostart_is_enabled(autostart) ? "yes" : "no"); + + /* Clean up */ + native_autostart_destroy(autostart); + + printf("Example completed successfully!\n\n"); + printf("This example demonstrated:\n"); + printf(" * native_autostart_is_supported() - Check platform support\n"); + printf(" * native_autostart_create_with_id_and_name() - Create with ID and name\n"); + printf(" * native_autostart_get_id() - Get identifier\n"); + printf(" * native_autostart_get_display_name() - Get display name\n"); + printf(" * native_autostart_set_display_name() - Update display name\n"); + printf(" * native_autostart_set_program() - Set executable and arguments\n"); + printf(" * native_autostart_get_executable_path() - Get configured executable\n"); + printf(" * native_autostart_enable() - Register auto-start with the OS\n"); + printf(" * native_autostart_disable() - Remove auto-start from the OS\n"); + printf(" * native_autostart_is_enabled() - Query current registration state\n"); + printf(" * native_autostart_destroy() - Free resources\n"); + + return 0; +} diff --git a/examples/autostart_example/CMakeLists.txt b/examples/autostart_example/CMakeLists.txt new file mode 100644 index 0000000..70c5fd2 --- /dev/null +++ b/examples/autostart_example/CMakeLists.txt @@ -0,0 +1,16 @@ +cmake_minimum_required(VERSION 3.10) + +project(autostart_example) + +# Set C++ standard +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +# Add executable +add_executable(autostart_example main.cpp) + +# Link with the native API library +target_link_libraries(autostart_example nativeapi) + +# Set include directories +target_include_directories(autostart_example PRIVATE ../../include) diff --git a/examples/autostart_example/main.cpp b/examples/autostart_example/main.cpp new file mode 100644 index 0000000..21a1ab3 --- /dev/null +++ b/examples/autostart_example/main.cpp @@ -0,0 +1,89 @@ +#include +#include +#include + +#include "nativeapi.h" + +using namespace nativeapi; + +int main() { + std::cout << "AutoStart Example\n"; + std::cout << "=================\n\n"; + + // Check if auto-start is supported on this platform + if (!AutoStart::IsSupported()) { + std::cout << "AutoStart is not supported on this platform.\n"; + return 0; + } + + std::cout << "AutoStart is supported on this platform.\n\n"; + + // Create an AutoStart manager with a custom identifier and display name + AutoStart autostart("com.example.myapp", "My Example App"); + + // Display current configuration + std::cout << "AutoStart configuration:\n"; + std::cout << " ID: " << autostart.GetId() << "\n"; + std::cout << " Display name: " << autostart.GetDisplayName() << "\n"; + std::cout << " Executable: " << autostart.GetExecutablePath() << "\n\n"; + + // Set a custom program path and arguments + autostart.SetProgram(autostart.GetExecutablePath(), {"--minimized", "--autostart"}); + + std::cout << "After SetProgram:\n"; + std::cout << " Executable: " << autostart.GetExecutablePath() << "\n"; + auto args = autostart.GetArguments(); + std::cout << " Arguments: "; + for (const auto& arg : args) { + std::cout << arg << " "; + } + std::cout << "\n\n"; + + // Check current state before enabling + std::cout << "Is enabled (before Enable): " << (autostart.IsEnabled() ? "yes" : "no") << "\n"; + + // Enable auto-start + std::cout << "Enabling auto-start...\n"; + if (autostart.Enable()) { + std::cout << "Auto-start enabled successfully.\n"; + } else { + std::cout << "Failed to enable auto-start.\n"; + return 1; + } + + // Verify it is now enabled + std::cout << "Is enabled (after Enable): " << (autostart.IsEnabled() ? "yes" : "no") << "\n\n"; + + // Update the display name and re-enable to update the stored entry + autostart.SetDisplayName("My Example App (Updated)"); + std::cout << "Updated display name to: " << autostart.GetDisplayName() << "\n"; + autostart.Enable(); + + // Disable auto-start + std::cout << "\nDisabling auto-start...\n"; + if (autostart.Disable()) { + std::cout << "Auto-start disabled successfully.\n"; + } else { + std::cout << "Failed to disable auto-start.\n"; + return 1; + } + + // Verify it is now disabled + std::cout << "Is enabled (after Disable): " << (autostart.IsEnabled() ? "yes" : "no") << "\n\n"; + + std::cout << "Example completed successfully!\n\n"; + std::cout << "This example demonstrated:\n"; + std::cout << " * AutoStart::IsSupported() - Check platform support\n"; + std::cout << " * AutoStart(id, name) - Construct with identifier and display name\n"; + std::cout << " * AutoStart::GetId() - Get identifier\n"; + std::cout << " * AutoStart::GetDisplayName() - Get display name\n"; + std::cout << " * AutoStart::SetDisplayName() - Update display name\n"; + std::cout << " * AutoStart::SetProgram() - Set executable path and arguments\n"; + std::cout << " * AutoStart::GetExecutablePath() - Get configured executable\n"; + std::cout << " * AutoStart::GetArguments() - Get configured arguments\n"; + std::cout << " * AutoStart::Enable() - Register auto-start with the OS\n"; + std::cout << " * AutoStart::Disable() - Remove auto-start from the OS\n"; + std::cout << " * AutoStart::IsEnabled() - Query current registration state\n"; + + return 0; +} From df4694e14c2069c09e1492148715a54c2dee63ec Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 1 Mar 2026 05:56:42 +0000 Subject: [PATCH 3/3] Remove _codeql_detected_source_root from tracking, add to .gitignore Co-authored-by: lijy91 <3889523+lijy91@users.noreply.github.com> --- .gitignore | 1 + _codeql_detected_source_root | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) delete mode 120000 _codeql_detected_source_root diff --git a/.gitignore b/.gitignore index 33389b6..c975fa4 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ build-macos/ build-ohos/ build-windows/ cmake-build-debug/ +_codeql_detected_source_root # Generated test binaries and object files *.o diff --git a/_codeql_detected_source_root b/_codeql_detected_source_root deleted file mode 120000 index 945c9b4..0000000 --- a/_codeql_detected_source_root +++ /dev/null @@ -1 +0,0 @@ -. \ No newline at end of file