aio-capacitor 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.
Files changed (3) hide show
  1. package/index.d.ts +143 -0
  2. package/index.js +547 -0
  3. package/package.json +35 -0
package/index.d.ts ADDED
@@ -0,0 +1,143 @@
1
+ import { type I_logItem } from 'aio-utils';
2
+ export type NotificationItem = {
3
+ id: number;
4
+ title: string;
5
+ body: string;
6
+ fireAt: number;
7
+ status: 'pending' | 'scheduled' | 'done';
8
+ };
9
+ export type I_speak = {
10
+ text: string;
11
+ lang?: 'fa-IR' | 'en-US';
12
+ rate?: number;
13
+ pitch?: number;
14
+ };
15
+ type PermissionName = "CAMERA" | "ACCESS_FINE_LOCATION" | "ACCESS_COARSE_LOCATION" | "POST_NOTIFICATIONS";
16
+ export declare class AIOCapacitor {
17
+ onLog: ((log: I_logItem) => void) | undefined;
18
+ constructor(p?: {
19
+ onLog?: (log: I_logItem) => void;
20
+ });
21
+ getPlatform: () => 'web' | 'android' | 'ios';
22
+ isNative: () => boolean;
23
+ addLog: (log: I_logItem) => void;
24
+ vibrate: (p: {
25
+ pattern?: number[];
26
+ density?: 'light' | 'medium' | 'heavy';
27
+ }) => Promise<void>;
28
+ vibratePattern: (pattern: number[]) => Promise<void>;
29
+ vibrateImpact: (style?: 'light' | 'medium' | 'heavy') => Promise<void>;
30
+ getPermissions: (permissionNames: PermissionName[]) => Promise<void>;
31
+ speak: (p: {
32
+ text: string;
33
+ lang?: 'fa-IR' | 'en-US';
34
+ rate?: number;
35
+ pitch?: number;
36
+ }) => Promise<void>;
37
+ getSpeakList: () => Promise<any>;
38
+ storageSave: (name: string, value: any) => Promise<void>;
39
+ storageLoad: (name: string, def: any) => Promise<any>;
40
+ copy: (text: string) => Promise<void>;
41
+ paste: () => Promise<string>;
42
+ readText: (file: any) => Promise<any>;
43
+ readPath: (path: string, type: 'text' | 'imageSrc' | 'arrayBuffer') => Promise<{
44
+ success: boolean;
45
+ result: any;
46
+ message?: string;
47
+ }>;
48
+ writeFile: (data: string, path: string, encoding?: boolean) => Promise<any>;
49
+ save: (data: string | File | Blob, path: string) => Promise<{
50
+ success: boolean;
51
+ message: any;
52
+ }>;
53
+ shareText: (text: string, title?: string) => Promise<{
54
+ success: boolean;
55
+ error?: undefined;
56
+ } | {
57
+ success: boolean;
58
+ error: any;
59
+ }>;
60
+ shareFile: (file: Blob | File, fileName?: string) => Promise<any>;
61
+ getLocation: () => Promise<{
62
+ success: boolean;
63
+ latitude?: number;
64
+ longitude?: number;
65
+ accuracy?: number;
66
+ source?: "gps" | "cache" | "network";
67
+ error?: string;
68
+ }>;
69
+ awake: (state?: boolean) => Promise<any>;
70
+ isAwake: () => Promise<any>;
71
+ }
72
+ type DB = {
73
+ save: (item: NotificationItem) => Promise<void>;
74
+ getAll: () => Promise<NotificationItem[]>;
75
+ update: (id: number, patch: Partial<NotificationItem>) => Promise<void>;
76
+ };
77
+ export declare class NotificationService {
78
+ private db;
79
+ constructor(db: DB);
80
+ init(): Promise<void>;
81
+ notifyAt(date: number, title: string, body: string): Promise<number>;
82
+ private schedule;
83
+ private fireNow;
84
+ resync(): Promise<void>;
85
+ cancel(id: number): Promise<void>;
86
+ list(): Promise<any>;
87
+ }
88
+ export declare class Tracker {
89
+ private watchId;
90
+ onSuccess: (coord: {
91
+ latitude: number;
92
+ longitude: number;
93
+ }) => void;
94
+ onFailed: (message: string) => void;
95
+ onLog: ((log: I_logItem) => void) | undefined;
96
+ constructor(p: {
97
+ onSuccess: (coord: {
98
+ latitude: number;
99
+ longitude: number;
100
+ }) => void;
101
+ onFailed: (message: string) => void;
102
+ onLog?: (log: I_logItem) => void;
103
+ });
104
+ start(): void;
105
+ stop(): Promise<void>;
106
+ isTracking(): boolean;
107
+ }
108
+ export type I_FileRecordType = 'image' | 'file' | 'json' | 'text';
109
+ export type I_FileRecord = {
110
+ id: string;
111
+ name: string;
112
+ path: string;
113
+ type: I_FileRecordType;
114
+ createdAt: number;
115
+ meta?: any;
116
+ };
117
+ export declare class FileRegistry {
118
+ private store;
119
+ private onChange;
120
+ private storageKey;
121
+ isNative: boolean;
122
+ private webStorage;
123
+ private initialRecords;
124
+ constructor(p: {
125
+ onChange: (v: I_FileRecord[]) => void;
126
+ storageKey: string;
127
+ mock?: I_FileRecord[];
128
+ });
129
+ private init;
130
+ private initialLoad;
131
+ private save;
132
+ add(p: {
133
+ type: I_FileRecordType;
134
+ path: string;
135
+ name?: string;
136
+ meta?: any;
137
+ }): I_FileRecord;
138
+ rename(id: string, newName?: string): I_FileRecord;
139
+ remove(id: string): void;
140
+ list: () => I_FileRecord[];
141
+ getById: (id: string) => I_FileRecord | null;
142
+ }
143
+ export {};
package/index.js ADDED
@@ -0,0 +1,547 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { Capacitor } from '@capacitor/core';
11
+ import { Preferences } from '@capacitor/preferences';
12
+ import { Clipboard } from '@capacitor/clipboard';
13
+ import { Camera } from '@capacitor/camera';
14
+ import { Geolocation } from '@capacitor/geolocation';
15
+ import { PushNotifications } from '@capacitor/push-notifications';
16
+ import { TextToSpeech } from '@capacitor-community/text-to-speech';
17
+ import { Filesystem, Directory, Encoding } from '@capacitor/filesystem';
18
+ import { Haptics, ImpactStyle } from '@capacitor/haptics';
19
+ import { Share } from '@capacitor/share';
20
+ import { LocalNotifications } from '@capacitor/local-notifications';
21
+ import { FileClass, Storage } from 'aio-utils';
22
+ import { KeepAwake } from '@capacitor-community/keep-awake';
23
+ export class AIOCapacitor {
24
+ constructor(p) {
25
+ this.getPlatform = () => Capacitor.getPlatform();
26
+ this.isNative = () => ['android', 'ios'].indexOf(Capacitor.getPlatform()) !== -1;
27
+ this.addLog = (log) => {
28
+ if (!this.onLog) {
29
+ return;
30
+ }
31
+ this.onLog(log);
32
+ };
33
+ this.vibrate = (p) => __awaiter(this, void 0, void 0, function* () {
34
+ if (p.pattern) {
35
+ yield this.vibratePattern(p.pattern);
36
+ }
37
+ else if (p.density) {
38
+ this.vibrateImpact(p.density);
39
+ }
40
+ });
41
+ this.vibratePattern = (pattern) => __awaiter(this, void 0, void 0, function* () {
42
+ try {
43
+ for (const duration of pattern) {
44
+ yield Haptics.vibrate();
45
+ yield new Promise(r => setTimeout(r, duration));
46
+ }
47
+ }
48
+ catch (err) {
49
+ console.error('Haptics pattern error:', err);
50
+ }
51
+ });
52
+ this.vibrateImpact = (...args_1) => __awaiter(this, [...args_1], void 0, function* (style = 'medium') {
53
+ try {
54
+ const map = {
55
+ light: ImpactStyle.Light,
56
+ medium: ImpactStyle.Medium,
57
+ heavy: ImpactStyle.Heavy,
58
+ };
59
+ yield Haptics.impact({ style: map[style] });
60
+ }
61
+ catch (err) {
62
+ console.error('Haptics impact error:', err);
63
+ }
64
+ });
65
+ this.getPermissions = (permissionNames) => __awaiter(this, void 0, void 0, function* () {
66
+ var _a, _b, _c, _d, _e;
67
+ for (const permission of permissionNames) {
68
+ try {
69
+ switch (permission) {
70
+ case "CAMERA": {
71
+ yield Camera.requestPermissions();
72
+ (_a = this.addLog) === null || _a === void 0 ? void 0 : _a.call(this, { message: "CAMERA permission requested", status: "success" });
73
+ break;
74
+ }
75
+ case "ACCESS_FINE_LOCATION":
76
+ case "ACCESS_COARSE_LOCATION": {
77
+ yield Geolocation.requestPermissions();
78
+ (_b = this.addLog) === null || _b === void 0 ? void 0 : _b.call(this, { message: "LOCATION permission requested", status: "success" });
79
+ break;
80
+ }
81
+ case "POST_NOTIFICATIONS": {
82
+ yield PushNotifications.requestPermissions();
83
+ (_c = this.addLog) === null || _c === void 0 ? void 0 : _c.call(this, { message: "NOTIFICATION permission requested", status: "success" });
84
+ break;
85
+ }
86
+ default:
87
+ (_d = this.addLog) === null || _d === void 0 ? void 0 : _d.call(this, { message: `Permission not supported: ${permission}`, status: "error" });
88
+ }
89
+ }
90
+ catch (err) {
91
+ (_e = this.addLog) === null || _e === void 0 ? void 0 : _e.call(this, {
92
+ message: `Permission error for ${permission}: ${err === null || err === void 0 ? void 0 : err.message}`,
93
+ status: "error"
94
+ });
95
+ }
96
+ }
97
+ });
98
+ this.speak = (p) => __awaiter(this, void 0, void 0, function* () {
99
+ try {
100
+ yield TextToSpeech.speak({
101
+ text: p.text, lang: p.lang || 'en-US', rate: p.rate || 1, pitch: p.pitch === undefined ? 1 : p.pitch, volume: 1, category: 'ambient'
102
+ });
103
+ }
104
+ catch (err) {
105
+ console.error('TTS error:', err);
106
+ }
107
+ });
108
+ this.getSpeakList = () => __awaiter(this, void 0, void 0, function* () {
109
+ return yield TextToSpeech.getSupportedLanguages();
110
+ });
111
+ this.storageSave = (name, value) => __awaiter(this, void 0, void 0, function* () {
112
+ try {
113
+ yield Preferences.set({ key: name, value: JSON.stringify(value) });
114
+ }
115
+ catch (err) {
116
+ console.error('storageSave error:', err);
117
+ }
118
+ });
119
+ this.storageLoad = (name, def) => __awaiter(this, void 0, void 0, function* () {
120
+ try {
121
+ const { value } = yield Preferences.get({ key: name });
122
+ if (value === null || value === undefined) {
123
+ yield Preferences.set({ key: name, value: JSON.stringify(def), });
124
+ return def;
125
+ }
126
+ return JSON.parse(value);
127
+ }
128
+ catch (err) {
129
+ console.error('storageLoad error:', err);
130
+ return def;
131
+ }
132
+ });
133
+ this.copy = (text) => __awaiter(this, void 0, void 0, function* () {
134
+ try {
135
+ yield Clipboard.write({ string: text, });
136
+ }
137
+ catch (err) {
138
+ console.error('Clipboard copy error:', err);
139
+ }
140
+ });
141
+ this.paste = () => __awaiter(this, void 0, void 0, function* () {
142
+ try {
143
+ const { value } = yield Clipboard.read();
144
+ return value || '';
145
+ }
146
+ catch (err) {
147
+ console.error('Clipboard paste error:', err);
148
+ return '';
149
+ }
150
+ });
151
+ this.readText = (file) => __awaiter(this, void 0, void 0, function* () {
152
+ return yield new FileClass().readInput(file, 'text');
153
+ });
154
+ this.readPath = (path, type) => __awaiter(this, void 0, void 0, function* () {
155
+ const fs = new FileClass();
156
+ try {
157
+ const res = yield Filesystem.readFile({ path, directory: Directory.Documents });
158
+ if (!(res === null || res === void 0 ? void 0 : res.data)) {
159
+ return { success: false, result: null, message: 'Empty file' };
160
+ }
161
+ const blobRes = fs.base64ToBlob(res.data);
162
+ if (!blobRes.success) {
163
+ return blobRes;
164
+ }
165
+ return fs.readInput(blobRes.result, type);
166
+ }
167
+ catch (e) {
168
+ return { success: false, result: null, message: (e === null || e === void 0 ? void 0 : e.message) || 'Storage read failed' };
169
+ }
170
+ });
171
+ this.writeFile = (data, path, encoding) => __awaiter(this, void 0, void 0, function* () { return yield Filesystem.writeFile({ path, data, directory: Directory.Documents, encoding: encoding ? Encoding.UTF8 : undefined }); });
172
+ this.save = (data, path) => __awaiter(this, void 0, void 0, function* () {
173
+ try {
174
+ const fs = new FileClass();
175
+ if (typeof data === 'string' && !fs.isUrl(data)) {
176
+ try {
177
+ yield this.writeFile(data, path, true);
178
+ return { success: true, message: '' };
179
+ }
180
+ catch (err) {
181
+ return { success: false, message: (err === null || err === void 0 ? void 0 : err.message) || err };
182
+ }
183
+ }
184
+ else {
185
+ const res1 = yield fs.toDataUrl(data);
186
+ if (!res1.success) {
187
+ return { success: false, message: res1.message };
188
+ }
189
+ const res2 = yield fs.toBase64(res1.result);
190
+ if (!res2.success) {
191
+ return { success: false, message: res2.message };
192
+ }
193
+ yield this.writeFile(res2.result, path);
194
+ return { success: true, message: '' };
195
+ }
196
+ }
197
+ catch (err) {
198
+ return { success: false, message: (err === null || err === void 0 ? void 0 : err.message) || err };
199
+ }
200
+ });
201
+ this.shareText = (text, title) => __awaiter(this, void 0, void 0, function* () {
202
+ try {
203
+ yield Share.share({ title: title || 'Share', text });
204
+ return { success: true };
205
+ }
206
+ catch (err) {
207
+ return { success: false, error: (err === null || err === void 0 ? void 0 : err.message) || err };
208
+ }
209
+ });
210
+ this.shareFile = (file_1, ...args_2) => __awaiter(this, [file_1, ...args_2], void 0, function* (file, fileName = `file_${Date.now()}`) {
211
+ try {
212
+ const res = yield new FileClass().toDataUrl(file);
213
+ if (!res.success) {
214
+ return res;
215
+ }
216
+ yield Share.share({ title: fileName, url: res.result, dialogTitle: 'Share File' });
217
+ return { success: true };
218
+ }
219
+ catch (err) {
220
+ return { success: false, error: (err === null || err === void 0 ? void 0 : err.message) || err };
221
+ }
222
+ });
223
+ this.getLocation = () => __awaiter(this, void 0, void 0, function* () {
224
+ try {
225
+ // 1. اول سریع‌ترین حالت (کش / آخرین موقعیت)
226
+ try {
227
+ const cached = yield Geolocation.getCurrentPosition({
228
+ enableHighAccuracy: false,
229
+ timeout: 2000,
230
+ maximumAge: 60000
231
+ });
232
+ if (cached === null || cached === void 0 ? void 0 : cached.coords) {
233
+ return {
234
+ success: true,
235
+ latitude: cached.coords.latitude,
236
+ longitude: cached.coords.longitude,
237
+ accuracy: cached.coords.accuracy,
238
+ source: "cache"
239
+ };
240
+ }
241
+ }
242
+ catch (_) {
243
+ // ignore cache failure
244
+ }
245
+ // 2. حالت دقیق (GPS + WiFi + Cell fusion)
246
+ const position = yield Geolocation.getCurrentPosition({
247
+ enableHighAccuracy: true,
248
+ timeout: 15000,
249
+ maximumAge: 0
250
+ });
251
+ return {
252
+ success: true,
253
+ latitude: position.coords.latitude,
254
+ longitude: position.coords.longitude,
255
+ accuracy: position.coords.accuracy,
256
+ source: "gps"
257
+ };
258
+ }
259
+ catch (err) {
260
+ // 3. fallback نهایی (هیچ چیزی جواب نداد)
261
+ return {
262
+ success: false,
263
+ error: (err === null || err === void 0 ? void 0 : err.message) || "Location unavailable"
264
+ };
265
+ }
266
+ });
267
+ this.awake = (state) => __awaiter(this, void 0, void 0, function* () {
268
+ let _awake;
269
+ if (state === true) {
270
+ _awake = true;
271
+ }
272
+ else if (state === false) {
273
+ _awake = false;
274
+ }
275
+ else {
276
+ const _isAwake = yield this.isAwake();
277
+ _awake = !_isAwake;
278
+ }
279
+ if (_awake) {
280
+ yield KeepAwake.allowSleep();
281
+ }
282
+ else {
283
+ yield KeepAwake.keepAwake();
284
+ }
285
+ return _awake;
286
+ });
287
+ this.isAwake = () => __awaiter(this, void 0, void 0, function* () { return yield KeepAwake.isKeptAwake(); });
288
+ this.onLog = p === null || p === void 0 ? void 0 : p.onLog;
289
+ }
290
+ }
291
+ export class NotificationService {
292
+ constructor(db) { this.db = db; }
293
+ // -------------------------
294
+ // INIT (CRITICAL)
295
+ // -------------------------
296
+ init() {
297
+ return __awaiter(this, void 0, void 0, function* () {
298
+ yield LocalNotifications.requestPermissions();
299
+ yield this.resync();
300
+ });
301
+ }
302
+ // -------------------------
303
+ // CREATE NOTIFICATION
304
+ // -------------------------
305
+ notifyAt(date, title, body) {
306
+ return __awaiter(this, void 0, void 0, function* () {
307
+ const id = Date.now();
308
+ const item = {
309
+ id,
310
+ title,
311
+ body,
312
+ fireAt: date,
313
+ status: 'pending'
314
+ };
315
+ yield this.db.save(item);
316
+ yield this.schedule(item);
317
+ return id;
318
+ });
319
+ }
320
+ // -------------------------
321
+ // SCHEDULE TO OS
322
+ // -------------------------
323
+ schedule(item) {
324
+ return __awaiter(this, void 0, void 0, function* () {
325
+ if (item.fireAt <= Date.now()) {
326
+ yield this.fireNow(item);
327
+ return;
328
+ }
329
+ yield LocalNotifications.schedule({
330
+ notifications: [
331
+ {
332
+ id: item.id,
333
+ title: item.title,
334
+ body: item.body,
335
+ schedule: {
336
+ at: new Date(item.fireAt)
337
+ }
338
+ }
339
+ ]
340
+ });
341
+ yield this.db.update(item.id, {
342
+ status: 'scheduled'
343
+ });
344
+ });
345
+ }
346
+ // -------------------------
347
+ // IMMEDIATE NOTIFICATION
348
+ // -------------------------
349
+ fireNow(item) {
350
+ return __awaiter(this, void 0, void 0, function* () {
351
+ yield LocalNotifications.schedule({
352
+ notifications: [
353
+ {
354
+ id: item.id,
355
+ title: item.title,
356
+ body: item.body,
357
+ schedule: { at: new Date() }
358
+ }
359
+ ]
360
+ });
361
+ yield this.db.update(item.id, {
362
+ status: 'done'
363
+ });
364
+ });
365
+ }
366
+ // -------------------------
367
+ // RESYNC AFTER RESTART
368
+ // -------------------------
369
+ resync() {
370
+ return __awaiter(this, void 0, void 0, function* () {
371
+ const all = yield this.db.getAll();
372
+ const pending = all.filter(i => i.status !== 'done');
373
+ for (const item of pending) {
374
+ yield this.schedule(item);
375
+ }
376
+ });
377
+ }
378
+ // -------------------------
379
+ // CANCEL
380
+ // -------------------------
381
+ cancel(id) {
382
+ return __awaiter(this, void 0, void 0, function* () {
383
+ yield LocalNotifications.cancel({
384
+ notifications: [{ id }]
385
+ });
386
+ yield this.db.update(id, {
387
+ status: 'done'
388
+ });
389
+ });
390
+ }
391
+ // -------------------------
392
+ // LIST (DEBUG)
393
+ // -------------------------
394
+ list() {
395
+ return __awaiter(this, void 0, void 0, function* () {
396
+ return yield LocalNotifications.getPending();
397
+ });
398
+ }
399
+ }
400
+ // const notifications = new NotificationService(db);
401
+ // await notifications.init();
402
+ // await notifications.notifyAt(
403
+ // Date.now() + 10000,
404
+ // "Hello",
405
+ // "This is persistent notification"
406
+ // );
407
+ export class Tracker {
408
+ constructor(p) {
409
+ this.watchId = null;
410
+ this.onSuccess = p.onSuccess;
411
+ this.onFailed = p.onFailed;
412
+ this.onLog = p.onLog || (() => { });
413
+ }
414
+ start() {
415
+ if (this.watchId) {
416
+ return;
417
+ }
418
+ Geolocation.watchPosition({
419
+ enableHighAccuracy: true,
420
+ timeout: 10000,
421
+ maximumAge: 3000
422
+ }, (position, err) => {
423
+ if (err) {
424
+ this.onFailed(err.message || 'Location Error');
425
+ return;
426
+ }
427
+ if (!position) {
428
+ return;
429
+ }
430
+ this.onSuccess({
431
+ latitude: position.coords.latitude,
432
+ longitude: position.coords.longitude
433
+ });
434
+ }).then((id) => {
435
+ this.watchId = id;
436
+ });
437
+ }
438
+ stop() {
439
+ return __awaiter(this, void 0, void 0, function* () {
440
+ if (!this.watchId) {
441
+ return;
442
+ }
443
+ yield Geolocation.clearWatch({
444
+ id: this.watchId
445
+ });
446
+ this.watchId = null;
447
+ });
448
+ }
449
+ isTracking() {
450
+ return !!this.watchId;
451
+ }
452
+ }
453
+ export class FileRegistry {
454
+ constructor(p) {
455
+ this.store = new Map();
456
+ this.storageKey = '';
457
+ this.isNative = false;
458
+ this.initialRecords = [];
459
+ this.init = () => __awaiter(this, void 0, void 0, function* () {
460
+ yield this.initialLoad();
461
+ this.onChange(this.list());
462
+ });
463
+ this.initialLoad = () => __awaiter(this, void 0, void 0, function* () {
464
+ let raw;
465
+ if (!this.isNative) {
466
+ raw = this.webStorage.load('records', this.initialRecords);
467
+ }
468
+ else {
469
+ raw = yield new AIOCapacitor().storageLoad(this.storageKey, this.initialRecords);
470
+ }
471
+ raw = raw === null || !raw ? [] : raw;
472
+ this.store = new Map(raw.map((i) => [i.id, i]));
473
+ });
474
+ this.save = () => __awaiter(this, void 0, void 0, function* () {
475
+ const raw = this.list();
476
+ if (!this.isNative) {
477
+ this.webStorage.save('records', raw);
478
+ }
479
+ else {
480
+ yield new AIOCapacitor().storageSave(this.storageKey, raw);
481
+ }
482
+ this.onChange(raw);
483
+ });
484
+ this.list = () => [...this.store.values()];
485
+ this.getById = (id) => this.store.get(id) || null;
486
+ if (p.mock) {
487
+ this.initialRecords = p.mock;
488
+ }
489
+ const a = new AIOCapacitor();
490
+ this.webStorage = new Storage(p.storageKey);
491
+ this.isNative = a.isNative();
492
+ this.storageKey = p.storageKey;
493
+ this.onChange = p.onChange;
494
+ this.init();
495
+ }
496
+ add(p) {
497
+ const { type, path, meta } = p;
498
+ if (['image', 'file', 'json', 'text'].indexOf(type) === -1) {
499
+ alert('file type should be image or file or json or text');
500
+ return;
501
+ }
502
+ if (!path) {
503
+ alert('missing file path');
504
+ return;
505
+ }
506
+ const id = crypto.randomUUID();
507
+ const createdAt = Date.now();
508
+ const name = p.name || window.prompt('inter file name');
509
+ if (!name || name === null) {
510
+ return;
511
+ }
512
+ const records = this.list();
513
+ if (records.find((o) => o.name === name)) {
514
+ const res = window.confirm('a file by this name is already exist, do you want to overwrite?');
515
+ if (!res) {
516
+ return;
517
+ }
518
+ }
519
+ const record = { id, createdAt, name, type, path, meta };
520
+ this.store.set(id, record);
521
+ this.save();
522
+ return record;
523
+ }
524
+ rename(id, newName) {
525
+ const record = this.getById(id);
526
+ if (!record) {
527
+ return;
528
+ }
529
+ const name = newName || window.prompt('inter file new name');
530
+ if (!name || name === null) {
531
+ return;
532
+ }
533
+ const records = this.list();
534
+ if (records.find((o) => o.name === name)) {
535
+ alert('a file by this name is already exist, you cannot rename');
536
+ return;
537
+ }
538
+ const newRecord = Object.assign(Object.assign({}, record), { name });
539
+ this.store.set(id, newRecord);
540
+ this.save();
541
+ return newRecord;
542
+ }
543
+ remove(id) {
544
+ this.store.delete(id);
545
+ this.save();
546
+ }
547
+ }
package/package.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "aio-capacitor",
3
+ "version": "1.0.0",
4
+ "description": "",
5
+ "main": "index.js",
6
+ "types": "index.d.ts",
7
+ "scripts": {
8
+ "test": "echo \"Error: no test specified\" && exit 1"
9
+ },
10
+ "dependencies": {
11
+ "aio-utils": "latest",
12
+ "@capacitor/core": "^8.4.0",
13
+ "@capacitor/preferences": "^8.0.1",
14
+ "@capacitor/clipboard": "^8.0.1",
15
+ "@capacitor/camera": "^8.2.0",
16
+ "@capacitor/geolocation": "^8.2.0",
17
+ "@capacitor/push-notifications": "^8.1.1",
18
+ "@capacitor-community/text-to-speech": "^8.0.0",
19
+ "@capacitor/filesystem": "^8.1.2",
20
+ "@capacitor/haptics": "^8.0.2",
21
+ "@capacitor/share": "^8.0.1",
22
+ "@capacitor/local-notifications": "^8.2.0",
23
+ "@capacitor-community/keep-awake": "^8.0.1"
24
+ },
25
+ "repository": {
26
+ "type": "git",
27
+ "url": "git+https://github.com/mohammadFeiz/aio-capacitor.git"
28
+ },
29
+ "author": "",
30
+ "license": "ISC",
31
+ "bugs": {
32
+ "url": "https://github.com/mohammadFeiz/aio-capacitor/issues"
33
+ },
34
+ "homepage": "https://github.com/mohammadFeiz/aio-capacitor#readme"
35
+ }