Skip to content

Commit

Permalink
Merge pull request #34 from albireox/sound_profile
Browse files Browse the repository at this point in the history
Custom Sound Profiles
  • Loading branch information
Ryski2 authored May 3, 2024
2 parents 990d737 + 28d32a1 commit 4bde74e
Show file tree
Hide file tree
Showing 26 changed files with 319 additions and 16 deletions.
Binary file modified .yarn/install-state.gz
Binary file not shown.
Binary file added resources/sounds/STUI_AxisHalt.wav
Binary file not shown.
Binary file added resources/sounds/STUI_AxisSlew.wav
Binary file not shown.
Binary file added resources/sounds/STUI_AxisTrack.wav
Binary file not shown.
Binary file added resources/sounds/STUI_CommandDone.wav
Binary file not shown.
Binary file added resources/sounds/STUI_CommandFailed.wav
Binary file not shown.
Binary file added resources/sounds/STUI_CriticalAlert.wav
Binary file not shown.
Binary file added resources/sounds/STUI_ExposureBegins.wav
Binary file not shown.
Binary file added resources/sounds/STUI_ExposureEnds.wav
Binary file not shown.
Binary file added resources/sounds/STUI_FiducialCrossing.wav
Binary file not shown.
Binary file added resources/sounds/STUI_Glass.wav
Binary file not shown.
Binary file added resources/sounds/STUI_GuidingBegins.wav
Binary file not shown.
Binary file added resources/sounds/STUI_GuidingEnds.wav
Binary file not shown.
Binary file added resources/sounds/STUI_GuidingFailed.wav
Binary file not shown.
Binary file added resources/sounds/STUI_LogHighlightedText.wav
Binary file not shown.
Binary file added resources/sounds/STUI_MessageReceived.wav
Binary file not shown.
Binary file added resources/sounds/STUI_NoGuideStar.wav
Binary file not shown.
Binary file added resources/sounds/STUI_SeriousAlert.wav
Binary file not shown.
Binary file added resources/sounds/STUI_Silence.wav
Binary file not shown.
52 changes: 46 additions & 6 deletions src/main/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ import { config, store, subscriptions as storeSubscriptions } from './store';
import connectAndAuthorise from './tron/tools';
import { tron } from './tron/tron';
import { CommandStatus } from './tron/types';
import { playSound } from './utils';
const fs = require("fs");
const os = require('os');


export default function loadEvents() {
// app events
Expand Down Expand Up @@ -159,20 +163,45 @@ export default function loadEvents() {
return stdout;
}
);

ipcMain.handle('tools:open-in-browser', async (event, path: string) =>
shell.openExternal(path)
);

ipcMain.handle('tools:play-sound', async (event, type: string) => {
const file = store.get(`sounds.${type}`, null);
if (!file) return;
playSound(type);
});

