aboutsummaryrefslogtreecommitdiffstats
path: root/src/models
diff options
context:
space:
mode:
authorLibravatar Vijay Raghavan Aravamudhan <vraravam@users.noreply.github.com>2021-06-17 14:17:37 +0000
committerLibravatar GitHub <noreply@github.com>2021-06-17 19:47:37 +0530
commita8253a9f6e5cd30760c3fcbf05767e7276b191c1 (patch)
tree32bd59f5ce3df73b91ed50728cf6a3d339e9b2e2 /src/models
parentRun ALL builds if no OSes were chosen (manual trigger) (#1529) (diff)
downloadferdium-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')
-rw-r--r--src/models/Service.js18
-rw-r--r--src/models/UserAgent.js35
2 files changed, 49 insertions, 4 deletions
diff --git a/src/models/Service.js b/src/models/Service.js
index d0c6a7103..50115f605 100644
--- a/src/models/Service.js
+++ b/src/models/Service.js
@@ -107,6 +107,8 @@ export default class Service {
107 return null; 107 return null;
108 } 108 }
109 109
110 this.userAgentModel = new UserAgent(recipe.overrideUserAgent);
111
110 this.id = data.id || this.id; 112 this.id = data.id || this.id;
111 this.name = data.name || this.name; 113 this.name = data.name || this.name;
112 this.team = data.team || this.team; 114 this.team = data.team || this.team;
@@ -141,6 +143,8 @@ export default class Service {
141 143
142 this.spellcheckerLanguage = data.spellcheckerLanguage !== undefined ? data.spellcheckerLanguage : this.spellcheckerLanguage; 144 this.spellcheckerLanguage = data.spellcheckerLanguage !== undefined ? data.spellcheckerLanguage : this.spellcheckerLanguage;
143 145
146 this.userAgentPref = data.userAgentPref !== undefined ? data.userAgentPref : this.userAgentPref;
147
144 this.isHibernationEnabled = data.isHibernationEnabled !== undefined ? data.isHibernationEnabled : this.isHibernationEnabled; 148 this.isHibernationEnabled = data.isHibernationEnabled !== undefined ? data.isHibernationEnabled : this.isHibernationEnabled;
145 149
146 this.recipe = recipe; 150 this.recipe = recipe;
@@ -156,8 +160,6 @@ export default class Service {
156 this.isHibernating = true; 160 this.isHibernating = true;
157 } 161 }
158 162
159 this.userAgentModel = new UserAgent(recipe.overrideUserAgent);
160
161 autorun(() => { 163 autorun(() => {
162 if (!this.isEnabled) { 164 if (!this.isEnabled) {
163 this.webview = null; 165 this.webview = null;
@@ -243,6 +245,18 @@ export default class Service {
243 return this.userAgentModel.userAgent; 245 return this.userAgentModel.userAgent;
244 } 246 }
245 247
248 @computed get userAgentPref() {
249 return this.userAgentModel.userAgentPref;
250 }
251
252 set userAgentPref(pref) {
253 this.userAgentModel.userAgentPref = pref;
254 }
255
256 @computed get defaultUserAgent() {
257 return this.userAgentModel.defaultUserAgent;
258 }
259
246 @computed get partition() { 260 @computed get partition() {
247 return this.recipe.partition || `persist:service-${this.id}`; 261 return this.recipe.partition || `persist:service-${this.id}`;
248 } 262 }
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) {