akanjs 2.2.1-rc.1 → 2.2.1-rc.2
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/client/capacitor.ts +48 -27
- package/package.json +1 -1
package/client/capacitor.ts
CHANGED
|
@@ -145,6 +145,7 @@ type CapacitorModuleMap = {
|
|
|
145
145
|
type CapacitorImportCache = Partial<{
|
|
146
146
|
[K in keyof CapacitorModuleMap]: Promise<CapacitorModuleMap[keyof CapacitorModuleMap]>;
|
|
147
147
|
}>;
|
|
148
|
+
type CapacitorPluginRegistry = Record<string, unknown>;
|
|
148
149
|
|
|
149
150
|
declare global {
|
|
150
151
|
|
|
@@ -169,58 +170,78 @@ const loadCapacitorModule = <K extends keyof CapacitorModuleMap>(
|
|
|
169
170
|
return loaded;
|
|
170
171
|
};
|
|
171
172
|
|
|
172
|
-
const
|
|
173
|
-
|
|
174
|
-
const
|
|
175
|
-
|
|
176
|
-
|
|
173
|
+
const getCapacitorPlugin = <Plugin>(name: string): Plugin => {
|
|
174
|
+
const capacitor = (globalThis as typeof globalThis & { Capacitor?: { Plugins?: CapacitorPluginRegistry } }).Capacitor;
|
|
175
|
+
const plugin = capacitor?.Plugins?.[name];
|
|
176
|
+
if (!plugin) throw new Error(`Capacitor plugin "${name}" is not available.`);
|
|
177
|
+
return plugin as Plugin;
|
|
178
|
+
};
|
|
177
179
|
|
|
178
180
|
export const loadCapacitorApp = () =>
|
|
179
|
-
loadCapacitorModule("app", () =>
|
|
181
|
+
loadCapacitorModule("app", async () => ({ App: getCapacitorPlugin<CapacitorAppModule["App"]>("App") }));
|
|
180
182
|
|
|
181
183
|
export const loadCapacitorBrowser = () =>
|
|
182
|
-
loadCapacitorModule("browser", () =>
|
|
184
|
+
loadCapacitorModule("browser", async () => ({
|
|
185
|
+
Browser: getCapacitorPlugin<CapacitorBrowserModule["Browser"]>("Browser"),
|
|
186
|
+
}));
|
|
183
187
|
|
|
184
188
|
export const loadCapacitorCamera = () =>
|
|
185
|
-
loadCapacitorModule("camera", () =>
|
|
189
|
+
loadCapacitorModule("camera", async () => ({
|
|
190
|
+
Camera: getCapacitorPlugin<CapacitorCameraModule["Camera"]>("Camera"),
|
|
191
|
+
CameraResultType: { DataUrl: "dataUrl" },
|
|
192
|
+
CameraSource: { Prompt: "PROMPT", Camera: "CAMERA", Photos: "PHOTOS" },
|
|
193
|
+
}));
|
|
186
194
|
|
|
187
195
|
export const loadCapacitorContacts = () =>
|
|
188
|
-
loadCapacitorModule("contacts", () =>
|
|
189
|
-
|
|
190
|
-
);
|
|
196
|
+
loadCapacitorModule("contacts", async () => ({
|
|
197
|
+
Contacts: getCapacitorPlugin<CapacitorContactsModule["Contacts"]>("Contacts"),
|
|
198
|
+
}));
|
|
191
199
|
|
|
192
200
|
export const loadCapacitorCore = () =>
|
|
193
|
-
loadCapacitorModule("core", () =>
|
|
201
|
+
loadCapacitorModule("core", async () => ({
|
|
202
|
+
CapacitorCookies: getCapacitorPlugin<CapacitorCoreModule["CapacitorCookies"]>("CapacitorCookies"),
|
|
203
|
+
}));
|
|
194
204
|
|
|
195
205
|
export const loadCapacitorDevice = () =>
|
|
196
|
-
loadCapacitorModule("device", () =>
|
|
206
|
+
loadCapacitorModule("device", async () => ({
|
|
207
|
+
Device: getCapacitorPlugin<CapacitorDeviceModule["Device"]>("Device"),
|
|
208
|
+
}));
|
|
197
209
|
|
|
198
210
|
export const loadCapacitorFcm = () =>
|
|
199
|
-
loadCapacitorModule("fcm", () =>
|
|
211
|
+
loadCapacitorModule("fcm", async () => ({ FCM: getCapacitorPlugin<CapacitorFcmModule["FCM"]>("FCM") }));
|
|
200
212
|
|
|
201
213
|
export const loadCapacitorGeolocation = () =>
|
|
202
|
-
loadCapacitorModule("geolocation", () =>
|
|
203
|
-
|
|
204
|
-
);
|
|
214
|
+
loadCapacitorModule("geolocation", async () => ({
|
|
215
|
+
Geolocation: getCapacitorPlugin<CapacitorGeolocationModule["Geolocation"]>("Geolocation"),
|
|
216
|
+
}));
|
|
205
217
|
|
|
206
218
|
export const loadCapacitorHaptics = () =>
|
|
207
|
-
loadCapacitorModule("haptics", () =>
|
|
219
|
+
loadCapacitorModule("haptics", async () => ({
|
|
220
|
+
Haptics: getCapacitorPlugin<CapacitorHapticsModule["Haptics"]>("Haptics"),
|
|
221
|
+
ImpactStyle: { Light: "LIGHT", Medium: "MEDIUM", Heavy: "HEAVY" },
|
|
222
|
+
}));
|
|
208
223
|
|
|
209
224
|
export const loadCapacitorKeyboard = () =>
|
|
210
|
-
loadCapacitorModule("keyboard", () =>
|
|
225
|
+
loadCapacitorModule("keyboard", async () => ({
|
|
226
|
+
Keyboard: getCapacitorPlugin<CapacitorKeyboardModule["Keyboard"]>("Keyboard"),
|
|
227
|
+
}));
|
|
211
228
|
|
|
212
229
|
export const loadCapacitorPreferences = () =>
|
|
213
|
-
loadCapacitorModule("preferences", () =>
|
|
214
|
-
|
|
215
|
-
);
|
|
230
|
+
loadCapacitorModule("preferences", async () => ({
|
|
231
|
+
Preferences: getCapacitorPlugin<CapacitorPreferencesModule["Preferences"]>("Preferences"),
|
|
232
|
+
}));
|
|
216
233
|
|
|
217
234
|
export const loadCapacitorPushNotifications = () =>
|
|
218
|
-
loadCapacitorModule("pushNotifications", () =>
|
|
219
|
-
|
|
220
|
-
);
|
|
235
|
+
loadCapacitorModule("pushNotifications", async () => ({
|
|
236
|
+
PushNotifications: getCapacitorPlugin<CapacitorPushNotificationsModule["PushNotifications"]>("PushNotifications"),
|
|
237
|
+
}));
|
|
221
238
|
|
|
222
239
|
export const loadCapacitorSafeArea = () =>
|
|
223
|
-
loadCapacitorModule("safeArea", () =>
|
|
240
|
+
loadCapacitorModule("safeArea", async () => ({
|
|
241
|
+
SafeArea: getCapacitorPlugin<CapacitorSafeAreaModule["SafeArea"]>("SafeArea"),
|
|
242
|
+
}));
|
|
224
243
|
|
|
225
244
|
export const loadCapacitorUpdater = () =>
|
|
226
|
-
loadCapacitorModule("updater", () =>
|
|
245
|
+
loadCapacitorModule("updater", async () => ({
|
|
246
|
+
CapacitorUpdater: getCapacitorPlugin<CapacitorUpdaterModule["CapacitorUpdater"]>("CapacitorUpdater"),
|
|
247
|
+
}));
|