commit bf52f67c8552f6ea7740e973d34c54ae4840a0d1 Author: pg Date: Fri Jan 22 00:00:27 2016 +0100 Init commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a6ec74b --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +node_modules/ +*.swp diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/assets/.clientApp.js.swp b/assets/.clientApp.js.swp new file mode 100644 index 0000000..7f870ec Binary files /dev/null and b/assets/.clientApp.js.swp differ diff --git a/assets/clientApp.js b/assets/clientApp.js new file mode 100644 index 0000000..c83bad3 --- /dev/null +++ b/assets/clientApp.js @@ -0,0 +1,32 @@ +//var bla = function + +$(document).ready(function(){ + var row = function(data){ + + var htmlobj = "
"+data.title+" |"+ data.url+ + //"
"+ "" + "" + //return "
"+data.title+"
| "+ data.url+"
"+ "
" + 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("

"+data.title +"

") + $("#ressources_list").append(row(data)) + $(".presLink").click(function(){ + console.log(this.value) + }) + } + }) + + + }) + }) + diff --git a/back.png b/back.png new file mode 100644 index 0000000..a0ad9bc Binary files /dev/null and b/back.png differ diff --git a/main.js b/main.js new file mode 100644 index 0000000..1f11f0e --- /dev/null +++ b/main.js @@ -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); + +}) diff --git a/package.json b/package.json new file mode 100644 index 0000000..2eafb4d --- /dev/null +++ b/package.json @@ -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" + } +} diff --git a/views/.index.jade.swp b/views/.index.jade.swp new file mode 100644 index 0000000..a94f7fa Binary files /dev/null and b/views/.index.jade.swp differ diff --git a/views/index.jade b/views/index.jade new file mode 100644 index 0000000..a2fb15c --- /dev/null +++ b/views/index.jade @@ -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 +