Skip to content

Commit

Permalink
port
Browse files Browse the repository at this point in the history
  • Loading branch information
donavanbecker committed Jan 22, 2024
1 parent e74dbf6 commit ba4e1ca
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 24 deletions.
45 changes: 24 additions & 21 deletions src/homebridge-ui/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@
Support
</button>
</div>
<div id="disabledBanner" class="alert alert-secondary mb-0 mt-3" role="alert" style="display: none;">
Plugin is currently disabled
<button id="disabledEnable" type="button" class="btn btn-link p-0 m-0 float-right">
Enable
</button>
</div>
<div id="pageAccount" class="mt-4" style="display: none;">
<div class="alert alert-warning" style="display: none;" id="validateForm">
Please enter both values
Expand All @@ -63,10 +69,6 @@
<label for="inputConsumerSecret">Consumer Secret <span class="text-danger">*</span></label>
<input type="text" class="form-control" id="inputConsumerSecret">
</div>
<div class="form-group">
<label for="inputPort">Port <span class="text-danger">*</span></label>
<input type="text" class="form-control" id="inputPort">
</div>
<div class="form-group text-center">
<button type="button" class="btn btn-primary" id="backToIntro">&larr;</button>
<button type="button" class="btn btn-primary" id="linkButton">Continue &rarr;</button>
Expand Down Expand Up @@ -170,11 +172,6 @@ <h5>Disclaimer</h5>
try {
const currentConfig = await homebridge.getPluginConfig()
const hostname = window.location.hostname
let port = '8585'
if (currentConfig[0].port) {
document.getElementById('inputPort').value = currentConfig[0].port
port = currentConfig[0].port
}
try {
await homebridge.request('Start Resideo Login Server')
} catch (err) {
Expand All @@ -191,9 +188,6 @@ <h5>Disclaimer</h5>
accessToken: event.data.access,
refreshToken: event.data.refresh
}
currentConfig[0] = {
port: event.data.port
}
await homebridge.updatePluginConfig(currentConfig)
await homebridge.savePluginConfig()
homebridge.toast.success("Successfully Linked Resideo Account", "homebridge-resideo")
Expand All @@ -218,8 +212,7 @@ <h5>Disclaimer</h5>
document.getElementById('validateForm').style.display = 'none'
if (
!document.getElementById('inputConsumerKey').value ||
!document.getElementById('inputConsumerSecret').value ||
!document.getElementById('inputPort').value
!document.getElementById('inputConsumerSecret').value
) {
document.getElementById('validateForm').style.display = 'block'
return
Expand All @@ -228,7 +221,7 @@ <h5>Disclaimer</h5>
const h = 700;
const y = window.top.outerHeight / 2 + window.top.screenY - (h / 2);
const x = window.top.outerWidth / 2 + window.top.screenX - (w / 2);
const urlToOpen = 'http://' + hostname + `:${port}/start?` +
const urlToOpen = 'http://' + hostname + ':8585/start?' +
'key=' + document.getElementById('inputConsumerKey').value +
'&secret=' + document.getElementById('inputConsumerSecret').value +
'&host=' + encodeURI(hostname);
Expand Down Expand Up @@ -261,7 +254,7 @@ <h5>Disclaimer</h5>
}
showIntro = () => {
const introLink = document.getElementById('introLink')
document.getElementById('copyMe').value = 'http://' + hostname + `:${port}/auth`
document.getElementById('copyMe').value = 'http://' + hostname + ':8585/auth'
introLink.addEventListener('click', () => {
homebridge.showSpinner()
document.getElementById('pageIntro').style.display = 'none'
Expand Down Expand Up @@ -396,13 +389,8 @@ <h5>Disclaimer</h5>
if (currentConfig[0] && currentConfig[0].credentials) {
const key = currentConfig[0].credentials.consumerKey || ''
const secret = currentConfig[0].credentials.consumerSecret || ''
let port = '8585'
if (currentConfig[0].port) {
port = currentConfig[0].port
}
document.getElementById('inputConsumerKey').value = key
document.getElementById('inputConsumerSecret').value = secret
document.getElementById('inputPort').value = port
if (key && secret) {
isRelink = true
document.getElementById('unLinkButton').style.display = 'inline-block'
Expand All @@ -418,13 +406,28 @@ <h5>Disclaimer</h5>
}
homebridge.hideSpinner()
}
showDisabledBanner = () => {
document.getElementById('disabledBanner').style.display = 'block'
}
enablePlugin = async () => {
homebridge.showSpinner()
document.getElementById('disabledBanner').style.display = 'none'
currentConfig[0].disablePlugin = false
await homebridge.updatePluginConfig(currentConfig)
await homebridge.savePluginConfig()
homebridge.hideSpinner()
}
menuHome.addEventListener('click', () => showSupport())
menuAccount.addEventListener('click', () => showAccount())
menuDevices.addEventListener('click', () => showDevices())
menuSettings.addEventListener('click', () => showSettings())
disabledEnable.addEventListener('click', () => enablePlugin())
if (currentConfig.length) {
document.getElementById('menuWrapper').style.display = 'inline-flex'
showAccount()
if (currentConfig[0].disablePlugin) {
showDisabledBanner()
}
} else {
currentConfig.push({ name: 'Resideo' })
await homebridge.updatePluginConfig(currentConfig)
Expand Down
4 changes: 1 addition & 3 deletions src/homebridge-ui/server.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
/* eslint-disable no-console */
import { HomebridgePluginUiServer } from '@homebridge/plugin-ui-utils';
import { AuthorizeURL, ResideoPlatformConfig, TokenURL } from '../settings.js';
import { AuthorizeURL, TokenURL } from '../settings.js';
import { request } from 'undici';
import { createServer } from 'http';
import fs from 'fs';
import url from 'node:url';

class PluginUiServer extends HomebridgePluginUiServer {
public readonly config!: ResideoPlatformConfig;
public port!: string;
public key!: string;
public secret!: string;
Expand All @@ -16,7 +15,6 @@ class PluginUiServer extends HomebridgePluginUiServer {
constructor(
) {
super();
//const port = this.port || '8585';

this.onRequest('Start Resideo Login Server', (): any => {

Expand Down

0 comments on commit ba4e1ca

Please sign in to comment.