mirror of
https://github.com/Eugeny/tabby.git
synced 2024-11-30 22:53:31 +03:00
check tabs before closing the window (fixes #520)
This commit is contained in:
parent
12d1fb9334
commit
eb81b9fd01
@ -24,6 +24,7 @@ export class Window {
|
|||||||
private window: BrowserWindow
|
private window: BrowserWindow
|
||||||
private windowConfig: ElectronConfig
|
private windowConfig: ElectronConfig
|
||||||
private windowBounds: Rectangle
|
private windowBounds: Rectangle
|
||||||
|
private closing = false
|
||||||
|
|
||||||
get visible$ (): Observable<boolean> { return this.visible }
|
get visible$ (): Observable<boolean> { return this.visible }
|
||||||
|
|
||||||
@ -145,7 +146,12 @@ export class Window {
|
|||||||
this.window.on('enter-full-screen', () => this.window.webContents.send('host:window-enter-full-screen'))
|
this.window.on('enter-full-screen', () => this.window.webContents.send('host:window-enter-full-screen'))
|
||||||
this.window.on('leave-full-screen', () => this.window.webContents.send('host:window-leave-full-screen'))
|
this.window.on('leave-full-screen', () => this.window.webContents.send('host:window-leave-full-screen'))
|
||||||
|
|
||||||
this.window.on('close', () => {
|
this.window.on('close', event => {
|
||||||
|
if (!this.closing) {
|
||||||
|
event.preventDefault()
|
||||||
|
this.window.webContents.send('host:window-close-request')
|
||||||
|
return
|
||||||
|
}
|
||||||
this.windowConfig.set('windowBoundaries', this.windowBounds)
|
this.windowConfig.set('windowBoundaries', this.windowBounds)
|
||||||
this.windowConfig.set('maximized', this.window.isMaximized())
|
this.windowConfig.set('maximized', this.window.isMaximized())
|
||||||
})
|
})
|
||||||
@ -244,6 +250,11 @@ export class Window {
|
|||||||
this.window.moveTop()
|
this.window.moveTop()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
ipcMain.on('window-close', () => {
|
||||||
|
this.closing = true
|
||||||
|
this.window.close()
|
||||||
|
})
|
||||||
|
|
||||||
this.window.webContents.on('new-window', event => event.preventDefault())
|
this.window.webContents.on('new-window', event => event.preventDefault())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ button.btn.btn-secondary.btn-maximize(
|
|||||||
svg(version='1.1', width='10', height='10')
|
svg(version='1.1', width='10', height='10')
|
||||||
path(d='M 0,0 0,10 10,10 10,0 Z M 1,1 9,1 9,9 1,9 Z')
|
path(d='M 0,0 0,10 10,10 10,0 Z M 1,1 9,1 9,9 1,9 Z')
|
||||||
button.btn.btn-secondary.btn-close(
|
button.btn.btn-secondary.btn-close(
|
||||||
(click)='hostApp.getWindow().close()',
|
(click)='app.closeWindow()'
|
||||||
)
|
)
|
||||||
svg(version='1.1', width='10', height='10')
|
svg(version='1.1', width='10', height='10')
|
||||||
path(d='M 0,0 0,0.7 4.3,5 0,9.3 0,10 0.7,10 5,5.7 9.3,10 10,10 10,9.3 5.7,5 10,0.7 10,0 9.3,0 5,4.3 0.7,0 Z')
|
path(d='M 0,0 0,0.7 4.3,5 0,9.3 0,10 0.7,10 5,5.7 9.3,10 10,10 10,9.3 5.7,5 10,0.7 10,0 9.3,0 5,4.3 0.7,0 Z')
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import { Component } from '@angular/core'
|
import { Component } from '@angular/core'
|
||||||
import { HostAppService } from '../services/hostApp.service'
|
import { HostAppService } from '../services/hostApp.service'
|
||||||
|
import { AppService } from '../services/app.service'
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'window-controls',
|
selector: 'window-controls',
|
||||||
@ -7,5 +8,5 @@ import { HostAppService } from '../services/hostApp.service'
|
|||||||
styles: [require('./windowControls.component.scss')],
|
styles: [require('./windowControls.component.scss')],
|
||||||
})
|
})
|
||||||
export class WindowControlsComponent {
|
export class WindowControlsComponent {
|
||||||
constructor (public hostApp: HostAppService) { }
|
constructor (public hostApp: HostAppService, public app: AppService) { }
|
||||||
}
|
}
|
||||||
|
@ -64,6 +64,8 @@ export class AppService {
|
|||||||
log: LogService,
|
log: LogService,
|
||||||
) {
|
) {
|
||||||
this.logger = log.create('app')
|
this.logger = log.create('app')
|
||||||
|
|
||||||
|
this.hostApp.windowCloseRequest$.subscribe(() => this.closeWindow())
|
||||||
}
|
}
|
||||||
|
|
||||||
openNewTab (type: TabComponentType, inputs?: any): BaseTabComponent {
|
openNewTab (type: TabComponentType, inputs?: any): BaseTabComponent {
|
||||||
@ -158,6 +160,18 @@ export class AppService {
|
|||||||
this.tabClosed.next(tab)
|
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 () {
|
emitReady () {
|
||||||
this.ready.next(null)
|
this.ready.next(null)
|
||||||
this.ready.complete()
|
this.ready.complete()
|
||||||
|
@ -28,6 +28,7 @@ export class HostAppService {
|
|||||||
private cliRunCommand = new Subject<string[]>()
|
private cliRunCommand = new Subject<string[]>()
|
||||||
private cliPaste = new Subject<string>()
|
private cliPaste = new Subject<string>()
|
||||||
private configChangeBroadcast = new Subject<void>()
|
private configChangeBroadcast = new Subject<void>()
|
||||||
|
private windowCloseRequest = new Subject<void>()
|
||||||
private logger: Logger
|
private logger: Logger
|
||||||
private windowId: number
|
private windowId: number
|
||||||
|
|
||||||
@ -37,6 +38,7 @@ export class HostAppService {
|
|||||||
get cliRunCommand$ (): Observable<string[]> { return this.cliRunCommand }
|
get cliRunCommand$ (): Observable<string[]> { return this.cliRunCommand }
|
||||||
get cliPaste$ (): Observable<string> { return this.cliPaste }
|
get cliPaste$ (): Observable<string> { return this.cliPaste }
|
||||||
get configChangeBroadcast$ (): Observable<void> { return this.configChangeBroadcast }
|
get configChangeBroadcast$ (): Observable<void> { return this.configChangeBroadcast }
|
||||||
|
get windowCloseRequest$ (): Observable<void> { return this.windowCloseRequest }
|
||||||
|
|
||||||
constructor (
|
constructor (
|
||||||
private zone: NgZone,
|
private zone: NgZone,
|
||||||
@ -72,6 +74,10 @@ export class HostAppService {
|
|||||||
this.zone.run(() => this.shown.emit())
|
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(() => {
|
electron.ipcRenderer.on('host:second-instance', (_$event, argv: any, cwd: string) => this.zone.run(() => {
|
||||||
this.logger.info('Second instance', argv)
|
this.logger.info('Second instance', argv)
|
||||||
const op = argv._[0]
|
const op = argv._[0]
|
||||||
@ -186,6 +192,10 @@ export class HostAppService {
|
|||||||
this.electron.ipcRenderer.send('window-bring-to-front')
|
this.electron.ipcRenderer.send('window-bring-to-front')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
closeWindow () {
|
||||||
|
this.electron.ipcRenderer.send('window-close')
|
||||||
|
}
|
||||||
|
|
||||||
quit () {
|
quit () {
|
||||||
this.logger.info('Quitting')
|
this.logger.info('Quitting')
|
||||||
this.electron.app.quit()
|
this.electron.app.quit()
|
||||||
|
@ -266,7 +266,7 @@ ngb-tabset.vertical(type='pills', [activeId]='activeTab')
|
|||||||
tr(*ngFor='let hotkey of hotkeyDescriptions|filterBy:["name"]:hotkeyFilter')
|
tr(*ngFor='let hotkey of hotkeyDescriptions|filterBy:["name"]:hotkeyFilter')
|
||||||
td {{hotkey.name}}
|
td {{hotkey.name}}
|
||||||
td {{hotkey.id}}
|
td {{hotkey.id}}
|
||||||
td
|
td.pr-5
|
||||||
multi-hotkey-input(
|
multi-hotkey-input(
|
||||||
[model]='getHotkey(hotkey.id)',
|
[model]='getHotkey(hotkey.id)',
|
||||||
(modelChange)='setHotkey(hotkey.id, $event); config.save(); docking.dock()'
|
(modelChange)='setHotkey(hotkey.id, $event); config.save(); docking.dock()'
|
||||||
|
Loading…
Reference in New Issue
Block a user