| 31 | } |
| 32 | |
| 33 | function init() { |
| 34 | isSurge = () => { |
| 35 | return undefined === this.$httpClient ? false : true |
| 36 | } |
| 37 | isQuanX = () => { |
| 38 | return undefined === this.$task ? false : true |
| 39 | } |
| 40 | getdata = (key) => { |
| 41 | if (isSurge()) return $persistentStore.read(key) |
| 42 | if (isQuanX()) return $prefs.valueForKey(key) |
| 43 | } |
| 44 | setdata = (key, val) => { |
| 45 | if (isSurge()) return $persistentStore.write(key, val) |
| 46 | if (isQuanX()) return $prefs.setValueForKey(key, val) |
| 47 | } |
| 48 | msg = (title, subtitle, body) => { |
| 49 | if (isSurge()) $notification.post(title, subtitle, body) |
| 50 | if (isQuanX()) $notify(title, subtitle, body) |
| 51 | } |
| 52 | log = (message) => console.log(message) |
| 53 | get = (url, cb) => { |
| 54 | if (isSurge()) { |
| 55 | $httpClient.get(url, cb) |
| 56 | } |
| 57 | if (isQuanX()) { |
| 58 | url.method = 'GET' |
| 59 | $task.fetch(url).then((resp) => cb(null, resp, resp.body)) |
| 60 | } |
| 61 | } |
| 62 | post = (url, cb) => { |
| 63 | if (isSurge()) { |
| 64 | $httpClient.post(url, cb) |
| 65 | } |
| 66 | if (isQuanX()) { |
| 67 | url.method = 'POST' |
| 68 | $task.fetch(url).then((resp) => cb(null, resp, resp.body)) |
| 69 | } |
| 70 | } |
| 71 | done = (value = {}) => { |
| 72 | $done(value) |
| 73 | } |
| 74 | return { isSurge, isQuanX, msg, log, getdata, setdata, get, post, done } |
| 75 | } |