Skip to content

Commit

Permalink
Updates for v1.0.10
Browse files Browse the repository at this point in the history
  • Loading branch information
cold-logic committed Apr 11, 2024
1 parent af01315 commit bb259cf
Show file tree
Hide file tree
Showing 9 changed files with 558 additions and 106 deletions.
60 changes: 60 additions & 0 deletions .github/workflows/compile-linux.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Build Linux App

on:
push:
branches: [ compile-exe, main ]
pull_request:
branches: [ compile-exe, main ]

jobs:

build-linux:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: 20

- name: Install pnpm
uses: pnpm/action-setup@v3
with:
version: 8
run_install: false

- name: Get pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- uses: actions/cache@v4
name: Setup pnpm cache
with:
path: ${{ env.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Install dependencies
run: pnpm install --frozen-lockfile

- name: Create .env file
run: |
echo "GH_TOKEN=${{ secrets.GITHUB_TOKEN }}" >> .env
- name: Build Electron App
run: |
# Build the Electron app
npm run build
# Package the app into a Linux app
npm run package-linux
- name: Upload Artifact
uses: actions/upload-artifact@v4
with:
name: linux-app
path: dist/*.AppImage
61 changes: 61 additions & 0 deletions .github/workflows/compile-macos.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Build macOS App

on:
push:
branches: [ compile-exe, main ]
pull_request:
branches: [ compile-exe, main ]

jobs:

build-macos:
runs-on: macos-latest

steps:
- uses: actions/checkout@v4

- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: 20

- name: Install pnpm
uses: pnpm/action-setup@v3
with:
version: 8
run_install: false

- name: Get pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
echo "CSC_IDENTITY_AUTO_DISCOVERY=false" >> $GITHUB_ENV
- uses: actions/cache@v4
name: Setup pnpm cache
with:
path: ${{ env.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Install dependencies
run: pnpm install --frozen-lockfile

- name: Create .env file
run: |
echo "GH_TOKEN=${{ secrets.GITHUB_TOKEN }}" >> .env
- name: Build Electron App
run: |
# Build the Electron app
npm run build
# Package the app into a macOS app
npm run package-mac
- name: Upload Artifact
uses: actions/upload-artifact@v4
with:
name: macos-app
path: dist/*.dmg
63 changes: 63 additions & 0 deletions .github/workflows/compile-windows.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Build Windows App

on:
push:
branches: [ compile-exe, main ]
pull_request:
branches: [ compile-exe, main ]

jobs:

build-windows:
runs-on: windows-latest

steps:
- uses: actions/checkout@v4

- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: 20

- name: Install pnpm
uses: pnpm/action-setup@v3
with:
version: 8
run_install: false

- name: Get pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- uses: actions/cache@v4
name: Setup pnpm cache
with:
path: ${{ env.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Install dependencies
run: pnpm install --frozen-lockfile

- name: Setup MSBuild
uses: microsoft/setup-msbuild@v2

- name: Create .env file
run: |
echo "GH_TOKEN=${{ secrets.GITHUB_TOKEN }}" >> .env
- name: Build Electron App
run: |
# Build the Electron app
npm run build
# Package the app into a Windows executable
npm run package-win
- name: Upload Artifact
uses: actions/upload-artifact@v4
with:
name: windows-executable
path: dist/*.exe
1 change: 0 additions & 1 deletion .node-version

This file was deleted.

2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1 +1 @@
nodejs 18.17.1
nodejs 20.12.1
92 changes: 62 additions & 30 deletions app/browser/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
/* global $ */

window.$ = window.jQuery = require('jquery')
require('jquery-knob/dist/jquery.knob.min.js')
window.$ = window.jQuery = require('jquery');
require('jquery-knob/dist/jquery.knob.min.js');

const net = require('net');
const dgram = require('node:dgram'); // dgram is UDP
const net = require('node:net');
const os = require('node:os');

const HEOS_BROADCAST_ADDR = "239.255.255.250";
let connection, ui, lastCommand, discovery_interval;

// Before the window closes, de-register and disconnect
Expand Down Expand Up @@ -97,52 +101,68 @@ discover();
* Functions
******************************/

function broadcast_address() {
if (os.platform() == "win32") {
let addresses = [];
const ifaces = os.networkInterfaces();
Object.values(ifaces).forEach((i) => {
let iface_addresses = i.filter(iface => iface.family == "IPv4" && !iface.internal).map(iface => iface.address);

// create broadcast address from interface adress
iface_addresses = iface_addresses.map(addr => {
let blocks = addr.split(".");
blocks[3] = "255";
return blocks.join(".");
});

addresses.push(...iface_addresses);
});
return addresses;
} else {
return [ HEOS_BROADCAST_ADDR ];
}
}

function discover() {
const dgram = require('dgram'); // dgram is UDP
const client = dgram.createSocket('udp4');
client.bind(null, function () {
client.on('error', (err) => {
console.error(`client error:\n${err.stack}`);
client.close();
});
client.on('listening', () => {
const address = client.address();
console.log(`listening ${address.address}:${address.port}`);
const BROADCAST_ADDR = broadcast_address()[0];
const message = Buffer.from(
'M-SEARCH * HTTP/1.1\r\n' +
'HOST: 239.255.255.250:1900\r\n' +
`HOST: ${HEOS_BROADCAST_ADDR}:1900\r\n` +
'MAN: "ssdp:discover"\r\n' +
'ST: urn:schemas-denon-com:device:ACT-Denon:1\r\n' + // Essential, used by the client to specify what they want to discover, eg 'ST:ge:fridge'
'MX: 1\r\n' + // 1 second to respond (but they all respond immediately?)
'\r\n'
);
console.log('Sending on port ' + client.address().port);

client.on('message', function (msg, rinfo) {
console.log(`server got: ${msg} from ${rinfo.address}:${rinfo.port}`);
if ( msg.indexOf('ST: urn:schemas-denon-com:device:ACT-Denon:1') > -1) {
client.close()
connect(rinfo.address)
clearInterval(discovery_interval)
}
});
client.send(message, 0, message.length, 1900, '239.255.255.250');
client.send(message, 0, message.length, 1900, BROADCAST_ADDR);
console.log('sent discovery request...');
});
client.on('message', function (msg, rinfo) {
console.log(`client got: ${msg} from ${rinfo.address}:${rinfo.port}`);
if ( msg.indexOf('ST: urn:schemas-denon-com:device:ACT-Denon:1') > -1) {
client.close();
connect(rinfo.address);
clearInterval(discovery_interval);
}
});
client.bind(null);
if (!discovery_interval) // Setup an interval to keep trying to discover speakers
discovery_interval = setInterval(discover, 10000)
}

// Connect to the speaker
function connect(ip) {
const connectListener = () => { // gets triggered on successful connection
console.log('connected to server!');
setTimeout(function () {
sendCmd('system/register_for_change_events', {
enable: 'off'
});
sendCmd('player/get_players');
sendCmd('system/register_for_change_events', {
enable: 'on'
});
}, 1000);
}
connection = net.createConnection({
host: ip,
port: 1255
}, connectListener);
});
connection.on('error', err => {
console.error(new Date(), String(err))
if (err && err.code && err.code === 'ECONNREFUSED') {
Expand All @@ -152,6 +172,18 @@ function connect(ip) {
}, 3e4); // retry every 30 seconds
}
})
connection.on('connect', () => { // gets triggered on successful connection
console.log('connected to server!');
setTimeout(function () {
sendCmd('system/register_for_change_events', {
enable: 'off'
});
sendCmd('player/get_players');
sendCmd('system/register_for_change_events', {
enable: 'on'
});
}, 1000);
});
connection.on('data', function(data) {
const events = data.toString().split('\r\n');
for (const event of events) {
Expand Down
6 changes: 3 additions & 3 deletions app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
"productName": "Heos Controller",
"description": "Controller for Denon Heos speakers",
"author": "Christopher Davison",
"version": "1.0.9",
"version": "1.0.10",
"name": "heos-controller",
"main": "index.js",
"dependencies": {
"bootstrap": "^3.4.1",
"electron-log": "^4.4.8",
"electron-updater": "^4.6.5",
"electron-log": "^5.1.2",
"electron-updater": "^6.1.8",
"jquery": "^3.7.1",
"jquery-knob": "ssh://git@github.com:aterrien/jQuery-Knob.git"
},
Expand Down
11 changes: 7 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
{
"name": "heos-controller",
"version": "1.0.9",
"version": "1.0.10",
"description": "Controller for Denon Heos speakers",
"repository": "https://github.com/cold-logic/heos-controller",
"main": "app/index.js",
"scripts": {
"pack": "env-cmd electron-builder --dir",
"dist": "env-cmd electron-builder",
"build": "env-cmd electron-builder build",
"package-linux": "env-cmd electron-builder --linux",
"package-mac": "env-cmd electron-builder --mac --arm64 --x64",
"package-win": "env-cmd electron-builder --win --ia32 --x64",
"release": "build",
"start": "electron app",
"test": "echo \"Error: no test specified\" && exit 1"
Expand All @@ -34,10 +37,10 @@
]
}
},
"packageManager": "pnpm@8.6.8",
"packageManager": "pnpm@8.15.6",
"dependencies": {
"electron": "^22.3.25",
"electron-builder": "^24.6.4",
"electron": "^29.2.0",
"electron-builder": "^24.13.3",
"env-cmd": "^10.1.0"
},
"workspaces": [
Expand Down
Loading

0 comments on commit bb259cf

Please sign in to comment.