Changeset View
Changeset View
Standalone View
Standalone View
extension/options.js
Show First 20 Lines • Show All 91 Lines • ▼ Show 20 Line(s) | 38 | storage.get(DEFAULT_EXTENSION_SETTINGS, function (items) { | |||
---|---|---|---|---|---|
92 | } | 92 | } | ||
93 | 93 | | |||
94 | if (typeof cb === "function") { | 94 | if (typeof cb === "function") { | ||
95 | cb(true); | 95 | cb(true); | ||
96 | } | 96 | } | ||
97 | }); | 97 | }); | ||
98 | } | 98 | } | ||
99 | 99 | | |||
100 | function saveSettings(cb) { | 100 | function saveSettings(cb) { | ||
fvogt: AFAICT it doesn't conflict, but IMO it's a bit confusing if there's both a global array… | |||||
broulik: I'll rename this to `getSubsystemStatus()` then | |||||
101 | var settings = {}; | 101 | var settings = {}; | ||
102 | 102 | | |||
103 | let controls = document.querySelectorAll("[data-extension]"); | 103 | let controls = document.querySelectorAll("[data-extension]"); | ||
104 | for (let control of controls) { | 104 | for (let control of controls) { | ||
105 | let extension = control.dataset.extension; | 105 | let extension = control.dataset.extension; | ||
106 | 106 | | |||
107 | if (!DEFAULT_EXTENSION_SETTINGS.hasOwnProperty(extension)) { | 107 | if (!DEFAULT_EXTENSION_SETTINGS.hasOwnProperty(extension)) { | ||
108 | console.warn("Cannot save settings for extension", extension, "which isn't in DEFAULT_EXTENSION_SETTINGS"); | 108 | console.warn("Cannot save settings for extension", extension, "which isn't in DEFAULT_EXTENSION_SETTINGS"); | ||
▲ Show 20 Lines • Show All 68 Lines • ▼ Show 20 Line(s) | 176 | if (IS_FIREFOX) { | |||
177 | document.querySelectorAll("[data-not-show-in=firefox]").forEach(function (item) { | 177 | document.querySelectorAll("[data-not-show-in=firefox]").forEach(function (item) { | ||
178 | item.style.display = "none"; | 178 | item.style.display = "none"; | ||
179 | }); | 179 | }); | ||
180 | } | 180 | } | ||
181 | 181 | | |||
182 | // check whether the platform is supported before loading and activating settings | 182 | // check whether the platform is supported before loading and activating settings | ||
183 | chrome.runtime.getPlatformInfo(function (info) { | 183 | chrome.runtime.getPlatformInfo(function (info) { | ||
184 | if (!SUPPORTED_PLATFORMS.includes(info.os)) { | 184 | if (!SUPPORTED_PLATFORMS.includes(info.os)) { | ||
185 | document.body.classList.add("not-supported"); | 185 | document.body.classList.add("os-not-supported"); | ||
186 | return; | 186 | return; | ||
187 | } | 187 | } | ||
188 | 188 | | |||
189 | loadSettings(function () { | 189 | loadSettings(function () { | ||
190 | var mpris = document.querySelector("[data-extension=mpris]"); | 190 | var mpris = document.querySelector("[data-extension=mpris]"); | ||
191 | var mprisEx = document.querySelector("[data-extension=mprisMediaSessions]"); | 191 | var mprisEx = document.querySelector("[data-extension=mprisMediaSessions]"); | ||
192 | mpris.addEventListener("change", function() { | 192 | mpris.addEventListener("change", function() { | ||
193 | mprisEx.disabled = !mpris.checked; | 193 | mprisEx.disabled = !mpris.checked; | ||
194 | }); | 194 | }); | ||
195 | mprisEx.disabled = !mpris.checked; | 195 | mprisEx.disabled = !mpris.checked; | ||
196 | }); | 196 | }); | ||
197 | | ||||
198 | // When getSubsystemStatus fails we assume it's an old host without any of the new features | ||||
199 | // for which we added the requires-extension attributes. Disable all of them initially | ||||
200 | // and then have the supported ones enabled below. | ||||
201 | document.querySelectorAll("[data-requires-extension]").forEach((item) => { | ||||
202 | item.classList.add("not-supported", "by-host"); | ||||
203 | }); | ||||
204 | | ||||
205 | sendMessage("settings", "getSubsystemStatus").then((status) => { | ||||
206 | document.querySelectorAll("[data-requires-extension]").forEach((item) => { | ||||
207 | let requiresExtension = item.dataset.requiresExtension; | ||||
fvogt: Consistency (and grammar): `let requiresExtension` | |||||
208 | | ||||
209 | if (requiresExtension && !status.hasOwnProperty(requiresExtension)) { | ||||
210 | console.log("Extension", requiresExtension, "is not supported by this version of the host"); | ||||
211 | return; // continue | ||||
212 | } | ||||
213 | | ||||
214 | let requiresMinimumVersion = Number(item.dataset.requiresExtensionVersionMinimum); | ||||
215 | if (requiresMinimumVersion) { | ||||
fvogt: Redundant | |||||
216 | let runningVersion = status[requiresExtension].version; | ||||
217 | if (runningVersion < requiresMinimumVersion) { | ||||
218 | console.log("Extension", requiresExtension, "of version", requiresMinimumVersion, "is required but only", runningVersion, "is present in the host"); | ||||
219 | return; // continue | ||||
220 | } | ||||
221 | } | ||||
222 | | ||||
223 | item.classList.remove("not-supported", "by-host"); | ||||
224 | }); | ||||
225 | }).catch((e) => { | ||||
226 | // The host is most likely not working correctly | ||||
227 | // If we run this against an older host which doesn't support message replies | ||||
228 | // this handler is never entered, so we really encountered an error just now! | ||||
229 | console.warn("Failed to determine subsystem status", e); | ||||
230 | // TODO show helpful error message in UI | ||||
231 | }); | ||||
197 | }); | 232 | }); | ||
198 | 233 | | |||
199 | document.getElementById("open-krunner-settings").addEventListener("click", function (event) { | 234 | document.getElementById("open-krunner-settings").addEventListener("click", function (event) { | ||
200 | sendMessage("settings", "openKRunnerSettings"); | 235 | sendMessage("settings", "openKRunnerSettings"); | ||
201 | event.preventDefault(); | 236 | event.preventDefault(); | ||
202 | }); | 237 | }); | ||
203 | 238 | | |||
204 | // Make translators credit behave like the one in KAboutData | 239 | // Make translators credit behave like the one in KAboutData | ||
Show All 14 Lines |
AFAICT it doesn't conflict, but IMO it's a bit confusing if there's both a global array subsystemStatus in extension.js and a function subsystemStatus() in options.js.