Skip to content

Add AutoStart example programs for macOS#41

Merged
lijy91 merged 3 commits intomainfrom
copilot/implement-autostart-macos
Mar 1, 2026
Merged

Add AutoStart example programs for macOS#41
lijy91 merged 3 commits intomainfrom
copilot/implement-autostart-macos

Conversation

Copy link
Contributor

Copilot AI commented Mar 1, 2026

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 full nativeapi::AutoStart API: construction, SetProgram(), Enable() / Disable() / IsEnabled(), and SetDisplayName() with re-registration
  • examples/autostart_c_example/ — C example covering the native_autostart_* C API with correct free_c_str() memory management; avoids native_autostart_get_arguments() since its new[]-allocated array requires delete[] and is not safely freeable from C
  • CMakeLists.txt — registers both examples in the top-level build
// C++ usage
AutoStart autostart("com.example.myapp", "My App");
autostart.SetProgram(autostart.GetExecutablePath(), {"--minimized"});
autostart.Enable();
assert(autostart.IsEnabled());
autostart.Disable();
// C usage
native_autostart_t as = native_autostart_create_with_id_and_name("com.example.myapp", "My App");
native_autostart_enable(as);
native_autostart_disable(as);
native_autostart_destroy(as);
Original prompt

This section details on the original issue you should resolve

<issue_title>[macOS] Implement AutoStart</issue_title>
<issue_description></issue_description>

Comments on the Issue (you are @copilot in this section)


💡 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.

Copilot AI and others added 2 commits March 1, 2026 05:56
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 lijy91 marked this pull request as ready for review March 1, 2026 08:44
Copilot AI review requested due to automatic review settings March 1, 2026 08:44
@lijy91 lijy91 merged commit 4ad2ebf into main Mar 1, 2026
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.txt and 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 to native_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 skip native_autostart_set_program() and rely on native_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 (after SetDisplayName) 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[macOS] Implement AutoStart

3 participants