Skip to content

Commit 1f8bebb

Browse files
committed
Rename autostart -> launch_at_login and update examples
Rename the AutoStart API and related artifacts to LaunchAtLogin across the codebase. Updated include/nativeapi.h to reference launch_at_login, renamed src/autostart.h -> src/launch_at_login.h and class AutoStart -> LaunchAtLogin, and updated platform implementations accordingly. Replaced the C API (native_autostart_*) with corresponding native_launch_at_login_* headers and implementation, adding new src/capi/launch_at_login_c.* and removing the old autostart C API files. Removed old autostart example targets/files and added equivalent launch_at_login_example and launch_at_login_c_example sources and CMakeLists; updated top-level CMakeLists to reference the new example directories. Several platform and example files were renamed or moved to reflect the API name change. This change consolidates naming for clarity and updates build configuration and examples to the new API.
1 parent 422703d commit 1f8bebb

21 files changed

Lines changed: 771 additions & 757 deletions

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ add_subdirectory(src)
1010
# Add example programs subdirectory
1111
add_subdirectory(examples/application_example)
1212
add_subdirectory(examples/application_c_example)
13-
add_subdirectory(examples/autostart_example)
14-
add_subdirectory(examples/autostart_c_example)
13+
add_subdirectory(examples/launch_at_login_example)
14+
add_subdirectory(examples/launch_at_login_c_example)
1515
add_subdirectory(examples/display_example)
1616
add_subdirectory(examples/display_c_example)
1717
add_subdirectory(examples/id_allocator_example)

examples/autostart_c_example/CMakeLists.txt

Lines changed: 0 additions & 15 deletions
This file was deleted.

examples/autostart_c_example/main.c

Lines changed: 0 additions & 107 deletions
This file was deleted.

examples/autostart_example/CMakeLists.txt

Lines changed: 0 additions & 16 deletions
This file was deleted.

examples/autostart_example/main.cpp