if (path.isAbsolute(file)) {
sound.play(file);
} else {
sound.play('/sounds', file);
ipcMain.handle('tools:create-local-copy', async (event, path: string, name: string) => {
try{
const localPath = os.homedir() + '/.config/sdss/boson/sounds/';
fs.mkdir(localPath, { recursive: true }, (err) => {
if (err) throw err;
});
fs.copyFileSync(path, localPath + name, fs.constants.COPYFILE_EXCL);
return localPath + name;
} catch {
return false;
}
});

ipcMain.handle('tools:verify-sound-list', async (event) => {
const soundList = store.get('audio.user_sounds');
let toRemove = [];
for ( const sound of soundList) {
if (sound.startsWith('/')){
try {
fs.statSync(sound);
} catch (e) {
toRemove.push(sound);
}
}
}
const newSoundList = soundList.filter( ( missing ) => !toRemove.includes( missing ) );
return newSoundList;

})

// Dialogs
ipcMain.handle(
'dialog:show-message-box',
Expand All @@ -187,4 +216,15 @@ export default function loadEvents() {
await dialog.showErrorBox(title, content);
}
);

ipcMain.handle(
'dialog:list-files',
async (event) => {
const selection = await dialog.showOpenDialog({
properties: ['openFile', 'multiSelections'],
filters: [{ name: 'Sounds', extensions: ['wav', 'mp3']}]
})
return selection;
}
);
}
8 changes: 8 additions & 0 deletions src/main/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,12 @@ const ElectronAPI = {
playSound: (type: string) => {
return ipcRenderer.invoke('tools:play-sound', type);
},
createLocalCopy: (path: string, name: string) => {
return ipcRenderer.invoke('tools:create-local-copy', path, name);
},
verifySoundList:() => {
return ipcRenderer.invoke('tools:verify-sound-list');
}
},
dialog: {
showMessageBox: async (
Expand All @@ -156,6 +162,8 @@ const ElectronAPI = {
ipcRenderer.invoke('dialog:show-message-box', options),
showErrorBox: async (title: string, content: string): Promise<void> =>
ipcRenderer.invoke('dialog:show-error-box', title, content),
listFiles: async (): Promise<void> =>
ipcRenderer.invoke('dialog:list-files')
},
};

Expand Down
26 changes: 25 additions & 1 deletion src/main/store/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,32 @@ const store = new Store({
exposure_start: 'woodblock.wav',
exposure_end: 'bell_soft_long.wav',
},
});
})
},
'>=0.4.3': (st) => {
st.set('audio.user_sounds', ['bar_long.wav', 'bell_soft_long.wav', 'bell_soft_short.wav',
'buzz_error_long.wav', 'buzz_error_short.wav', 'chime_long.wav',
'click.wav', 'cowbell_high.wav', 'cowbell_low.wav', 'error.wav',
'high_buzz_error.wav', 'hit_long.wav', 'jingle_bell.wav', 'low_error.wav',
'marimba.wav', 'marimba_sharp.wav', 'synth_error_long.wav',
'synth_soft_short.wav','synth_string_echo.wav', 'synth_strings_long.wav',
'synth_strings_short.wav','woodblock.wav']
)},
'>=0.4.5': (st) => {
st.set('audio.user_sounds', ['bar_long.wav', 'bell_soft_long.wav', 'bell_soft_short.wav',
'buzz_error_long.wav', 'buzz_error_short.wav', 'chime_long.wav',
'click.wav', 'cowbell_high.wav', 'cowbell_low.wav', 'error.wav',
'high_buzz_error.wav', 'hit_long.wav', 'jingle_bell.wav', 'low_error.wav',
'marimba.wav', 'marimba_sharp.wav', 'synth_error_long.wav',
'synth_soft_short.wav','synth_string_echo.wav', 'synth_strings_long.wav',
'synth_strings_short.wav','woodblock.wav', 'STUI_AxisHalt.wav',
'STUI_AxisSlew.wav','STUI_AxisTrack.wav','STUI_CommandDone.wav',
'STUI_CommandFailed.wav','STUI_CriticalAlert.wav','STUI_ExposureBegins.wav',
'STUI_ExposureEnds.wav','STUI_FiducialCrossing.wav','STUI_Glass.wav',
'STUI_GuidingBegins.wav','STUI_GuidingEnds.wav','STUI_GuidingFailed.wav',
'STUI_LogHighlightedText.wav','STUI_MessageReceived.wav','STUI_NoGuideStar.wav',
'STUI_SeriousAlert.wav','STUI_Silence.wav']
)}
},
});

