Skip to content
This repository has been archived by the owner on Nov 15, 2018. It is now read-only.

Commit

Permalink
change to version 0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
matthinc committed May 13, 2017
1 parent 06078f9 commit cdcda23
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 76 deletions.
106 changes: 32 additions & 74 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ const os = require('os')
const storage = require('electron-json-storage')
const config = require(path.join(__dirname, '/config.js'))

var win
var browserWindow

function createWindow () {
win = new BrowserWindow({
browserWindow = new BrowserWindow({
height: config.size.height,
icon: 'assets/icon.ico',
kiosk: config.kiosk,
Expand All @@ -17,21 +17,21 @@ function createWindow () {
width: config.size.width
})

win.url = config.url
win.os = os.platform()
win.password = ''
browserWindow.url = config.url
browserWindow.os = os.platform()
browserWindow.password = ''

// Show connect-view if config.url is undefined
if (config.url) {
win.url = config.url
win.password = config.password
browserWindow.url = config.url
browserWindow.password = config.password
load('index.html')
} else {
// Try to load config from json file
storage.get('config', (err, data) => {
if (!err && data.url) {
win.url = data.url
win.password = data.password
browserWindow.url = data.url
browserWindow.password = data.password
load('index.html')
} else {
// show connect-view if config was not found in the json
Expand All @@ -40,15 +40,15 @@ function createWindow () {
})
}

win.connect = (url, password) => {
win.url = url
win.password = password
browserWindow.connect = (url, password) => {
browserWindow.url = url
browserWindow.password = password
storage.set('config', { url, password })
load('index.html')
}

win.on('closed', () => {
win = null
browserWindow.on('closed', () => {
browserWindow = null
})

if (config.menu) {
Expand All @@ -65,7 +65,7 @@ app.on('window-all-closed', () => {
})

app.on('activate', () => {
if (win === null) {
if (browserWindow === null) {
createWindow()
}
})
Expand All @@ -76,78 +76,36 @@ app.on('activate', () => {
function createMenu () {
let menuTemplate = [{
label: 'Go',
submenu: [{
label: 'States',
click: () => {
if (win.url) {
setPage('states')
}
}
},
{
label: 'History',
click: () => {
if (win.url) {
setPage('history')
}
}
},
{
label: 'Map',
click: () => {
if (win.url) {
setPage('map')
}
}
},
{
label: 'Services',
click: () => {
if (win.url) {
setPage('dev-service')
}
}
}
submenu: [
{label: 'States', click: () => setPage('states')},
{label: 'History', click: () => setPage('history')},
{label: 'Map', click: () => setPage('map')},
{label: 'Services', click: () => setPage('dev-service')}
]
},
{
label: 'Edit',
submenu: [{
role: 'copy'
},
{
role: 'selectall'
},
{
role: 'paste'
}
submenu: [
{role: 'copy'},
{role: 'selectall'},
{role: 'paste'}
]
},

{
label: 'Developer',
submenu: [{
role: 'toggledevtools'
},
{
label: 'Reset configuration',
click: () => {
storage.set('config', {})
}
}
submenu: [
{role: 'toggledevtools'},
{label: 'Reset configuration', click: () => storage.set('config', {})}
]
}
]
// Mac default menu
if (os.platform() === 'darwin') {
menuTemplate.unshift({
label: 'Home Assistant',
submenu: [{
role: 'about'
},
{
role: 'quit'
}
submenu: [
{role: 'about'},
{role: 'quit'}
]
})
}
Expand All @@ -156,13 +114,13 @@ function createMenu () {
}

function load (html) {
win.loadURL(url.format({
browserWindow.loadURL(url.format({
pathname: path.join(__dirname, 'src', html),
protocol: 'file:',
slashes: true
}))
}

function setPage (page) {
win.webContents.send('change', { page })
browserWindow.webContents.send('change', { page })
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "home_assistant_electron",
"version": "0.2.0",
"version": "0.3.0",
"description": "Create Home Assistant Electron app ==================================",
"main": "index.js",
"scripts": {
Expand Down
7 changes: 6 additions & 1 deletion src/script.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const {remote, ipcRenderer} = require('electron')
const {remote, ipcRenderer, shell} = require('electron')

window.onload = () => {
var frame = document.getElementById('content_frame')
Expand All @@ -9,6 +9,11 @@ window.onload = () => {
if (remote.getCurrentWindow().os !== 'darwin') {
titlebar.parentNode.removeChild(titlebar)
}

frame.addEventListener('new-window', (event) => {
shell.openExternal(event.url)
event.preventDefault()
})
}

ipcRenderer.on('load', (event, data) => {
Expand Down

0 comments on commit cdcda23

Please sign in to comment.