mirror of
https://github.com/Llewellynvdm/nativefier.git
synced 2024-12-22 18:18:55 +00:00
Implement injection of .js
This commit is contained in:
parent
4351906a42
commit
4d49c01ff3
0
app/inject/_placeholder
Normal file
0
app/inject/_placeholder
Normal file
@ -2,8 +2,12 @@
|
||||
Preload file that will be executed in the renderer process
|
||||
*/
|
||||
import electron from 'electron';
|
||||
import path from 'path';
|
||||
import fs from 'fs';
|
||||
const {ipcRenderer, webFrame} = electron;
|
||||
|
||||
const INJECT_JS_PATH = path.join(__dirname, '../../', 'inject/inject.js');
|
||||
|
||||
setNotificationCallback((title, opt) => {
|
||||
ipcRenderer.send('notification', title, opt);
|
||||
});
|
||||
@ -26,6 +30,7 @@ document.addEventListener('DOMContentLoaded', event => {
|
||||
ipcRenderer.send('contextMenuOpened', targetHref);
|
||||
}, false);
|
||||
|
||||
injectScripts();
|
||||
});
|
||||
|
||||
ipcRenderer.on('params', (event, message) => {
|
||||
@ -62,3 +67,11 @@ function clickSelector(element) {
|
||||
const mouseEvent = new MouseEvent('click');
|
||||
element.dispatchEvent(mouseEvent);
|
||||
}
|
||||
|
||||
function injectScripts() {
|
||||
const needToInject = fs.existsSync(INJECT_JS_PATH);
|
||||
if (!needToInject) {
|
||||
return;
|
||||
}
|
||||
require(INJECT_JS_PATH);
|
||||
}
|
||||
|
@ -18,7 +18,7 @@
|
||||
"clean": "gulp clean",
|
||||
"build": "gulp build",
|
||||
"watch": "while true ; do gulp watch ; done",
|
||||
"package-placeholder": "npm run build && node lib/cli.js http://www.bennish.net/web-notifications.html ~/Desktop --overwrite --name notification-test --icon ./test-resources/iconSampleGrey.png && open ~/Desktop/notification-test-darwin-x64/notification-test.app",
|
||||
"package-placeholder": "npm run build && node lib/cli.js http://www.bennish.net/web-notifications.html ~/Desktop --overwrite --name notification-test --icon ./test-resources/iconSampleGrey.png --inject ./test-resources/test-injection.js && open ~/Desktop/notification-test-darwin-x64/notification-test.app",
|
||||
"start-placeholder": "npm run build && electron app",
|
||||
"release": "gulp release"
|
||||
},
|
||||
|
@ -24,7 +24,30 @@ function buildApp(src, dest, options, callback) {
|
||||
}
|
||||
|
||||
fs.writeFileSync(path.join(dest, '/nativefier.json'), JSON.stringify(appArgs));
|
||||
changeAppPackageJsonName(dest, appArgs.name, appArgs.targetUrl);
|
||||
|
||||
maybeCopyScripts(options.inject, dest, error => {
|
||||
if (error) {
|
||||
callback(error);
|
||||
return;
|
||||
}
|
||||
|
||||
changeAppPackageJsonName(dest, appArgs.name, appArgs.targetUrl);
|
||||
callback();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function maybeCopyScripts(src, dest, callback) {
|
||||
if (!fs.existsSync(src)) {
|
||||
callback();
|
||||
return;
|
||||
}
|
||||
|
||||
copy(src, path.join(dest, 'inject', 'inject.js'), error => {
|
||||
if (error) {
|
||||
callback(`Error Copying injection files: ${error}`);
|
||||
return;
|
||||
}
|
||||
callback();
|
||||
});
|
||||
}
|
||||
|
@ -31,6 +31,7 @@ if (require.main === module) {
|
||||
.option('--ignore-certificate', 'ignore certificate related errors')
|
||||
.option('--insecure', 'enable loading of insecure content, defaults to false')
|
||||
.option('--flash <value>', 'path to Chrome flash plugin, find it in `Chrome://plugins`')
|
||||
.option('--inject <value>', 'path to a javascript file to be injected')
|
||||
.parse(process.argv);
|
||||
|
||||
if (!process.argv.slice(2).length) {
|
||||
|
@ -48,7 +48,8 @@ function optionsFactory(inpOptions, callback) {
|
||||
userAgent: inpOptions.userAgent || getFakeUserAgent(),
|
||||
ignoreCertificate: inpOptions.ignoreCertificate || false,
|
||||
insecure: inpOptions.insecure || false,
|
||||
flashPluginDir: inpOptions.flash || null
|
||||
flashPluginDir: inpOptions.flash || null,
|
||||
inject: inpOptions.inject || null
|
||||
};
|
||||
|
||||
if (inpOptions.honest) {
|
||||
|
1
test-resources/test-injection.js
Normal file
1
test-resources/test-injection.js
Normal file
@ -0,0 +1 @@
|
||||
console.log('This is a test injecton script');
|
Loading…
Reference in New Issue
Block a user