mirror of
https://github.com/Llewellynvdm/nativefier.git
synced 2024-12-22 10:08:55 +00:00
Initial commit
This commit is contained in:
parent
d33c1e5fa2
commit
104821b759
2
.gitignore
vendored
2
.gitignore
vendored
@ -2,7 +2,7 @@ node_modules
|
||||
.DS_Store
|
||||
build/
|
||||
|
||||
# the file used to pass variables from the cli to the app
|
||||
# the file used to pass variables from the cli to the app
|
||||
app/targetUrl.txt
|
||||
|
||||
|
||||
|
6
app/assets/css/main.css
Normal file
6
app/assets/css/main.css
Normal file
@ -0,0 +1,6 @@
|
||||
html, body {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
27
app/assets/js/index.js
Normal file
27
app/assets/js/index.js
Normal file
@ -0,0 +1,27 @@
|
||||
/**
|
||||
* Created by JiaHao on 5/7/15.
|
||||
*/
|
||||
|
||||
var ipc = require('ipc');
|
||||
|
||||
ipc.on('params', function(message) {
|
||||
|
||||
var appArgs = JSON.parse(message);
|
||||
|
||||
console.log(appArgs.targetUrl);
|
||||
console.log(appArgs.name);
|
||||
|
||||
document.title = appArgs.name;
|
||||
|
||||
var webView = document.createElement('webview');
|
||||
|
||||
webView.setAttribute('src', appArgs.targetUrl);
|
||||
webView.setAttribute('autosize', 'on');
|
||||
webView.setAttribute('minwidth', '600');
|
||||
webView.setAttribute('minheight', '800');
|
||||
|
||||
var webViewDiv = document.getElementById('webViewDiv');
|
||||
webViewDiv.appendChild(webView);
|
||||
|
||||
});
|
||||
|
16
app/index.html
Normal file
16
app/index.html
Normal file
@ -0,0 +1,16 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Nativefier</title>
|
||||
<link rel="stylesheet" href="assets/css/main.css">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<div id="webViewDiv" style="width:100%; height:100%"></div>
|
||||
|
||||
<script src="assets/js/index.js"></script>
|
||||
|
||||
</body>
|
||||
</html>
|
53
app/main.js
Normal file
53
app/main.js
Normal file
@ -0,0 +1,53 @@
|
||||
/**
|
||||
* Created by JiaHao on 4/7/15.
|
||||
*/
|
||||
|
||||
|
||||
var app = require('app');
|
||||
var fs = require('fs');
|
||||
var BrowserWindow = require('browser-window');
|
||||
|
||||
const APP_ARGS_FILE_PATH = __dirname + '/targetUrl.txt';
|
||||
require('crash-reporter').start();
|
||||
|
||||
var mainWindow = null;
|
||||
|
||||
app.on('window-all-closed', function() {
|
||||
if (process.platform != 'darwin') {
|
||||
app.quit();
|
||||
}
|
||||
});
|
||||
|
||||
app.on('ready', function() {
|
||||
mainWindow = new BrowserWindow(
|
||||
{
|
||||
width: 1280,
|
||||
height: 800,
|
||||
'web-preferences': {
|
||||
javascript: true,
|
||||
plugins: true,
|
||||
}
|
||||
}
|
||||
);
|
||||
mainWindow.loadUrl('file://' + __dirname + '/index.html');
|
||||
|
||||
//mainWindow.openDevTools();
|
||||
mainWindow.webContents.on('did-finish-load', function() {
|
||||
|
||||
fs.readFile(__dirname + '/targetUrl.txt', 'utf8', function (error, data) {
|
||||
if (error) {
|
||||
console.error('Error reading file: ' + error);
|
||||
} else {
|
||||
mainWindow.webContents.send('params', data);
|
||||
}
|
||||
|
||||
})
|
||||
});
|
||||
|
||||
|
||||
mainWindow.on('closed', function() {
|
||||
mainWindow = null;
|
||||
})
|
||||
|
||||
});
|
||||
|
19
app/package.json
Normal file
19
app/package.json
Normal file
@ -0,0 +1,19 @@
|
||||
{
|
||||
"name": "NativeFier",
|
||||
"version": "0.0.1",
|
||||
"description": "Wrap single-page web apps natiely",
|
||||
"main": "main.js",
|
||||
"dependencies": {
|
||||
"electron-prebuilt": "^0.29.1"
|
||||
},
|
||||
"devDependencies": {},
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"keywords": [
|
||||
"desktop",
|
||||
"electron"
|
||||
],
|
||||
"author": "Jia Hao",
|
||||
"license": "ISC"
|
||||
}
|
14
cli.js
14
cli.js
@ -4,8 +4,8 @@ var args = require('minimist')(process.argv.slice(2), {boolean: ['prune', 'asar'
|
||||
var packager = require('./')
|
||||
var usage = fs.readFileSync(__dirname + '/usage.txt').toString()
|
||||
|
||||
args.dir = args._[0]
|
||||
args.name = args._[1]
|
||||
args.dir = './app';
|
||||
args.name = args._[0];
|
||||
|
||||
var protocolSchemes = [].concat(args.protocol || [])
|
||||
var protocolNames = [].concat(args['protocol-name'] || [])
|
||||
@ -16,11 +16,19 @@ if (protocolSchemes && protocolNames && protocolNames.length === protocolSchemes
|
||||
})
|
||||
}
|
||||
|
||||
if (!args.dir || !args.name || !args.version || (!args.all && (!args.platform || !args.arch))) {
|
||||
if (!args.dir || !args.name || !args.version || !args.target || (!args.all && (!args.platform || !args.arch))) {
|
||||
console.error(usage)
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
var appArgs = {
|
||||
name: args.name,
|
||||
targetUrl: args.target
|
||||
};
|
||||
|
||||
fs.writeFileSync('./app/targetUrl.txt', JSON.stringify(appArgs));
|
||||
|
||||
|
||||
packager(args, function done (err, appPaths) {
|
||||
if (err) {
|
||||
if (err.message) console.error(err.message)
|
||||
|
@ -1,12 +1,13 @@
|
||||
Usage: electron-packager <sourcedir> <appname> --platform=<platform> --arch=<arch> --version=<version>
|
||||
Usage: electron-packager <appname> --target=<url> --platform=<platform> --arch=<arch> --version=<version>
|
||||
|
||||
Required options
|
||||
|
||||
target target url for the single page app
|
||||
platform all, or one or more of: linux, win32, darwin (comma-delimited if multiple)
|
||||
arch all, ia32, x64
|
||||
version see https://github.com/atom/electron/releases
|
||||
|
||||
Example electron-packager ./ FooBar --platform=darwin --arch=x64 --version=0.28.2
|
||||
Example electron-packager FooBar --target=http://messenger.com --platform=darwin --arch=x64 --version=0.28.2
|
||||
|
||||
Optional options
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user