aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/services/content/ServiceWebview.js
diff options
context:
space:
mode:
authorLibravatar André Oliveira <37463445+SpecialAro@users.noreply.github.com>2022-08-04 00:12:03 +0100
committerLibravatar GitHub <noreply@github.com>2022-08-03 23:12:03 +0000
commitc2509e860752e23812bb408e331c02c918aadd54 (patch)
treeb855163ad1bddaaa19c47a9cea2713c6899ea1a5 /src/components/services/content/ServiceWebview.js
parentRevert to older working version of 'macos-notification-state' (diff)
downloadferdium-app-c2509e860752e23812bb408e331c02c918aadd54.tar.gz
ferdium-app-c2509e860752e23812bb408e331c02c918aadd54.tar.zst
ferdium-app-c2509e860752e23812bb408e331c02c918aadd54.zip
chore: change values inside mobx actions to fix console warnings (#532)
Diffstat (limited to 'src/components/services/content/ServiceWebview.js')
-rw-r--r--src/components/services/content/ServiceWebview.js128
1 files changed, 0 insertions, 128 deletions
diff --git a/src/components/services/content/ServiceWebview.js b/src/components/services/content/ServiceWebview.js
deleted file mode 100644
index 502f87225..000000000
--- a/src/components/services/content/ServiceWebview.js
+++ /dev/null
@@ -1,128 +0,0 @@
1import { Component } from 'react';
2import PropTypes from 'prop-types';
3import { observer } from 'mobx-react';
4import { makeObservable, observable, reaction } from 'mobx';
5import ElectronWebView from 'react-electron-web-view';
6import { join } from 'path';
7
8import ServiceModel from '../../../models/Service';
9
10const debug = require('../../../preload-safe-debug')('Ferdium:Services');
11
12class ServiceWebview extends Component {
13 static propTypes = {
14 service: PropTypes.instanceOf(ServiceModel).isRequired,
15 setWebviewReference: PropTypes.func.isRequired,
16 detachService: PropTypes.func.isRequired,
17 isSpellcheckerEnabled: PropTypes.bool.isRequired,
18 };
19
20 @observable webview = null;
21
22 constructor(props) {
23 super(props);
24
25 makeObservable(this);
26
27 reaction(
28 () => this.webview,
29 () => {
30 if (this.webview && this.webview.view) {
31 this.webview.view.addEventListener('console-message', e => {
32 debug('Service logged a message:', e.message);
33 });
34 this.webview.view.addEventListener('did-navigate', () => {
35 if (this.props.service._webview) {
36 document.title = `Ferdium - ${this.props.service.name} ${
37 this.props.service.dialogTitle
38 ? ` - ${this.props.service.dialogTitle}`
39 : ''
40 } ${`- ${this.props.service._webview.getTitle()}`}`;
41 }
42 });
43 }
44 },
45 );
46 }
47
48 componentWillUnmount() {
49 const { service, detachService } = this.props;
50 detachService({ service });
51 }
52
53 refocusWebview = () => {
54 const { webview } = this;
55 debug('Refocus Webview is called', this.props.service);
56 if (!webview) return;
57 if (this.props.service.isActive) {
58 webview.view.blur();
59 webview.view.focus();
60 window.setTimeout(() => {
61 document.title = `Ferdium - ${this.props.service.name} ${
62 this.props.service.dialogTitle
63 ? ` - ${this.props.service.dialogTitle}`
64 : ''
65 } ${`- ${this.props.service._webview.getTitle()}`}`;
66 }, 100);
67 } else {
68 debug('Refocus not required - Not active service');
69 }
70 };
71
72 render() {
73 const { service, setWebviewReference, isSpellcheckerEnabled } = this.props;
74
75 const preloadScript = join(
76 __dirname,
77 '..',
78 '..',
79 '..',
80 'webview',
81 'recipe.js',
82 );
83
84 return (
85 <ElectronWebView
86 ref={webview => {
87 this.webview = webview;
88 if (webview && webview.view) {
89 webview.view.addEventListener(
90 'did-stop-loading',
91 this.refocusWebview,
92 );
93 }
94 }}
95 autosize
96 src={service.url}
97 preload={preloadScript}
98 partition={service.partition}
99 onDidAttach={() => {
100 // Force the event handler to run in a new task.
101 // This resolves a race condition when the `did-attach` is called,
102 // but the webview is not attached to the DOM yet:
103 // https://github.com/electron/electron/issues/31918
104 // This prevents us from immediately attaching listeners such as `did-stop-load`:
105 // https://github.com/ferdium/ferdium-app/issues/157
106 setTimeout(() => {
107 setWebviewReference({
108 serviceId: service.id,
109 webview: this.webview.view,
110 });
111 }, 0);
112 }}
113 onUpdateTargetUrl={this.updateTargetUrl}
114 useragent={service.userAgent}
115 disablewebsecurity={
116 service.recipe.disablewebsecurity ? true : undefined
117 }
118 allowpopups
119 nodeintegration
120 webpreferences={`spellcheck=${
121 isSpellcheckerEnabled ? 1 : 0
122 }, contextIsolation=1`}
123 />
124 );
125 }
126}
127
128export default observer(ServiceWebview);