forked from Acode-Foundation/Acode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplugin.js
More file actions
242 lines (229 loc) · 8.93 KB
/
plugin.js
File metadata and controls
242 lines (229 loc) · 8.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
module.exports = {
isManageExternalStorageDeclared: function (success, error) {
cordova.exec(success, error, 'System', 'isManageExternalStorageDeclared', []);
},
hasGrantedStorageManager: function (success, error) {
cordova.exec(success, error, 'System', 'hasGrantedStorageManager', []);
},
requestStorageManager: function (success, error) {
cordova.exec(success, error, 'System', 'requestStorageManager', []);
},
copyToUri: function (srcUri, destUri, fileName, success, error) {
cordova.exec(success, error, 'System', 'copyToUri', [srcUri, destUri, fileName]);
},
fileExists: function (path, countSymlinks, success, error) {
cordova.exec(success, error, 'System', 'fileExists', [path, String(countSymlinks)]);
},
createSymlink: function (target, linkPath, success, error) {
cordova.exec(success, error, 'System', 'createSymlink', [target, linkPath]);
},
writeText: function (path, content, success, error) {
cordova.exec(success, error, 'System', 'writeText', [path, content]);
},
deleteFile: function (path, success, error) {
cordova.exec(success, error, 'System', 'deleteFile', [path]);
},
setExec: function (path, executable, success, error) {
cordova.exec(success, error, 'System', 'setExec', [path, String(executable)]);
},
getNativeLibraryPath: function (success, error) {
cordova.exec(success, error, 'System', 'getNativeLibraryPath', []);
},
getFilesDir: function (success, error) {
cordova.exec(success, error, 'System', 'getFilesDir', []);
},
getRewardStatus: function (success, error) {
cordova.exec(success, error, 'System', 'getRewardStatus', []);
},
redeemReward: function (offerId, success, error) {
cordova.exec(success, error, 'System', 'redeemReward', [offerId]);
},
getParentPath: function (path, success, error) {
cordova.exec(success, error, 'System', 'getParentPath', [path]);
},
listChildren: function (path, success, error) {
cordova.exec(success, error, 'System', 'listChildren', [path]);
},
mkdirs: function (path, success, error) {
cordova.exec(success, error, 'System', 'mkdirs', [path]);
},
getArch: function (success, error) {
cordova.exec(success, error, 'System', 'getArch', []);
},
clearCache: function (success, fail) {
return cordova.exec(success, fail, "System", "clearCache", []);
},
getWebviewInfo: function (onSuccess, onFail) {
cordova.exec(onSuccess, onFail, 'System', 'get-webkit-info', []);
},
isPowerSaveMode: function (onSuccess, onFail) {
cordova.exec(onSuccess, onFail, 'System', 'is-powersave-mode', []);
},
fileAction: function (fileUri, filename, action, mimeType, onFail) {
if (typeof action !== 'string') {
onFail = action || function () { };
action = filename;
filename = '';
} else if (typeof mimeType !== 'string') {
onFail = mimeType || function () { };
mimeType = action;
action = filename;
filename = '';
} else if (typeof onFail !== 'function') {
onFail = function () { };
}
action = "android.intent.action." + action;
cordova.exec(function () { }, onFail, 'System', 'file-action', [fileUri, filename, action, mimeType]);
},
getAppInfo: function (onSuccess, onFail) {
cordova.exec(onSuccess, onFail, 'System', 'get-app-info', []);
},
addShortcut: function (shortcut, onSuccess, onFail) {
var id, label, description, icon, data;
id = shortcut.id;
label = shortcut.label;
description = shortcut.description;
icon = shortcut.icon;
data = shortcut.data;
action = shortcut.action;
cordova.exec(onSuccess, onFail, 'System', 'add-shortcut', [id, label, description, icon, action, data]);
},
removeShortcut: function (id, onSuccess, onFail) {
cordova.exec(onSuccess, onFail, 'System', 'remove-shortcut', [id]);
},
pinShortcut: function (id, onSuccess, onFail) {
cordova.exec(onSuccess, onFail, 'System', 'pin-shortcut', [id]);
},
pinFileShortcut: function (shortcut, onSuccess, onFail) {
cordova.exec(onSuccess, onFail, 'System', 'pin-file-shortcut', [shortcut]);
},
manageAllFiles: function (onSuccess, onFail) {
cordova.exec(onSuccess, onFail, 'System', 'manage-all-files', []);
},
getAndroidVersion: function (onSuccess, onFail) {
cordova.exec(onSuccess, onFail, 'System', 'get-android-version', []);
},
isExternalStorageManager: function (onSuccess, onFail) {
cordova.exec(onSuccess, onFail, 'System', 'is-external-storage-manager', []);
},
requestPermission: function (permission, onSuccess, onFail) {
cordova.exec(onSuccess, onFail, 'System', 'request-permission', [permission]);
},
requestPermissions: function (permissions, onSuccess, onFail) {
cordova.exec(onSuccess, onFail, 'System', 'request-permissions', [permissions]);
},
hasPermission: function (permission, onSuccess, onFail) {
cordova.exec(onSuccess, onFail, 'System', 'has-permission', [permission]);
},
openInBrowser: function (src) {
cordova.exec(null, null, 'System', 'open-in-browser', [src]);
},
launchApp: function (app, className, data, onSuccess, onFail) {
cordova.exec(onSuccess, onFail, 'System', 'launch-app', [app, className, data]);
},
inAppBrowser: function (url, title, showButtons, disableCache) {
var myInAppBrowser = {
onOpenExternalBrowser: null,
onError: null,
};
cordova.exec(function (data) {
if (typeof data !== 'string') {
console.warn('System.inAppBrowser: invalid callback payload', data);
return;
}
var separatorIndex = data.indexOf(':');
if (separatorIndex < 0) {
console.warn('System.inAppBrowser: malformed callback payload', data);
return;
}
var dataTag = data.slice(0, separatorIndex);
var dataUrl = data.slice(separatorIndex + 1);
if (dataTag === 'onOpenExternalBrowser') {
if (typeof myInAppBrowser.onOpenExternalBrowser === 'function') {
myInAppBrowser.onOpenExternalBrowser(dataUrl);
} else {
console.warn('System.inAppBrowser: onOpenExternalBrowser handler is not set');
}
}
}, function (err) {
if (typeof myInAppBrowser.onError === 'function') {
myInAppBrowser.onError(err);
return;
}
console.warn('System.inAppBrowser error callback not handled', err);
}, 'System', 'in-app-browser', [url, title, !!showButtons, disableCache]);
return myInAppBrowser;
},
setUiTheme: function (systemBarColor, theme, onSuccess, onFail) {
const color = systemBarColor.toLowerCase();
if (color === '#ffffff' || color === '#ffffffff') {
systemBarColor = '#fffffe';
}
cordova.exec((out) => {
window.statusbar.setBackgroundColor(systemBarColor);
if (typeof onSuccess === "function") {
onSuccess(out);
}
}, onFail, 'System', 'set-ui-theme', [systemBarColor, theme]);
},
setIntentHandler: function (handler, onerror) {
cordova.exec(handler, onerror, 'System', 'set-intent-handler', []);
},
getCordovaIntent: function (onSuccess, onFail) {
cordova.exec(onSuccess, onFail, 'System', 'get-cordova-intent', []);
},
setInputType: function (type, onSuccess, onFail) {
cordova.exec(onSuccess, onFail, 'System', 'set-input-type', [type]);
},
setNativeContextMenuDisabled: function (disabled, onSuccess, onFail) {
cordova.exec(
onSuccess,
onFail,
'System',
'set-native-context-menu-disabled',
[String(!!disabled)],
);
},
getGlobalSetting: function (key, onSuccess, onFail) {
cordova.exec(onSuccess, onFail, 'System', 'get-global-setting', [key]);
},
/**
* Compare file content with provided text in a background thread.
* @param {string} fileUri - The URI of the file to read
* @param {string} encoding - The character encoding to use
* @param {string} currentText - The text to compare against
* @returns {Promise<boolean>} - Resolves to true if content differs, false if same
*/
compareFileText: function (fileUri, encoding, currentText) {
return new Promise((resolve, reject) => {
cordova.exec(
function(result) {
resolve(result === 1);
},
reject,
'System',
'compare-file-text',
[fileUri, encoding, currentText]
);
});
},
/**
* Compare two text strings in a background thread.
* @param {string} text1 - First text to compare
* @param {string} text2 - Second text to compare
* @returns {Promise<boolean>} - Resolves to true if texts differ, false if same
*/
compareTexts: function (text1, text2) {
return new Promise((resolve, reject) => {
cordova.exec(
function(result) {
resolve(result === 1);
},
reject,
'System',
'compare-texts',
[text1, text2]
);
});
}
};