This repository has been archived on 2024-10-25. You can view files and clone it, but cannot push or open issues or pull requests.
CrunchyDL/src/electron/singleInstance.ts

24 lines
535 B
TypeScript
Raw Normal View History

2024-04-16 20:20:30 +02:00
import { App, BrowserWindow } from 'electron'
export default (app: App, win: BrowserWindow) => {
2024-05-01 01:45:45 +02:00
const gotTheLock = app.requestSingleInstanceLock()
2024-04-16 20:20:30 +02:00
2024-05-01 01:45:45 +02:00
if (!gotTheLock) {
app.quit()
return true
2024-04-16 20:20:30 +02:00
}
2024-05-01 01:45:45 +02:00
app.on('second-instance', (_, _argv) => {
if (win) {
win.show()
if (win.isMinimized()) win.restore()
win.focus()
}
})
app.on('open-url', function (event, url) {
event.preventDefault()
win.webContents.send('deeplink', url)
})
2024-04-16 20:20:30 +02:00
}