Skip to content

Commit

Permalink
prefs for noti/sound; default prefs bug; progress bar for updates; up…
Browse files Browse the repository at this point in the history
…date badge
  • Loading branch information
lacymorrow committed Mar 24, 2022
1 parent f452b79 commit 77977da
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 30 deletions.
43 changes: 38 additions & 5 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,12 @@ const appUpdate = () => {
if ( checkboxTrue( prefs.value( 'app.updates' ), 'updates' ) ) {

log.info( 'Setting: Automatic Updates' )
mainWindow.setProgressBar(50/100 || -1)

autoUpdater.logger = log

autoUpdater.on( 'update-available', () => {

playSound( 'UPDATE' )
mainWindow.webContents.send( 'update_available' )

if ( is.linux ) {
Expand Down Expand Up @@ -154,12 +155,15 @@ const appUpdate = () => {
message = message + ' (' + progressObject.transferred + '/' + progressObject.total + ')'
log.info( message )

// Dock progress bar
mainWindow.setProgressBar(progressObject.percent/100 || -1)
} )

autoUpdater.on( 'update-downloaded', () => {

playSound( 'DONE' )
mainWindow.webContents.send( 'notify', { title: 'CrossOver has been Updated', body: 'Relaunch to take effect' } )
app.dock.setBadge('!')
notification( { title: 'CrossOver has been Updated', body: 'Relaunch to take effect' } )
// playSound( 'DONE' )

} )
const FOUR_HOURS = 1000 * 60 * 60 * 4
Expand All @@ -186,6 +190,8 @@ if ( is.linux || !checkboxTrue( prefs.value( 'app.gpu' ), 'gpu' ) ) {
app.commandLine.appendSwitch( 'disable-gpu' )
app.disableHardwareAcceleration()

} else {
log.info( 'Setting: Enable GPU' )
}

// Prevent window from being garbage collected
Expand Down Expand Up @@ -223,7 +229,7 @@ const createMainWindow = async isShadowWindow => {
width: APP_WIDTH,
height: APP_HEIGHT,
webPreferences: {
contextIsolation: !is.linux,
contextIsolation: true,
enableRemoteModule: true,
nativeWindowOpen: true,
nodeIntegration: false,
Expand Down Expand Up @@ -1197,6 +1203,7 @@ const registerEvents = () => {
// Sync prefs to renderer
prefs.on( 'save', preferences => {

console.log(preferences.app)
syncSettings( preferences )

} )
Expand Down Expand Up @@ -1322,6 +1329,8 @@ const registerIpc = () => {
ipcMain.on( 'center_window', () => {

log.info( 'Center window' )

playSound( 'CENTER' )
centerAppWindow()

} )
Expand All @@ -1340,13 +1349,23 @@ const registerIpc = () => {

}

const notification = (options) => {
if(checkboxTrue( prefs.value( 'app.notify' ), 'notify' )) {
mainWindow.webContents.send( 'notify', options )
}
}

const preloadSounds = () => {

mainWindow.webContents.send( 'preload_sounds', path.join( __static, 'sounds' ) + path.sep )

}

const playSound = sound => mainWindow.webContents.send( 'play_sound', sound )
const playSound = sound => {
if(checkboxTrue( prefs.value( 'app.sounds' ), 'sounds' )) {
mainWindow.webContents.send( 'play_sound', sound )
}
}

const syncSettings = preferences => {

Expand Down Expand Up @@ -1577,6 +1596,20 @@ const unregisterIOHook = () => {

}

const resetPreference = (key) => {
try {
const [groupId, id] = key.split('.')
const group = prefs.defaults[groupId]
const defaultValue = group[id]

log.info(`Setting default value ${defaultValue} for ${key}`)
prefs.value(key, defaultValue)
} catch(e) {
log.warn(e)
}

}

// Temp until implemented in electron-preferences
const resetPreferences = () => {

Expand Down
30 changes: 25 additions & 5 deletions src/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ const preferences = new ElectronPreferences( {
},
app: {
updates: [ 'updates' ],
boot: [],
sounds: [ 'sounds' ],
notify: [ 'notify' ],
gpu: [ 'gpu' ],
boot: [],
},
keybinds: {
reset: 'Control+Shift+Alt+R',
Expand Down Expand Up @@ -357,13 +359,22 @@ const preferences = new ElectronPreferences( {
help: 'CrossOver will make a network connection to GitHub.com. No personal data is sent.',
},
{
label: 'Run at startup',
key: 'system',
label: 'Enable Sounds',
key: 'sounds',
type: 'checkbox',
options: [
{ label: 'Start on system boot', value: 'boot' },
{ label: 'Allow CrossOver to play audio', value: 'sounds' },
],
help: 'CrossOver will start when your computer starts.',
help: 'CrossOver makes a little noise to indicate certain events.',
},
{
label: 'Enable Notifications',
key: 'notify',
type: 'checkbox',
options: [
{ label: 'Allow CrossOver to create system notifications', value: 'notify' },
],
help: 'CrossOver will notify you about any issues or new updates.',
},
{
label: 'Hardware acceleration',
Expand All @@ -374,6 +385,15 @@ const preferences = new ElectronPreferences( {
],
help: 'If you are having issues with FPS, try disabling hardware acceleration. You must restart CrossOver for this to take effect.',
},
{
label: 'Run at startup',
key: 'system',
type: 'checkbox',
options: [
{ label: 'Start on system boot', value: 'boot' },
],
help: 'CrossOver will start when your computer starts.',
},
{
label: 'Reset CrossOver Settings',
buttonLabel: 'Reset Settings',
Expand Down
41 changes: 22 additions & 19 deletions src/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,25 @@

( () => {

try {
// try {

window.crossover.unhandled( {
reportButton( error ) {
// window.crossover.unhandled( {
// reportButton( error ) {

window.crossover.openNewGitHubIssue( {
user: 'lacymorrow',
repo: 'crossover',
body: `\`\`\`\n${error.stack}\n\`\`\`\n\n---\n\n${window.crossover.debugInfo()}`,
} )
// window.crossover.openNewGitHubIssue( {
// user: 'lacymorrow',
// repo: 'crossover',
// body: `\`\`\`\n${error.stack}\n\`\`\`\n\n---\n\n${window.crossover.debugInfo()}`,
// } )

},
} )
// },
// } )

} catch ( error ) {
// } catch ( error ) {

console.log( error )
// console.log( error )

}
// }

// DOM elements
const background = document.querySelector( '.background' )
Expand Down Expand Up @@ -68,9 +68,14 @@
// Notifications
window.crossover.receive( 'notify', arg => {

const notif = new window.Notification( arg.title || 'CrossOver Test Notification', {
body: arg.body || 'You shouldn\'t be seeing this',
// Silent: true // We'll play our own sound
if (!arg.title || !arg.body) {
console.error('Invalid Notification, title and body are required.')
return;
}

const notif = new window.Notification( arg.title, {
body: arg.body,
silent: arg.silent // We'll play our own sound
} )

// If the user clicks in the Notifications Center, show the app
Expand All @@ -85,8 +90,6 @@
// Auto Update info
window.crossover.receive( 'update_available', () => {

window.crossover.play( 'UPDATE' )

// Change top-left icon
infoBtn.querySelector( '.move-icon' ).classList.add( 'd-none' )
infoBtn.querySelector( '.info-icon' ).classList.remove( 'd-none' )
Expand Down Expand Up @@ -264,7 +267,7 @@
crosshairElement.addEventListener( 'dblclick', () => {

window.crossover.send( 'center_window' )
window.crossover.play( 'CENTER' )


} )

Expand Down
5 changes: 4 additions & 1 deletion src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ const debounce = ( func, delay ) => {

}

const checkboxTrue = ( value, key ) => ( typeof value === 'object' && value.includes( key ) )
const checkboxTrue = ( value, key ) => {
// console.log(value, key, typeof value === 'object', value.includes( key ))
return ( typeof value === 'object' && value.includes( key ) )
}

/* eslint-disable no-prototype-builtins */
/**
Expand Down

0 comments on commit 77977da

Please sign in to comment.