diff options
Diffstat (limited to 'src/webview/plugin.js')
-rw-r--r-- | src/webview/plugin.js | 115 |
1 files changed, 0 insertions, 115 deletions
diff --git a/src/webview/plugin.js b/src/webview/plugin.js deleted file mode 100644 index 6d4e65062..000000000 --- a/src/webview/plugin.js +++ /dev/null | |||
@@ -1,115 +0,0 @@ | |||
1 | import { ipcRenderer } from 'electron'; | ||
2 | import path from 'path'; | ||
3 | import { observable } from 'mobx'; | ||
4 | |||
5 | import RecipeWebview from './lib/RecipeWebview'; | ||
6 | |||
7 | import spellchecker, { switchDict, disable as disableSpellchecker } from './spellchecker'; | ||
8 | import { injectDarkModeStyle, isDarkModeStyleInjected, removeDarkModeStyle } from './darkmode'; | ||
9 | import contextMenu from './contextMenu'; | ||
10 | import './notifications'; | ||
11 | |||
12 | const debug = require('debug')('Franz:Plugin'); | ||
13 | |||
14 | window.franzSettings = {}; | ||
15 | let serviceData; | ||
16 | let overrideSpellcheckerLanguage = false; | ||
17 | |||
18 | |||
19 | ipcRenderer.on('initializeRecipe', (e, data) => { | ||
20 | const modulePath = path.join(data.recipe.path, 'webview.js'); | ||
21 | // Delete module from cache | ||
22 | delete require.cache[require.resolve(modulePath)]; | ||
23 | try { | ||
24 | // eslint-disable-next-line | ||
25 | require(modulePath)(new RecipeWebview(), data); | ||
26 | debug('Initialize Recipe', data); | ||
27 | |||
28 | serviceData = data; | ||
29 | |||
30 | if (data.isDarkModeEnabled) { | ||
31 | injectDarkModeStyle(data.recipe.path); | ||
32 | debug('Add dark theme styles'); | ||
33 | } | ||
34 | |||
35 | if (data.spellcheckerLanguage) { | ||
36 | debug('Overriding spellchecker language to', data.spellcheckerLanguage); | ||
37 | switchDict(data.spellcheckerLanguage); | ||
38 | |||
39 | overrideSpellcheckerLanguage = true; | ||
40 | } | ||
41 | } catch (err) { | ||
42 | debug('Recipe initialization failed', err); | ||
43 | } | ||
44 | }); | ||
45 | |||
46 | // Needs to run asap to intialize dictionaries | ||
47 | (async () => { | ||
48 | const spellcheckingProvider = await spellchecker(); | ||
49 | contextMenu(spellcheckingProvider); | ||
50 | })(); | ||
51 | |||
52 | ipcRenderer.on('settings-update', async (e, data) => { | ||
53 | debug('Settings update received', data); | ||
54 | |||
55 | if (!data.enableSpellchecking) { | ||
56 | disableSpellchecker(); | ||
57 | } else if (!overrideSpellcheckerLanguage) { | ||
58 | debug('Setting spellchecker language based on app settings to', data.spellcheckerLanguage); | ||
59 | switchDict(data.spellcheckerLanguage); | ||
60 | } | ||
61 | |||
62 | window.franzSettings = data; | ||
63 | }); | ||
64 | |||
65 | ipcRenderer.on('service-settings-update', (e, data) => { | ||
66 | debug('Service settings update received', data); | ||
67 | |||
68 | serviceData = data; | ||
69 | |||
70 | if (data.isDarkModeEnabled && !isDarkModeStyleInjected()) { | ||
71 | injectDarkModeStyle(serviceData.recipe.path); | ||
72 | |||
73 | debug('Enable service dark mode'); | ||
74 | } else if (!data.isDarkModeEnabled && isDarkModeStyleInjected()) { | ||
75 | removeDarkModeStyle(); | ||
76 | |||
77 | debug('Disable service dark mode'); | ||
78 | } | ||
79 | |||
80 | if (data.spellcheckerLanguage) { | ||
81 | debug('Overriding spellchecker language to', data.spellcheckerLanguage); | ||
82 | switchDict(data.spellcheckerLanguage); | ||
83 | |||
84 | overrideSpellcheckerLanguage = true; | ||
85 | } else { | ||
86 | debug('Going back to default spellchecker language to', window.franzSettings.spellcheckerLanguage); | ||
87 | switchDict(window.franzSettings.spellcheckerLanguage); | ||
88 | |||
89 | overrideSpellcheckerLanguage = false; | ||
90 | } | ||
91 | }); | ||
92 | |||
93 | // Needed for current implementation of electrons 'login' event 🤦 | ||
94 | ipcRenderer.on('get-service-id', (event) => { | ||
95 | debug('Asking for service id', event); | ||
96 | |||
97 | event.sender.send('service-id', serviceData.id); | ||
98 | }); | ||
99 | |||
100 | |||
101 | document.addEventListener('DOMContentLoaded', () => { | ||
102 | ipcRenderer.sendToHost('hello'); | ||
103 | }, false); | ||
104 | |||
105 | // Patching window.open | ||
106 | const originalWindowOpen = window.open; | ||
107 | |||
108 | window.open = (url, frameName, features) => { | ||
109 | // We need to differentiate if the link should be opened in a popup or in the systems default browser | ||
110 | if (!frameName && !features) { | ||
111 | return ipcRenderer.sendToHost('new-window', url); | ||
112 | } | ||
113 | |||
114 | return originalWindowOpen(url, frameName, features); | ||
115 | }; | ||