diff options
Diffstat (limited to 'src/webview')
-rw-r--r-- | src/webview/contextMenu.js | 2 | ||||
-rw-r--r-- | src/webview/darkmode.js | 2 | ||||
-rw-r--r-- | src/webview/darkmode/ignore.js | 3 | ||||
-rw-r--r-- | src/webview/lib/RecipeWebview.js | 10 | ||||
-rw-r--r-- | src/webview/notifications.js | 2 | ||||
-rw-r--r-- | src/webview/recipe.js | 58 | ||||
-rw-r--r-- | src/webview/spellchecker.js | 2 |
7 files changed, 68 insertions, 11 deletions
diff --git a/src/webview/contextMenu.js b/src/webview/contextMenu.js index d3b976554..acd62d675 100644 --- a/src/webview/contextMenu.js +++ b/src/webview/contextMenu.js | |||
@@ -8,7 +8,7 @@ import { | |||
8 | import { isDevMode, isMac } from '../environment'; | 8 | import { isDevMode, isMac } from '../environment'; |
9 | import { SPELLCHECKER_LOCALES } from '../i18n/languages'; | 9 | import { SPELLCHECKER_LOCALES } from '../i18n/languages'; |
10 | 10 | ||
11 | const debug = require('debug')('Franz:contextMenu'); | 11 | const debug = require('debug')('Ferdi:contextMenu'); |
12 | 12 | ||
13 | const { Menu } = remote; | 13 | const { Menu } = remote; |
14 | 14 | ||
diff --git a/src/webview/darkmode.js b/src/webview/darkmode.js index 73c7007c6..ab629435c 100644 --- a/src/webview/darkmode.js +++ b/src/webview/darkmode.js | |||
@@ -3,7 +3,7 @@ | |||
3 | import path from 'path'; | 3 | import path from 'path'; |
4 | import fs from 'fs-extra'; | 4 | import fs from 'fs-extra'; |
5 | 5 | ||
6 | const debug = require('debug')('Franz:DarkMode'); | 6 | const debug = require('debug')('Ferdi:DarkMode'); |
7 | 7 | ||
8 | const chars = [...'abcdefghijklmnopqrstuvwxyz']; | 8 | const chars = [...'abcdefghijklmnopqrstuvwxyz']; |
9 | 9 | ||
diff --git a/src/webview/darkmode/ignore.js b/src/webview/darkmode/ignore.js new file mode 100644 index 000000000..110df364f --- /dev/null +++ b/src/webview/darkmode/ignore.js | |||
@@ -0,0 +1,3 @@ | |||
1 | export default [ | ||
2 | 'discordapp.com', | ||
3 | ]; | ||
diff --git a/src/webview/lib/RecipeWebview.js b/src/webview/lib/RecipeWebview.js index be29142af..877e45e35 100644 --- a/src/webview/lib/RecipeWebview.js +++ b/src/webview/lib/RecipeWebview.js | |||
@@ -39,9 +39,15 @@ class RecipeWebview { | |||
39 | if (this.countCache.direct === direct | 39 | if (this.countCache.direct === direct |
40 | && this.countCache.indirect === indirect) return; | 40 | && this.countCache.indirect === indirect) return; |
41 | 41 | ||
42 | // Parse number to integer | ||
43 | // This will correct errors that recipes may introduce, e.g. | ||
44 | // by sending a String instead of an integer | ||
45 | const directInt = parseInt(direct, 10); | ||
46 | const indirectInt = parseInt(indirect, 10); | ||
47 | |||
42 | const count = { | 48 | const count = { |
43 | direct: direct > 0 ? direct : 0, | 49 | direct: directInt > 0 ? directInt : 0, |
44 | indirect: indirect > 0 ? indirect : 0, | 50 | indirect: indirectInt > 0 ? indirectInt : 0, |
45 | }; | 51 | }; |
46 | 52 | ||
47 | ipcRenderer.sendToHost('messages', count); | 53 | ipcRenderer.sendToHost('messages', count); |
diff --git a/src/webview/notifications.js b/src/webview/notifications.js index f8fe53e1b..021f05cc3 100644 --- a/src/webview/notifications.js +++ b/src/webview/notifications.js | |||
@@ -1,7 +1,7 @@ | |||
1 | import { ipcRenderer } from 'electron'; | 1 | import { ipcRenderer } from 'electron'; |
2 | import uuidV1 from 'uuid/v1'; | 2 | import uuidV1 from 'uuid/v1'; |
3 | 3 | ||
4 | const debug = require('debug')('Franz:Notifications'); | 4 | const debug = require('debug')('Ferdi:Notifications'); |
5 | 5 | ||
6 | class Notification { | 6 | class Notification { |
7 | static permission = 'granted'; | 7 | static permission = 'granted'; |
diff --git a/src/webview/recipe.js b/src/webview/recipe.js index c223b73de..b30199f03 100644 --- a/src/webview/recipe.js +++ b/src/webview/recipe.js | |||
@@ -1,8 +1,15 @@ | |||
1 | import { ipcRenderer } from 'electron'; | 1 | import { ipcRenderer } from 'electron'; |
2 | import path from 'path'; | 2 | import path from 'path'; |
3 | import { autorun, computed, observable } from 'mobx'; | 3 | import { autorun, computed, observable } from 'mobx'; |
4 | import fs from 'fs-extra'; | ||
4 | import { loadModule } from 'cld3-asm'; | 5 | import { loadModule } from 'cld3-asm'; |
5 | import { debounce } from 'lodash'; | 6 | import { debounce } from 'lodash'; |
7 | import { | ||
8 | enable as enableDarkMode, | ||
9 | disable as disableDarkMode, | ||
10 | } from 'darkreader'; | ||
11 | |||
12 | import ignoreList from './darkmode/ignore'; | ||
6 | 13 | ||
7 | import RecipeWebview from './lib/RecipeWebview'; | 14 | import RecipeWebview from './lib/RecipeWebview'; |
8 | 15 | ||
@@ -13,7 +20,7 @@ import './notifications'; | |||
13 | 20 | ||
14 | import { DEFAULT_APP_SETTINGS } from '../config'; | 21 | import { DEFAULT_APP_SETTINGS } from '../config'; |
15 | 22 | ||
16 | const debug = require('debug')('Franz:Plugin'); | 23 | const debug = require('debug')('Ferdi:Plugin'); |
17 | 24 | ||
18 | class RecipeController { | 25 | class RecipeController { |
19 | @observable settings = { | 26 | @observable settings = { |
@@ -109,12 +116,27 @@ class RecipeController { | |||
109 | } | 116 | } |
110 | } | 117 | } |
111 | 118 | ||
112 | if (this.settings.service.isDarkModeEnabled) { | 119 | if (this.settings.service.isDarkModeEnabled || this.settings.app.darkMode) { |
113 | debug('Enable dark mode'); | 120 | debug('Enable dark mode'); |
114 | injectDarkModeStyle(this.settings.service.recipe.path); | 121 | |
115 | } else if (isDarkModeStyleInjected()) { | 122 | // Check if recipe has a darkmode.css |
123 | const darkModeStyle = path.join(this.settings.service.recipe.path, 'darkmode.css'); | ||
124 | const darkModeExists = fs.pathExistsSync(darkModeStyle); | ||
125 | |||
126 | if (darkModeExists) { | ||
127 | injectDarkModeStyle(this.settings.service.recipe.path); | ||
128 | } else if (!ignoreList.includes(window.location.host)) { | ||
129 | // Use darkreader instead | ||
130 | enableDarkMode(); | ||
131 | } | ||
132 | } else { | ||
116 | debug('Remove dark mode'); | 133 | debug('Remove dark mode'); |
117 | removeDarkModeStyle(); | 134 | |
135 | if (isDarkModeStyleInjected()) { | ||
136 | removeDarkModeStyle(); | ||
137 | } else { | ||
138 | disableDarkMode(); | ||
139 | } | ||
118 | } | 140 | } |
119 | } | 141 | } |
120 | 142 | ||
@@ -174,6 +196,32 @@ new RecipeController(); | |||
174 | const originalWindowOpen = window.open; | 196 | const originalWindowOpen = window.open; |
175 | 197 | ||
176 | window.open = (url, frameName, features) => { | 198 | window.open = (url, frameName, features) => { |
199 | if (!url && !frameName && !features) { | ||
200 | // The service hasn't yet supplied a URL (as used in Skype). | ||
201 | // Return a new dummy window object and wait for the service to change the properties | ||
202 | const newWindow = { | ||
203 | location: { | ||
204 | href: '', | ||
205 | }, | ||
206 | }; | ||
207 | |||
208 | const checkInterval = setInterval(() => { | ||
209 | // Has the service changed the URL yet? | ||
210 | if (newWindow.location.href !== '') { | ||
211 | // Open the new URL | ||
212 | window.open(newWindow.location.href); | ||
213 | clearInterval(checkInterval); | ||
214 | } | ||
215 | }, 0); | ||
216 | |||
217 | setTimeout(() => { | ||
218 | // Stop checking for location changes after 1 second | ||
219 | clearInterval(checkInterval); | ||
220 | }, 1000); | ||
221 | |||
222 | return newWindow; | ||
223 | } | ||
224 | |||
177 | // We need to differentiate if the link should be opened in a popup or in the systems default browser | 225 | // We need to differentiate if the link should be opened in a popup or in the systems default browser |
178 | if (!frameName && !features) { | 226 | if (!frameName && !features) { |
179 | return ipcRenderer.sendToHost('new-window', url); | 227 | return ipcRenderer.sendToHost('new-window', url); |
diff --git a/src/webview/spellchecker.js b/src/webview/spellchecker.js index 06cbd283a..27380676d 100644 --- a/src/webview/spellchecker.js +++ b/src/webview/spellchecker.js | |||
@@ -6,7 +6,7 @@ import { readFileSync } from 'fs'; | |||
6 | import { DICTIONARY_PATH } from '../config'; | 6 | import { DICTIONARY_PATH } from '../config'; |
7 | import { SPELLCHECKER_LOCALES } from '../i18n/languages'; | 7 | import { SPELLCHECKER_LOCALES } from '../i18n/languages'; |
8 | 8 | ||
9 | const debug = require('debug')('Franz:spellchecker'); | 9 | const debug = require('debug')('Ferdi:spellchecker'); |
10 | 10 | ||
11 | let provider; | 11 | let provider; |
12 | let currentDict; | 12 | let currentDict; |