Skip to content

Commit b18b3eb

Browse files
committed
More changes
1 parent b87425d commit b18b3eb

7 files changed

Lines changed: 76 additions & 90 deletions

app/break-preload.mjs

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,15 @@
1-
import { contextBridge, ipcRenderer } from 'electron'
2-
import humanizeDuration from 'humanize-duration'
3-
import * as utils from './utils/utils.js'
4-
import './exposes/expose-process.js'
1+
import {
2+
exposeI18next,
3+
exposeLongBreak,
4+
exposeProcess,
5+
exposeSettings,
6+
exposeStretchly,
7+
exposeUtils
8+
} from './utils/context-bridge-exposers.js'
59

6-
contextBridge.exposeInMainWorld('i18next', {
7-
t: (key, options) => ipcRenderer.invoke('i18next-translate', key, options),
8-
dir: () => ipcRenderer.invoke('i18next-dir')
9-
})
10-
11-
contextBridge.exposeInMainWorld('settings', {
12-
get: (key) => ipcRenderer.invoke('settings-get', key)
13-
})
14-
15-
contextBridge.exposeInMainWorld('breaks', {
16-
sendBreakData: () => ipcRenderer.invoke('send-break-data'),
17-
finishBreak: () => ipcRenderer.send('finish-break', false),
18-
postponeBreak: () => ipcRenderer.send('postpone-break'),
19-
signalLoaded: () => ipcRenderer.send('long-break-loaded'),
20-
formatKeyboardShortcut: utils.formatKeyboardShortcut,
21-
formatTimeRemaining: async (milliseconds, locale) => {
22-
const i18n = {
23-
t: (key, options) => ipcRenderer.invoke('i18next-translate', key, options)
24-
}
25-
return utils.formatTimeRemaining(milliseconds, locale, i18n, humanizeDuration)
26-
},
27-
canPostpone: utils.canPostpone,
28-
canSkip: utils.canSkip
29-
})
10+
exposeI18next()
11+
exposeLongBreak()
12+
exposeProcess()
13+
exposeSettings()
14+
exposeStretchly()
15+
exposeUtils()

