diff options
author | 2021-06-17 14:17:37 +0000 | |
---|---|---|
committer | 2021-06-17 19:47:37 +0530 | |
commit | a8253a9f6e5cd30760c3fcbf05767e7276b191c1 (patch) | |
tree | 32bd59f5ce3df73b91ed50728cf6a3d339e9b2e2 /src/models/UserAgent.js | |
parent | Run ALL builds if no OSes were chosen (manual trigger) (#1529) (diff) | |
download | ferdium-app-a8253a9f6e5cd30760c3fcbf05767e7276b191c1.tar.gz ferdium-app-a8253a9f6e5cd30760c3fcbf05767e7276b191c1.tar.zst ferdium-app-a8253a9f6e5cd30760c3fcbf05767e7276b191c1.zip |
User agent as a user-preference (#1535)
Introduced a global and a service-specific 'user-agent' value that can be set by the user from the preference section.
The global override is in Advanced, while the service override was moved to the bottom of the service editor form (and now occupies the full width of the form).
Show 'restart reqd' prompt for user-agent setting.
The order of the user-agent is the following:
1. Any request header overrides in the recipe will still override the user agent string.
2. If the user has set a user agent override for the service, use that.
3. If the recipe has a predefined user agent, use that.
4. If the user has set a global user agent override, use that.
5. Otherwise, use the user agent string corresponding to the underlying Electron version.
If the current webpage is the Google login form, we still remove the Chrome version number from the user agent string.
The value that would be used if no custom override is set (recipe-provided value or global override for the service, current Electron instance for the global override) is shown as a placeholder in the input box on the corresponding setting screen.
Co-authored-by: Kristóf Marussy <kristof@marussy.com>
Diffstat (limited to 'src/models/UserAgent.js')
-rw-r--r-- | src/models/UserAgent.js | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/src/models/UserAgent.js b/src/models/UserAgent.js index f51f2e5a6..f1d08e306 100644 --- a/src/models/UserAgent.js +++ b/src/models/UserAgent.js | |||
@@ -18,7 +18,9 @@ export default class UserAgent { | |||
18 | 18 | ||
19 | @observable chromelessUserAgent = false; | 19 | @observable chromelessUserAgent = false; |
20 | 20 | ||
21 | @observable getUserAgent = defaultUserAgent; | 21 | @observable userAgentPref = null; |
22 | |||
23 | @observable getUserAgent = null; | ||
22 | 24 | ||
23 | constructor(overrideUserAgent = null) { | 25 | constructor(overrideUserAgent = null) { |
24 | if (typeof overrideUserAgent === 'function') { | 26 | if (typeof overrideUserAgent === 'function') { |
@@ -36,8 +38,37 @@ export default class UserAgent { | |||
36 | }); | 38 | }); |
37 | } | 39 | } |
38 | 40 | ||
41 | @computed get defaultUserAgent() { | ||
42 | if (typeof this.getUserAgent === 'function') { | ||
43 | return this.getUserAgent(); | ||
44 | } | ||
45 | const globalPref = window.ferdi.stores.settings.all.app.userAgentPref; | ||
46 | if (typeof globalPref === 'string') { | ||
47 | const trimmed = globalPref.trim(); | ||
48 | if (trimmed !== '') { | ||
49 | return trimmed; | ||
50 | } | ||
51 | } | ||
52 | return defaultUserAgent(); | ||
53 | } | ||
54 | |||
55 | @computed get userAgentWithChromeVersion() { | ||
56 | if (typeof this.userAgentPref === 'string') { | ||
57 | const trimmed = this.userAgentPref.trim(); | ||
58 | if (trimmed !== '') { | ||
59 | return trimmed; | ||
60 | } | ||
61 | } | ||
62 | return this.defaultUserAgent; | ||
63 | } | ||
64 | |||
65 | @computed get userAgentWithoutChromeVersion() { | ||
66 | const withChrome = this.userAgentWithChromeVersion; | ||
67 | return withChrome.replace(/Chrome\/[0-9.]+/, 'Chrome'); | ||
68 | } | ||
69 | |||
39 | @computed get userAgent() { | 70 | @computed get userAgent() { |
40 | return this.chromelessUserAgent ? defaultUserAgent(true) : this.getUserAgent(); | 71 | return this.chromelessUserAgent ? this.userAgentWithoutChromeVersion : this.userAgentWithChromeVersion; |
41 | } | 72 | } |
42 | 73 | ||
43 | @action setWebviewReference(webview) { | 74 | @action setWebviewReference(webview) { |