Init commit

This commit is contained in:
pg 2016-01-22 00:00:27 +01:00
commit bf52f67c85
9 changed files with 204 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
node_modules/
*.swp

0
README.md Normal file
View File

BIN
assets/.clientApp.js.swp Normal file

Binary file not shown.

32
assets/clientApp.js Normal file
View File

@ -0,0 +1,32 @@
//var bla = function
$(document).ready(function(){
var row = function(data){
var htmlobj = "<div>"+data.title+" |"+ data.url+
//" </div>"+ "<div class='presLink'><button value='"+ data.url+"'> launch </button></div>"
"<button class='presLink' value='"+data.url+"' > launch </button></div>"
//return "<div><div>"+data.title+"</div> <div>| "+ data.url+" </div>"+ "<button class='.presLink'value='bla'> launch </button></div>"
return htmlobj
}
$("#addUrl").click(function(){
console.log("Hey")
var url=$("#urlText").val()
$.post("/", {url:url}, function(data){
console.log(data)
if (data.url){
//$("#ressources_list").append("<div> <p>"+data.title +"</p></div>")
$("#ressources_list").append(row(data))
$(".presLink").click(function(){
console.log(this.value)
})
}
})
})
})

BIN
back.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 39 KiB

132
main.js Normal file
View File

@ -0,0 +1,132 @@
'use strict';
const util = require('util');
const EventEmitter = require('events');
const electron = require('electron');
const app = electron.app; // Module to control application life.
const BrowserWindow = electron.BrowserWindow; // Module to create native browser window.
var fs = require("fs");
var Notify = require('fs.notify');
var validUrl = require('valid-url');
var express = require('express');
var webapp = express();
var MetaInspector = require('node-metainspector');
var bodyParser = require('body-parser')
require('crash-reporter').start();
const refresh = new Refresh();
function Refresh() {
EventEmitter.call(this);
}
util.inherits(Refresh, EventEmitter);
var default_url="file://" + process.cwd() + "/back.png"
var url_file = process.cwd() + "/url.txt"
var files = [ url_file ]
// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
var mainWindow = null;
var notifications = new Notify(files);
webapp.set('view engine', 'jade');
webapp.use(express.static('assets'));
webapp.use( bodyParser.json() ); // to support JSON-encoded bodies
webapp.use(bodyParser.urlencoded({ // to support URL-encoded bodies
extended: true
}));
//webapp.use(express.json()); // to support JSON-encoded bodies
//webapp.use(express.urlencoded());
webapp.get('/', function (req, res) {
res.render('index', {ressources:[]});
});
webapp.post("/", function(req,res){
console.log("/new")
var resp = res
var candidate = req.body.url
console.log(candidate)
if( validUrl.isUri(candidate) ){
var client = new MetaInspector(candidate, { timeout: 5000 });
client.on("fetch", function(){
console.log("Description: " + client.description);
//imainWindow.loadURL(candidate);
refresh.emit('event',candidate)
resp.send({title:client.title, url:candidate, description: client.description})
});
client.on("error", function(err){
resp.send("ERR");
console.log(error);
});
client.fetch();
}
else {
console.log("Invalid URL: " + candidate)
resp.send("ERR");
}
})
webapp.listen(3000, function () {
console.log('Example app listening on port 3000!');
});
// Quit when all windows are closed.
app.on('window-all-closed', function() {
// On OS X it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
if (process.platform != 'darwin') {
app.quit();
}
});
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
app.on('ready', function() {
// Create the browser window.
mainWindow = new BrowserWindow({width: 800, height: 600});
// and load the index.html of the app.
mainWindow.loadURL(default_url);
// Open the DevTools.
//mainWindow.webContents.openDevTools();
refresh.on('event', function(url) {
console.log("got data", url)
//console.log(mainWindow)
const options = {"extraHeaders" : "pragma: no-cache\n"}
mainWindow.loadURL(url, options);
});
// Emitted when the window is closed.
mainWindow.on('closed', function() {
// Dereference the window object, usually you would store windows
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element.
mainWindow = null;
});
});
app.on('uncaughtException', function (error) {
console.log(error) // Handle the error
})
app.on('certificate-error', function(event, webContents, url, error, certificate, callback) {
console.log(error, certificate)
event.preventDefault();
callback(true);
})

17
package.json Normal file
View File

@ -0,0 +1,17 @@
{
"name": "your-app",
"version": "0.1.0",
"main": "main.js",
"dependencies": {
"body-parser": "^1.14.2",
"express": "^4.13.3",
"fs.notify": "0.0.4",
"jade": "^1.11.0",
"node-metainspector": "gabceb/node-metainspector",
"request": "^2.67.0",
"valid-url": "^1.0.9"
},
"devDependencies": {
"electron-rebuild": "^1.1.1"
}
}

BIN
views/.index.jade.swp Normal file

Binary file not shown.

21
views/index.jade Normal file
View File

@ -0,0 +1,21 @@
html
head
link(rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous")
link(link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" integrity="sha384-fLW2N01lMqjakBkx3l/M9EahuwpSfeNvV63J5ezn3uZzapT0u7EYsXMjQV+0En5r" crossorigin="anonymous")
script(src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/md5.js")
script(src="//code.jquery.com/jquery-1.12.0.min.js")
script(src="clientApp.js")
title Fancy title
body
#input_and_control
div.input
span.label url
input(type="text", name="url",id="urlText")
input(type="submit", value="add", id="addUrl")
#ressources_list