Expand Down
14 changes: 13 additions & 1 deletion src/main/store/user.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,19 @@
"axis_slew": "marimba.wav",
"exposure_start": "woodblock.wav",
"exposure_end": "bell_soft_long.wav"
}
},
"user_sounds": ["bar_long.wav", "bell_soft_long.wav", "bell_soft_short.wav",
"buzz_error_long.wav", "buzz_error_short.wav", "chime_long.wav",
"click.wav", "cowbell_high.wav", "cowbell_low.wav", "error.wav",
"high_buzz_error.wav", "hit_long.wav", "jingle_bell.wav", "low_error.wav",
"marimba.wav", "marimba_sharp.wav", "synth_error_long.wav",
"synth_soft_short.wav","synth_string_echo.wav", "synth_strings_long.wav",
"synth_strings_short.wav","woodblock.wav","AxisHalt.wav", "ExposureEnds.wav",
"MessageReceived.wav", "AxisSlew.wav", "STUI_AxisHalt.wav","STUI_AxisSlew.wav",
"STUI_AxisTrack.wav","STUI_CommandDone.wav","STUI_CommandFailed.wav","STUI_CriticalAlert.wav",
"STUI_ExposureBegins.wav","STUI_ExposureEnds.wav","STUI_FiducialCrossing.wav","STUI_Glass.wav",
"STUI_GuidingBegins.wav","STUI_GuidingEnds.wav","STUI_GuidingFailed.wav","STUI_LogHighlightedText.wav",
"STUI_MessageReceived.wav","STUI_NoGuideStar.wav","STUI_SeriousAlert.wav","STUI_Silence.wav"]
},
"maxLogMessages": 50000,
"updateChannel": "stable",
Expand Down
14 changes: 11 additions & 3 deletions src/main/tron/tron.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ export class TronConnection {

// Parse messages and play sounds.
if (/\S+\s\d+\s\S+\s[f!]/.test(reply.rawLine)) {
console.log(reply.rawLine);
playSound('error');
} else if (/alert=\S+/.test(reply.rawLine)) {
playSound('error_serious');
Expand Down Expand Up @@ -388,9 +389,7 @@ export class TronConnection {
(reply.sender === 'apogee' &&
/\S+\s\d+\s\S+\s\S\sexposureState=done/.test(reply.rawLine)) ||
(reply.sender === 'boss' &&
/\S+\s\d+\s\S+\s\S\stext="writing BOSS FITS files/.test(
reply.rawLine
)) ||
/\S+\s\d+\s\S+\s\S\stext="Readout complete/.test(reply.rawLine)) ||
(reply.sender === 'yao' &&
/\S+\s\d+\s\S+\s\S\sfilenames=/.test(reply.rawLine))
) {
Expand Down Expand Up @@ -490,6 +489,7 @@ export class TronConnection {
this.keywordListeners.set(sender, current);

const untracked: string[] = [];
const observatory: string = store.get('connection.observatory') ?? 'APO';

keywords.forEach((key, idx) => {
const trackedKeyword = this.trackedKeywords.get(key);
Expand All @@ -509,6 +509,14 @@ export class TronConnection {
.filter((kw) => kw.startsWith(actor))
.map((kw) => kw.split('.')[1]);

// HACK: quick fix to avoid error sound when connecting to an
// observatory without the specific actor.
if (actor === 'yao' && observatory === 'APO') {
return true;
} else if (actor === 'boss' && observatory === 'LCO') {
return true;
}

this.sendCommand(`keys getFor=${actor} ${actorKeys.join(' ')}`, true)
.awaitUntilDone()
.then(({ replies }) => {
Expand Down
6 changes: 4 additions & 2 deletions src/main/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ export interface PlaySoundOpts {
export function playSound(type: string, opts?: PlaySoundOpts) {
const { overrideMode = false } = opts || {};

const file = store.get(`audio.sounds.${type}`, null);
const soundList = store.get('audio.user_sounds', null);
// return the file name if it is in the user_sounds list, otherwise get the associated filename for the sound type
const file = soundList.includes(type) ? type: store.get(`audio.sounds.${type}`, null);
if (!file) return;

const mode: string = store.get('audio.mode');
Expand All @@ -35,7 +37,7 @@ export function playSound(type: string, opts?: PlaySoundOpts) {
if (mode === 'off') return;
if (mode === 'minimal' && !minimals.includes(type)) return;
}

if (path.isAbsolute(file)) {
sound.play(file);
} else if (MAIN_WINDOW_VITE_DEV_SERVER_URL) {
Expand Down
Loading

0 comments on commit 4bde74e

Please sign in to comment.