| 216 | } |
| 217 | |
| 218 | function init() { |
| 219 | isSurge = () => { |
| 220 | return undefined === this.$httpClient ? false : true |
| 221 | } |
| 222 | isQuanX = () => { |
| 223 | return undefined === this.$task ? false : true |
| 224 | } |
| 225 | getdata = (key) => { |
| 226 | if (isSurge()) return $persistentStore.read(key) |
| 227 | if (isQuanX()) return $prefs.valueForKey(key) |
| 228 | } |
| 229 | setdata = (key, val) => { |
| 230 | if (isSurge()) return $persistentStore.write(key, val) |
| 231 | if (isQuanX()) return $prefs.setValueForKey(key, val) |
| 232 | } |
| 233 | msg = (title, subtitle, body) => { |
| 234 | if (isSurge()) $notification.post(title, subtitle, body) |
| 235 | if (isQuanX()) $notify(title, subtitle, body) |
| 236 | } |
| 237 | log = (message) => console.log(message) |
| 238 | get = (url, cb) => { |
| 239 | if (url['headers'] != undefined) { |
| 240 | delete url['headers']['Content-Length'] |
| 241 | console.log(url['headers']) |
| 242 | } |
| 243 | if (isSurge()) { |
| 244 | $httpClient.get(url, cb) |
| 245 | } |
| 246 | if (isQuanX()) { |
| 247 | url.method = 'GET' |
| 248 | $task.fetch(url).then((resp) => cb(null, resp, resp.body)) |
| 249 | } |
| 250 | } |
| 251 | post = (url, cb) => { |
| 252 | if (url['headers'] != undefined) { |
| 253 | delete url['headers']['Content-Length'] |
| 254 | console.log(url['headers']) |
| 255 | } |
| 256 | if (isSurge()) { |
| 257 | $httpClient.post(url, cb) |
| 258 | } |
| 259 | if (isQuanX()) { |
| 260 | url.method = 'POST' |
| 261 | $task.fetch(url).then((resp) => cb(null, resp, resp.body)) |
| 262 | } |
| 263 | } |
| 264 | done = (value = {}) => { |
| 265 | $done(value) |
| 266 | } |
| 267 | return { isSurge, isQuanX, msg, log, getdata, setdata, get, post, done } |
| 268 | } |