mirror of
https://github.com/Eugeny/tabby.git
synced 2025-10-05 22:44:55 +00:00
check tabs before closing the window (fixes #520)
This commit is contained in:
@@ -64,6 +64,8 @@ export class AppService {
|
||||
log: LogService,
|
||||
) {
|
||||
this.logger = log.create('app')
|
||||
|
||||
this.hostApp.windowCloseRequest$.subscribe(() => this.closeWindow())
|
||||
}
|
||||
|
||||
openNewTab (type: TabComponentType, inputs?: any): BaseTabComponent {
|
||||
@@ -158,6 +160,18 @@ export class AppService {
|
||||
this.tabClosed.next(tab)
|
||||
}
|
||||
|
||||
async closeWindow () {
|
||||
for (let tab of this.tabs) {
|
||||
if (!await tab.canClose()) {
|
||||
return
|
||||
}
|
||||
}
|
||||
for (let tab of this.tabs) {
|
||||
tab.destroy()
|
||||
}
|
||||
this.hostApp.closeWindow()
|
||||
}
|
||||
|
||||
emitReady () {
|
||||
this.ready.next(null)
|
||||
this.ready.complete()
|
||||
|
@@ -28,6 +28,7 @@ export class HostAppService {
|
||||
private cliRunCommand = new Subject<string[]>()
|
||||
private cliPaste = new Subject<string>()
|
||||
private configChangeBroadcast = new Subject<void>()
|
||||
private windowCloseRequest = new Subject<void>()
|
||||
private logger: Logger
|
||||
private windowId: number
|
||||
|
||||
@@ -37,6 +38,7 @@ export class HostAppService {
|
||||
get cliRunCommand$ (): Observable<string[]> { return this.cliRunCommand }
|
||||
get cliPaste$ (): Observable<string> { return this.cliPaste }
|
||||
get configChangeBroadcast$ (): Observable<void> { return this.configChangeBroadcast }
|
||||
get windowCloseRequest$ (): Observable<void> { return this.windowCloseRequest }
|
||||
|
||||
constructor (
|
||||
private zone: NgZone,
|
||||
@@ -72,6 +74,10 @@ export class HostAppService {
|
||||
this.zone.run(() => this.shown.emit())
|
||||
})
|
||||
|
||||
electron.ipcRenderer.on('host:window-close-request', () => {
|
||||
this.zone.run(() => this.windowCloseRequest.next())
|
||||
})
|
||||
|
||||
electron.ipcRenderer.on('host:second-instance', (_$event, argv: any, cwd: string) => this.zone.run(() => {
|
||||
this.logger.info('Second instance', argv)
|
||||
const op = argv._[0]
|
||||
@@ -186,6 +192,10 @@ export class HostAppService {
|
||||
this.electron.ipcRenderer.send('window-bring-to-front')
|
||||
}
|
||||
|
||||
closeWindow () {
|
||||
this.electron.ipcRenderer.send('window-close')
|
||||
}
|
||||
|
||||
quit () {
|
||||
this.logger.info('Quitting')
|
||||
this.electron.app.quit()
|
||||
|
Reference in New Issue
Block a user