()
| 98 | } |
| 99 | |
| 100 | function compatible_tool() { |
| 101 | const isSurge = typeof $httpClient != "undefined"; |
| 102 | const isQuanX = typeof $task != "undefined"; |
| 103 | const isStash = typeof $environment == "object" && $environment["stash-version"]; |
| 104 | const adapterStatus = (response) => { |
| 105 | if (response && response.statusCode) { |
| 106 | response.status = response.statusCode; |
| 107 | } |
| 108 | return response |
| 109 | }; |
| 110 | this.read = (key) => { |
| 111 | if (isQuanX) return $prefs.valueForKey(key); |
| 112 | if (isSurge) return $persistentStore.read(key); |
| 113 | }; |
| 114 | this.write = (value, key) => { |
| 115 | if (isQuanX) return $prefs.setValueForKey(value, key); |
| 116 | if (isSurge) return $persistentStore.write(value, key); |
| 117 | }; |
| 118 | this.notify = (title, subtitle, message) => { |
| 119 | if (isQuanX) $notify(title, subtitle, message); |
| 120 | if (isSurge) $notification.post(title, subtitle, message); |
| 121 | }; |
| 122 | this.http = (options, callback) => { |
| 123 | if (options.policy) { |
| 124 | options.node = options.policy; |
| 125 | options.opts = { policy: options.policy }; |
| 126 | if (isStash) options.headers = { |
| 127 | ...options.headers, |
| 128 | ...{ "X-Stash-Selected-Proxy": encodeURIComponent(options.policy) } |
| 129 | }; |
| 130 | } |
| 131 | if (isQuanX) { |
| 132 | $task.fetch(options).then(response => { |
| 133 | callback(null, adapterStatus(response), response.body) |
| 134 | }, reason => callback(reason.error, null, null)) |
| 135 | } |
| 136 | if (isSurge) { |
| 137 | $httpClient[options.method](options, (error, response, body) => { |
| 138 | callback(error, adapterStatus(response), body) |
| 139 | }) |
| 140 | } |
| 141 | }; |
| 142 | this.done = (value = {}) => { |
| 143 | if (value.response && isQuanX) { |
| 144 | value.response.status = `HTTP/1.1 ${value.response.status}`; |
| 145 | } |
| 146 | $done((value.response && isQuanX) ? value.response : value) |
| 147 | } |
| 148 | }; |
nothing calls this directly
no test coverage detected