@saltcorn/mobile-app 1.1.0-beta.8 → 1.1.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/.babelrc +3 -0
- package/build_scripts/modify_android_manifest.js +47 -0
- package/build_scripts/modify_gradle_cfg.js +21 -0
- package/package.json +21 -12
- package/src/.eslintrc +21 -0
- package/src/helpers/api.js +43 -0
- package/src/helpers/auth.js +191 -0
- package/src/helpers/common.js +189 -0
- package/{www/js/utils/table_utils.js → src/helpers/db_schema.js} +18 -40
- package/src/helpers/file_system.js +102 -0
- package/{www/js/utils/global_utils.js → src/helpers/navigation.js} +189 -332
- package/src/helpers/offline_mode.js +645 -0
- package/src/index.js +20 -0
- package/src/init.js +424 -0
- package/src/routing/index.js +98 -0
- package/{www/js → src/routing}/mocks/request.js +5 -5
- package/{www/js → src/routing}/mocks/response.js +1 -1
- package/{www/js → src/routing}/routes/api.js +10 -15
- package/{www/js → src/routing}/routes/auth.js +12 -6
- package/{www/js → src/routing}/routes/delete.js +9 -6
- package/{www/js → src/routing}/routes/edit.js +9 -6
- package/src/routing/routes/error.js +6 -0
- package/{www/js → src/routing}/routes/fields.js +7 -2
- package/{www/js → src/routing}/routes/page.js +15 -10
- package/{www/js → src/routing}/routes/sync.js +17 -8
- package/{www/js → src/routing}/routes/view.js +20 -15
- package/{www/js/routes/common.js → src/routing/utils.js} +18 -13
- package/unsecure-default-key.jks +0 -0
- package/webpack.config.js +31 -0
- package/www/data/encoded_site_logo.js +1 -0
- package/www/index.html +23 -493
- package/www/js/{utils/iframe_view_utils.js → iframe_view_utils.js} +193 -274
- package/config.xml +0 -27
- package/res/icon/android/icon.png +0 -0
- package/res/screen/android/splash-icon.png +0 -0
- package/res/screen/ios/Default@2x~universal~anyany.png +0 -0
- package/www/js/routes/error.js +0 -5
- package/www/js/routes/init.js +0 -76
- package/www/js/utils/file_helpers.js +0 -108
- package/www/js/utils/offline_mode_helper.js +0 -625
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { Filesystem, Encoding, Directory } from "@capacitor/filesystem";
|
|
2
|
+
|
|
3
|
+
export async function writeFile(name, directory, content) {
|
|
4
|
+
try {
|
|
5
|
+
await Filesystem.writeFile({
|
|
6
|
+
path: name,
|
|
7
|
+
data: content,
|
|
8
|
+
directory: directory,
|
|
9
|
+
encoding: Encoding.UTF8,
|
|
10
|
+
});
|
|
11
|
+
} catch (error) {
|
|
12
|
+
console.log("Unable to write file", error);
|
|
13
|
+
throw error;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export async function readFile(name, directory) {
|
|
18
|
+
try {
|
|
19
|
+
const contents = await Filesystem.readFile({
|
|
20
|
+
path: name,
|
|
21
|
+
directory: directory,
|
|
22
|
+
encoding: Encoding.UTF8,
|
|
23
|
+
});
|
|
24
|
+
return contents.data;
|
|
25
|
+
} catch (error) {
|
|
26
|
+
console.log("Unable to read file", error);
|
|
27
|
+
throw error;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export async function fileExists(name, directory) {
|
|
32
|
+
try {
|
|
33
|
+
await Filesystem.stat({ path: name, directory: directory });
|
|
34
|
+
return true;
|
|
35
|
+
} catch (error) {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export async function writeJSON(name, directory, json) {
|
|
41
|
+
const contents = JSON.stringify(json);
|
|
42
|
+
await writeFile(name, directory, contents);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function getDirEntryCordova(directory) {
|
|
46
|
+
return new Promise((resolve, reject) => {
|
|
47
|
+
window.resolveLocalFileSystemURL(
|
|
48
|
+
directory,
|
|
49
|
+
function (fs) {
|
|
50
|
+
resolve(fs);
|
|
51
|
+
},
|
|
52
|
+
function (error) {
|
|
53
|
+
reject(error);
|
|
54
|
+
}
|
|
55
|
+
);
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export async function readBinaryCordova(fileName, dirName) {
|
|
60
|
+
const dirEntry = await getDirEntryCordova(dirName);
|
|
61
|
+
return new Promise((resolve, reject) => {
|
|
62
|
+
dirEntry.getFile(
|
|
63
|
+
fileName,
|
|
64
|
+
{ create: false, exclusive: false },
|
|
65
|
+
function (fileEntry) {
|
|
66
|
+
fileEntry.file(function (file) {
|
|
67
|
+
let reader = new FileReader();
|
|
68
|
+
reader.onloadend = function (e) {
|
|
69
|
+
resolve({ buffer: this.result, file: file });
|
|
70
|
+
};
|
|
71
|
+
reader.readAsArrayBuffer(file);
|
|
72
|
+
});
|
|
73
|
+
},
|
|
74
|
+
function (err) {
|
|
75
|
+
console.log(`unable to read ${fileName}`);
|
|
76
|
+
console.log(err);
|
|
77
|
+
reject(err);
|
|
78
|
+
}
|
|
79
|
+
);
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// TODO get this working
|
|
84
|
+
// export function normalizeFilePath(filePath) {
|
|
85
|
+
// if (filePath.startsWith("file:///")) {
|
|
86
|
+
// return filePath.replace("file:///storage/emulated/0/", "");
|
|
87
|
+
// }
|
|
88
|
+
// return filePath;
|
|
89
|
+
// }
|
|
90
|
+
|
|
91
|
+
// export async function readBinary(name, directory) {
|
|
92
|
+
// try {
|
|
93
|
+
// const file = await Filesystem.readFile({
|
|
94
|
+
// path: normalizeFilePath(`${directory}/${name}`),
|
|
95
|
+
// directory: Directory.ExternalStorage,
|
|
96
|
+
// });
|
|
97
|
+
// return Uint8Array.from(file.data, (char) => char.charCodeAt(0));
|
|
98
|
+
// } catch (error) {
|
|
99
|
+
// console.log("Unable to read file", error);
|
|
100
|
+
// throw error;
|
|
101
|
+
// }
|
|
102
|
+
// }
|