Skip to content

Commit

Permalink
Merge pull request hokein#30 from hokein/electron-v1
Browse files Browse the repository at this point in the history
Update to Electron v1.1.1.
  • Loading branch information
hokein committed May 22, 2016
2 parents 0ffc12a + 3c3c683 commit 98c839c
Show file tree
Hide file tree
Showing 261 changed files with 781 additions and 858 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
# Electron Sample Apps

This repository contains Electron sample apps to illustrate the usage of
[Electron APIs](https://github.com/atom/electron/tree/master/docs).
[Electron APIs](https://github.com/electron/electron/tree/master/docs).

These sample apps are migrated from [nw-sample-apps](https://github.com/zcbenz/nw-sample-apps),
[chrome-app-sample](https://github.com/GoogleChrome/chrome-app-samples) and
[chromium extensions examples](https://code.google.com/p/chromium/codesearch#chromium/src/chrome/common/extensions/docs/examples/&sq=package:chromium&type=cs).

All the sample test on v0.30.2.
All samples are test on Electron v1.1.1.

## How to run apps

1. Install Electron via `npm install -g electron-prebuilt`.
1. Install Electron via `npm install -g electron-prebuilt@1.1.1`.

2. Run the sample via `electron <electron-sample-apps-path>/<sample-name>`.

If you want to know more about Electron app's development, please refer to the
[official docs](https://github.com/atom/electron/blob/master/docs/tutorial/quick-start.md).
[official docs](https://github.com/electron/electron/blob/master/docs/tutorial/quick-start.md).

## License

Expand Down
60 changes: 27 additions & 33 deletions camera/main.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,27 @@
var app = require('app'); // Module to control application life.
var BrowserWindow = require('browser-window'); // Module to create native browser window.

// Report crashes to our server.
require('crash-reporter').start();

// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the javascript object is GCed.
var mainWindow = null;

// Quit when all windows are closed.
app.on('window-all-closed', function() {
if (process.platform != 'darwin')
app.quit();
});

// This method will be called when Electron has done everything
// initialization and ready for creating 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('file://' + __dirname + '/index.html');

// 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;
});
});
const {app, BrowserWindow} = require('electron');

let mainWindow;

// Quit when all windows are closed.
app.on('window-all-closed', function() {
if (process.platform != 'darwin')
app.quit();
});

// This method will be called when Electron has done everything
// initialization and ready for creating 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('file://' + __dirname + '/index.html');

// 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;
});
});
2 changes: 1 addition & 1 deletion camera/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name" : "camera-demo",
"version" : "0.1.0",
"version" : "1.1.0",
"main" : "main.js"
}
41 changes: 20 additions & 21 deletions client-certificate/main.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
var app = require('app');
var BrowserWindow = require('browser-window');

var mainWindow = null;

app.on('window-all-closed', function() {
if (process.platform != 'darwin')
app.quit();
});

//app.commandLine.appendSwitch('client-certificate',
//'X:\\workspace\\client-certificates\\ssl\\client.crt');

app.on('ready', function() {
mainWindow = new BrowserWindow({
'width': 800,
'height': 600,
});

mainWindow.loadUrl('https://localhost:5000');
});
const {app, BrowserWindow} = require('electron');

let mainWindow;

app.on('window-all-closed', function() {
if (process.platform != 'darwin')
app.quit();
});

//app.commandLine.appendSwitch('client-certificate',
//'path/to/client-certificates/ssl/client.crt');

app.on('ready', function() {
mainWindow = new BrowserWindow({
'width': 800,
'height': 600,
});

mainWindow.loadURL('https://localhost:5000');
});
10 changes: 5 additions & 5 deletions client-certificate/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name" : "client-certificate-demo",
"version" : "0.1.0",
"main" : "main.js"
}
{
"name" : "client-certificate-demo",
"version" : "1.1.0",
"main" : "main.js"
}
42 changes: 21 additions & 21 deletions client-certificate/server.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
var https = require('https');
var fs = require('fs');

var options = {
key: fs.readFileSync('ssl/server.key'),
cert: fs.readFileSync('ssl/server.crt'),
ca: fs.readFileSync('ssl/rootCA.crt'),
requestCert: true,
rejectUnauthorized: false
};

https.createServer(options, function (req, res) {
console.log('Receive a request.');
if (req.client.authorized) {
res.writeHead(200);
res.end('approved\n');
} else {
res.writeHead(401);
res.end('denied\n');
}
}).listen(5000);
const https = require('https');
const fs = require('fs');

const options = {
key: fs.readFileSync('ssl/server.key'),
cert: fs.readFileSync('ssl/server.crt'),
ca: fs.readFileSync('ssl/rootCA.crt'),
requestCert: true,
rejectUnauthorized: false
};

https.createServer(options, function (req, res) {
console.log('Receive a request.');
if (req.client.authorized) {
res.writeHead(200);
res.end('approved\n');
} else {
res.writeHead(401);
res.end('denied\n');
}
}).listen(5000);
8 changes: 4 additions & 4 deletions cookies/main.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
var app = require('app');
var BrowserWindow = require('browser-window');
const {app, BrowserWindow} = require('electron');

let mainWindow;

