@zulfio/react-native-alarm-kit 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Alarmkit.podspec +35 -0
- package/LICENSE +20 -0
- package/README.md +163 -0
- package/android/CMakeLists.txt +24 -0
- package/android/build.gradle +129 -0
- package/android/gradle.properties +5 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/cpp/cpp-adapter.cpp +6 -0
- package/android/src/main/java/com/alarmkit/AlarmkitPackage.kt +22 -0
- package/android/src/main/java/com/margelo/nitro/alarmkit/Alarmkit.kt +7 -0
- package/ios/AlarmKit.swift +296 -0
- package/lib/module/AlarmKit.nitro.js +4 -0
- package/lib/module/AlarmKit.nitro.js.map +1 -0
- package/lib/module/index.js +40 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/AlarmKit.nitro.d.ts +24 -0
- package/lib/typescript/src/AlarmKit.nitro.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +11 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/nitro.json +17 -0
- package/nitrogen/generated/android/alarmkit+autolinking.cmake +78 -0
- package/nitrogen/generated/android/alarmkit+autolinking.gradle +27 -0
- package/nitrogen/generated/android/alarmkitOnLoad.cpp +46 -0
- package/nitrogen/generated/android/alarmkitOnLoad.hpp +25 -0
- package/nitrogen/generated/android/c++/JAlarmCountdown.hpp +57 -0
- package/nitrogen/generated/android/c++/JAlarmWeekday.hpp +74 -0
- package/nitrogen/generated/android/c++/JCustomizableAlarmButton.hpp +61 -0
- package/nitrogen/generated/android/c++/JHybridAlarmKitSpec.cpp +180 -0
- package/nitrogen/generated/android/c++/JHybridAlarmKitSpec.hpp +68 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/alarmkit/AlarmCountdown.kt +27 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/alarmkit/AlarmWeekday.kt +30 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/alarmkit/CustomizableAlarmButton.kt +28 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/alarmkit/HybridAlarmKitSpec.kt +76 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/alarmkit/alarmkitOnLoad.kt +35 -0
- package/nitrogen/generated/ios/AlarmKit+autolinking.rb +60 -0
- package/nitrogen/generated/ios/AlarmKit-Swift-Cxx-Bridge.cpp +72 -0
- package/nitrogen/generated/ios/AlarmKit-Swift-Cxx-Bridge.hpp +309 -0
- package/nitrogen/generated/ios/AlarmKit-Swift-Cxx-Umbrella.hpp +56 -0
- package/nitrogen/generated/ios/AlarmKitAutolinking.mm +33 -0
- package/nitrogen/generated/ios/AlarmKitAutolinking.swift +25 -0
- package/nitrogen/generated/ios/c++/HybridAlarmKitSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridAlarmKitSpecSwift.hpp +130 -0
- package/nitrogen/generated/ios/swift/AlarmCountdown.swift +70 -0
- package/nitrogen/generated/ios/swift/AlarmWeekday.swift +60 -0
- package/nitrogen/generated/ios/swift/CustomizableAlarmButton.swift +57 -0
- package/nitrogen/generated/ios/swift/Func_void_bool.swift +46 -0
- package/nitrogen/generated/ios/swift/Func_void_std__exception_ptr.swift +46 -0
- package/nitrogen/generated/ios/swift/Func_void_std__optional_std__string_.swift +52 -0
- package/nitrogen/generated/ios/swift/Func_void_std__string.swift +46 -0
- package/nitrogen/generated/ios/swift/Func_void_std__vector_std__string_.swift +46 -0
- package/nitrogen/generated/ios/swift/HybridAlarmKitSpec.swift +54 -0
- package/nitrogen/generated/ios/swift/HybridAlarmKitSpec_cxx.swift +271 -0
- package/nitrogen/generated/shared/c++/AlarmCountdown.hpp +73 -0
- package/nitrogen/generated/shared/c++/AlarmWeekday.hpp +98 -0
- package/nitrogen/generated/shared/c++/CustomizableAlarmButton.hpp +77 -0
- package/nitrogen/generated/shared/c++/HybridAlarmKitSpec.cpp +27 -0
- package/nitrogen/generated/shared/c++/HybridAlarmKitSpec.hpp +79 -0
- package/package.json +168 -0
- package/src/AlarmKit.nitro.ts +48 -0
- package/src/index.tsx +96 -0
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// JAlarmWeekday.hpp
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © 2026 Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#include <fbjni/fbjni.h>
|
|
11
|
+
#include "AlarmWeekday.hpp"
|
|
12
|
+
|
|
13
|
+
namespace margelo::nitro::alarmkit {
|
|
14
|
+
|
|
15
|
+
using namespace facebook;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The C++ JNI bridge between the C++ enum "AlarmWeekday" and the the Kotlin enum "AlarmWeekday".
|
|
19
|
+
*/
|
|
20
|
+
struct JAlarmWeekday final: public jni::JavaClass<JAlarmWeekday> {
|
|
21
|
+
public:
|
|
22
|
+
static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/alarmkit/AlarmWeekday;";
|
|
23
|
+
|
|
24
|
+
public:
|
|
25
|
+
/**
|
|
26
|
+
* Convert this Java/Kotlin-based enum to the C++ enum AlarmWeekday.
|
|
27
|
+
*/
|
|
28
|
+
[[maybe_unused]]
|
|
29
|
+
[[nodiscard]]
|
|
30
|
+
AlarmWeekday toCpp() const {
|
|
31
|
+
static const auto clazz = javaClassStatic();
|
|
32
|
+
static const auto fieldOrdinal = clazz->getField<int>("_ordinal");
|
|
33
|
+
int ordinal = this->getFieldValue(fieldOrdinal);
|
|
34
|
+
return static_cast<AlarmWeekday>(ordinal);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
public:
|
|
38
|
+
/**
|
|
39
|
+
* Create a Java/Kotlin-based enum with the given C++ enum's value.
|
|
40
|
+
*/
|
|
41
|
+
[[maybe_unused]]
|
|
42
|
+
static jni::alias_ref<JAlarmWeekday> fromCpp(AlarmWeekday value) {
|
|
43
|
+
static const auto clazz = javaClassStatic();
|
|
44
|
+
static const auto fieldMONDAY = clazz->getStaticField<JAlarmWeekday>("MONDAY");
|
|
45
|
+
static const auto fieldTUESDAY = clazz->getStaticField<JAlarmWeekday>("TUESDAY");
|
|
46
|
+
static const auto fieldWEDNESDAY = clazz->getStaticField<JAlarmWeekday>("WEDNESDAY");
|
|
47
|
+
static const auto fieldTHURSDAY = clazz->getStaticField<JAlarmWeekday>("THURSDAY");
|
|
48
|
+
static const auto fieldFRIDAY = clazz->getStaticField<JAlarmWeekday>("FRIDAY");
|
|
49
|
+
static const auto fieldSATURDAY = clazz->getStaticField<JAlarmWeekday>("SATURDAY");
|
|
50
|
+
static const auto fieldSUNDAY = clazz->getStaticField<JAlarmWeekday>("SUNDAY");
|
|
51
|
+
|
|
52
|
+
switch (value) {
|
|
53
|
+
case AlarmWeekday::MONDAY:
|
|
54
|
+
return clazz->getStaticFieldValue(fieldMONDAY);
|
|
55
|
+
case AlarmWeekday::TUESDAY:
|
|
56
|
+
return clazz->getStaticFieldValue(fieldTUESDAY);
|
|
57
|
+
case AlarmWeekday::WEDNESDAY:
|
|
58
|
+
return clazz->getStaticFieldValue(fieldWEDNESDAY);
|
|
59
|
+
case AlarmWeekday::THURSDAY:
|
|
60
|
+
return clazz->getStaticFieldValue(fieldTHURSDAY);
|
|
61
|
+
case AlarmWeekday::FRIDAY:
|
|
62
|
+
return clazz->getStaticFieldValue(fieldFRIDAY);
|
|
63
|
+
case AlarmWeekday::SATURDAY:
|
|
64
|
+
return clazz->getStaticFieldValue(fieldSATURDAY);
|
|
65
|
+
case AlarmWeekday::SUNDAY:
|
|
66
|
+
return clazz->getStaticFieldValue(fieldSUNDAY);
|
|
67
|
+
default:
|
|
68
|
+
std::string stringValue = std::to_string(static_cast<int>(value));
|
|
69
|
+
throw std::invalid_argument("Invalid enum value (" + stringValue + "!");
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
} // namespace margelo::nitro::alarmkit
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// JCustomizableAlarmButton.hpp
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © 2026 Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#include <fbjni/fbjni.h>
|
|
11
|
+
#include "CustomizableAlarmButton.hpp"
|
|
12
|
+
|
|
13
|
+
#include <string>
|
|
14
|
+
|
|
15
|
+
namespace margelo::nitro::alarmkit {
|
|
16
|
+
|
|
17
|
+
using namespace facebook;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The C++ JNI bridge between the C++ struct "CustomizableAlarmButton" and the the Kotlin data class "CustomizableAlarmButton".
|
|
21
|
+
*/
|
|
22
|
+
struct JCustomizableAlarmButton final: public jni::JavaClass<JCustomizableAlarmButton> {
|
|
23
|
+
public:
|
|
24
|
+
static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/alarmkit/CustomizableAlarmButton;";
|
|
25
|
+
|
|
26
|
+
public:
|
|
27
|
+
/**
|
|
28
|
+
* Convert this Java/Kotlin-based struct to the C++ struct CustomizableAlarmButton by copying all values to C++.
|
|
29
|
+
*/
|
|
30
|
+
[[maybe_unused]]
|
|
31
|
+
[[nodiscard]]
|
|
32
|
+
CustomizableAlarmButton toCpp() const {
|
|
33
|
+
static const auto clazz = javaClassStatic();
|
|
34
|
+
static const auto fieldText = clazz->getField<jni::JString>("text");
|
|
35
|
+
jni::local_ref<jni::JString> text = this->getFieldValue(fieldText);
|
|
36
|
+
static const auto fieldTextColor = clazz->getField<jni::JString>("textColor");
|
|
37
|
+
jni::local_ref<jni::JString> textColor = this->getFieldValue(fieldTextColor);
|
|
38
|
+
static const auto fieldIcon = clazz->getField<jni::JString>("icon");
|
|
39
|
+
jni::local_ref<jni::JString> icon = this->getFieldValue(fieldIcon);
|
|
40
|
+
return CustomizableAlarmButton(
|
|
41
|
+
text->toStdString(),
|
|
42
|
+
textColor->toStdString(),
|
|
43
|
+
icon->toStdString()
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
public:
|
|
48
|
+
/**
|
|
49
|
+
* Create a Java/Kotlin-based struct by copying all values from the given C++ struct to Java.
|
|
50
|
+
*/
|
|
51
|
+
[[maybe_unused]]
|
|
52
|
+
static jni::local_ref<JCustomizableAlarmButton::javaobject> fromCpp(const CustomizableAlarmButton& value) {
|
|
53
|
+
return newInstance(
|
|
54
|
+
jni::make_jstring(value.text),
|
|
55
|
+
jni::make_jstring(value.textColor),
|
|
56
|
+
jni::make_jstring(value.icon)
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
} // namespace margelo::nitro::alarmkit
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// JHybridAlarmKitSpec.cpp
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © 2026 Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
#include "JHybridAlarmKitSpec.hpp"
|
|
9
|
+
|
|
10
|
+
// Forward declaration of `CustomizableAlarmButton` to properly resolve imports.
|
|
11
|
+
namespace margelo::nitro::alarmkit { struct CustomizableAlarmButton; }
|
|
12
|
+
// Forward declaration of `AlarmCountdown` to properly resolve imports.
|
|
13
|
+
namespace margelo::nitro::alarmkit { struct AlarmCountdown; }
|
|
14
|
+
// Forward declaration of `AlarmWeekday` to properly resolve imports.
|
|
15
|
+
namespace margelo::nitro::alarmkit { enum class AlarmWeekday; }
|
|
16
|
+
|
|
17
|
+
#include <NitroModules/Promise.hpp>
|
|
18
|
+
#include <NitroModules/JPromise.hpp>
|
|
19
|
+
#include <string>
|
|
20
|
+
#include <optional>
|
|
21
|
+
#include <vector>
|
|
22
|
+
#include "CustomizableAlarmButton.hpp"
|
|
23
|
+
#include "JCustomizableAlarmButton.hpp"
|
|
24
|
+
#include "AlarmCountdown.hpp"
|
|
25
|
+
#include "JAlarmCountdown.hpp"
|
|
26
|
+
#include "AlarmWeekday.hpp"
|
|
27
|
+
#include "JAlarmWeekday.hpp"
|
|
28
|
+
|
|
29
|
+
namespace margelo::nitro::alarmkit {
|
|
30
|
+
|
|
31
|
+
jni::local_ref<JHybridAlarmKitSpec::jhybriddata> JHybridAlarmKitSpec::initHybrid(jni::alias_ref<jhybridobject> jThis) {
|
|
32
|
+
return makeCxxInstance(jThis);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
void JHybridAlarmKitSpec::registerNatives() {
|
|
36
|
+
registerHybrid({
|
|
37
|
+
makeNativeMethod("initHybrid", JHybridAlarmKitSpec::initHybrid),
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
size_t JHybridAlarmKitSpec::getExternalMemorySize() noexcept {
|
|
42
|
+
static const auto method = javaClassStatic()->getMethod<jlong()>("getMemorySize");
|
|
43
|
+
return method(_javaPart);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Properties
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
// Methods
|
|
50
|
+
std::shared_ptr<Promise<bool>> JHybridAlarmKitSpec::requestAlarmPermission() {
|
|
51
|
+
static const auto method = javaClassStatic()->getMethod<jni::local_ref<JPromise::javaobject>()>("requestAlarmPermission");
|
|
52
|
+
auto __result = method(_javaPart);
|
|
53
|
+
return [&]() {
|
|
54
|
+
auto __promise = Promise<bool>::create();
|
|
55
|
+
__result->cthis()->addOnResolvedListener([=](const jni::alias_ref<jni::JObject>& __boxedResult) {
|
|
56
|
+
auto __result = jni::static_ref_cast<jni::JBoolean>(__boxedResult);
|
|
57
|
+
__promise->resolve(static_cast<bool>(__result->value()));
|
|
58
|
+
});
|
|
59
|
+
__result->cthis()->addOnRejectedListener([=](const jni::alias_ref<jni::JThrowable>& __throwable) {
|
|
60
|
+
jni::JniException __jniError(__throwable);
|
|
61
|
+
__promise->reject(std::make_exception_ptr(__jniError));
|
|
62
|
+
});
|
|
63
|
+
return __promise;
|
|
64
|
+
}();
|
|
65
|
+
}
|
|
66
|
+
std::shared_ptr<Promise<std::string>> JHybridAlarmKitSpec::scheduleFixedAlarm(const std::string& title, const CustomizableAlarmButton& stopBtn, const std::string& tintColor, const std::optional<CustomizableAlarmButton>& secondaryBtn, std::optional<double> timestamp, const std::optional<AlarmCountdown>& countdown) {
|
|
67
|
+
static const auto method = javaClassStatic()->getMethod<jni::local_ref<JPromise::javaobject>(jni::alias_ref<jni::JString> /* title */, jni::alias_ref<JCustomizableAlarmButton> /* stopBtn */, jni::alias_ref<jni::JString> /* tintColor */, jni::alias_ref<JCustomizableAlarmButton> /* secondaryBtn */, jni::alias_ref<jni::JDouble> /* timestamp */, jni::alias_ref<JAlarmCountdown> /* countdown */)>("scheduleFixedAlarm");
|
|
68
|
+
auto __result = method(_javaPart, jni::make_jstring(title), JCustomizableAlarmButton::fromCpp(stopBtn), jni::make_jstring(tintColor), secondaryBtn.has_value() ? JCustomizableAlarmButton::fromCpp(secondaryBtn.value()) : nullptr, timestamp.has_value() ? jni::JDouble::valueOf(timestamp.value()) : nullptr, countdown.has_value() ? JAlarmCountdown::fromCpp(countdown.value()) : nullptr);
|
|
69
|
+
return [&]() {
|
|
70
|
+
auto __promise = Promise<std::string>::create();
|
|
71
|
+
__result->cthis()->addOnResolvedListener([=](const jni::alias_ref<jni::JObject>& __boxedResult) {
|
|
72
|
+
auto __result = jni::static_ref_cast<jni::JString>(__boxedResult);
|
|
73
|
+
__promise->resolve(__result->toStdString());
|
|
74
|
+
});
|
|
75
|
+
__result->cthis()->addOnRejectedListener([=](const jni::alias_ref<jni::JThrowable>& __throwable) {
|
|
76
|
+
jni::JniException __jniError(__throwable);
|
|
77
|
+
__promise->reject(std::make_exception_ptr(__jniError));
|
|
78
|
+
});
|
|
79
|
+
return __promise;
|
|
80
|
+
}();
|
|
81
|
+
}
|
|
82
|
+
std::shared_ptr<Promise<std::string>> JHybridAlarmKitSpec::scheduleRelativeAlarm(const std::string& title, const CustomizableAlarmButton& stopBtn, const std::string& tintColor, double hour, double minute, const std::vector<AlarmWeekday>& repeats, const std::optional<CustomizableAlarmButton>& secondaryBtn, const std::optional<AlarmCountdown>& countdown) {
|
|
83
|
+
static const auto method = javaClassStatic()->getMethod<jni::local_ref<JPromise::javaobject>(jni::alias_ref<jni::JString> /* title */, jni::alias_ref<JCustomizableAlarmButton> /* stopBtn */, jni::alias_ref<jni::JString> /* tintColor */, double /* hour */, double /* minute */, jni::alias_ref<jni::JArrayClass<JAlarmWeekday>> /* repeats */, jni::alias_ref<JCustomizableAlarmButton> /* secondaryBtn */, jni::alias_ref<JAlarmCountdown> /* countdown */)>("scheduleRelativeAlarm");
|
|
84
|
+
auto __result = method(_javaPart, jni::make_jstring(title), JCustomizableAlarmButton::fromCpp(stopBtn), jni::make_jstring(tintColor), hour, minute, [&]() {
|
|
85
|
+
size_t __size = repeats.size();
|
|
86
|
+
jni::local_ref<jni::JArrayClass<JAlarmWeekday>> __array = jni::JArrayClass<JAlarmWeekday>::newArray(__size);
|
|
87
|
+
for (size_t __i = 0; __i < __size; __i++) {
|
|
88
|
+
const auto& __element = repeats[__i];
|
|
89
|
+
__array->setElement(__i, *JAlarmWeekday::fromCpp(__element));
|
|
90
|
+
}
|
|
91
|
+
return __array;
|
|
92
|
+
}(), secondaryBtn.has_value() ? JCustomizableAlarmButton::fromCpp(secondaryBtn.value()) : nullptr, countdown.has_value() ? JAlarmCountdown::fromCpp(countdown.value()) : nullptr);
|
|
93
|
+
return [&]() {
|
|
94
|
+
auto __promise = Promise<std::string>::create();
|
|
95
|
+
__result->cthis()->addOnResolvedListener([=](const jni::alias_ref<jni::JObject>& __boxedResult) {
|
|
96
|
+
auto __result = jni::static_ref_cast<jni::JString>(__boxedResult);
|
|
97
|
+
__promise->resolve(__result->toStdString());
|
|
98
|
+
});
|
|
99
|
+
__result->cthis()->addOnRejectedListener([=](const jni::alias_ref<jni::JThrowable>& __throwable) {
|
|
100
|
+
jni::JniException __jniError(__throwable);
|
|
101
|
+
__promise->reject(std::make_exception_ptr(__jniError));
|
|
102
|
+
});
|
|
103
|
+
return __promise;
|
|
104
|
+
}();
|
|
105
|
+
}
|
|
106
|
+
std::shared_ptr<Promise<bool>> JHybridAlarmKitSpec::cancelAlarm(const std::string& id) {
|
|
107
|
+
static const auto method = javaClassStatic()->getMethod<jni::local_ref<JPromise::javaobject>(jni::alias_ref<jni::JString> /* id */)>("cancelAlarm");
|
|
108
|
+
auto __result = method(_javaPart, jni::make_jstring(id));
|
|
109
|
+
return [&]() {
|
|
110
|
+
auto __promise = Promise<bool>::create();
|
|
111
|
+
__result->cthis()->addOnResolvedListener([=](const jni::alias_ref<jni::JObject>& __boxedResult) {
|
|
112
|
+
auto __result = jni::static_ref_cast<jni::JBoolean>(__boxedResult);
|
|
113
|
+
__promise->resolve(static_cast<bool>(__result->value()));
|
|
114
|
+
});
|
|
115
|
+
__result->cthis()->addOnRejectedListener([=](const jni::alias_ref<jni::JThrowable>& __throwable) {
|
|
116
|
+
jni::JniException __jniError(__throwable);
|
|
117
|
+
__promise->reject(std::make_exception_ptr(__jniError));
|
|
118
|
+
});
|
|
119
|
+
return __promise;
|
|
120
|
+
}();
|
|
121
|
+
}
|
|
122
|
+
std::shared_ptr<Promise<bool>> JHybridAlarmKitSpec::cancelAllAlarms() {
|
|
123
|
+
static const auto method = javaClassStatic()->getMethod<jni::local_ref<JPromise::javaobject>()>("cancelAllAlarms");
|
|
124
|
+
auto __result = method(_javaPart);
|
|
125
|
+
return [&]() {
|
|
126
|
+
auto __promise = Promise<bool>::create();
|
|
127
|
+
__result->cthis()->addOnResolvedListener([=](const jni::alias_ref<jni::JObject>& __boxedResult) {
|
|
128
|
+
auto __result = jni::static_ref_cast<jni::JBoolean>(__boxedResult);
|
|
129
|
+
__promise->resolve(static_cast<bool>(__result->value()));
|
|
130
|
+
});
|
|
131
|
+
__result->cthis()->addOnRejectedListener([=](const jni::alias_ref<jni::JThrowable>& __throwable) {
|
|
132
|
+
jni::JniException __jniError(__throwable);
|
|
133
|
+
__promise->reject(std::make_exception_ptr(__jniError));
|
|
134
|
+
});
|
|
135
|
+
return __promise;
|
|
136
|
+
}();
|
|
137
|
+
}
|
|
138
|
+
std::shared_ptr<Promise<std::optional<std::string>>> JHybridAlarmKitSpec::getAlarm(const std::string& id) {
|
|
139
|
+
static const auto method = javaClassStatic()->getMethod<jni::local_ref<JPromise::javaobject>(jni::alias_ref<jni::JString> /* id */)>("getAlarm");
|
|
140
|
+
auto __result = method(_javaPart, jni::make_jstring(id));
|
|
141
|
+
return [&]() {
|
|
142
|
+
auto __promise = Promise<std::optional<std::string>>::create();
|
|
143
|
+
__result->cthis()->addOnResolvedListener([=](const jni::alias_ref<jni::JObject>& __boxedResult) {
|
|
144
|
+
auto __result = jni::static_ref_cast<jni::JString>(__boxedResult);
|
|
145
|
+
__promise->resolve(__result != nullptr ? std::make_optional(__result->toStdString()) : std::nullopt);
|
|
146
|
+
});
|
|
147
|
+
__result->cthis()->addOnRejectedListener([=](const jni::alias_ref<jni::JThrowable>& __throwable) {
|
|
148
|
+
jni::JniException __jniError(__throwable);
|
|
149
|
+
__promise->reject(std::make_exception_ptr(__jniError));
|
|
150
|
+
});
|
|
151
|
+
return __promise;
|
|
152
|
+
}();
|
|
153
|
+
}
|
|
154
|
+
std::shared_ptr<Promise<std::vector<std::string>>> JHybridAlarmKitSpec::getAllAlarms() {
|
|
155
|
+
static const auto method = javaClassStatic()->getMethod<jni::local_ref<JPromise::javaobject>()>("getAllAlarms");
|
|
156
|
+
auto __result = method(_javaPart);
|
|
157
|
+
return [&]() {
|
|
158
|
+
auto __promise = Promise<std::vector<std::string>>::create();
|
|
159
|
+
__result->cthis()->addOnResolvedListener([=](const jni::alias_ref<jni::JObject>& __boxedResult) {
|
|
160
|
+
auto __result = jni::static_ref_cast<jni::JArrayClass<jni::JString>>(__boxedResult);
|
|
161
|
+
__promise->resolve([&]() {
|
|
162
|
+
size_t __size = __result->size();
|
|
163
|
+
std::vector<std::string> __vector;
|
|
164
|
+
__vector.reserve(__size);
|
|
165
|
+
for (size_t __i = 0; __i < __size; __i++) {
|
|
166
|
+
auto __element = __result->getElement(__i);
|
|
167
|
+
__vector.push_back(__element->toStdString());
|
|
168
|
+
}
|
|
169
|
+
return __vector;
|
|
170
|
+
}());
|
|
171
|
+
});
|
|
172
|
+
__result->cthis()->addOnRejectedListener([=](const jni::alias_ref<jni::JThrowable>& __throwable) {
|
|
173
|
+
jni::JniException __jniError(__throwable);
|
|
174
|
+
__promise->reject(std::make_exception_ptr(__jniError));
|
|
175
|
+
});
|
|
176
|
+
return __promise;
|
|
177
|
+
}();
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
} // namespace margelo::nitro::alarmkit
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridAlarmKitSpec.hpp
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © 2026 Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#include <NitroModules/JHybridObject.hpp>
|
|
11
|
+
#include <fbjni/fbjni.h>
|
|
12
|
+
#include "HybridAlarmKitSpec.hpp"
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
namespace margelo::nitro::alarmkit {
|
|
18
|
+
|
|
19
|
+
using namespace facebook;
|
|
20
|
+
|
|
21
|
+
class JHybridAlarmKitSpec: public jni::HybridClass<JHybridAlarmKitSpec, JHybridObject>,
|
|
22
|
+
public virtual HybridAlarmKitSpec {
|
|
23
|
+
public:
|
|
24
|
+
static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/alarmkit/HybridAlarmKitSpec;";
|
|
25
|
+
static jni::local_ref<jhybriddata> initHybrid(jni::alias_ref<jhybridobject> jThis);
|
|
26
|
+
static void registerNatives();
|
|
27
|
+
|
|
28
|
+
protected:
|
|
29
|
+
// C++ constructor (called from Java via `initHybrid()`)
|
|
30
|
+
explicit JHybridAlarmKitSpec(jni::alias_ref<jhybridobject> jThis) :
|
|
31
|
+
HybridObject(HybridAlarmKitSpec::TAG),
|
|
32
|
+
_javaPart(jni::make_global(jThis)) {}
|
|
33
|
+
|
|
34
|
+
public:
|
|
35
|
+
~JHybridAlarmKitSpec() override {
|
|
36
|
+
// Hermes GC can destroy JS objects on a non-JNI Thread.
|
|
37
|
+
jni::ThreadScope::WithClassLoader([&] { _javaPart.reset(); });
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
public:
|
|
41
|
+
size_t getExternalMemorySize() noexcept override;
|
|
42
|
+
|
|
43
|
+
public:
|
|
44
|
+
inline const jni::global_ref<JHybridAlarmKitSpec::javaobject>& getJavaPart() const noexcept {
|
|
45
|
+
return _javaPart;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
public:
|
|
49
|
+
// Properties
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
public:
|
|
53
|
+
// Methods
|
|
54
|
+
std::shared_ptr<Promise<bool>> requestAlarmPermission() override;
|
|
55
|
+
std::shared_ptr<Promise<std::string>> scheduleFixedAlarm(const std::string& title, const CustomizableAlarmButton& stopBtn, const std::string& tintColor, const std::optional<CustomizableAlarmButton>& secondaryBtn, std::optional<double> timestamp, const std::optional<AlarmCountdown>& countdown) override;
|
|
56
|
+
std::shared_ptr<Promise<std::string>> scheduleRelativeAlarm(const std::string& title, const CustomizableAlarmButton& stopBtn, const std::string& tintColor, double hour, double minute, const std::vector<AlarmWeekday>& repeats, const std::optional<CustomizableAlarmButton>& secondaryBtn, const std::optional<AlarmCountdown>& countdown) override;
|
|
57
|
+
std::shared_ptr<Promise<bool>> cancelAlarm(const std::string& id) override;
|
|
58
|
+
std::shared_ptr<Promise<bool>> cancelAllAlarms() override;
|
|
59
|
+
std::shared_ptr<Promise<std::optional<std::string>>> getAlarm(const std::string& id) override;
|
|
60
|
+
std::shared_ptr<Promise<std::vector<std::string>>> getAllAlarms() override;
|
|
61
|
+
|
|
62
|
+
private:
|
|
63
|
+
friend HybridBase;
|
|
64
|
+
using HybridBase::HybridBase;
|
|
65
|
+
jni::global_ref<JHybridAlarmKitSpec::javaobject> _javaPart;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
} // namespace margelo::nitro::alarmkit
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// AlarmCountdown.kt
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © 2026 Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
package com.margelo.nitro.alarmkit
|
|
9
|
+
|
|
10
|
+
import androidx.annotation.Keep
|
|
11
|
+
import com.facebook.proguard.annotations.DoNotStrip
|
|
12
|
+
import com.margelo.nitro.core.*
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Represents the JavaScript object/struct "AlarmCountdown".
|
|
16
|
+
*/
|
|
17
|
+
@DoNotStrip
|
|
18
|
+
@Keep
|
|
19
|
+
data class AlarmCountdown
|
|
20
|
+
@DoNotStrip
|
|
21
|
+
@Keep
|
|
22
|
+
constructor(
|
|
23
|
+
val preAlert: Double?,
|
|
24
|
+
val postAlert: Double?
|
|
25
|
+
) {
|
|
26
|
+
/* main constructor */
|
|
27
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// AlarmWeekday.kt
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © 2026 Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
package com.margelo.nitro.alarmkit
|
|
9
|
+
|
|
10
|
+
import androidx.annotation.Keep
|
|
11
|
+
import com.facebook.proguard.annotations.DoNotStrip
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Represents the JavaScript enum/union "AlarmWeekday".
|
|
15
|
+
*/
|
|
16
|
+
@DoNotStrip
|
|
17
|
+
@Keep
|
|
18
|
+
enum class AlarmWeekday {
|
|
19
|
+
MONDAY,
|
|
20
|
+
TUESDAY,
|
|
21
|
+
WEDNESDAY,
|
|
22
|
+
THURSDAY,
|
|
23
|
+
FRIDAY,
|
|
24
|
+
SATURDAY,
|
|
25
|
+
SUNDAY;
|
|
26
|
+
|
|
27
|
+
@DoNotStrip
|
|
28
|
+
@Keep
|
|
29
|
+
private val _ordinal = ordinal
|
|
30
|
+
}
|
package/nitrogen/generated/android/kotlin/com/margelo/nitro/alarmkit/CustomizableAlarmButton.kt
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// CustomizableAlarmButton.kt
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © 2026 Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
package com.margelo.nitro.alarmkit
|
|
9
|
+
|
|
10
|
+
import androidx.annotation.Keep
|
|
11
|
+
import com.facebook.proguard.annotations.DoNotStrip
|
|
12
|
+
import com.margelo.nitro.core.*
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Represents the JavaScript object/struct "CustomizableAlarmButton".
|
|
16
|
+
*/
|
|
17
|
+
@DoNotStrip
|
|
18
|
+
@Keep
|
|
19
|
+
data class CustomizableAlarmButton
|
|
20
|
+
@DoNotStrip
|
|
21
|
+
@Keep
|
|
22
|
+
constructor(
|
|
23
|
+
val text: String,
|
|
24
|
+
val textColor: String,
|
|
25
|
+
val icon: String
|
|
26
|
+
) {
|
|
27
|
+
/* main constructor */
|
|
28
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridAlarmKitSpec.kt
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © 2026 Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
package com.margelo.nitro.alarmkit
|
|
9
|
+
|
|
10
|
+
import androidx.annotation.Keep
|
|
11
|
+
import com.facebook.jni.HybridData
|
|
12
|
+
import com.facebook.proguard.annotations.DoNotStrip
|
|
13
|
+
import com.margelo.nitro.core.*
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* A Kotlin class representing the AlarmKit HybridObject.
|
|
17
|
+
* Implement this abstract class to create Kotlin-based instances of AlarmKit.
|
|
18
|
+
*/
|
|
19
|
+
@DoNotStrip
|
|
20
|
+
@Keep
|
|
21
|
+
@Suppress(
|
|
22
|
+
"KotlinJniMissingFunction", "unused",
|
|
23
|
+
"RedundantSuppression", "RedundantUnitReturnType", "SimpleRedundantLet",
|
|
24
|
+
"LocalVariableName", "PropertyName", "PrivatePropertyName", "FunctionName"
|
|
25
|
+
)
|
|
26
|
+
abstract class HybridAlarmKitSpec: HybridObject() {
|
|
27
|
+
@DoNotStrip
|
|
28
|
+
private var mHybridData: HybridData = initHybrid()
|
|
29
|
+
|
|
30
|
+
init {
|
|
31
|
+
super.updateNative(mHybridData)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
override fun updateNative(hybridData: HybridData) {
|
|
35
|
+
mHybridData = hybridData
|
|
36
|
+
super.updateNative(hybridData)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Properties
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
// Methods
|
|
43
|
+
@DoNotStrip
|
|
44
|
+
@Keep
|
|
45
|
+
abstract fun requestAlarmPermission(): Promise<Boolean>
|
|
46
|
+
|
|
47
|
+
@DoNotStrip
|
|
48
|
+
@Keep
|
|
49
|
+
abstract fun scheduleFixedAlarm(title: String, stopBtn: CustomizableAlarmButton, tintColor: String, secondaryBtn: CustomizableAlarmButton?, timestamp: Double?, countdown: AlarmCountdown?): Promise<String>
|
|
50
|
+
|
|
51
|
+
@DoNotStrip
|
|
52
|
+
@Keep
|
|
53
|
+
abstract fun scheduleRelativeAlarm(title: String, stopBtn: CustomizableAlarmButton, tintColor: String, hour: Double, minute: Double, repeats: Array<AlarmWeekday>, secondaryBtn: CustomizableAlarmButton?, countdown: AlarmCountdown?): Promise<String>
|
|
54
|
+
|
|
55
|
+
@DoNotStrip
|
|
56
|
+
@Keep
|
|
57
|
+
abstract fun cancelAlarm(id: String): Promise<Boolean>
|
|
58
|
+
|
|
59
|
+
@DoNotStrip
|
|
60
|
+
@Keep
|
|
61
|
+
abstract fun cancelAllAlarms(): Promise<Boolean>
|
|
62
|
+
|
|
63
|
+
@DoNotStrip
|
|
64
|
+
@Keep
|
|
65
|
+
abstract fun getAlarm(id: String): Promise<String?>
|
|
66
|
+
|
|
67
|
+
@DoNotStrip
|
|
68
|
+
@Keep
|
|
69
|
+
abstract fun getAllAlarms(): Promise<Array<String>>
|
|
70
|
+
|
|
71
|
+
private external fun initHybrid(): HybridData
|
|
72
|
+
|
|
73
|
+
companion object {
|
|
74
|
+
private const val TAG = "HybridAlarmKitSpec"
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// alarmkitOnLoad.kt
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © 2026 Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
package com.margelo.nitro.alarmkit
|
|
9
|
+
|
|
10
|
+
import android.util.Log
|
|
11
|
+
|
|
12
|
+
internal class alarmkitOnLoad {
|
|
13
|
+
companion object {
|
|
14
|
+
private const val TAG = "alarmkitOnLoad"
|
|
15
|
+
private var didLoad = false
|
|
16
|
+
/**
|
|
17
|
+
* Initializes the native part of "alarmkit".
|
|
18
|
+
* This method is idempotent and can be called more than once.
|
|
19
|
+
*/
|
|
20
|
+
@JvmStatic
|
|
21
|
+
fun initializeNative() {
|
|
22
|
+
if (didLoad) return
|
|
23
|
+
try {
|
|
24
|
+
Log.i(TAG, "Loading alarmkit C++ library...")
|
|
25
|
+
System.loadLibrary("alarmkit")
|
|
26
|
+
Log.i(TAG, "Successfully loaded alarmkit C++ library!")
|
|
27
|
+
didLoad = true
|
|
28
|
+
} catch (e: Error) {
|
|
29
|
+
Log.e(TAG, "Failed to load alarmkit C++ library! Is it properly installed and linked? " +
|
|
30
|
+
"Is the name correct? (see `CMakeLists.txt`, at `add_library(...)`)", e)
|
|
31
|
+
throw e
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
#
|
|
2
|
+
# AlarmKit+autolinking.rb
|
|
3
|
+
# This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
# https://github.com/mrousavy/nitro
|
|
5
|
+
# Copyright © 2026 Marc Rousavy @ Margelo
|
|
6
|
+
#
|
|
7
|
+
|
|
8
|
+
# This is a Ruby script that adds all files generated by Nitrogen
|
|
9
|
+
# to the given podspec.
|
|
10
|
+
#
|
|
11
|
+
# To use it, add this to your .podspec:
|
|
12
|
+
# ```ruby
|
|
13
|
+
# Pod::Spec.new do |spec|
|
|
14
|
+
# # ...
|
|
15
|
+
#
|
|
16
|
+
# # Add all files generated by Nitrogen
|
|
17
|
+
# load 'nitrogen/generated/ios/AlarmKit+autolinking.rb'
|
|
18
|
+
# add_nitrogen_files(spec)
|
|
19
|
+
# end
|
|
20
|
+
# ```
|
|
21
|
+
|
|
22
|
+
def add_nitrogen_files(spec)
|
|
23
|
+
Pod::UI.puts "[NitroModules] 🔥 AlarmKit is boosted by nitro!"
|
|
24
|
+
|
|
25
|
+
spec.dependency "NitroModules"
|
|
26
|
+
|
|
27
|
+
current_source_files = Array(spec.attributes_hash['source_files'])
|
|
28
|
+
spec.source_files = current_source_files + [
|
|
29
|
+
# Generated cross-platform specs
|
|
30
|
+
"nitrogen/generated/shared/**/*.{h,hpp,c,cpp,swift}",
|
|
31
|
+
# Generated bridges for the cross-platform specs
|
|
32
|
+
"nitrogen/generated/ios/**/*.{h,hpp,c,cpp,mm,swift}",
|
|
33
|
+
]
|
|
34
|
+
|
|
35
|
+
current_public_header_files = Array(spec.attributes_hash['public_header_files'])
|
|
36
|
+
spec.public_header_files = current_public_header_files + [
|
|
37
|
+
# Generated specs
|
|
38
|
+
"nitrogen/generated/shared/**/*.{h,hpp}",
|
|
39
|
+
# Swift to C++ bridging helpers
|
|
40
|
+
"nitrogen/generated/ios/AlarmKit-Swift-Cxx-Bridge.hpp"
|
|
41
|
+
]
|
|
42
|
+
|
|
43
|
+
current_private_header_files = Array(spec.attributes_hash['private_header_files'])
|
|
44
|
+
spec.private_header_files = current_private_header_files + [
|
|
45
|
+
# iOS specific specs
|
|
46
|
+
"nitrogen/generated/ios/c++/**/*.{h,hpp}",
|
|
47
|
+
# Views are framework-specific and should be private
|
|
48
|
+
"nitrogen/generated/shared/**/views/**/*"
|
|
49
|
+
]
|
|
50
|
+
|
|
51
|
+
current_pod_target_xcconfig = spec.attributes_hash['pod_target_xcconfig'] || {}
|
|
52
|
+
spec.pod_target_xcconfig = current_pod_target_xcconfig.merge({
|
|
53
|
+
# Use C++ 20
|
|
54
|
+
"CLANG_CXX_LANGUAGE_STANDARD" => "c++20",
|
|
55
|
+
# Enables C++ <-> Swift interop (by default it's only C)
|
|
56
|
+
"SWIFT_OBJC_INTEROP_MODE" => "objcxx",
|
|
57
|
+
# Enables stricter modular headers
|
|
58
|
+
"DEFINES_MODULE" => "YES",
|
|
59
|
+
})
|
|
60
|
+
end
|