Skip to content

Commit

Permalink
fix sounds; fix shadow focusing main window
Browse files Browse the repository at this point in the history
  • Loading branch information
lacymorrow committed May 17, 2022
1 parent 553c7cb commit d350f05
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 23 deletions.
7 changes: 4 additions & 3 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
- Add labels or tooltips for buttons
- electron builder dont bundle unneeded files
- click tray show menu; dblclick show app
- SECURITY: remove unsafe-eval; turn off remote module
Todo: when updating electron to 12+:
- Test iohook
Expand Down Expand Up @@ -141,9 +142,6 @@ const ready = async () => {

}

/* SOUND */
sound.preload()

/* Press Play >>> */
await init()

Expand All @@ -153,6 +151,9 @@ const ready = async () => {
/* MENU */
menu.init()

/* SOUND */
sound.preload()

/* AUTO-UPDATE */
autoUpdate.update()

Expand Down
3 changes: 2 additions & 1 deletion src/main/crossover.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ const keyboardShortcuts = () => {
keybind: `${accelerator}+C`,
fn() {

sound.play( 'CENTER' )
windows.center()

},
Expand Down Expand Up @@ -184,7 +185,7 @@ const lockWindow = ( lock, targetWindow = windows.win ) => {

/* DO STUFF */
windows.hideSettingsWindow()
windows.hideChooserWindow( { focus: true } )
windows.hideChooserWindow()
targetWindow.closable = !lock
targetWindow.setFocusable( !lock )
targetWindow.webContents.send( 'lock_window', lock )
Expand Down
2 changes: 2 additions & 0 deletions src/main/register.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ const appEvents = () => {
// Opening 2nd instance focuses app
app.on( 'second-instance', async () => {

console.warn( 'Creating second app instance' )

// If locked, unlock, else create shadow window
if ( windows.win ) {

Expand Down
2 changes: 1 addition & 1 deletion src/renderer/chooser.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="utf-8">
<title>Crosshairs</title>
<meta http-equiv="Content-Security-Policy" content="default-src 'self' 'unsafe-inline'">
<meta http-equiv="Content-Security-Policy" content="default-src 'self' 'unsafe-inline' 'unsafe-eval';">
<link rel="stylesheet" href="styles/dist/index.css">
<script type="text/javascript" src="vendor/feather/feather-icons.min.js"></script>
</head>
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="utf-8">
<title>CrossOver</title>
<meta http-equiv="Content-Security-Policy" content="default-src 'self' 'unsafe-inline'">
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self' 'unsafe-eval' 'unsafe-inline'; media-src *;">
<link rel="stylesheet" href="styles/dist/index.css">
<script type="text/javascript" src="vendor/feather/feather-icons.min.js"></script>
<script type="text/javascript" src="vendor/inline-svg/inline-svg.min.js"></script>
Expand Down
6 changes: 6 additions & 0 deletions src/renderer/lib/sounds.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ const sounds = {

function preload( basepath = '' ) {

if ( !basepath ) {

console.warn( 'Basepath not provided, sounds may not work properly.' )

}

let audio
for ( const name in sounds ) {

Expand Down
28 changes: 13 additions & 15 deletions src/renderer/preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const {
const unhandled = require( 'electron-unhandled' )
const config = require( '../config/config.js' )
const { debounce } = require( '../config/utils.js' )
const { play, preload } = require( './lib/sounds.js' )
const { play: playSound, preload: preloadSounds } = require( './lib/sounds.js' )

// Console.log( 'contextBridge:', contextBridge.internalContextBridge, contextBridge.internalContextBridge.contextIsolationEnabled )

Expand All @@ -15,8 +15,8 @@ const api = {
debounce,
isMacOs: navigator.userAgent.indexOf( 'Mac' ) !== -1,
isWindows: navigator.userAgent.indexOf( 'Win' ) !== -1,
play,
preload,
playSound,
preloadSounds,
unhandled,
send( channel, ...args ) {

Expand Down Expand Up @@ -56,25 +56,23 @@ const api = {

},

invoke( channel, arg ) {
// invoke( channel, arg ) {

console.log( 'preload', arg )
// const validChannels = new Set( [
// 'invoke_test', 'get_bounds', 'play_sound',
// ] )

const validChannels = new Set( [
'invoke_test', 'get_bounds', 'play_sound',
] )
// if ( validChannels.has( channel ) ) {

if ( validChannels.has( channel ) ) {
// ipcRenderer.invoke( channel, arg )

ipcRenderer.invoke( channel, arg )
// } else {

} else {
// console.warn( `Renderer refused to invoke IPC message on ${channel}` )

console.warn( `Renderer refused to invoke IPC message on ${channel}` )
// }

}

},
// },

}

Expand Down
4 changes: 2 additions & 2 deletions src/renderer/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,13 @@
// Sounds
window.crossover.receive( 'preload_sounds', arg => {

window.crossover.preload( arg )
window.crossover.preloadSounds( arg )

} )

window.crossover.receive( 'play_sound', arg => {

window.crossover.play( arg )
window.crossover.playSound( arg )

} )

Expand Down

0 comments on commit d350f05

Please sign in to comment.