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

Commit

Permalink
Add support for Configurator addon
Browse files Browse the repository at this point in the history
  • Loading branch information
matthinc committed May 17, 2018
1 parent 2052820 commit 5cebc3e
Show file tree
Hide file tree
Showing 8 changed files with 192 additions and 137 deletions.
36 changes: 22 additions & 14 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,43 +18,42 @@ function createWindow () {
width: 800
})


browserWindow.os = os.platform()
browserWindow.settings = settings

loadHomeAssistantOrLoginPage()

//Change window dimensions if provided
// Change window dimensions if provided
if (settings.hasDimensions()) {
browserWindow.setContentSize(settings.width(), settings.height(), false)
}

//Change window position if provided
// Change window position if provided
if (settings.hasPosition()) {
browserWindow.setPosition(settings.xpos(), settings.ypos())
}

createMenu()

//Connect to home assistant
// Connect to home assistant
browserWindow.connect = (url, password) => {
browserWindow.url = url
browserWindow.password = password
settings.setUrlAndPassword(url, password)
loadHomeAssistantOrLoginPage()
}

//Save settings and reconnect to home assistant
// Save settings and reconnect to home assistant
browserWindow.reload = () => {
loadHomeAssistantOrLoginPage()
}

//Notifiy UI that the theme color has changed
// Notifiy UI that the theme color has changed
browserWindow.setColor = (color) => {
browserWindow.webContents.send('colorChange', {color})
}

//Reset EVERYTHING
// Reset EVERYTHING
browserWindow.reset = () => {
settings.deleteAll()
app.quit()
Expand All @@ -66,7 +65,7 @@ function createWindow () {
browserWindow = null
})

//Save window bounds on close
// Save window bounds on close
browserWindow.on('close', () => {
settings.saveWindowBounds(browserWindow.getPosition()[0], browserWindow.getPosition()[1],
browserWindow.getBounds().width, browserWindow.getBounds().height)
Expand All @@ -75,7 +74,7 @@ function createWindow () {

app.on('ready', createWindow)

//Just OSX-Stuff
// Just OSX-Stuff
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit()
Expand All @@ -88,6 +87,15 @@ app.on('activate', () => {
}
})

/**
* Fake basic-auth
*/
app.on('login', function (event, webContents, request, authInfo, callback) {
event.preventDefault()
let credentials = settings.configuratorCredentials()
callback(credentials.username, credentials.password)
})

/**
* Create the application menu
*/
Expand All @@ -96,7 +104,7 @@ function createMenu () {
Menu.setApplicationMenu(menu)
}

//Load a HTML page
// Load a HTML page
function load (html) {
browserWindow.loadURL(url.format({
pathname: path.join(__dirname, 'src', html),
Expand All @@ -105,13 +113,13 @@ function load (html) {
}))
}

//Switch HomeAssistant page (eg. State)
// Switch HomeAssistant page (eg. State)
function setPage (page) {
browserWindow.webContents.send('change', { page })
}

//Load HomeAssistant or configuration view
function loadHomeAssistantOrLoginPage() {
// Load HomeAssistant or configuration view
function loadHomeAssistantOrLoginPage () {
if (settings.kiosk()) {
browserWindow.setFullScreen(true)
}
Expand All @@ -123,4 +131,4 @@ function loadHomeAssistantOrLoginPage() {
} else {
load('connect.html')
}
}
}
40 changes: 20 additions & 20 deletions menu.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
module.exports = function (browserWindow, darwin, load, setPage) {
var menu = [{
label: 'Go',
submenu: [
module.exports = function (browserWindow, darwin, load, setPage) {
var menu = [{
label: 'Go',
submenu: [
{ label: 'States', accelerator: 'Cmd+1', click: () => setPage('states') },
{ label: 'History', accelerator: 'Cmd+2', click: () => setPage('history') },
{ label: 'Map', accelerator: 'Cmd+3', click: () => setPage('map') },
{ label: 'Configuration', accelerator: 'Cmd+4', click: () => setPage('config') },
{ label: 'Services', accelerator: 'Cmd+5', click: () => setPage('dev-service') },
{ type: 'separator' },
{ label: 'Preferences...', click: () => load('settings.html') }
]
}, {
label: 'Edit',
submenu: [{ role: 'copy' }, { role: 'selectall' }, { role: 'paste' }]
}, {
label: 'Developer',
submenu: [
]
}, {
label: 'Edit',
submenu: [{ role: 'copy' }, { role: 'selectall' }, { role: 'paste' }]
}, {
label: 'Developer',
submenu: [
{ role: 'toggledevtools' },
{ label: 'Reload', accelerator: 'Cmd+Shift+R', click: () => browserWindow.webContents.send('reload', {}) }]
}]
}]
// Mac default menu
if (darwin) {
menu.unshift({
label: 'Home Assistant',
submenu: [
if (darwin) {
menu.unshift({
label: 'Home Assistant',
submenu: [
{ role: 'about' },
{ role: 'quit' }]
})
}
})
}

return menu
}
return menu
}
20 changes: 20 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 5cebc3e

Please sign in to comment.