Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Initial commit for demo.
  • Loading branch information
Vj3k0 committed May 7, 2017
1 parent bb627bc commit bd9c2ce
Show file tree
Hide file tree
Showing 9 changed files with 1,134 additions and 0 deletions.
13 changes: 13 additions & 0 deletions app.html
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>Application</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<button id="btn1">Hello World</button>
<button id="btn2">Electron rocks!</button>
<script src="./app.js"></script>
</body>
</html>
13 changes: 13 additions & 0 deletions app.js
@@ -0,0 +1,13 @@
const { ipcRenderer } = require('electron');

document.addEventListener('DOMContentLoaded', () => {
setupClickHandler('btn1')
setupClickHandler('btn2')
});

function setupClickHandler(btnName) {
var btn = document.getElementById(btnName);
btn.onclick = () => {
ipcRenderer.send('show-message', btn.innerText);
}
}
12 changes: 12 additions & 0 deletions content.html
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>Content</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<div id="message"></div>
<script src="./content.js"></script>
</body>
</html>
18 changes: 18 additions & 0 deletions content.js
@@ -0,0 +1,18 @@
function findGetParameter(parameterName) {
let result = null,
tmp = [];
location.search
.substr(1)
.split('&')
.forEach(item => {
tmp = item.split('=');
if (tmp[0] === parameterName) result = decodeURIComponent(tmp[1]);
});
return result;
}

document.addEventListener('DOMContentLoaded', () => {
let msg = findGetParameter('message');
var theDiv = document.getElementById('message');
theDiv.innerHTML = 'Message received: <b>' + msg + '</b>';
});
59 changes: 59 additions & 0 deletions index.js
@@ -0,0 +1,59 @@
const {app, BrowserWindow, ipcMain} = require('electron')
const path = require('path')
const url = require('url')

// 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.
let win

function createWindow () {
// Create the browser window.
win = new BrowserWindow({width: 800, height: 600})

// and load the index.html of the app.
win.loadURL(url.format({
pathname: path.join(__dirname, 'main.html'),
protocol: 'file:',
slashes: true
}))

// Open the DevTools.
win.webContents.openDevTools()

// Emitted when the window is closed.
win.on('closed', () => {
// 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.
win = null
})
}

// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on('ready', createWindow)

// Quit when all windows are closed.
app.on('window-all-closed', () => {
// On macOS 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()
// }
})

app.on('activate', () => {
// On macOS it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (win === null) {
createWindow()
}
})

ipcMain.on('show-message', (event, msg) => {
if (win) {
win.webContents.send('show-message', msg);
}

})
17 changes: 17 additions & 0 deletions main.html
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>Main</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="node_modules/electron-tabs/electron-tabs.css">
</head>
<body>
<div class="etabs-tabgroup">
<div class="etabs-tabs"></div>
<div class="etabs-buttons"></div>
</div>
<div class="etabs-views"></div>
<script src="./main.js"></script>
</body>
</html>
61 changes: 61 additions & 0 deletions main.js
@@ -0,0 +1,61 @@
const TabGroup = require('electron-tabs');
const dragula = require('dragula');

let tabGroup = new TabGroup({
newTab: {
title: 'Search',
icon: 'fa fa-search'
},
closeButtonText: '&#x2715;',
ready: tabGroup => {
dragula([tabGroup.tabContainer], {
direction: 'horizontal'
});
}
});

let tab = tabGroup.addTab({
title: 'Home',
src: './app.html',
webviewAttributes: {
'nodeintegration': true
},
icon: 'fa fa-home',
visible: true,
closable: false,
active: true,
ready: tab => {
// Open dev tools for webview
let webview = tab.webview;
if (!!webview) {
webview.addEventListener('dom-ready', () => {
webview.openDevTools();
})
}
}
});

const { ipcRenderer } = require('electron');

ipcRenderer.on('show-message', (event, msg) => {

let tab = tabGroup.addTab({
title: `Title: ${msg}`,
src: `./content.html?message=${msg}`,
webviewAttributes: {
'nodeintegration': true
},
icon: 'fa fa-comment',
visible: true,
active: true,
ready: tab => {
// Open dev tools for webview
let webview = tab.webview;
if (!!webview) {
webview.addEventListener('dom-ready', () => {
webview.openDevTools();
})
}
}
});
})
25 changes: 25 additions & 0 deletions package.json
@@ -0,0 +1,25 @@
{
"name": "electron-tabs",
"version": "1.0.0",
"description": "",
"main": "index.js",
"dependencies": {
"dragula": "^3.7.2",
"electron": "^1.6.6",
"electron-tabs": "^0.6.0"
},
"devDependencies": {},
"scripts": {
"start": "electron ."
},
"repository": {
"type": "git",
"url": "git+https://github.com/Vj3k0/electron-tabs.git"
},
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/Vj3k0/electron-tabs/issues"
},
"homepage": "https://github.com/Vj3k0/electron-tabs#readme"
}

0 comments on commit bd9c2ce

Please sign in to comment.