Skip to content

Commit

Permalink
Strict mode enhancements
Browse files Browse the repository at this point in the history
  • Loading branch information
hovancik committed Nov 8, 2024
1 parent e8831fb commit e8849b9
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 30 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
## [Unreleased]
### Added
- Bengali, Catalan, Greek and Serbian translations
- it is not possible to close app during break that is in strict mode

### Fixed
- error when end break shortcut is not set
Expand All @@ -16,6 +17,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- improved break window loading
- updated many translations
- better icons for "Show time in tray"
- `showBreakActionsInStrictMode` migrated to `showTrayMenuInStrictMode`

## [1.16.0] - 2024-08-11
### Added
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -370,8 +370,8 @@ To hide Stretchly icon in menubar/tray, set the value of `showTrayIcon` from `tr

Note that this will disable graphical way of opening Stretchly Preferences. To access Preferences, you will have to use command line options (ie: `stretchly preferences` on Linux).

#### Show break actions (Skip, Pause, Reset) in Strict Mode
If you want to show options 'Skip to next break', 'Pause' or 'Reset Breaks' even while in Strict mode, set `showBreakActionsInStrictMode` to `true`.
#### Show tray menu in Strict Mode
If you want to show tray menu even while in Strict mode, set `showTrayMenuInStrictMode` to `true`.

## Contributor Preferences

Expand Down
67 changes: 40 additions & 27 deletions app/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ let myStretchlyWindow = null
let settings
let pausedForSuspendOrLock = false
let nextIdea = null
let appIsQuitting = false
let updateChecker
let currentTrayIconPath = null
let currentTrayMenuTemplate = null
Expand Down Expand Up @@ -161,9 +160,16 @@ app.on('ready', initialize)
app.on('window-all-closed', () => {
// do nothing, so app wont get closed
})
app.on('before-quit', () => {
appIsQuitting = true
globalShortcut.unregisterAll()
app.on('before-quit', (event) => {
if ((breakPlanner.scheduler.reference === 'finishMicrobreak' && settings.get('microbreakStrictMode')) ||
(breakPlanner.scheduler.reference === 'finishBreak' && settings.get('breakStrictMode'))
) {
log.info('Stretchly: preventing app closure (in break with strict mode)')
event.preventDefault()
} else {
globalShortcut.unregisterAll()
app.quit()
}
})

async function initialize (isAppStart = true) {
Expand All @@ -181,18 +187,28 @@ async function initialize (isAppStart = true) {
},
migrations: {
'1.13.0': store => {
if (store.get('pauseBreaksShortcut')) {
if (store.has('pauseBreaksShortcut')) {
store.set('pauseBreaksToggleShortcut', store.get('pauseBreaksShortcut'))
log.info(`Stretchly: settings pauseBreaksToggleShortcut to "${store.get('pauseBreaksShortcut')}"`)
store.delete('pauseBreaksShortcut')
log.info('Stretchly: removing pauseBreaksShortcut')
} else {
log.info('Stretchly: not migrating pauseBreaksShortcut')
}
if (store.get('pauseBreaksShortcut')) {
if (store.has('pauseBreaksShortcut')) {
store.delete('resumeBreaksShortcut')
log.info('Stretchly: removing resumeBreaksShortcut')
}
},
'1.17.0': store => {
if (store.has('showBreakActionsInStrictMode')) {
store.set('showTrayMenuInStrictMode', store.get('showBreakActionsInStrictMode'))
log.info(`Stretchly: settings showTrayMenuInStrictMode to "${store.get('showBreakActionsInStrictMode')}"`)
store.delete('showBreakActionsInStrictMode')
log.info('Stretchly: removing showBreakActionsInStrictMode')
} else {
log.info('Stretchly: not migrating showBreakActionsInStrictMode')
}
}
},
watch: true
Expand Down Expand Up @@ -774,10 +790,10 @@ function startMicrobreak () {
microbreakWinLocal.setAlwaysOnTop(!showBreaksAsRegularWindows, 'pop-up-menu')
if (microbreakWinLocal) {
microbreakWinLocal.on('close', (e) => {
if (settings.get('showBreaksAsRegularWindows')) {
if (!appIsQuitting && !microbreakWinLocal.fullScreen) {
e.preventDefault()
}
if (settings.get('microbreakStrictMode')) {
// not doing anything
log.info('Stretchly: preventing closing break window as in strict mode')
e.preventDefault()
}
})
microbreakWinLocal.on('closed', () => {
Expand Down Expand Up @@ -922,10 +938,10 @@ function startBreak () {
breakWinLocal.setAlwaysOnTop(!showBreaksAsRegularWindows, 'pop-up-menu')
if (breakWinLocal) {
breakWinLocal.on('close', (e) => {
if (settings.get('showBreaksAsRegularWindows')) {
if (!appIsQuitting && !breakWinLocal.fullScreen) {
e.preventDefault()
}
if (settings.get('breakStrictMode')) {
// not doing anything
log.info('Stretchly: preventing closing break window as in strict mode')
e.preventDefault()
}
})
breakWinLocal.on('closed', () => {
Expand Down Expand Up @@ -1214,13 +1230,16 @@ function getTrayMenuTemplate () {
})
}

if (breakPlanner.scheduler.reference === 'finishMicrobreak' && settings.get('microbreakStrictMode') &&
!settings.get('showBreakActionsInStrictMode')) {
// nothing
} else if (breakPlanner.scheduler.reference === 'finishBreak' && settings.get('breakStrictMode') &&
!settings.get('showBreakActionsInStrictMode')) {
// nothing
} else if (!(breakPlanner.isPaused || breakPlanner.dndManager.isOnDnd || breakPlanner.appExclusionsManager.isSchedulerCleared)) {
if ((breakPlanner.scheduler.reference === 'finishMicrobreak' && settings.get('microbreakStrictMode') &&
!settings.get('showTrayMenuInStrictMode')) ||
(breakPlanner.scheduler.reference === 'finishBreak' && settings.get('breakStrictMode') &&
!settings.get('showTrayMenuInStrictMode'))
) {
// empty menu, we are in strict mode
return trayMenu
}

if (!(breakPlanner.isPaused || breakPlanner.dndManager.isOnDnd || breakPlanner.appExclusionsManager.isSchedulerCleared)) {
let submenu = []
if (settings.get('microbreak')) {
submenu = submenu.concat([{
Expand Down Expand Up @@ -1250,12 +1269,6 @@ function getTrayMenuTemplate () {
updateTray()
}
})
} else if (breakPlanner.scheduler.reference === 'finishMicrobreak' && settings.get('microbreakStrictMode') &&
!settings.get('showBreakActionsInStrictMode')) {
// nothing
} else if (breakPlanner.scheduler.reference === 'finishBreak' && settings.get('breakStrictMode') &&
!settings.get('showBreakActionsInStrictMode')) {
// nothing
} else if (!(breakPlanner.dndManager.isOnDnd || breakPlanner.appExclusionsManager.isSchedulerCleared)) {
trayMenu.push({
label: i18next.t('main.pause'),
Expand Down
2 changes: 1 addition & 1 deletion app/utils/defaultSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,5 @@ module.exports = {
skipToNextMiniBreakShortcut: '',
skipToNextLongBreakShortcut: '',
resetBreaksShortcut: '',
showBreakActionsInStrictMode: false
showTrayMenuInStrictMode: false
}

0 comments on commit e8849b9

Please sign in to comment.