Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Initial commit for demo.
- Loading branch information
Showing
9 changed files
with
1,134 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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>'; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
|
||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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: '✕', | ||
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(); | ||
}) | ||
} | ||
} | ||
}); | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
} |
Oops, something went wrong.