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