diff --git a/src/fw/apps/system/toggle/shutdown.c b/src/fw/apps/system/toggle/shutdown.c new file mode 100644 index 000000000..883190707 --- /dev/null +++ b/src/fw/apps/system/toggle/shutdown.c @@ -0,0 +1,63 @@ +/* SPDX-FileCopyrightText: 2025 The PebbleOS Contributors */ +/* SPDX-License-Identifier: Apache-2.0 */ + +#include "shutdown.h" + +#include "applib/app.h" +#include "applib/ui/dialogs/actionable_dialog.h" +#include "applib/ui/dialogs/dialog.h" +#include "kernel/event_loop.h" +#include "process_management/app_manager.h" +#include "pbl/services/i18n/i18n.h" +#include "resource/resource_ids.auto.h" +#include "shell/normal/battery_ui.h" + +static void prv_do_shutdown(void *data) { + battery_ui_handle_shut_down(); +} + +static void prv_shutdown_confirm_cb(ClickRecognizerRef recognizer, void *context) { + actionable_dialog_pop((ActionableDialog *)context); + launcher_task_add_callback(prv_do_shutdown, NULL); +} + +static void prv_shutdown_back_cb(ClickRecognizerRef recognizer, void *context) { + actionable_dialog_pop((ActionableDialog *)context); +} + +static void prv_shutdown_click_provider(void *context) { + window_single_click_subscribe(BUTTON_ID_SELECT, prv_shutdown_confirm_cb); + window_single_click_subscribe(BUTTON_ID_BACK, prv_shutdown_back_cb); +} + +static void prv_main(void) { + ActionableDialog *a_dialog = actionable_dialog_create("Shutdown"); + Dialog *dialog = actionable_dialog_get_dialog(a_dialog); + + actionable_dialog_set_action_bar_type(a_dialog, DialogActionBarConfirm, NULL); + actionable_dialog_set_click_config_provider(a_dialog, prv_shutdown_click_provider); + + dialog_set_text_color(dialog, GColorWhite); + dialog_set_background_color(dialog, GColorCobaltBlue); + /// Confirmation message shown in the shutdown Quick Launch dialog. + dialog_set_text(dialog, i18n_get("Do you want to shut down?", a_dialog)); + dialog_set_icon(dialog, RESOURCE_ID_GENERIC_QUESTION_LARGE); + + i18n_free_all(a_dialog); + + app_actionable_dialog_push(a_dialog); + app_event_loop(); +} + +const PebbleProcessMd *shutdown_toggle_get_app_info(void) { + static const PebbleProcessMdSystem s_app_info = { + .common = { + .main_func = &prv_main, + .uuid = SHUTDOWN_TOGGLE_UUID, + .visibility = ProcessVisibilityQuickLaunch, + }, + /// Name of the Shutdown Quick Launch option shown in Quick Launch settings. + .name = i18n_noop("Shutdown"), + }; + return &s_app_info.common; +} diff --git a/src/fw/apps/system/toggle/shutdown.h b/src/fw/apps/system/toggle/shutdown.h new file mode 100644 index 000000000..03820cc9d --- /dev/null +++ b/src/fw/apps/system/toggle/shutdown.h @@ -0,0 +1,11 @@ +/* SPDX-FileCopyrightText: 2025 The PebbleOS Contributors */ +/* SPDX-License-Identifier: Apache-2.0 */ + +#pragma once + +#include "process_management/app_manager.h" + +#define SHUTDOWN_TOGGLE_UUID {0x8b, 0x9a, 0x7c, 0x3e, 0x45, 0xd1, 0x4f, 0x89, \ + 0xb2, 0x56, 0xee, 0xcc, 0xdd, 0xbb, 0xaa, 0x01} + +const PebbleProcessMd *shutdown_toggle_get_app_info(void); diff --git a/src/fw/shell/normal/system_app_registry_list.json b/src/fw/shell/normal/system_app_registry_list.json index be4e331e7..2ef6f32ff 100644 --- a/src/fw/shell/normal/system_app_registry_list.json +++ b/src/fw/shell/normal/system_app_registry_list.json @@ -574,6 +574,11 @@ "enum": "AIRPLANE_MODE_TOGGLE", "md_fn": "airplane_mode_toggle_get_app_info" }, + { + "id": -100, + "enum": "SHUTDOWN_TOGGLE", + "md_fn": "shutdown_toggle_get_app_info" + }, { "id": -96, "enum": "TIMELINE_PAST",