var mainWindow = null;
app.on('ready', function() {
mainWindow = new BrowserWindow({width: 400, height: 360});
mainWindow.loadUrl('file://' + __dirname + '/manager.html');
mainWindow.loadURL('file://' + __dirname + '/manager.html');
});

28 changes: 13 additions & 15 deletions cookies/manager.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var win = require('remote').getCurrentWindow();
const ses = require('electron').remote.getCurrentWebContents().session;

// A simple Timer class.
function Timer() {
Expand Down Expand Up @@ -108,27 +108,25 @@ function removeAll() {
});
});
cache.reset();
var count = all_cookies.length;
var timer = new Timer();
for (var i = 0; i < count; i++) {
removeCookie(all_cookies[i]);
for (let cookie of all_cookies) {
removeCookie(cookie);
}
timer.reset();
win.webContents.session.cookies.get({}, function(cookies) {
for (var i in cookies) {
cache.add(cookies[i]);
removeCookie(cookies[i]);
ses.cookies.get({}, function(cookies) {
for (let cookie in cookies) {
cache.add(cookie);
removeCookie(cookie);
}
});
}

function removeCookie(cookie) {
var url = "http" + (cookie.secure ? "s" : "") + "://" + cookie.domain +
cookie.path;
win.webContents.session.cookies.remove({"url": url, "name": cookie.name},
function(error) {
if (error) throw error;
update(cookie);
ses.cookies.remove(url, cookie.name, function(error) {
if (error) throw error;
update(cookie);
});
}

Expand Down Expand Up @@ -225,12 +223,12 @@ function update(cookie) {
function onload() {
focusFilter();
var timer = new Timer();
win.webContents.session.cookies.get({}, function(error, cookies) {
ses.cookies.get({}, function(error, cookies) {
if (error) throw error;
console.log(cookies);
start = new Date();
for (var i in cookies) {
cache.add(cookies[i]);
for (let cookie of cookies) {
cache.add(cookie);
}
timer.reset();
reloadCookieTable();
Expand Down
2 changes: 1 addition & 1 deletion cookies/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name" : "cookies-demo",
"version" : "0.1.0",
"version" : "1.1.0",
"main" : "main.js"
}
7 changes: 4 additions & 3 deletions cookies/readme.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# Cookies

A sample app allows you to manipulate your cookies data using [cookies](
https://github.com/atom/electron/blob/master/docs/api/browser-window.md#sessioncookies) API.
A sample app allows you to manipulate your cookies data using [cookies][1] API.

## APIs

[Session.cookies](https://github.com/atom/electron/blob/master/docs/api/browser-window.md#sessioncookies)
[Session.cookies][1]

## Screenshot

![screenshot](/cookies/screenshot/screenshot.png)

[1]: https://github.com/electron/electron/blob/master/docs/api/session.md#sescookies
8 changes: 4 additions & 4 deletions crash-report/app.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var crashReporter = require('crash-reporter');
const {crashReporter} = require('electron');

crashReporter.start({submitUrl: 'http://127.0.0.1:9999'});
crashReporter.start({submitURL: 'http://127.0.0.1:9999', companyName: 'sample'});

function showCrashReporter(report) {
return "<tr><td>" + report.date + "</td>" +
Expand All @@ -15,8 +15,8 @@ window.onload = function() {
"</tr>\n";

var div = document.getElementById("crash_reporters");
for (var i = 0; i < reporters.length; ++i) {
table += showCrashReporter(reporters[i]);
for (let reporter of reporters) {
table += showCrashReporter(reporter);
}
div.innerHTML = table;
document.getElementById('crash').onclick = function() {
Expand Down
51 changes: 25 additions & 26 deletions crash-report/main.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
var app = require('app');
var BrowserWindow = require('browser-window');
var http = require('http');
var crashReporter = require('crash-reporter');
crashReporter.start({submitUrl: 'http://127.0.0.1:9999'});

function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min)) + min;
}

// Crash-report collection server
var server = http.createServer(function(req, res) {
// Handle the uploaded crash report from client here
// ...
// Response the crash report id on server to client.
res.end(getRandomInt(1000, 9999).toString());
});

var mainWindow = null;
app.on('ready', function() {
server.listen(9999, '127.0.0.1', function () {
mainWindow = new BrowserWindow({width: 800, height: 600});
mainWindow.loadUrl('file://' + __dirname + '/index.html');
mainWindow.toggleDevTools();
});
});
const {app, BrowserWindow, crashReporter} = require('electron');
const http = require('http');

crashReporter.start({submitURL: 'http://127.0.0.1:9999', companyName: 'sample'});

function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min)) + min;
}

// Crash-report collection server
var server = http.createServer(function(req, res) {
// Handle the uploaded crash report from client here
// ...
// Response the crash report id on server to client.
res.end(getRandomInt(1000, 9999).toString());
});

var mainWindow = null;
app.on('ready', function() {
server.listen(9999, '127.0.0.1', function () {
mainWindow = new BrowserWindow({width: 800, height: 600});
mainWindow.loadURL('file://' + __dirname + '/index.html');
mainWindow.toggleDevTools();
});
});
2 changes: 1 addition & 1 deletion crash-report/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name" : "crash-report-demo",
"version" : "0.1.0",
"version" : "1.1.0",
"main" : "main.js"
}
Loading

0 comments on commit 98c839c

Please sign in to comment.