Merged
Conversation
Co-authored-by: lijy91 <3889523+lijy91@users.noreply.github.com>
Co-authored-by: lijy91 <3889523+lijy91@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Implement auto start for macOS application
Add AutoStart example programs for macOS
Mar 1, 2026
lijy91
approved these changes
Mar 1, 2026
There was a problem hiding this comment.
Pull request overview
Adds new example programs demonstrating how to use the macOS AutoStart feature via both the C++ and C APIs, and wires them into the top-level CMake build so they’re built alongside other examples.
Changes:
- Added a C++ AutoStart example covering construction, program/args configuration, enable/disable, and display-name update.
- Added a C AutoStart example demonstrating the C API and
free_c_str()usage. - Registered both examples in the root
CMakeLists.txtand updated.gitignore.
Reviewed changes
Copilot reviewed 5 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| examples/autostart_example/main.cpp | New C++ example exercising nativeapi::AutoStart end-to-end. |
| examples/autostart_example/CMakeLists.txt | Builds the C++ autostart example and links it with nativeapi. |
| examples/autostart_c_example/main.c | New C example using the native_autostart_* API and free_c_str(). |
| examples/autostart_c_example/CMakeLists.txt | Builds the C autostart example and links it with nativeapi. |
| CMakeLists.txt | Adds both new examples as subdirectories in the top-level build. |
| .gitignore | Ignores CodeQL’s detected source root marker file. |
Comments suppressed due to low confidence (4)
examples/autostart_c_example/main.c:41
- In this example, if
native_autostart_get_executable_path()returns NULL, the code passes an empty string tonative_autostart_set_program(). That can lead to confusing behavior (the set_program call succeeds locally but Enable may later fail or re-detect a different path). Consider treating a NULL/empty executable path as an error (print a message and exit), or skipnative_autostart_set_program()and rely onnative_autostart_enable()'s default executable detection while still demonstrating argument configuration another way.
/* 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);
examples/autostart_c_example/main.c:41
- The return value of
native_autostart_set_program()is ignored. If it fails (e.g., invalid path), the example continues and later failures are harder to attribute. Consider checking the return value and aborting with a clear message.
const char* arguments[] = {"--minimized", "--autostart"};
native_autostart_set_program(autostart, executable ? executable : "", arguments, 2);
free_c_str(executable);
examples/autostart_c_example/main.c:73
- The second
native_autostart_enable()call (after updating the display name) ignores its return value. If re-registration fails, the example prints the updated name but the on-disk/OS registration may not match. Consider checking the return and reporting failure.
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);
examples/autostart_example/main.cpp:60
- The second
Enable()call (afterSetDisplayName) ignores its return value. If re-registration fails, the example will still proceed and may imply the OS entry was updated when it wasn't. Consider checking the return and printing an error (or at least warning) when it fails.
autostart.SetDisplayName("My Example App (Updated)");
std::cout << "Updated display name to: " << autostart.GetDisplayName() << "\n";
autostart.Enable();
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The macOS AutoStart implementation (via
~/Library/LaunchAgents/plist files) was in place but had no example programs demonstrating its usage.Changes
examples/autostart_example/— C++ example covering the fullnativeapi::AutoStartAPI: construction,SetProgram(),Enable()/Disable()/IsEnabled(), andSetDisplayName()with re-registrationexamples/autostart_c_example/— C example covering thenative_autostart_*C API with correctfree_c_str()memory management; avoidsnative_autostart_get_arguments()since itsnew[]-allocated array requiresdelete[]and is not safely freeable from CCMakeLists.txt— registers both examples in the top-level buildOriginal prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.