aboutsummaryrefslogtreecommitdiffstats
path: root/src/models
diff options
context:
space:
mode:
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) {