| 83 | } |
| 84 | } |
| 85 | function init() { |
| 86 | isSurge = () => { |
| 87 | return undefined === this.$httpClient ? false : true |
| 88 | } |
| 89 | isQuanX = () => { |
| 90 | return undefined === this.$task ? false : true |
| 91 | } |
| 92 | getdata = (key) => { |
| 93 | if (isSurge()) return $persistentStore.read(key) |
| 94 | if (isQuanX()) return $prefs.valueForKey(key) |
| 95 | } |
| 96 | setdata = (key, val) => { |
| 97 | if (isSurge()) return $persistentStore.write(key, val) |
| 98 | if (isQuanX()) return $prefs.setValueForKey(key, val) |
| 99 | } |
| 100 | msg = (title, subtitle, body) => { |
| 101 | if (isSurge()) $notification.post(title, subtitle, body) |
| 102 | if (isQuanX()) $notify(title, subtitle, body) |
| 103 | } |
| 104 | log = (message) => console.log(message) |
| 105 | get = (url, cb) => { |
| 106 | if (isSurge()) { |
| 107 | $httpClient.get(url, cb) |
| 108 | } |
| 109 | if (isQuanX()) { |
| 110 | url.method = 'GET' |
| 111 | $task.fetch(url).then((resp) => cb(null, {}, resp.body)) |
| 112 | } |
| 113 | } |
| 114 | post = (url, cb) => { |
| 115 | if (isSurge()) { |
| 116 | $httpClient.post(url, cb) |
| 117 | } |
| 118 | if (isQuanX()) { |
| 119 | url.method = 'POST' |
| 120 | $task.fetch(url).then((resp) => cb(null, {}, resp.body)) |
| 121 | } |
| 122 | } |
| 123 | done = (value = {}) => { |
| 124 | $done(value) |
| 125 | } |
| 126 | return { isSurge, isQuanX, msg, log, getdata, setdata, get, post, done } |
| 127 | } |
| 128 | sy.done() |