akanjs 2.2.1-rc.0 → 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 -25
- 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,56 +170,78 @@ const loadCapacitorModule = <K extends keyof CapacitorModuleMap>(
|
|
|
169
170
|
return loaded;
|
|
170
171
|
};
|
|
171
172
|
|
|
172
|
-
const
|
|
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
|
+
};
|
|
173
179
|
|
|
174
180
|
export const loadCapacitorApp = () =>
|
|
175
|
-
loadCapacitorModule("app", () =>
|
|
181
|
+
loadCapacitorModule("app", async () => ({ App: getCapacitorPlugin<CapacitorAppModule["App"]>("App") }));
|
|
176
182
|
|
|
177
183
|
export const loadCapacitorBrowser = () =>
|
|
178
|
-
loadCapacitorModule("browser", () =>
|
|
184
|
+
loadCapacitorModule("browser", async () => ({
|
|
185
|
+
Browser: getCapacitorPlugin<CapacitorBrowserModule["Browser"]>("Browser"),
|
|
186
|
+
}));
|
|
179
187
|
|
|
180
188
|
export const loadCapacitorCamera = () =>
|
|
181
|
-
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
|
+
}));
|
|
182
194
|
|
|
183
195
|
export const loadCapacitorContacts = () =>
|
|
184
|
-
loadCapacitorModule("contacts", () =>
|
|
185
|
-
|
|
186
|
-
);
|
|
196
|
+
loadCapacitorModule("contacts", async () => ({
|
|
197
|
+
Contacts: getCapacitorPlugin<CapacitorContactsModule["Contacts"]>("Contacts"),
|
|
198
|
+
}));
|
|
187
199
|
|
|
188
200
|
export const loadCapacitorCore = () =>
|
|
189
|
-
loadCapacitorModule("core", () =>
|
|
201
|
+
loadCapacitorModule("core", async () => ({
|
|
202
|
+
CapacitorCookies: getCapacitorPlugin<CapacitorCoreModule["CapacitorCookies"]>("CapacitorCookies"),
|
|
203
|
+
}));
|
|
190
204
|
|
|
191
205
|
export const loadCapacitorDevice = () =>
|
|
192
|
-
loadCapacitorModule("device", () =>
|
|
206
|
+
loadCapacitorModule("device", async () => ({
|
|
207
|
+
Device: getCapacitorPlugin<CapacitorDeviceModule["Device"]>("Device"),
|
|
208
|
+
}));
|
|
193
209
|
|
|
194
210
|
export const loadCapacitorFcm = () =>
|
|
195
|
-
loadCapacitorModule("fcm", () =>
|
|
211
|
+
loadCapacitorModule("fcm", async () => ({ FCM: getCapacitorPlugin<CapacitorFcmModule["FCM"]>("FCM") }));
|
|
196
212
|
|
|
197
213
|
export const loadCapacitorGeolocation = () =>
|
|
198
|
-
loadCapacitorModule("geolocation", () =>
|
|
199
|
-
|
|
200
|
-
);
|
|
214
|
+
loadCapacitorModule("geolocation", async () => ({
|
|
215
|
+
Geolocation: getCapacitorPlugin<CapacitorGeolocationModule["Geolocation"]>("Geolocation"),
|
|
216
|
+
}));
|
|
201
217
|
|
|
202
218
|
export const loadCapacitorHaptics = () =>
|
|
203
|
-
loadCapacitorModule("haptics", () =>
|
|
219
|
+
loadCapacitorModule("haptics", async () => ({
|
|
220
|
+
Haptics: getCapacitorPlugin<CapacitorHapticsModule["Haptics"]>("Haptics"),
|
|
221
|
+
ImpactStyle: { Light: "LIGHT", Medium: "MEDIUM", Heavy: "HEAVY" },
|
|
222
|
+
}));
|
|
204
223
|
|
|
205
224
|
export const loadCapacitorKeyboard = () =>
|
|
206
|
-
loadCapacitorModule("keyboard", () =>
|
|
225
|
+
loadCapacitorModule("keyboard", async () => ({
|
|
226
|
+
Keyboard: getCapacitorPlugin<CapacitorKeyboardModule["Keyboard"]>("Keyboard"),
|
|
227
|
+
}));
|
|
207
228
|
|
|
208
229
|
export const loadCapacitorPreferences = () =>
|
|
209
|
-
loadCapacitorModule("preferences", () =>
|
|
210
|
-
|
|
211
|
-
);
|
|
230
|
+
loadCapacitorModule("preferences", async () => ({
|
|
231
|
+
Preferences: getCapacitorPlugin<CapacitorPreferencesModule["Preferences"]>("Preferences"),
|
|
232
|
+
}));
|
|
212
233
|
|
|
213
234
|
export const loadCapacitorPushNotifications = () =>
|
|
214
|
-
loadCapacitorModule("pushNotifications", () =>
|
|
215
|
-
|
|
216
|
-
);
|
|
235
|
+
loadCapacitorModule("pushNotifications", async () => ({
|
|
236
|
+
PushNotifications: getCapacitorPlugin<CapacitorPushNotificationsModule["PushNotifications"]>("PushNotifications"),
|
|
237
|
+
}));
|
|
217
238
|
|
|
218
239
|
export const loadCapacitorSafeArea = () =>
|
|
219
|
-
loadCapacitorModule("safeArea", () =>
|
|
220
|
-
|
|
221
|
-
);
|
|
240
|
+
loadCapacitorModule("safeArea", async () => ({
|
|
241
|
+
SafeArea: getCapacitorPlugin<CapacitorSafeAreaModule["SafeArea"]>("SafeArea"),
|
|
242
|
+
}));
|
|
222
243
|
|
|
223
244
|
export const loadCapacitorUpdater = () =>
|
|
224
|
-
loadCapacitorModule("updater", () =>
|
|
245
|
+
loadCapacitorModule("updater", async () => ({
|
|
246
|
+
CapacitorUpdater: getCapacitorPlugin<CapacitorUpdaterModule["CapacitorUpdater"]>("CapacitorUpdater"),
|
|
247
|
+
}));
|