Browse Source

Init commit

pg 4 years ago
commit
bf52f67c85
9 changed files with 204 additions and 0 deletions
  1. 2
    0
      .gitignore
  2. 0
    0
      README.md
  3. BIN
      assets/.clientApp.js.swp
  4. 32
    0
      assets/clientApp.js
  5. BIN
      back.png
  6. 132
    0
      main.js
  7. 17
    0
      package.json
  8. BIN
      views/.index.jade.swp
  9. 21
    0
      views/index.jade

+ 2
- 0
.gitignore View File

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

+ 0
- 0
README.md View File


BIN
assets/.clientApp.js.swp View File


+ 32
- 0
assets/clientApp.js View File

@@ -0,0 +1,32 @@
1
+//var bla = function
2
+
3
+$(document).ready(function(){
4
+ var row = function(data){
5
+ 
6
+  var htmlobj = "<div>"+data.title+" |"+ data.url+
7
+    //" </div>"+ "<div class='presLink'><button value='"+ data.url+"'> launch </button></div>"
8
+     "<button  class='presLink' value='"+data.url+"' > launch </button></div>"
9
+  //return "<div><div>"+data.title+"</div> <div>| "+ data.url+" </div>"+ "<button class='.presLink'value='bla'> launch </button></div>"
10
+   return htmlobj
11
+
12
+  }
13
+
14
+
15
+  $("#addUrl").click(function(){
16
+    console.log("Hey")
17
+    var url=$("#urlText").val()
18
+   $.post("/", {url:url}, function(data){
19
+      console.log(data)
20
+      if (data.url){
21
+        //$("#ressources_list").append("<div> <p>"+data.title +"</p></div>")
22
+        $("#ressources_list").append(row(data))
23
+        $(".presLink").click(function(){
24
+        console.log(this.value)
25
+      })
26
+      }
27
+    })
28
+
29
+
30
+  })
31
+  })
32
+

BIN
back.png View File


+ 132
- 0
main.js View File

