From 104821b759a2557a71ae3f8ae3ad79211791089e Mon Sep 17 00:00:00 2001 From: Jia Hao Date: Sun, 5 Jul 2015 14:08:13 +0800 Subject: [PATCH] Initial commit --- .gitignore | 2 +- app/assets/css/main.css | 6 +++++ app/assets/js/index.js | 27 +++++++++++++++++++++ app/index.html | 16 +++++++++++++ app/main.js | 53 +++++++++++++++++++++++++++++++++++++++++ app/package.json | 19 +++++++++++++++ cli.js | 14 ++++++++--- usage.txt | 5 ++-- 8 files changed, 136 insertions(+), 6 deletions(-) create mode 100644 app/assets/css/main.css create mode 100644 app/assets/js/index.js create mode 100644 app/index.html create mode 100644 app/main.js create mode 100644 app/package.json diff --git a/.gitignore b/.gitignore index f769ca5..0809b03 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/app/assets/css/main.css b/app/assets/css/main.css new file mode 100644 index 0000000..29851f1 --- /dev/null +++ b/app/assets/css/main.css @@ -0,0 +1,6 @@ +html, body { + width: 100%; + height: 100%; + margin: 0; + padding: 0; +} \ No newline at end of file diff --git a/app/assets/js/index.js b/app/assets/js/index.js new file mode 100644 index 0000000..2042142 --- /dev/null +++ b/app/assets/js/index.js @@ -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); + +}); + diff --git a/app/index.html b/app/index.html new file mode 100644 index 0000000..3f5b1e7 --- /dev/null +++ b/app/index.html @@ -0,0 +1,16 @@ + + + + + Nativefier + + + + + +
+ + + + + \ No newline at end of file diff --git a/app/main.js b/app/main.js new file mode 100644 index 0000000..fa26256 --- /dev/null +++ b/app/main.js @@ -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; + }) + +}); + diff --git a/app/package.json b/app/package.json new file mode 100644 index 0000000..a960bbd --- /dev/null +++ b/app/package.json @@ -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" +} diff --git a/cli.js b/cli.js index 9bb0c4f..e441f3b 100755 --- a/cli.js +++ b/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) diff --git a/usage.txt b/usage.txt index 73a1e33..1b9aa4a 100644 --- a/usage.txt +++ b/usage.txt @@ -1,12 +1,13 @@ -Usage: electron-packager --platform= --arch= --version= +Usage: electron-packager --target= --platform= --arch= --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