Lines changed: 0 additions & 89 deletions
This file was deleted.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
cmake_minimum_required(VERSION 3.10)
2+
3+
project(launch_at_login_c_example)
4+
5+
set(CMAKE_C_STANDARD 11)
6+
set(CMAKE_C_STANDARD_REQUIRED ON)
7+
8+
# Add executable
9+
add_executable(launch_at_login_c_example main.c)
10+
11+
# Link with the native API library
12+
target_link_libraries(launch_at_login_c_example nativeapi)
13+
14+
# Set include directories
15+
target_include_directories(launch_at_login_c_example PRIVATE ../../include)
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
#include <nativeapi.h>
2+
#include <stdio.h>
3+
#include <stdlib.h>
4+
5+
int main(void) {
6+
printf("LaunchAtLogin C API Example\n");
7+
printf("=======================\n\n");
8+
9+
/* Check if launch-at-login is supported on this platform */
10+
if (!native_launch_at_login_is_supported()) {
11+
printf("LaunchAtLogin is not supported on this platform.\n");
12+
return 0;
13+
}
14+
15+
printf("LaunchAtLogin is supported on this platform.\n\n");
16+
17+
/* Create a LaunchAtLogin manager with a custom identifier and display name */
18+
native_launch_at_login_t launch_at_login =
19+
native_launch_at_login_create_with_id_and_name("com.example.myapp.c", "My C Example App");
20+
if (!launch_at_login) {
21+
printf("Failed to create LaunchAtLogin instance.\n");
22+
return 1;
23+
}
24+
25+
/* Display current configuration */
26+
char* id = native_launch_at_login_get_id(launch_at_login);
27+
char* display_name = native_launch_at_login_get_display_name(launch_at_login);
28+
char* executable = native_launch_at_login_get_executable_path(launch_at_login);
29+
30+
printf("LaunchAtLogin configuration:\n");
31+
printf(" ID: %s\n", id ? id : "(null)");
32+
printf(" Display name: %s\n", display_name ? display_name : "(null)");
33+
printf(" Executable: %s\n\n", executable ? executable : "(null)");
34+
35+
free_c_str(id);
36+
free_c_str(display_name);
37+
38+
/* Set a custom program path and arguments */
39+
const char* arguments[] = {"--minimized", "--launch_at_login"};
40+
native_launch_at_login_set_program(launch_at_login, executable ? executable : "", arguments, 2);
41+
free_c_str(executable);
42+
43+
/* Retrieve and display the updated executable path */
44+
char* exec_path = native_launch_at_login_get_executable_path(launch_at_login);
45+
printf("After SetProgram:\n");
46+
printf(" Executable: %s\n", exec_path ? exec_path : "(null)");
47+
printf(" Arguments: --minimized --launch_at_login\n\n");
48+
free_c_str(exec_path);
49+
50+
/* Check current state before enabling */
51+
printf("Is enabled (before Enable): %s\n",
52+
native_launch_at_login_is_enabled(launch_at_login) ? "yes" : "no");
53+
54+
/* Enable launch-at-login */
55+
printf("Enabling launch-at-login...\n");
56+
if (native_launch_at_login_enable(launch_at_login)) {
57+
printf("Launch-at-login enabled successfully.\n");
58+
} else {
59+
printf("Failed to enable launch-at-login.\n");
60+
native_launch_at_login_destroy(launch_at_login);
61+
return 1;
62+
}
63+
64+
/* Verify it is now enabled */
65+
printf("Is enabled (after Enable): %s\n\n",
66+
native_launch_at_login_is_enabled(launch_at_login) ? "yes" : "no");
67+
68+
/* Update the display name and re-enable to update the stored entry */
69+
native_launch_at_login_set_display_name(launch_at_login, "My C Example App (Updated)");
70+
char* updated_name = native_launch_at_login_get_display_name(launch_at_login);
71+
printf("Updated display name to: %s\n", updated_name ? updated_name : "(null)");
72+
free_c_str(updated_name);
73+
native_launch_at_login_enable(launch_at_login);
74+
75+
/* Disable launch-at-login */
76+
printf("\nDisabling launch-at-login...\n");
77+
if (native_launch_at_login_disable(launch_at_login)) {
78+
printf("Launch-at-login disabled successfully.\n");
79+
} else {
80+
printf("Failed to disable launch-at-login.\n");
81+
native_launch_at_login_destroy(launch_at_login);
82+
return 1;
83+
}
84+
85+
/* Verify it is now disabled */
86+
printf("Is enabled (after Disable): %s\n\n",
87+
native_launch_at_login_is_enabled(launch_at_login) ? "yes" : "no");
88+
89+
/* Clean up */
90+
native_launch_at_login_destroy(launch_at_login);
91+
92+
printf("Example completed successfully!\n\n");
93+
printf("This example demonstrated:\n");
94+
printf(" * native_launch_at_login_is_supported() - Check platform support\n");
95+
printf(" * native_launch_at_login_create_with_id_and_name() - Create with ID and name\n");
96+
printf(" * native_launch_at_login_get_id() - Get identifier\n");
97+
printf(" * native_launch_at_login_get_display_name() - Get display name\n");
98+
printf(" * native_launch_at_login_set_display_name() - Update display name\n");
99+
printf(" * native_launch_at_login_set_program() - Set executable and arguments\n");
100+
printf(" * native_launch_at_login_get_executable_path() - Get configured executable\n");
101+
printf(
102+
" * native_launch_at_login_enable() - Register launch-at-login with the "
103+
"OS\n");
104+
printf(
105+
" * native_launch_at_login_disable() - Remove launch-at-login from the "
106+
"OS\n");
107+
printf(
108+
" * native_launch_at_login_is_enabled() - Query current registration "
109+
"state\n");
110+
printf(" * native_launch_at_login_destroy() - Free resources\n");
111+
112+
return 0;
113+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
cmake_minimum_required(VERSION 3.10)
2+
3+
project(launch_at_login_example)
4+
5+
# Set C++ standard
6+
set(CMAKE_CXX_STANDARD 17)
7+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
8+
9+
# Add executable
10+
add_executable(launch_at_login_example main.cpp)
11+
12+
# Link with the native API library
13+
target_link_libraries(launch_at_login_example nativeapi)
14+
15+
# Set include directories
16+
target_include_directories(launch_at_login_example PRIVATE ../../include)

0 commit comments

Comments
 (0)