Skip to content

Commit ca5a8b6

Browse files
committed
Extract script tags to renderer.js file
1 parent 7881376 commit ca5a8b6

File tree

3 files changed

+47
-43
lines changed

3 files changed

+47
-43
lines changed

default_app/index.html

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -113,24 +113,6 @@
113113
</style>
114114
</head>
115115
<body>
116-
<script>
117-
const {remote, shell} = require('electron');
118-
119-
const execPath = remote.process.execPath;
120-
const command = execPath + ' path-to-your-app';
121-
122-
document.onclick = function(e) {
123-
e.preventDefault();
124-
if (e.target.tagName == 'A')
125-
shell.openExternal(e.target.href);
126-
return false;
127-
};
128-
document.ondragover = document.ondrop = function(e) {
129-
e.preventDefault();
130-
return false;
131-
};
132-
</script>
133-
134116
<div class="header">
135117
<svg class="header-icon" viewBox="0 0 32 32" xmlns="http://www.w3.org/2000/svg" aria-hidden="true">
136118
<g stroke="none" fill="none" fill-rule="evenodd">
@@ -185,31 +167,7 @@
185167
</div>
186168

187169
<script>
188-
const holder = document.getElementById('holder');
189-
holder.ondragover = function () {
190-
this.className = 'hover';
191-
return false;
192-
};
193-
holder.ondragleave = holder.ondragend = function () {
194-
this.className = '';
195-
return false;
196-
};
197-
holder.ondrop = function (e) {
198-
this.className = '';
199-
e.preventDefault();
200-
201-
const file = e.dataTransfer.files[0];
202-
require('child_process').execFile(execPath, [file.path], {
203-
detached: true, stdio: 'ignore'
204-
}).unref();
205-
return false;
206-
};
207-
208-
const version = process.versions.electron;
209-
document.querySelector('.header-version').innerText = version;
210-
document.querySelector('.command-example').innerText = command;
211-
document.querySelector('.quick-start-link').href = `https://github.com/electron/electron/blob/v${version}/docs/tutorial/quick-start.md`;
212-
document.querySelector('.docs-link').href = `https://github.com/electron/electron/tree/v${version}/docs#readme`;
170+
require('./renderer')
213171
</script>
214172
</body>
215173
</html>

default_app/renderer.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
const {remote, shell} = require('electron')
2+
const {execFile} = require('child_process')
3+
4+
const {execPath} = remote.process
5+
6+
document.onclick = function (e) {
7+
e.preventDefault()
8+
if (e.target.tagName === 'A') {
9+
shell.openExternal(e.target.href)
10+
}
11+
return false
12+
}
13+
14+
document.ondragover = document.ondrop = function (e) {
15+
e.preventDefault()
16+
return false
17+
}
18+
19+
const holder = document.getElementById('holder')
20+
holder.ondragover = function () {
21+
this.className = 'hover'
22+
return false
23+
}
24+
25+
holder.ondragleave = holder.ondragend = function () {
26+
this.className = ''
27+
return false
28+
}
29+
30+
holder.ondrop = function (e) {
31+
this.className = ''
32+
e.preventDefault()
33+
34+
const file = e.dataTransfer.files[0]
35+
execFile(execPath, [file.path], {
36+
detached: true, stdio: 'ignore'
37+
}).unref()
38+
return false
39+
}
40+
41+
const version = process.versions.electron
42+
document.querySelector('.header-version').innerText = version
43+
document.querySelector('.command-example').innerText = `${execPath} path-to-your-app`
44+
document.querySelector('.quick-start-link').href = `https://github.com/electron/electron/blob/v${version}/docs/tutorial/quick-start.md`
45+
document.querySelector('.docs-link').href = `https://github.com/electron/electron/tree/v${version}/docs#readme`

filenames.gypi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989
'default_app/index.html',
9090
'default_app/main.js',
9191
'default_app/package.json',
92+
'default_app/renderer.js',
9293
],
9394
'lib_sources': [
9495
'atom/app/atom_content_client.cc',

0 commit comments

Comments
 (0)