| 280 | } |
| 281 | |
| 282 | function init() { |
| 283 | isSurge = () => { |
| 284 | return undefined === this.$httpClient ? false : true |
| 285 | } |
| 286 | isQuanX = () => { |
| 287 | return undefined === this.$task ? false : true |
| 288 | } |
| 289 | getdata = (key) => { |
| 290 | if (isSurge()) return $persistentStore.read(key) |
| 291 | if (isQuanX()) return $prefs.valueForKey(key) |
| 292 | } |
| 293 | setdata = (key, val) => { |
| 294 | if (isSurge()) return $persistentStore.write(key, val) |
| 295 | if (isQuanX()) return $prefs.setValueForKey(key, val) |
| 296 | } |
| 297 | msg = (title, subtitle, body) => { |
| 298 | if (isSurge()) $notification.post(title, subtitle, body) |
| 299 | if (isQuanX()) $notify(title, subtitle, body) |
| 300 | } |
| 301 | log = (message) => console.log(message) |
| 302 | get = (url, cb) => { |
| 303 | if (isSurge()) { |
| 304 | $httpClient.get(url, cb) |
| 305 | } |
| 306 | if (isQuanX()) { |
| 307 | url.method = 'GET' |
| 308 | $task.fetch(url).then((resp) => cb(null, resp, resp.body)) |
| 309 | } |
| 310 | } |
| 311 | post = (url, cb) => { |
| 312 | if (isSurge()) { |
| 313 | $httpClient.post(url, cb) |
| 314 | } |
| 315 | if (isQuanX()) { |
| 316 | url.method = 'POST' |
| 317 | $task.fetch(url).then((resp) => cb(null, resp, resp.body)) |
| 318 | } |
| 319 | } |
| 320 | done = (value = {}) => { |
| 321 | $done(value) |
| 322 | } |
| 323 | return { isSurge, isQuanX, msg, log, getdata, setdata, get, post, done } |
| 324 | } |