@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,271 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridAlarmKitSpec_cxx.swift
|
|
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
|
+
import Foundation
|
|
9
|
+
import NitroModules
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* A class implementation that bridges HybridAlarmKitSpec over to C++.
|
|
13
|
+
* In C++, we cannot use Swift protocols - so we need to wrap it in a class to make it strongly defined.
|
|
14
|
+
*
|
|
15
|
+
* Also, some Swift types need to be bridged with special handling:
|
|
16
|
+
* - Enums need to be wrapped in Structs, otherwise they cannot be accessed bi-directionally (Swift bug: https://github.com/swiftlang/swift/issues/75330)
|
|
17
|
+
* - Other HybridObjects need to be wrapped/unwrapped from the Swift TCxx wrapper
|
|
18
|
+
* - Throwing methods need to be wrapped with a Result<T, Error> type, as exceptions cannot be propagated to C++
|
|
19
|
+
*/
|
|
20
|
+
public class HybridAlarmKitSpec_cxx {
|
|
21
|
+
/**
|
|
22
|
+
* The Swift <> C++ bridge's namespace (`margelo::nitro::alarmkit::bridge::swift`)
|
|
23
|
+
* from `AlarmKit-Swift-Cxx-Bridge.hpp`.
|
|
24
|
+
* This contains specialized C++ templates, and C++ helper functions that can be accessed from Swift.
|
|
25
|
+
*/
|
|
26
|
+
public typealias bridge = margelo.nitro.alarmkit.bridge.swift
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Holds an instance of the `HybridAlarmKitSpec` Swift protocol.
|
|
30
|
+
*/
|
|
31
|
+
private var __implementation: any HybridAlarmKitSpec
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Holds a weak pointer to the C++ class that wraps the Swift class.
|
|
35
|
+
*/
|
|
36
|
+
private var __cxxPart: bridge.std__weak_ptr_margelo__nitro__alarmkit__HybridAlarmKitSpec_
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Create a new `HybridAlarmKitSpec_cxx` that wraps the given `HybridAlarmKitSpec`.
|
|
40
|
+
* All properties and methods bridge to C++ types.
|
|
41
|
+
*/
|
|
42
|
+
public init(_ implementation: any HybridAlarmKitSpec) {
|
|
43
|
+
self.__implementation = implementation
|
|
44
|
+
self.__cxxPart = .init()
|
|
45
|
+
/* no base class */
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Get the actual `HybridAlarmKitSpec` instance this class wraps.
|
|
50
|
+
*/
|
|
51
|
+
@inline(__always)
|
|
52
|
+
public func getHybridAlarmKitSpec() -> any HybridAlarmKitSpec {
|
|
53
|
+
return __implementation
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Casts this instance to a retained unsafe raw pointer.
|
|
58
|
+
* This acquires one additional strong reference on the object!
|
|
59
|
+
*/
|
|
60
|
+
public func toUnsafe() -> UnsafeMutableRawPointer {
|
|
61
|
+
return Unmanaged.passRetained(self).toOpaque()
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Casts an unsafe pointer to a `HybridAlarmKitSpec_cxx`.
|
|
66
|
+
* The pointer has to be a retained opaque `Unmanaged<HybridAlarmKitSpec_cxx>`.
|
|
67
|
+
* This removes one strong reference from the object!
|
|
68
|
+
*/
|
|
69
|
+
public class func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> HybridAlarmKitSpec_cxx {
|
|
70
|
+
return Unmanaged<HybridAlarmKitSpec_cxx>.fromOpaque(pointer).takeRetainedValue()
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Gets (or creates) the C++ part of this Hybrid Object.
|
|
75
|
+
* The C++ part is a `std::shared_ptr<margelo::nitro::alarmkit::HybridAlarmKitSpec>`.
|
|
76
|
+
*/
|
|
77
|
+
public func getCxxPart() -> bridge.std__shared_ptr_margelo__nitro__alarmkit__HybridAlarmKitSpec_ {
|
|
78
|
+
let cachedCxxPart = self.__cxxPart.lock()
|
|
79
|
+
if cachedCxxPart.__convertToBool() {
|
|
80
|
+
return cachedCxxPart
|
|
81
|
+
} else {
|
|
82
|
+
let newCxxPart = bridge.create_std__shared_ptr_margelo__nitro__alarmkit__HybridAlarmKitSpec_(self.toUnsafe())
|
|
83
|
+
__cxxPart = bridge.weakify_std__shared_ptr_margelo__nitro__alarmkit__HybridAlarmKitSpec_(newCxxPart)
|
|
84
|
+
return newCxxPart
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Get the memory size of the Swift class (plus size of any other allocations)
|
|
92
|
+
* so the JS VM can properly track it and garbage-collect the JS object if needed.
|
|
93
|
+
*/
|
|
94
|
+
@inline(__always)
|
|
95
|
+
public var memorySize: Int {
|
|
96
|
+
return MemoryHelper.getSizeOf(self.__implementation) + self.__implementation.memorySize
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// Properties
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
// Methods
|
|
103
|
+
@inline(__always)
|
|
104
|
+
public final func requestAlarmPermission() -> bridge.Result_std__shared_ptr_Promise_bool___ {
|
|
105
|
+
do {
|
|
106
|
+
let __result = try self.__implementation.requestAlarmPermission()
|
|
107
|
+
let __resultCpp = { () -> bridge.std__shared_ptr_Promise_bool__ in
|
|
108
|
+
let __promise = bridge.create_std__shared_ptr_Promise_bool__()
|
|
109
|
+
let __promiseHolder = bridge.wrap_std__shared_ptr_Promise_bool__(__promise)
|
|
110
|
+
__result
|
|
111
|
+
.then({ __result in __promiseHolder.resolve(__result) })
|
|
112
|
+
.catch({ __error in __promiseHolder.reject(__error.toCpp()) })
|
|
113
|
+
return __promise
|
|
114
|
+
}()
|
|
115
|
+
return bridge.create_Result_std__shared_ptr_Promise_bool___(__resultCpp)
|
|
116
|
+
} catch (let __error) {
|
|
117
|
+
let __exceptionPtr = __error.toCpp()
|
|
118
|
+
return bridge.create_Result_std__shared_ptr_Promise_bool___(__exceptionPtr)
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
@inline(__always)
|
|
123
|
+
public final func scheduleFixedAlarm(title: std.string, stopBtn: CustomizableAlarmButton, tintColor: std.string, secondaryBtn: bridge.std__optional_CustomizableAlarmButton_, timestamp: bridge.std__optional_double_, countdown: bridge.std__optional_AlarmCountdown_) -> bridge.Result_std__shared_ptr_Promise_std__string___ {
|
|
124
|
+
do {
|
|
125
|
+
let __result = try self.__implementation.scheduleFixedAlarm(title: String(title), stopBtn: stopBtn, tintColor: String(tintColor), secondaryBtn: { () -> CustomizableAlarmButton? in
|
|
126
|
+
if let __unwrapped = secondaryBtn.value {
|
|
127
|
+
return __unwrapped
|
|
128
|
+
} else {
|
|
129
|
+
return nil
|
|
130
|
+
}
|
|
131
|
+
}(), timestamp: timestamp.value, countdown: { () -> AlarmCountdown? in
|
|
132
|
+
if let __unwrapped = countdown.value {
|
|
133
|
+
return __unwrapped
|
|
134
|
+
} else {
|
|
135
|
+
return nil
|
|
136
|
+
}
|
|
137
|
+
}())
|
|
138
|
+
let __resultCpp = { () -> bridge.std__shared_ptr_Promise_std__string__ in
|
|
139
|
+
let __promise = bridge.create_std__shared_ptr_Promise_std__string__()
|
|
140
|
+
let __promiseHolder = bridge.wrap_std__shared_ptr_Promise_std__string__(__promise)
|
|
141
|
+
__result
|
|
142
|
+
.then({ __result in __promiseHolder.resolve(std.string(__result)) })
|
|
143
|
+
.catch({ __error in __promiseHolder.reject(__error.toCpp()) })
|
|
144
|
+
return __promise
|
|
145
|
+
}()
|
|
146
|
+
return bridge.create_Result_std__shared_ptr_Promise_std__string___(__resultCpp)
|
|
147
|
+
} catch (let __error) {
|
|
148
|
+
let __exceptionPtr = __error.toCpp()
|
|
149
|
+
return bridge.create_Result_std__shared_ptr_Promise_std__string___(__exceptionPtr)
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
@inline(__always)
|
|
154
|
+
public final func scheduleRelativeAlarm(title: std.string, stopBtn: CustomizableAlarmButton, tintColor: std.string, hour: Double, minute: Double, repeats: bridge.std__vector_AlarmWeekday_, secondaryBtn: bridge.std__optional_CustomizableAlarmButton_, countdown: bridge.std__optional_AlarmCountdown_) -> bridge.Result_std__shared_ptr_Promise_std__string___ {
|
|
155
|
+
do {
|
|
156
|
+
let __result = try self.__implementation.scheduleRelativeAlarm(title: String(title), stopBtn: stopBtn, tintColor: String(tintColor), hour: hour, minute: minute, repeats: repeats.map({ __item in __item }), secondaryBtn: { () -> CustomizableAlarmButton? in
|
|
157
|
+
if let __unwrapped = secondaryBtn.value {
|
|
158
|
+
return __unwrapped
|
|
159
|
+
} else {
|
|
160
|
+
return nil
|
|
161
|
+
}
|
|
162
|
+
}(), countdown: { () -> AlarmCountdown? in
|
|
163
|
+
if let __unwrapped = countdown.value {
|
|
164
|
+
return __unwrapped
|
|
165
|
+
} else {
|
|
166
|
+
return nil
|
|
167
|
+
}
|
|
168
|
+
}())
|
|
169
|
+
let __resultCpp = { () -> bridge.std__shared_ptr_Promise_std__string__ in
|
|
170
|
+
let __promise = bridge.create_std__shared_ptr_Promise_std__string__()
|
|
171
|
+
let __promiseHolder = bridge.wrap_std__shared_ptr_Promise_std__string__(__promise)
|
|
172
|
+
__result
|
|
173
|
+
.then({ __result in __promiseHolder.resolve(std.string(__result)) })
|
|
174
|
+
.catch({ __error in __promiseHolder.reject(__error.toCpp()) })
|
|
175
|
+
return __promise
|
|
176
|
+
}()
|
|
177
|
+
return bridge.create_Result_std__shared_ptr_Promise_std__string___(__resultCpp)
|
|
178
|
+
} catch (let __error) {
|
|
179
|
+
let __exceptionPtr = __error.toCpp()
|
|
180
|
+
return bridge.create_Result_std__shared_ptr_Promise_std__string___(__exceptionPtr)
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
@inline(__always)
|
|
185
|
+
public final func cancelAlarm(id: std.string) -> bridge.Result_std__shared_ptr_Promise_bool___ {
|
|
186
|
+
do {
|
|
187
|
+
let __result = try self.__implementation.cancelAlarm(id: String(id))
|
|
188
|
+
let __resultCpp = { () -> bridge.std__shared_ptr_Promise_bool__ in
|
|
189
|
+
let __promise = bridge.create_std__shared_ptr_Promise_bool__()
|
|
190
|
+
let __promiseHolder = bridge.wrap_std__shared_ptr_Promise_bool__(__promise)
|
|
191
|
+
__result
|
|
192
|
+
.then({ __result in __promiseHolder.resolve(__result) })
|
|
193
|
+
.catch({ __error in __promiseHolder.reject(__error.toCpp()) })
|
|
194
|
+
return __promise
|
|
195
|
+
}()
|
|
196
|
+
return bridge.create_Result_std__shared_ptr_Promise_bool___(__resultCpp)
|
|
197
|
+
} catch (let __error) {
|
|
198
|
+
let __exceptionPtr = __error.toCpp()
|
|
199
|
+
return bridge.create_Result_std__shared_ptr_Promise_bool___(__exceptionPtr)
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
@inline(__always)
|
|
204
|
+
public final func cancelAllAlarms() -> bridge.Result_std__shared_ptr_Promise_bool___ {
|
|
205
|
+
do {
|
|
206
|
+
let __result = try self.__implementation.cancelAllAlarms()
|
|
207
|
+
let __resultCpp = { () -> bridge.std__shared_ptr_Promise_bool__ in
|
|
208
|
+
let __promise = bridge.create_std__shared_ptr_Promise_bool__()
|
|
209
|
+
let __promiseHolder = bridge.wrap_std__shared_ptr_Promise_bool__(__promise)
|
|
210
|
+
__result
|
|
211
|
+
.then({ __result in __promiseHolder.resolve(__result) })
|
|
212
|
+
.catch({ __error in __promiseHolder.reject(__error.toCpp()) })
|
|
213
|
+
return __promise
|
|
214
|
+
}()
|
|
215
|
+
return bridge.create_Result_std__shared_ptr_Promise_bool___(__resultCpp)
|
|
216
|
+
} catch (let __error) {
|
|
217
|
+
let __exceptionPtr = __error.toCpp()
|
|
218
|
+
return bridge.create_Result_std__shared_ptr_Promise_bool___(__exceptionPtr)
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
@inline(__always)
|
|
223
|
+
public final func getAlarm(id: std.string) -> bridge.Result_std__shared_ptr_Promise_std__optional_std__string____ {
|
|
224
|
+
do {
|
|
225
|
+
let __result = try self.__implementation.getAlarm(id: String(id))
|
|
226
|
+
let __resultCpp = { () -> bridge.std__shared_ptr_Promise_std__optional_std__string___ in
|
|
227
|
+
let __promise = bridge.create_std__shared_ptr_Promise_std__optional_std__string___()
|
|
228
|
+
let __promiseHolder = bridge.wrap_std__shared_ptr_Promise_std__optional_std__string___(__promise)
|
|
229
|
+
__result
|
|
230
|
+
.then({ __result in __promiseHolder.resolve({ () -> bridge.std__optional_std__string_ in
|
|
231
|
+
if let __unwrappedValue = __result {
|
|
232
|
+
return bridge.create_std__optional_std__string_(std.string(__unwrappedValue))
|
|
233
|
+
} else {
|
|
234
|
+
return .init()
|
|
235
|
+
}
|
|
236
|
+
}()) })
|
|
237
|
+
.catch({ __error in __promiseHolder.reject(__error.toCpp()) })
|
|
238
|
+
return __promise
|
|
239
|
+
}()
|
|
240
|
+
return bridge.create_Result_std__shared_ptr_Promise_std__optional_std__string____(__resultCpp)
|
|
241
|
+
} catch (let __error) {
|
|
242
|
+
let __exceptionPtr = __error.toCpp()
|
|
243
|
+
return bridge.create_Result_std__shared_ptr_Promise_std__optional_std__string____(__exceptionPtr)
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
@inline(__always)
|
|
248
|
+
public final func getAllAlarms() -> bridge.Result_std__shared_ptr_Promise_std__vector_std__string____ {
|
|
249
|
+
do {
|
|
250
|
+
let __result = try self.__implementation.getAllAlarms()
|
|
251
|
+
let __resultCpp = { () -> bridge.std__shared_ptr_Promise_std__vector_std__string___ in
|
|
252
|
+
let __promise = bridge.create_std__shared_ptr_Promise_std__vector_std__string___()
|
|
253
|
+
let __promiseHolder = bridge.wrap_std__shared_ptr_Promise_std__vector_std__string___(__promise)
|
|
254
|
+
__result
|
|
255
|
+
.then({ __result in __promiseHolder.resolve({ () -> bridge.std__vector_std__string_ in
|
|
256
|
+
var __vector = bridge.create_std__vector_std__string_(__result.count)
|
|
257
|
+
for __item in __result {
|
|
258
|
+
__vector.push_back(std.string(__item))
|
|
259
|
+
}
|
|
260
|
+
return __vector
|
|
261
|
+
}()) })
|
|
262
|
+
.catch({ __error in __promiseHolder.reject(__error.toCpp()) })
|
|
263
|
+
return __promise
|
|
264
|
+
}()
|
|
265
|
+
return bridge.create_Result_std__shared_ptr_Promise_std__vector_std__string____(__resultCpp)
|
|
266
|
+
} catch (let __error) {
|
|
267
|
+
let __exceptionPtr = __error.toCpp()
|
|
268
|
+
return bridge.create_Result_std__shared_ptr_Promise_std__vector_std__string____(__exceptionPtr)
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// AlarmCountdown.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
|
+
#if __has_include(<NitroModules/JSIConverter.hpp>)
|
|
11
|
+
#include <NitroModules/JSIConverter.hpp>
|
|
12
|
+
#else
|
|
13
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
14
|
+
#endif
|
|
15
|
+
#if __has_include(<NitroModules/NitroDefines.hpp>)
|
|
16
|
+
#include <NitroModules/NitroDefines.hpp>
|
|
17
|
+
#else
|
|
18
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
19
|
+
#endif
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
#include <optional>
|
|
24
|
+
|
|
25
|
+
namespace margelo::nitro::alarmkit {
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* A struct which can be represented as a JavaScript object (AlarmCountdown).
|
|
29
|
+
*/
|
|
30
|
+
struct AlarmCountdown {
|
|
31
|
+
public:
|
|
32
|
+
std::optional<double> preAlert SWIFT_PRIVATE;
|
|
33
|
+
std::optional<double> postAlert SWIFT_PRIVATE;
|
|
34
|
+
|
|
35
|
+
public:
|
|
36
|
+
AlarmCountdown() = default;
|
|
37
|
+
explicit AlarmCountdown(std::optional<double> preAlert, std::optional<double> postAlert): preAlert(preAlert), postAlert(postAlert) {}
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
} // namespace margelo::nitro::alarmkit
|
|
41
|
+
|
|
42
|
+
namespace margelo::nitro {
|
|
43
|
+
|
|
44
|
+
using namespace margelo::nitro::alarmkit;
|
|
45
|
+
|
|
46
|
+
// C++ AlarmCountdown <> JS AlarmCountdown (object)
|
|
47
|
+
template <>
|
|
48
|
+
struct JSIConverter<AlarmCountdown> final {
|
|
49
|
+
static inline AlarmCountdown fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
|
|
50
|
+
jsi::Object obj = arg.asObject(runtime);
|
|
51
|
+
return AlarmCountdown(
|
|
52
|
+
JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, "preAlert")),
|
|
53
|
+
JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, "postAlert"))
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
static inline jsi::Value toJSI(jsi::Runtime& runtime, const AlarmCountdown& arg) {
|
|
57
|
+
jsi::Object obj(runtime);
|
|
58
|
+
obj.setProperty(runtime, "preAlert", JSIConverter<std::optional<double>>::toJSI(runtime, arg.preAlert));
|
|
59
|
+
obj.setProperty(runtime, "postAlert", JSIConverter<std::optional<double>>::toJSI(runtime, arg.postAlert));
|
|
60
|
+
return obj;
|
|
61
|
+
}
|
|
62
|
+
static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
|
|
63
|
+
if (!value.isObject()) {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
jsi::Object obj = value.getObject(runtime);
|
|
67
|
+
if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, "preAlert"))) return false;
|
|
68
|
+
if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, "postAlert"))) return false;
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
} // namespace margelo::nitro
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// AlarmWeekday.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
|
+
#if __has_include(<NitroModules/NitroHash.hpp>)
|
|
11
|
+
#include <NitroModules/NitroHash.hpp>
|
|
12
|
+
#else
|
|
13
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
14
|
+
#endif
|
|
15
|
+
#if __has_include(<NitroModules/JSIConverter.hpp>)
|
|
16
|
+
#include <NitroModules/JSIConverter.hpp>
|
|
17
|
+
#else
|
|
18
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
19
|
+
#endif
|
|
20
|
+
#if __has_include(<NitroModules/NitroDefines.hpp>)
|
|
21
|
+
#include <NitroModules/NitroDefines.hpp>
|
|
22
|
+
#else
|
|
23
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
24
|
+
#endif
|
|
25
|
+
|
|
26
|
+
namespace margelo::nitro::alarmkit {
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* An enum which can be represented as a JavaScript union (AlarmWeekday).
|
|
30
|
+
*/
|
|
31
|
+
enum class AlarmWeekday {
|
|
32
|
+
MONDAY SWIFT_NAME(monday) = 0,
|
|
33
|
+
TUESDAY SWIFT_NAME(tuesday) = 1,
|
|
34
|
+
WEDNESDAY SWIFT_NAME(wednesday) = 2,
|
|
35
|
+
THURSDAY SWIFT_NAME(thursday) = 3,
|
|
36
|
+
FRIDAY SWIFT_NAME(friday) = 4,
|
|
37
|
+
SATURDAY SWIFT_NAME(saturday) = 5,
|
|
38
|
+
SUNDAY SWIFT_NAME(sunday) = 6,
|
|
39
|
+
} CLOSED_ENUM;
|
|
40
|
+
|
|
41
|
+
} // namespace margelo::nitro::alarmkit
|
|
42
|
+
|
|
43
|
+
namespace margelo::nitro {
|
|
44
|
+
|
|
45
|
+
using namespace margelo::nitro::alarmkit;
|
|
46
|
+
|
|
47
|
+
// C++ AlarmWeekday <> JS AlarmWeekday (union)
|
|
48
|
+
template <>
|
|
49
|
+
struct JSIConverter<AlarmWeekday> final {
|
|
50
|
+
static inline AlarmWeekday fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
|
|
51
|
+
std::string unionValue = JSIConverter<std::string>::fromJSI(runtime, arg);
|
|
52
|
+
switch (hashString(unionValue.c_str(), unionValue.size())) {
|
|
53
|
+
case hashString("monday"): return AlarmWeekday::MONDAY;
|
|
54
|
+
case hashString("tuesday"): return AlarmWeekday::TUESDAY;
|
|
55
|
+
case hashString("wednesday"): return AlarmWeekday::WEDNESDAY;
|
|
56
|
+
case hashString("thursday"): return AlarmWeekday::THURSDAY;
|
|
57
|
+
case hashString("friday"): return AlarmWeekday::FRIDAY;
|
|
58
|
+
case hashString("saturday"): return AlarmWeekday::SATURDAY;
|
|
59
|
+
case hashString("sunday"): return AlarmWeekday::SUNDAY;
|
|
60
|
+
default: [[unlikely]]
|
|
61
|
+
throw std::invalid_argument("Cannot convert \"" + unionValue + "\" to enum AlarmWeekday - invalid value!");
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
static inline jsi::Value toJSI(jsi::Runtime& runtime, AlarmWeekday arg) {
|
|
65
|
+
switch (arg) {
|
|
66
|
+
case AlarmWeekday::MONDAY: return JSIConverter<std::string>::toJSI(runtime, "monday");
|
|
67
|
+
case AlarmWeekday::TUESDAY: return JSIConverter<std::string>::toJSI(runtime, "tuesday");
|
|
68
|
+
case AlarmWeekday::WEDNESDAY: return JSIConverter<std::string>::toJSI(runtime, "wednesday");
|
|
69
|
+
case AlarmWeekday::THURSDAY: return JSIConverter<std::string>::toJSI(runtime, "thursday");
|
|
70
|
+
case AlarmWeekday::FRIDAY: return JSIConverter<std::string>::toJSI(runtime, "friday");
|
|
71
|
+
case AlarmWeekday::SATURDAY: return JSIConverter<std::string>::toJSI(runtime, "saturday");
|
|
72
|
+
case AlarmWeekday::SUNDAY: return JSIConverter<std::string>::toJSI(runtime, "sunday");
|
|
73
|
+
default: [[unlikely]]
|
|
74
|
+
throw std::invalid_argument("Cannot convert AlarmWeekday to JS - invalid value: "
|
|
75
|
+
+ std::to_string(static_cast<int>(arg)) + "!");
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
|
|
79
|
+
if (!value.isString()) {
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
std::string unionValue = JSIConverter<std::string>::fromJSI(runtime, value);
|
|
83
|
+
switch (hashString(unionValue.c_str(), unionValue.size())) {
|
|
84
|
+
case hashString("monday"):
|
|
85
|
+
case hashString("tuesday"):
|
|
86
|
+
case hashString("wednesday"):
|
|
87
|
+
case hashString("thursday"):
|
|
88
|
+
case hashString("friday"):
|
|
89
|
+
case hashString("saturday"):
|
|
90
|
+
case hashString("sunday"):
|
|
91
|
+
return true;
|
|
92
|
+
default:
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
} // namespace margelo::nitro
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// CustomizableAlarmButton.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
|
+
#if __has_include(<NitroModules/JSIConverter.hpp>)
|
|
11
|
+
#include <NitroModules/JSIConverter.hpp>
|
|
12
|
+
#else
|
|
13
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
14
|
+
#endif
|
|
15
|
+
#if __has_include(<NitroModules/NitroDefines.hpp>)
|
|
16
|
+
#include <NitroModules/NitroDefines.hpp>
|
|
17
|
+
#else
|
|
18
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
19
|
+
#endif
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
#include <string>
|
|
24
|
+
|
|
25
|
+
namespace margelo::nitro::alarmkit {
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* A struct which can be represented as a JavaScript object (CustomizableAlarmButton).
|
|
29
|
+
*/
|
|
30
|
+
struct CustomizableAlarmButton {
|
|
31
|
+
public:
|
|
32
|
+
std::string text SWIFT_PRIVATE;
|
|
33
|
+
std::string textColor SWIFT_PRIVATE;
|
|
34
|
+
std::string icon SWIFT_PRIVATE;
|
|
35
|
+
|
|
36
|
+
public:
|
|
37
|
+
CustomizableAlarmButton() = default;
|
|
38
|
+
explicit CustomizableAlarmButton(std::string text, std::string textColor, std::string icon): text(text), textColor(textColor), icon(icon) {}
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
} // namespace margelo::nitro::alarmkit
|
|
42
|
+
|
|
43
|
+
namespace margelo::nitro {
|
|
44
|
+
|
|
45
|
+
using namespace margelo::nitro::alarmkit;
|
|
46
|
+
|
|
47
|
+
// C++ CustomizableAlarmButton <> JS CustomizableAlarmButton (object)
|
|
48
|
+
template <>
|
|
49
|
+
struct JSIConverter<CustomizableAlarmButton> final {
|
|
50
|
+
static inline CustomizableAlarmButton fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
|
|
51
|
+
jsi::Object obj = arg.asObject(runtime);
|
|
52
|
+
return CustomizableAlarmButton(
|
|
53
|
+
JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, "text")),
|
|
54
|
+
JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, "textColor")),
|
|
55
|
+
JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, "icon"))
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
static inline jsi::Value toJSI(jsi::Runtime& runtime, const CustomizableAlarmButton& arg) {
|
|
59
|
+
jsi::Object obj(runtime);
|
|
60
|
+
obj.setProperty(runtime, "text", JSIConverter<std::string>::toJSI(runtime, arg.text));
|
|
61
|
+
obj.setProperty(runtime, "textColor", JSIConverter<std::string>::toJSI(runtime, arg.textColor));
|
|
62
|
+
obj.setProperty(runtime, "icon", JSIConverter<std::string>::toJSI(runtime, arg.icon));
|
|
63
|
+
return obj;
|
|
64
|
+
}
|
|
65
|
+
static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
|
|
66
|
+
if (!value.isObject()) {
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
jsi::Object obj = value.getObject(runtime);
|
|
70
|
+
if (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, "text"))) return false;
|
|
71
|
+
if (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, "textColor"))) return false;
|
|
72
|
+
if (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, "icon"))) return false;
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
} // namespace margelo::nitro
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridAlarmKitSpec.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 "HybridAlarmKitSpec.hpp"
|
|
9
|
+
|
|
10
|
+
namespace margelo::nitro::alarmkit {
|
|
11
|
+
|
|
12
|
+
void HybridAlarmKitSpec::loadHybridMethods() {
|
|
13
|
+
// load base methods/properties
|
|
14
|
+
HybridObject::loadHybridMethods();
|
|
15
|
+
// load custom methods/properties
|
|
16
|
+
registerHybrids(this, [](Prototype& prototype) {
|
|
17
|
+
prototype.registerHybridMethod("requestAlarmPermission", &HybridAlarmKitSpec::requestAlarmPermission);
|
|
18
|
+
prototype.registerHybridMethod("scheduleFixedAlarm", &HybridAlarmKitSpec::scheduleFixedAlarm);
|
|
19
|
+
prototype.registerHybridMethod("scheduleRelativeAlarm", &HybridAlarmKitSpec::scheduleRelativeAlarm);
|
|
20
|
+
prototype.registerHybridMethod("cancelAlarm", &HybridAlarmKitSpec::cancelAlarm);
|
|
21
|
+
prototype.registerHybridMethod("cancelAllAlarms", &HybridAlarmKitSpec::cancelAllAlarms);
|
|
22
|
+
prototype.registerHybridMethod("getAlarm", &HybridAlarmKitSpec::getAlarm);
|
|
23
|
+
prototype.registerHybridMethod("getAllAlarms", &HybridAlarmKitSpec::getAllAlarms);
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
} // namespace margelo::nitro::alarmkit
|
|
@@ -0,0 +1,79 @@
|
|
|
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
|
+
#if __has_include(<NitroModules/HybridObject.hpp>)
|
|
11
|
+
#include <NitroModules/HybridObject.hpp>
|
|
12
|
+
#else
|
|
13
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
14
|
+
#endif
|
|
15
|
+
|
|
16
|
+
// Forward declaration of `CustomizableAlarmButton` to properly resolve imports.
|
|
17
|
+
namespace margelo::nitro::alarmkit { struct CustomizableAlarmButton; }
|
|
18
|
+
// Forward declaration of `AlarmCountdown` to properly resolve imports.
|
|
19
|
+
namespace margelo::nitro::alarmkit { struct AlarmCountdown; }
|
|
20
|
+
// Forward declaration of `AlarmWeekday` to properly resolve imports.
|
|
21
|
+
namespace margelo::nitro::alarmkit { enum class AlarmWeekday; }
|
|
22
|
+
|
|
23
|
+
#include <NitroModules/Promise.hpp>
|
|
24
|
+
#include <string>
|
|
25
|
+
#include "CustomizableAlarmButton.hpp"
|
|
26
|
+
#include <optional>
|
|
27
|
+
#include "AlarmCountdown.hpp"
|
|
28
|
+
#include <vector>
|
|
29
|
+
#include "AlarmWeekday.hpp"
|
|
30
|
+
|
|
31
|
+
namespace margelo::nitro::alarmkit {
|
|
32
|
+
|
|
33
|
+
using namespace margelo::nitro;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* An abstract base class for `AlarmKit`
|
|
37
|
+
* Inherit this class to create instances of `HybridAlarmKitSpec` in C++.
|
|
38
|
+
* You must explicitly call `HybridObject`'s constructor yourself, because it is virtual.
|
|
39
|
+
* @example
|
|
40
|
+
* ```cpp
|
|
41
|
+
* class HybridAlarmKit: public HybridAlarmKitSpec {
|
|
42
|
+
* public:
|
|
43
|
+
* HybridAlarmKit(...): HybridObject(TAG) { ... }
|
|
44
|
+
* // ...
|
|
45
|
+
* };
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
class HybridAlarmKitSpec: public virtual HybridObject {
|
|
49
|
+
public:
|
|
50
|
+
// Constructor
|
|
51
|
+
explicit HybridAlarmKitSpec(): HybridObject(TAG) { }
|
|
52
|
+
|
|
53
|
+
// Destructor
|
|
54
|
+
~HybridAlarmKitSpec() override = default;
|
|
55
|
+
|
|
56
|
+
public:
|
|
57
|
+
// Properties
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
public:
|
|
61
|
+
// Methods
|
|
62
|
+
virtual std::shared_ptr<Promise<bool>> requestAlarmPermission() = 0;
|
|
63
|
+
virtual 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) = 0;
|
|
64
|
+
virtual 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) = 0;
|
|
65
|
+
virtual std::shared_ptr<Promise<bool>> cancelAlarm(const std::string& id) = 0;
|
|
66
|
+
virtual std::shared_ptr<Promise<bool>> cancelAllAlarms() = 0;
|
|
67
|
+
virtual std::shared_ptr<Promise<std::optional<std::string>>> getAlarm(const std::string& id) = 0;
|
|
68
|
+
virtual std::shared_ptr<Promise<std::vector<std::string>>> getAllAlarms() = 0;
|
|
69
|
+
|
|
70
|
+
protected:
|
|
71
|
+
// Hybrid Setup
|
|
72
|
+
void loadHybridMethods() override;
|
|
73
|
+
|
|
74
|
+
protected:
|
|
75
|
+
// Tag for logging
|
|
76
|
+
static constexpr auto TAG = "AlarmKit";
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
} // namespace margelo::nitro::alarmkit
|