@@ -0,0 +1,132 @@
1
+'use strict';
2
+
3
+const util = require('util');
4
+const EventEmitter = require('events');
5
+const electron = require('electron');
6
+const app = electron.app;  // Module to control application life.
7
+const BrowserWindow = electron.BrowserWindow;  // Module to create native browser window.
8
+var fs = require("fs");
9
+var Notify = require('fs.notify');
10
+var validUrl = require('valid-url');
11
+var express = require('express');
12
+var webapp = express();
13
+var MetaInspector = require('node-metainspector');
14
+
15
+
16
+var bodyParser = require('body-parser')
17
+require('crash-reporter').start();
18
+
19
+
20
+const refresh = new Refresh();
21
+
22
+function Refresh() {
23
+  EventEmitter.call(this);
24
+}
25
+util.inherits(Refresh, EventEmitter);
26
+
27
+var default_url="file://" + process.cwd() + "/back.png"
28
+
29
+var url_file = process.cwd() + "/url.txt"
30
+var files = [ url_file ]
31
+
32
+// Keep a global reference of the window object, if you don't, the window will
33
+// be closed automatically when the JavaScript object is garbage collected.
34
+var mainWindow = null;
35
+var notifications = new Notify(files);
36
+
37
+webapp.set('view engine', 'jade');
38
+webapp.use(express.static('assets'));
39
+webapp.use( bodyParser.json() );       // to support JSON-encoded bodies
40
+webapp.use(bodyParser.urlencoded({     // to support URL-encoded bodies
41
+    extended: true
42
+})); 
43
+
44
+//webapp.use(express.json());       // to support JSON-encoded bodies
45
+//webapp.use(express.urlencoded());
46
+
47
+webapp.get('/', function (req, res) {
48
+    res.render('index', {ressources:[]});
49
+});
50
+webapp.post("/", function(req,res){
51
+    
52
+    console.log("/new")
53
+    var resp = res
54
+    var candidate = req.body.url
55
+    console.log(candidate)
56
+    if( validUrl.isUri(candidate) ){
57
+      var client = new MetaInspector(candidate, { timeout: 5000 });
58
+      client.on("fetch", function(){
59
+        console.log("Description: " + client.description);
60
+        //imainWindow.loadURL(candidate);
61
+        refresh.emit('event',candidate)
62
+        resp.send({title:client.title, url:candidate, description: client.description})    
63
+      
64
+      });
65
+
66
+      client.on("error", function(err){
67
+            resp.send("ERR");
68
+            console.log(error);
69
+      });
70
+
71
+      client.fetch();
72
+
73
+    }
74
+    else {
75
+      console.log("Invalid URL: " + candidate)
76
+      resp.send("ERR");
77
+    }
78
+             
79
+            
80
+})
81
+
82
+
83
+
84
+webapp.listen(3000, function () {
85
+    console.log('Example app listening on port 3000!');
86
+});
87
+
88
+// Quit when all windows are closed.
89
+app.on('window-all-closed', function() {
90
+  // On OS X it is common for applications and their menu bar
91
+  // to stay active until the user quits explicitly with Cmd + Q
92
+  if (process.platform != 'darwin') {
93
+    app.quit();
94
+  }
95
+});
96
+
97
+// This method will be called when Electron has finished
98
+// initialization and is ready to create browser windows.
99
+app.on('ready', function() {
100
+  // Create the browser window.
101
+  mainWindow = new BrowserWindow({width: 800, height: 600});
102
+
103
+  // and load the index.html of the app.
104
+  mainWindow.loadURL(default_url);
105
+  // Open the DevTools.
106
+  //mainWindow.webContents.openDevTools();
107
+  refresh.on('event', function(url) {
108
+    console.log("got data", url)
109
+    //console.log(mainWindow)
110
+    const options = {"extraHeaders" : "pragma: no-cache\n"}
111
+    mainWindow.loadURL(url, options); 
112
+  });
113
+  // Emitted when the window is closed.
114
+  mainWindow.on('closed', function() {
115
+    // Dereference the window object, usually you would store windows
116
+    // in an array if your app supports multi windows, this is the time
117
+    // when you should delete the corresponding element.
118
+    mainWindow = null;
119
+  });
120
+});
121
+
122
+app.on('uncaughtException', function (error) {
123
+   console.log(error) // Handle the error
124
+})
125
+
126
+
127
+app.on('certificate-error', function(event, webContents, url, error, certificate, callback) {
128
+  console.log(error, certificate) 
129
+   event.preventDefault();
130
+    callback(true);
131
+
132
+})

+ 17
- 0
package.json View File

@@ -0,0 +1,17 @@
1
+{
2
+  "name": "your-app",
3
+  "version": "0.1.0",
4
+  "main": "main.js",
5
+  "dependencies": {
6
+    "body-parser": "^1.14.2",
7
+    "express": "^4.13.3",
8
+    "fs.notify": "0.0.4",
9
+    "jade": "^1.11.0",
10
+    "node-metainspector": "gabceb/node-metainspector",
11
+    "request": "^2.67.0",
12
+    "valid-url": "^1.0.9"
13
+  },
14
+  "devDependencies": {
15
+    "electron-rebuild": "^1.1.1"
16
+  }
17
+}

BIN
views/.index.jade.swp View File


+ 21
- 0
views/index.jade View File

@@ -0,0 +1,21 @@
1
+html
2
+  head
3
+
4
+
5
+
6
+    link(rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous")
7
+    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")
8
+    script(src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/md5.js")
9
+    script(src="//code.jquery.com/jquery-1.12.0.min.js")
10
+    script(src="clientApp.js")
11
+    title Fancy title
12
+  body
13
+
14
+    #input_and_control      
15
+        div.input
16
+            span.label url
17
+            input(type="text", name="url",id="urlText")
18
+            input(type="submit", value="add", id="addUrl")
19
+  
20
+    #ressources_list
21
+      

Loading…
Cancel
Save