2021-07-25 11:25:36 -04:00
|
|
|
import db from '~/main/apis/core/datastore'
|
2021-04-10 09:01:55 -04:00
|
|
|
import { clipboard, Notification, dialog } from 'electron'
|
2020-03-19 09:03:21 -04:00
|
|
|
|
2020-06-28 03:30:58 -04:00
|
|
|
export const handleCopyUrl = (str: string): void => {
|
2020-05-04 04:50:29 -04:00
|
|
|
if (db.get('settings.autoCopy') !== false) {
|
2020-03-19 09:03:21 -04:00
|
|
|
clipboard.writeText(str)
|
|
|
|
}
|
|
|
|
}
|
2021-03-28 05:44:07 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* show notification
|
|
|
|
* @param options
|
|
|
|
*/
|
|
|
|
export const showNotification = (options: IPrivateShowNotificationOption = {
|
|
|
|
title: '',
|
|
|
|
body: '',
|
|
|
|
clickToCopy: false
|
|
|
|
}) => {
|
|
|
|
const notification = new Notification({
|
|
|
|
title: options.title,
|
2021-04-10 09:01:55 -04:00
|
|
|
body: options.body,
|
|
|
|
icon: options.icon || undefined
|
2021-03-28 05:44:07 -04:00
|
|
|
})
|
|
|
|
const handleClick = () => {
|
|
|
|
if (options.clickToCopy) {
|
|
|
|
clipboard.writeText(options.body)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
notification.once('click', handleClick)
|
|
|
|
notification.once('close', () => {
|
|
|
|
notification.removeListener('click', handleClick)
|
|
|
|
})
|
|
|
|
notification.show()
|
|
|
|
}
|
2021-04-10 09:01:55 -04:00
|
|
|
|
|
|
|
export const showMessageBox = (options: any) => {
|
2022-01-04 10:40:28 -05:00
|
|
|
return new Promise<IShowMessageBoxResult>(async (resolve) => {
|
2021-04-10 09:01:55 -04:00
|
|
|
dialog.showMessageBox(
|
|
|
|
options
|
|
|
|
).then((res) => {
|
|
|
|
resolve({
|
|
|
|
result: res.response,
|
|
|
|
checkboxChecked: res.checkboxChecked
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
export const calcDurationRange = (duration: number) => {
|
|
|
|
if (duration < 1000) {
|
|
|
|
return 500
|
|
|
|
} else if (duration < 1500) {
|
|
|
|
return 1000
|
|
|
|
} else if (duration < 3000) {
|
|
|
|
return 2000
|
|
|
|
} else if (duration < 5000) {
|
|
|
|
return 3000
|
|
|
|
} else if (duration < 7000) {
|
|
|
|
return 5000
|
|
|
|
} else if (duration < 10000) {
|
|
|
|
return 8000
|
|
|
|
} else if (duration < 12000) {
|
|
|
|
return 10000
|
|
|
|
} else if (duration < 20000) {
|
|
|
|
return 15000
|
|
|
|
} else if (duration < 30000) {
|
|
|
|
return 20000
|
|
|
|
}
|
|
|
|
// max range
|
|
|
|
return 100000
|
|
|
|
}
|