app/break-renderer.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ window.onload = async (event) => {
3232

3333
document.querySelectorAll('.tiptext').forEach(async tt => {
3434
const keyboardShortcut = await window.settings.get('endBreakShortcut')
35-
tt.innerHTML = await window.breaks.formatKeyboardShortcut(keyboardShortcut)
35+
tt.innerHTML = await window.utils.formatKeyboardShortcut(keyboardShortcut)
3636
})
3737

3838
window.setInterval(async () => {
@@ -43,11 +43,11 @@ window.onload = async (event) => {
4343
if (Date.now() - started < duration) {
4444
const passedPercent = (Date.now() - started) / duration * 100
4545
postponeElement.style.display =
46-
await window.breaks.canPostpone(postpone, passedPercent, postponePercent) ? 'flex' : 'none'
46+
await window.utils.canPostpone(postpone, passedPercent, postponePercent) ? 'flex' : 'none'
4747
closeElement.style.display =
48-
await window.breaks.canSkip(strictMode, postpone, passedPercent, postponePercent) ? 'flex' : 'none'
48+
await window.utils.canSkip(strictMode, postpone, passedPercent, postponePercent) ? 'flex' : 'none'
4949
progress.value = (100 - passedPercent) * progress.max / 100
50-
progressTime.innerHTML = await window.breaks.formatTimeRemaining(Math.trunc(duration - Date.now() + started),
50+
progressTime.innerHTML = await window.utils.formatTimeRemaining(Math.trunc(duration - Date.now() + started),
5151
await window.settings.get('language'))
5252
}
5353
}, 100)
Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,9 @@
1-
import { ipcRenderer, contextBridge } from 'electron'
2-
import './exposes/expose-process.js'
1+
import {
2+
exposeI18next,
3+
exposeProcess,
4+
exposeSettings
5+
} from './utils/context-bridge-exposers.js'
36

4-
contextBridge.exposeInMainWorld('settings', {
5-
currentSettings: async () => {
6-
return await ipcRenderer.invoke('current-settings')
7-
},
8-
saveSettings: async (key, value) => {
9-
ipcRenderer.send('save-setting', key, value)
10-
}
11-
})
12-
13-
contextBridge.exposeInMainWorld('i18next', {
14-
t: (key, options) => ipcRenderer.invoke('i18next-translate', key, options),
15-
dir: () => ipcRenderer.invoke('i18next-dir')
16-
})
7+
exposeI18next()
8+
exposeProcess()
9+
exposeSettings()

app/exposes/expose-process.js

Lines changed: 0 additions & 10 deletions
This file was deleted.

app/microbreak-preload.mjs

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,15 @@
1-
import { contextBridge, ipcRenderer } from 'electron'
2-
import humanizeDuration from 'humanize-duration'
3-
import * as utils from './utils/utils.js'
4-
import './exposes/expose-process.js'
1+
import {
2+
exposeI18next,
3+
exposeMiniBreak,
4+
exposeProcess,
5+
exposeSettings,
6+
exposeStretchly,
7+
exposeUtils
8+
} from './utils/context-bridge-exposers.js'
59

6-
contextBridge.exposeInMainWorld('i18next', {
7-
t: (key, options) => ipcRenderer.invoke('i18next-translate', key, options),
8-
dir: () => ipcRenderer.invoke('i18next-dir')
9-
})
10-
11-
contextBridge.exposeInMainWorld('settings', {
12-
get: (key) => ipcRenderer.invoke('settings-get', key)
13-
})
14-
15-
contextBridge.exposeInMainWorld('breaks', {
16-
sendBreakData: () => ipcRenderer.invoke('send-microbreak-data'),
17-
finishBreak: () => ipcRenderer.send('finish-microbreak', false),
18-
postponeBreak: () => ipcRenderer.send('postpone-microbreak'),
19-
signalLoaded: () => ipcRenderer.send('mini-break-loaded'),
20-
formatKeyboardShortcut: utils.formatKeyboardShortcut,
21-
formatTimeRemaining: async (milliseconds, locale) => {
22-
const i18n = {
23-
t: (key, options) => ipcRenderer.invoke('i18next-translate', key, options)
24-
}
25-
return utils.formatTimeRemaining(milliseconds, locale, i18n, humanizeDuration)
26-
},
27-
canPostpone: utils.canPostpone,
28-
canSkip: utils.canSkip
29-
})
10+
exposeI18next()
11+
exposeMiniBreak()
12+
exposeProcess()
13+
exposeSettings()
14+
exposeStretchly()
15+
exposeUtils()

app/microbreak-renderer.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ window.onload = async (event) => {
3131

3232
document.querySelectorAll('.tiptext').forEach(async tt => {
3333
const keyboardShortcut = await window.settings.get('endBreakShortcut')
34-
tt.innerHTML = await window.breaks.formatKeyboardShortcut(keyboardShortcut)
34+
tt.innerHTML = await window.utils.formatKeyboardShortcut(keyboardShortcut)
3535
})
3636

3737
window.setInterval(async () => {
@@ -42,11 +42,11 @@ window.onload = async (event) => {
4242
if (Date.now() - started < duration) {
4343
const passedPercent = (Date.now() - started) / duration * 100
4444
postponeElement.style.display =
45-
await window.breaks.canPostpone(postpone, passedPercent, postponePercent) ? 'flex' : 'none'
45+
await window.utils.canPostpone(postpone, passedPercent, postponePercent) ? 'flex' : 'none'
4646
closeElement.style.display =
47-
await window.breaks.canSkip(strictMode, postpone, passedPercent, postponePercent) ? 'flex' : 'none'
47+
await window.utils.canSkip(strictMode, postpone, passedPercent, postponePercent) ? 'flex' : 'none'
4848
progress.value = (100 - passedPercent) * progress.max / 100
49-
progressTime.innerHTML = await window.breaks.formatTimeRemaining(Math.trunc(duration - Date.now() + started),
49+
progressTime.innerHTML = await window.utils.formatTimeRemaining(Math.trunc(duration - Date.now() + started),
5050
await window.settings.get('language'))
5151
}
5252
}, 100)

app/utils/context-bridge-exposers.js

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import semver from 'semver'
2+
import humanizeDuration from 'humanize-duration'
23
import { contextBridge, ipcRenderer, shell } from 'electron'
34
import * as utils from './utils.js'
45

@@ -23,6 +24,24 @@ function exposeI18next () {
2324
})
2425
}
2526

27+
function exposeLongBreak () {
28+
contextBridge.exposeInMainWorld('breaks', {
29+
sendBreakData: () => ipcRenderer.invoke('send-break-data'),
30+
finishBreak: () => ipcRenderer.send('finish-break', false),
31+
postponeBreak: () => ipcRenderer.send('postpone-break'),
32+
signalLoaded: () => ipcRenderer.send('long-break-loaded')
33+
})
34+
}
35+
36+
function exposeMiniBreak () {
37+
contextBridge.exposeInMainWorld('breaks', {
38+
sendBreakData: () => ipcRenderer.invoke('send-microbreak-data'),
39+
finishBreak: () => ipcRenderer.send('finish-microbreak', false),
40+
postponeBreak: () => ipcRenderer.send('postpone-microbreak'),
41+
signalLoaded: () => ipcRenderer.send('mini-break-loaded')
42+
})
43+
}
44+
2645
function exposeProcess () {
2746
contextBridge.exposeInMainWorld('process', {
2847
platform: () => process.platform,
@@ -46,6 +65,7 @@ function exposeSemver () {
4665

4766
function exposeSettings () {
4867
contextBridge.exposeInMainWorld('settings', {
68+
get: (key) => ipcRenderer.invoke('settings-get', key),
4969
currentSettings: async () => {
5070
return await ipcRenderer.invoke('current-settings')
5171
},
@@ -84,16 +104,27 @@ function exposeStretchly () {
84104

85105
function exposeUtils () {
86106
contextBridge.exposeInMainWorld('utils', {
107+
formatKeyboardShortcut: utils.formatKeyboardShortcut,
108+
formatTimeRemaining: async (milliseconds, locale) => {
109+
const i18n = {
110+
t: (key, options) => ipcRenderer.invoke('i18next-translate', key, options)
111+
}
112+
return utils.formatTimeRemaining(milliseconds, locale, i18n, humanizeDuration)
113+
},
87114
shouldShowNotificationTitle: (platform, systemVersion) => {
88115
return utils.shouldShowNotificationTitle(platform, systemVersion, semver)
89-
}
116+
},
117+
canPostpone: utils.canPostpone,
118+
canSkip: utils.canSkip
90119
})
91120
}
92121

93122
export {
94123
exposeElectronApi,
95124
exposeGlobal,
96125
exposeI18next,
126+
exposeLongBreak,
127+
exposeMiniBreak,
97128
exposeSemver,
98129
exposeSettings,
99130
exposeStretchly,

0 commit comments

Comments
 (0)