-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from richrace/add-debug-menu
Add debug menu
- Loading branch information
Showing
9 changed files
with
171 additions
and
82 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import SimpleHeadphone from 'arctis-usb-finder/dist/interfaces/simple_headphone'; | ||
|
||
import { MenuItem } from 'electron'; | ||
|
||
function exportView(mainTray: any, headphone: SimpleHeadphone) { | ||
if (!headphone.isConnected) { | ||
mainTray.setTitle(''); | ||
return new MenuItem({ label: `${headphone.modelName} - Not connected`, type: 'normal' }); | ||
} | ||
|
||
let percentage = headphone.batteryPercent > 100 ? 100 : headphone.batteryPercent; | ||
percentage = percentage < 0 ? 0 : percentage; | ||
|
||
let text = `${headphone.modelName} - ${percentage}%`; | ||
|
||
// Set the Tool Tip and title so we don't have to click to see a percentage | ||
mainTray.setToolTip(`${text}`); | ||
mainTray.setTitle(` ${percentage}%`); | ||
|
||
if (headphone.isCharging) { | ||
text += ' 🔋 '; | ||
} | ||
|
||
if (headphone.isDischarging) { | ||
text += ' 🪫 '; | ||
} | ||
|
||
if (headphone.isMuted) { | ||
text += ' 🔇 '; | ||
} else { | ||
text += ' 🔊 '; | ||
} | ||
|
||
return new MenuItem({ label: text }); | ||
} | ||
|
||
export default exportView; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { getHeadphones, refreshHeadphones } from 'arctis-usb-finder'; | ||
import SimpleHeadphone from 'arctis-usb-finder/dist/interfaces/simple_headphone'; | ||
|
||
let cachedHeadphones: SimpleHeadphone[] = undefined; | ||
|
||
function loadHeadphones(force: boolean = false): SimpleHeadphone[] { | ||
if (force || cachedHeadphones === undefined) { | ||
cachedHeadphones = getHeadphones(); | ||
console.log('forced', cachedHeadphones); | ||
} else { | ||
cachedHeadphones = refreshHeadphones(cachedHeadphones); | ||
console.log('not forced', cachedHeadphones); | ||
} | ||
|
||
return cachedHeadphones; | ||
} | ||
|
||
export default loadHeadphones; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import ProbeResult from 'arctis-usb-finder/dist/interfaces/probe_result'; | ||
import UsbDevice from 'arctis-usb-finder/dist/interfaces/usb_device'; | ||
import Probe from 'arctis-usb-finder/dist/use_cases/probe'; | ||
|
||
import { MenuItem } from 'electron'; | ||
|
||
function debugMenu(): MenuItem { | ||
const probe = new Probe(); | ||
const steelseriesHeadsets = probe.steelseriesHeadsets(); | ||
const foundHeadphones = probe.testUnknownHeadset(steelseriesHeadsets); | ||
|
||
let probeMenuItems = [{ label: 'No headphones found' }]; | ||
let foundButNotConnected = [{ label: 'No headphones found' }]; | ||
|
||
const filteredSteelseriesHeadsets = steelseriesHeadsets.filter((headset) => { | ||
return foundHeadphones.some((foundHeadphone) => { | ||
console.log('comparing', headset.productId !== foundHeadphone.device.productId); | ||
return headset.productId !== foundHeadphone.device.productId; | ||
}); | ||
}); | ||
|
||
if (filteredSteelseriesHeadsets.length > 0) { | ||
foundButNotConnected = steelseriesHeadsets.reduce((menuItems, device: UsbDevice) => { | ||
menuItems.push({ | ||
label: device.realDevice().product, | ||
submenu: [ | ||
{ label: `Product ID: ${device.productId}` }, | ||
{ label: `Bytes: Uknown` }, | ||
{ label: `Report: Uknown` }, | ||
{ label: `Path: ${device.path()}` }, | ||
], | ||
}); | ||
|
||
return menuItems; | ||
}, []); | ||
} | ||
|
||
if (foundHeadphones.length > 0) { | ||
probeMenuItems = foundHeadphones.reduce((menuItems, result: ProbeResult) => { | ||
menuItems.push({ | ||
label: result.device.realDevice().product, | ||
submenu: [ | ||
{ label: `Product ID: ${result.device.productId}` }, | ||
{ label: `Bytes: ${result.matchedBytes}` }, | ||
{ label: `Report: ${result.matchedReport}` }, | ||
{ label: `Path: ${result.device.path()}` }, | ||
], | ||
}); | ||
|
||
return menuItems; | ||
}, []); | ||
} | ||
|
||
return new MenuItem({ | ||
label: 'Debug', | ||
type: 'submenu', | ||
submenu: [ | ||
{ label: 'Found but not connected', submenu: foundButNotConnected }, | ||
{ label: 'Found and possibly not confirgured', submenu: probeMenuItems }, | ||
], | ||
}); | ||
} | ||
|
||
export default debugMenu; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { MenuItem } from 'electron'; | ||
|
||
const helpMenuItem = () => | ||
new MenuItem({ | ||
label: 'Help', | ||
type: 'normal', | ||
click: async () => { | ||
const { shell } = require('electron'); | ||
await shell.openExternal('https://github.com/richrace/arctis-monitor'); | ||
}, | ||
}); | ||
|
||
export default helpMenuItem; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { app, MenuItem } from 'electron'; | ||
|
||
const quitMenuItem = () => | ||
new MenuItem({ | ||
label: 'Quit', | ||
type: 'normal', | ||
click: () => { | ||
app.quit(); | ||
}, | ||
}); | ||
|
||
export default quitMenuItem; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters