From 48a1dc84e9b4754b8ed16630be3e747381811560 Mon Sep 17 00:00:00 2001 From: Donavan Becker Date: Tue, 30 Jan 2024 23:32:50 -0600 Subject: [PATCH] v1.0.1 (#2) ## [1.0.1](https://github.com/donavanbecker/homebridge-cloudflared-tunnel/compare/v1.0.0...v1.0.1) (2024-01-31) ### What's Changes - Housekeeping and updated dependencies. **Full Changelog**: https://github.com/donavanbecker/homebridge-cloudflared-tunnel/compare/v1.0.0...v1.0.1 --- .github/workflows/release-drafter.yml | 3 +- CHANGELOG.md | 8 + LICENSE | 2 +- README.md | 2 + config.schema.json | 1 + homebridge-ui/server.cjs | 51 ------ package-lock.json | 145 +++++++++--------- package.json | 17 +- .../homebridge-ui}/public/index.html | 0 src/homebridge-ui/server.ts | 48 ++++++ src/platform.ts | 6 +- 11 files changed, 149 insertions(+), 134 deletions(-) delete mode 100644 homebridge-ui/server.cjs rename {homebridge-ui => src/homebridge-ui}/public/index.html (100%) create mode 100644 src/homebridge-ui/server.ts diff --git a/.github/workflows/release-drafter.yml b/.github/workflows/release-drafter.yml index de43b12..e521f3a 100644 --- a/.github/workflows/release-drafter.yml +++ b/.github/workflows/release-drafter.yml @@ -4,7 +4,8 @@ on: push: branches: [latest] pull_request: # required for autolabeler - types: [opened, reopened, synchronize] + branches: [latest] + types: [opened, reopened, synchronize, ready_for_review, review_requested] workflow_dispatch: jobs: diff --git a/CHANGELOG.md b/CHANGELOG.md index 873d173..9a7506f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,14 @@ All notable changes to this project will be documented in this file. This project uses [Semantic Versioning](https://semver.org/) +## [1.0.1](https://github.com/donavanbecker/homebridge-cloudflared-tunnel/compare/v1.0.0...v1.0.1) (2024-01-31) + +### What's Changes + +- Housekeeping and updated dependencies. + +**Full Changelog**: https://github.com/donavanbecker/homebridge-cloudflared-tunnel/compare/v1.0.0...v1.0.1 + ## [1.0.0](https://github.com/donavanbecker/homebridge-cloudflared-tunnel/compare/v0.1.0...v1.0.0) (2024-01-12) ### What's Changes diff --git a/LICENSE b/LICENSE index a3774e0..d483b33 100644 --- a/LICENSE +++ b/LICENSE @@ -1,5 +1,5 @@ ISC License (ISC) -Copyright (c) 2023 donavanbecker +Copyright (c) 2023-2024 donavanbecker Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above diff --git a/README.md b/README.md index 2174f7b..49cd1de 100644 --- a/README.md +++ b/README.md @@ -20,5 +20,7 @@ plugin allows you to run a Cloudflare-Tunnel for exposing your 1. Search for "Cloudflared Tunnel" on the plugin screen of [Homebridge UI](https://github.com/homebridge/homebridge-config-ui-x). 2. Click **Install**. +3. Set Auto Install of Cloudflared Tunnel in Plugin Configs. +4. Restart Plugin and Cloudlfare URL will be displayed in logs. diff --git a/config.schema.json b/config.schema.json index b79d863..ede3953 100644 --- a/config.schema.json +++ b/config.schema.json @@ -3,6 +3,7 @@ "pluginType": "platform", "singular": true, "customUi": true, + "customUiPath": "./dist/homebridge-ui", "headerDisplay": "

\n\n

The Homebridge Cloudflared Tunnel plugin allows you to run a Cloudflare-Tunnel for exposing your Homebridge instance for remote access.", "footerDisplay": "Your CloudflaredTunnel has been created. Please raise any issues on our [project page](https://github.com/donavanbecker/homebridge-cloudflared-tunnel/issues).\n\nIf you would like to have other features, fill out [Feature Request Form](https://github.com/donavanbecker/homebridge-cloudflared-tunnel/issues/new?assignees=&labels=&template=feature_request.md).", "schema": { diff --git a/homebridge-ui/server.cjs b/homebridge-ui/server.cjs deleted file mode 100644 index 1148857..0000000 --- a/homebridge-ui/server.cjs +++ /dev/null @@ -1,51 +0,0 @@ -/* eslint-disable no-console */ -/* eslint-disable no-undef */ -/* eslint-disable @typescript-eslint/no-var-requires */ -/* jshint node: true,esversion: 9, -W014, -W033 */ -/* eslint-disable new-cap */ -'use strict'; - -const { HomebridgePluginUiServer } = require('@homebridge/plugin-ui-utils'); -const fs = require('fs'); - -class PluginUiServer extends HomebridgePluginUiServer { - constructor() { - super(); - /* - A native method getCachedAccessories() was introduced in config-ui-x v4.37.0 - The following is for users who have a lower version of config-ui-x - */ - - this.onRequest('/getCachedAccessories', async () => { - try { - // Define the plugin and create the array to return - const plugin = 'homebridge-cloudflared-tunnel'; - const devicesToReturn = []; - - // The path and file of the cached accessories - const accFile = this.homebridgeStoragePath + '/accessories/cachedAccessories'; - - // Check the file exists - if (fs.existsSync(accFile)) { - // Read the cached accessories file - let cachedAccessories = await fs.promises.readFile(accFile); - - // Parse the JSON - cachedAccessories = JSON.parse(cachedAccessories); - - // We only want the accessories for this plugin - cachedAccessories.filter((accessory) => accessory.plugin === plugin).forEach((accessory) => devicesToReturn.push(accessory)); - } - - // Return the array - return devicesToReturn; - } catch (err) { - // Just return an empty accessory list in case of any errors - return []; - } - }); - this.ready(); - } -} - -(() => new PluginUiServer())(); diff --git a/package-lock.json b/package-lock.json index e506136..2a34c58 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "homebridge-cloudflared-tunnel", - "version": "1.0.0", + "version": "1.0.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "homebridge-cloudflared-tunnel", - "version": "1.0.0", + "version": "1.0.1", "funding": [ { "type": "Paypal", @@ -23,13 +23,13 @@ "untun": "^0.1.3" }, "devDependencies": { - "@types/node": "^20.11.0", - "@typescript-eslint/eslint-plugin": "^6.18.1", - "@typescript-eslint/parser": "^6.18.1", + "@types/node": "^20.11.13", + "@typescript-eslint/eslint-plugin": "^6.20.0", + "@typescript-eslint/parser": "^6.20.0", "eslint": "^8.56.0", "homebridge": "^1.7.0", - "nodemon": "^3.0.2", - "npm-check-updates": "^16.14.12", + "nodemon": "^3.0.3", + "npm-check-updates": "^16.14.14", "rimraf": "^5.0.5", "ts-node": "^10.9.2", "typescript": "^5.3.3" @@ -801,9 +801,9 @@ "dev": true }, "node_modules/@types/node": { - "version": "20.11.0", - "resolved": "https://registry.npmjs.org/@types/node/-/node-20.11.0.tgz", - "integrity": "sha512-o9bjXmDNcF7GbM4CNQpmi+TutCgap/K3w1JyKgxAjqx41zp9qlIAVFi0IhCNsJcXolEqLWhbFbEeL0PvYm4pcQ==", + "version": "20.11.13", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.11.13.tgz", + "integrity": "sha512-5G4zQwdiQBSWYTDAH1ctw2eidqdhMJaNsiIDKHFr55ihz5Trl2qqR8fdrT732yPBho5gkNxXm67OxWFBqX9aPg==", "dev": true, "dependencies": { "undici-types": "~5.26.4" @@ -816,16 +816,16 @@ "dev": true }, "node_modules/@typescript-eslint/eslint-plugin": { - "version": "6.18.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-6.18.1.tgz", - "integrity": "sha512-nISDRYnnIpk7VCFrGcu1rnZfM1Dh9LRHnfgdkjcbi/l7g16VYRri3TjXi9Ir4lOZSw5N/gnV/3H7jIPQ8Q4daA==", + "version": "6.20.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-6.20.0.tgz", + "integrity": "sha512-fTwGQUnjhoYHeSF6m5pWNkzmDDdsKELYrOBxhjMrofPqCkoC2k3B2wvGHFxa1CTIqkEn88nlW1HVMztjo2K8Hg==", "dev": true, "dependencies": { "@eslint-community/regexpp": "^4.5.1", - "@typescript-eslint/scope-manager": "6.18.1", - "@typescript-eslint/type-utils": "6.18.1", - "@typescript-eslint/utils": "6.18.1", - "@typescript-eslint/visitor-keys": "6.18.1", + "@typescript-eslint/scope-manager": "6.20.0", + "@typescript-eslint/type-utils": "6.20.0", + "@typescript-eslint/utils": "6.20.0", + "@typescript-eslint/visitor-keys": "6.20.0", "debug": "^4.3.4", "graphemer": "^1.4.0", "ignore": "^5.2.4", @@ -851,15 +851,15 @@ } }, "node_modules/@typescript-eslint/parser": { - "version": "6.18.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-6.18.1.tgz", - "integrity": "sha512-zct/MdJnVaRRNy9e84XnVtRv9Vf91/qqe+hZJtKanjojud4wAVy/7lXxJmMyX6X6J+xc6c//YEWvpeif8cAhWA==", + "version": "6.20.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-6.20.0.tgz", + "integrity": "sha512-bYerPDF/H5v6V76MdMYhjwmwgMA+jlPVqjSDq2cRqMi8bP5sR3Z+RLOiOMad3nsnmDVmn2gAFCyNgh/dIrfP/w==", "dev": true, "dependencies": { - "@typescript-eslint/scope-manager": "6.18.1", - "@typescript-eslint/types": "6.18.1", - "@typescript-eslint/typescript-estree": "6.18.1", - "@typescript-eslint/visitor-keys": "6.18.1", + "@typescript-eslint/scope-manager": "6.20.0", + "@typescript-eslint/types": "6.20.0", + "@typescript-eslint/typescript-estree": "6.20.0", + "@typescript-eslint/visitor-keys": "6.20.0", "debug": "^4.3.4" }, "engines": { @@ -879,13 +879,13 @@ } }, "node_modules/@typescript-eslint/scope-manager": { - "version": "6.18.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-6.18.1.tgz", - "integrity": "sha512-BgdBwXPFmZzaZUuw6wKiHKIovms97a7eTImjkXCZE04TGHysG+0hDQPmygyvgtkoB/aOQwSM/nWv3LzrOIQOBw==", + "version": "6.20.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-6.20.0.tgz", + "integrity": "sha512-p4rvHQRDTI1tGGMDFQm+GtxP1ZHyAh64WANVoyEcNMpaTFn3ox/3CcgtIlELnRfKzSs/DwYlDccJEtr3O6qBvA==", "dev": true, "dependencies": { - "@typescript-eslint/types": "6.18.1", - "@typescript-eslint/visitor-keys": "6.18.1" + "@typescript-eslint/types": "6.20.0", + "@typescript-eslint/visitor-keys": "6.20.0" }, "engines": { "node": "^16.0.0 || >=18.0.0" @@ -896,13 +896,13 @@ } }, "node_modules/@typescript-eslint/type-utils": { - "version": "6.18.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-6.18.1.tgz", - "integrity": "sha512-wyOSKhuzHeU/5pcRDP2G2Ndci+4g653V43gXTpt4nbyoIOAASkGDA9JIAgbQCdCkcr1MvpSYWzxTz0olCn8+/Q==", + "version": "6.20.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-6.20.0.tgz", + "integrity": "sha512-qnSobiJQb1F5JjN0YDRPHruQTrX7ICsmltXhkV536mp4idGAYrIyr47zF/JmkJtEcAVnIz4gUYJ7gOZa6SmN4g==", "dev": true, "dependencies": { - "@typescript-eslint/typescript-estree": "6.18.1", - "@typescript-eslint/utils": "6.18.1", + "@typescript-eslint/typescript-estree": "6.20.0", + "@typescript-eslint/utils": "6.20.0", "debug": "^4.3.4", "ts-api-utils": "^1.0.1" }, @@ -923,9 +923,9 @@ } }, "node_modules/@typescript-eslint/types": { - "version": "6.18.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-6.18.1.tgz", - "integrity": "sha512-4TuMAe+tc5oA7wwfqMtB0Y5OrREPF1GeJBAjqwgZh1lEMH5PJQgWgHGfYufVB51LtjD+peZylmeyxUXPfENLCw==", + "version": "6.20.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-6.20.0.tgz", + "integrity": "sha512-MM9mfZMAhiN4cOEcUOEx+0HmuaW3WBfukBZPCfwSqFnQy0grXYtngKCqpQN339X3RrwtzspWJrpbrupKYUSBXQ==", "dev": true, "engines": { "node": "^16.0.0 || >=18.0.0" @@ -936,13 +936,13 @@ } }, "node_modules/@typescript-eslint/typescript-estree": { - "version": "6.18.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-6.18.1.tgz", - "integrity": "sha512-fv9B94UAhywPRhUeeV/v+3SBDvcPiLxRZJw/xZeeGgRLQZ6rLMG+8krrJUyIf6s1ecWTzlsbp0rlw7n9sjufHA==", + "version": "6.20.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-6.20.0.tgz", + "integrity": "sha512-RnRya9q5m6YYSpBN7IzKu9FmLcYtErkDkc8/dKv81I9QiLLtVBHrjz+Ev/crAqgMNW2FCsoZF4g2QUylMnJz+g==", "dev": true, "dependencies": { - "@typescript-eslint/types": "6.18.1", - "@typescript-eslint/visitor-keys": "6.18.1", + "@typescript-eslint/types": "6.20.0", + "@typescript-eslint/visitor-keys": "6.20.0", "debug": "^4.3.4", "globby": "^11.1.0", "is-glob": "^4.0.3", @@ -964,17 +964,17 @@ } }, "node_modules/@typescript-eslint/utils": { - "version": "6.18.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-6.18.1.tgz", - "integrity": "sha512-zZmTuVZvD1wpoceHvoQpOiewmWu3uP9FuTWo8vqpy2ffsmfCE8mklRPi+vmnIYAIk9t/4kOThri2QCDgor+OpQ==", + "version": "6.20.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-6.20.0.tgz", + "integrity": "sha512-/EKuw+kRu2vAqCoDwDCBtDRU6CTKbUmwwI7SH7AashZ+W+7o8eiyy6V2cdOqN49KsTcASWsC5QeghYuRDTyOOg==", "dev": true, "dependencies": { "@eslint-community/eslint-utils": "^4.4.0", "@types/json-schema": "^7.0.12", "@types/semver": "^7.5.0", - "@typescript-eslint/scope-manager": "6.18.1", - "@typescript-eslint/types": "6.18.1", - "@typescript-eslint/typescript-estree": "6.18.1", + "@typescript-eslint/scope-manager": "6.20.0", + "@typescript-eslint/types": "6.20.0", + "@typescript-eslint/typescript-estree": "6.20.0", "semver": "^7.5.4" }, "engines": { @@ -989,12 +989,12 @@ } }, "node_modules/@typescript-eslint/visitor-keys": { - "version": "6.18.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-6.18.1.tgz", - "integrity": "sha512-/kvt0C5lRqGoCfsbmm7/CwMqoSkY3zzHLIjdhHZQW3VFrnz7ATecOHR7nb7V+xn4286MBxfnQfQhAmCI0u+bJA==", + "version": "6.20.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-6.20.0.tgz", + "integrity": "sha512-E8Cp98kRe4gKHjJD4NExXKz/zOJ1A2hhZc+IMVD6i7w4yjIvh6VyuRI0gRtxAsXtoC35uGMaQ9rjI2zJaXDEAw==", "dev": true, "dependencies": { - "@typescript-eslint/types": "6.18.1", + "@typescript-eslint/types": "6.20.0", "eslint-visitor-keys": "^3.4.1" }, "engines": { @@ -2263,9 +2263,9 @@ } }, "node_modules/fastq": { - "version": "1.16.0", - "resolved": "https://registry.npmjs.org/fastq/-/fastq-1.16.0.tgz", - "integrity": "sha512-ifCoaXsDrsdkWTtiNJX5uzHDsrck5TzfKKDcuFFTIrrc/BS076qgEIfoIy1VeZqViznfKiysPYTh/QeHtnIsYA==", + "version": "1.17.0", + "resolved": "https://registry.npmjs.org/fastq/-/fastq-1.17.0.tgz", + "integrity": "sha512-zGygtijUMT7jnk3h26kUms3BkSDp4IfIKjmnqI2tvx6nuBfiF1UqOxbnLfzdv+apBy+53oaImsKtMw/xYbW+1w==", "dev": true, "dependencies": { "reusify": "^1.0.4" @@ -4265,9 +4265,9 @@ } }, "node_modules/nodemon": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/nodemon/-/nodemon-3.0.2.tgz", - "integrity": "sha512-9qIN2LNTrEzpOPBaWHTm4Asy1LxXLSickZStAQ4IZe7zsoIpD/A7LWxhZV3t4Zu352uBcqVnRsDXSMR2Sc3lTA==", + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/nodemon/-/nodemon-3.0.3.tgz", + "integrity": "sha512-7jH/NXbFPxVaMwmBCC2B9F/V6X1VkEdNgx3iu9jji8WxWcvhMWkmhNWhI5077zknOnZnBzba9hZP6bCPJLSReQ==", "dev": true, "dependencies": { "chokidar": "^3.5.2", @@ -4411,9 +4411,9 @@ } }, "node_modules/npm-check-updates": { - "version": "16.14.12", - "resolved": "https://registry.npmjs.org/npm-check-updates/-/npm-check-updates-16.14.12.tgz", - "integrity": "sha512-5FvqaDX8AqWWTDQFbBllgLwoRXTvzlqVIRSKl9Kg8bYZTfNwMnrp1Zlmb5e/ocf11UjPTc+ShBFjYQ7kg6FL0w==", + "version": "16.14.14", + "resolved": "https://registry.npmjs.org/npm-check-updates/-/npm-check-updates-16.14.14.tgz", + "integrity": "sha512-Y3ajS/Ep40jM489rLBdz9jehn/BMil5s9fA4PSr2ZJxxSmtLWCSmRqsI2IEZ9Nb3MTMu8a3s7kBs0l+JbjdkTA==", "dev": true, "dependencies": { "chalk": "^5.3.0", @@ -4875,9 +4875,9 @@ } }, "node_modules/path-scurry/node_modules/lru-cache": { - "version": "10.1.0", - "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-10.1.0.tgz", - "integrity": "sha512-/1clY/ui8CzjKFyjdvwPWJUYKiFVXG2I2cY0ssG7h4+hwk+XOIX7ZSG9Q7TW8TW3Kp3BUSqgFWBLgL4PJ+Blag==", + "version": "10.2.0", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-10.2.0.tgz", + "integrity": "sha512-2bIM8x+VAf6JT4bKAljS1qUWgMsqZRPGJS6FSahIMPVvctcNhyVp7AJu7quxOW9jwkryBReKZY5tY5JYv2n/7Q==", "dev": true, "engines": { "node": "14 || >=16.14" @@ -5400,15 +5400,16 @@ "dev": true }, "node_modules/set-function-length": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/set-function-length/-/set-function-length-1.1.1.tgz", - "integrity": "sha512-VoaqjbBJKiWtg4yRcKBQ7g7wnGnLV3M8oLvVWwOk2PdYY6PEFegR1vezXR0tw6fZGF9csVakIRjrJiy2veSBFQ==", + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/set-function-length/-/set-function-length-1.2.0.tgz", + "integrity": "sha512-4DBHDoyHlM1IRPGYcoxexgh67y4ueR53FKV1yyxwFMY7aCqcN/38M1+SwZ/qJQ8iLv7+ck385ot4CcisOAPT9w==", "dev": true, "dependencies": { "define-data-property": "^1.1.1", - "get-intrinsic": "^1.2.1", + "function-bind": "^1.1.2", + "get-intrinsic": "^1.2.2", "gopd": "^1.0.1", - "has-property-descriptors": "^1.0.0" + "has-property-descriptors": "^1.0.1" }, "engines": { "node": ">= 0.4" @@ -5607,9 +5608,9 @@ } }, "node_modules/spdx-exceptions": { - "version": "2.3.0", - "resolved": "https://registry.npmjs.org/spdx-exceptions/-/spdx-exceptions-2.3.0.tgz", - "integrity": "sha512-/tTrYOC7PPI1nUAgx34hUpqXuyJG+DTHJTnIULG4rDygi4xu/tfgmq1e1cIRwRzwZgo4NLySi+ricLkZkw4i5A==", + "version": "2.4.0", + "resolved": "https://registry.npmjs.org/spdx-exceptions/-/spdx-exceptions-2.4.0.tgz", + "integrity": "sha512-hcjppoJ68fhxA/cjbN4T8N6uCUejN8yFw69ttpqtBeCbF3u13n7mb31NB9jKwGTTWWnt9IbRA/mf1FprYS8wfw==", "dev": true }, "node_modules/spdx-expression-parse": { diff --git a/package.json b/package.json index 9eb1582..b7b8bce 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "displayName": "Cloudflared Tunnel", "name": "homebridge-cloudflared-tunnel", - "version": "1.0.0", + "version": "1.0.1", "description": "The Cloudflared Tunnel plugin allows you to run a Cloudflare-Tunnel for exposing your homebridge instance for remote access.", "author": { "name": "donavanbecker", @@ -28,9 +28,10 @@ "update dependencies": "npm run check && npm run update", "lint": "eslint src/**.ts", "jlint": "eslint homebridge-ui/public/**.mjs", - "watch": "npm run build && npm link && nodemon", + "watch": "npm run build && npm run plugin-ui && npm link && nodemon", + "plugin-ui": "rsync ./src/homebridge-ui/public/index.html ./dist/homebridge-ui/public/", "build": "rimraf ./dist && tsc", - "prepublishOnly": "npm run lint && npm run build", + "prepublishOnly": "npm run lint && npm run build && npm run plugin-ui ", "postpublish": "npm run clean", "clean": "rimraf ./dist", "test": "eslint src/**.ts" @@ -56,13 +57,13 @@ "untun": "^0.1.3" }, "devDependencies": { - "@types/node": "^20.11.0", - "@typescript-eslint/eslint-plugin": "^6.18.1", - "@typescript-eslint/parser": "^6.18.1", + "@types/node": "^20.11.13", + "@typescript-eslint/eslint-plugin": "^6.20.0", + "@typescript-eslint/parser": "^6.20.0", "eslint": "^8.56.0", "homebridge": "^1.7.0", - "nodemon": "^3.0.2", - "npm-check-updates": "^16.14.12", + "nodemon": "^3.0.3", + "npm-check-updates": "^16.14.14", "rimraf": "^5.0.5", "ts-node": "^10.9.2", "typescript": "^5.3.3" diff --git a/homebridge-ui/public/index.html b/src/homebridge-ui/public/index.html similarity index 100% rename from homebridge-ui/public/index.html rename to src/homebridge-ui/public/index.html diff --git a/src/homebridge-ui/server.ts b/src/homebridge-ui/server.ts new file mode 100644 index 0000000..2a10616 --- /dev/null +++ b/src/homebridge-ui/server.ts @@ -0,0 +1,48 @@ +/* eslint-disable no-console */ +import { HomebridgePluginUiServer } from '@homebridge/plugin-ui-utils'; +import fs from 'fs'; + +class PluginUiServer extends HomebridgePluginUiServer { + constructor() { + super(); + /* + A native method getCachedAccessories() was introduced in config-ui-x v4.37.0 + The following is for users who have a lower version of config-ui-x + */ + this.onRequest('getCachedAccessories', () => { + try { + const plugin = 'homebridge-cloudflared-tunnel'; + const devicesToReturn = []; + + // The path and file of the cached accessories + const accFile = this.homebridgeStoragePath + '/accessories/cachedAccessories'; + + // Check the file exists + if (fs.existsSync(accFile)) { + // read the cached accessories file + const cachedAccessories: any[] = JSON.parse(fs.readFileSync(accFile, 'utf8')); + + cachedAccessories.forEach((accessory: any) => { + // Check the accessory is from this plugin + if (accessory.plugin === plugin) { + // Add the cached accessory to the array + devicesToReturn.push(accessory.accessory as never); + } + }); + } + // Return the array + return devicesToReturn; + } catch (err) { + // Just return an empty accessory list in case of any errors + return []; + } + }); + this.ready(); + } +} + +function startPluginUiServer(): PluginUiServer { + return new PluginUiServer(); +} + +startPluginUiServer(); \ No newline at end of file diff --git a/src/platform.ts b/src/platform.ts index b7a1bb4..726bd74 100644 --- a/src/platform.ts +++ b/src/platform.ts @@ -22,7 +22,11 @@ export class CloudflaredTunnelPlatform implements DynamicPlatformPlugin { platformLogging?: string; config!: CloudflaredTunnelPlatformConfig; - constructor(log: Logging, config: CloudflaredTunnelPlatformConfig, api: API) { + constructor( + log: Logging, + config: CloudflaredTunnelPlatformConfig, + api: API, + ) { // this.logs(); //this.debugLog(`Finished initializing platform: ${config.name}`);