mirror of
https://github.com/Eugeny/tabby.git
synced 2025-10-05 22:44:55 +00:00
more platform changes
This commit is contained in:
12
terminus-core/src/api/hostWindow.ts
Normal file
12
terminus-core/src/api/hostWindow.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { Observable } from 'rxjs'
|
||||
|
||||
export abstract class HostWindowService {
|
||||
abstract readonly closeRequest$: Observable<void>
|
||||
abstract readonly isFullscreen: boolean
|
||||
abstract reload (): void
|
||||
abstract setTitle (title?: string): void
|
||||
abstract toggleFullscreen (): void
|
||||
abstract minimize (): void
|
||||
abstract toggleMaximize (): void
|
||||
abstract close (): void
|
||||
}
|
@@ -10,9 +10,10 @@ export { Theme } from './theme'
|
||||
export { TabContextMenuItemProvider } from './tabContextMenuProvider'
|
||||
export { SelectorOption } from './selector'
|
||||
export { CLIHandler, CLIEvent } from './cli'
|
||||
export { PlatformService, ClipboardContent } from './platform'
|
||||
export { PlatformService, ClipboardContent, MessageBoxResult, MessageBoxOptions } from './platform'
|
||||
export { MenuItemOptions } from './menu'
|
||||
export { BootstrapData, BOOTSTRAP_DATA } from './mainProcess'
|
||||
export { HostWindowService } from './hostWindow'
|
||||
|
||||
export { AppService } from '../services/app.service'
|
||||
export { ConfigService } from '../services/config.service'
|
||||
|
@@ -6,9 +6,22 @@ export interface ClipboardContent {
|
||||
html?: string
|
||||
}
|
||||
|
||||
export interface MessageBoxOptions {
|
||||
type: 'warning'|'error'
|
||||
message: string
|
||||
detail?: string
|
||||
buttons: string[]
|
||||
defaultId?: number
|
||||
}
|
||||
|
||||
export interface MessageBoxResult {
|
||||
response: number
|
||||
}
|
||||
|
||||
export abstract class PlatformService {
|
||||
supportsWindowControls = false
|
||||
|
||||
abstract readClipboard (): string
|
||||
abstract setClipboard (content: ClipboardContent): void
|
||||
abstract loadConfig (): Promise<string>
|
||||
abstract saveConfig (content: string): Promise<void>
|
||||
@@ -66,4 +79,5 @@ export abstract class PlatformService {
|
||||
abstract openExternal (url: string): void
|
||||
abstract listFonts (): Promise<string[]>
|
||||
abstract popupContextMenu (menu: MenuItemOptions[], event?: MouseEvent): void
|
||||
abstract showMessageBox (options: MessageBoxOptions): Promise<MessageBoxResult>
|
||||
}
|
||||
|
@@ -1,15 +1,16 @@
|
||||
title-bar(
|
||||
*ngIf='!hostApp.isFullScreen && config.store.appearance.frame == "full" && config.store.appearance.dock == "off"',
|
||||
[class.inset]='hostApp.platform == Platform.macOS && !hostApp.isFullScreen'
|
||||
*ngIf='ready && !hostWindow.isFullScreen && config.store.appearance.frame == "full" && config.store.appearance.dock == "off"',
|
||||
[class.inset]='hostApp.platform == Platform.macOS && !hostWindow.isFullScreen'
|
||||
)
|
||||
|
||||
.content(
|
||||
*ngIf='ready',
|
||||
[class.tabs-on-top]='config.store.appearance.tabsLocation == "top" || config.store.appearance.tabsLocation == "left"',
|
||||
[class.tabs-on-side]='hasVerticalTabs()',
|
||||
)
|
||||
.tab-bar
|
||||
.inset.background(*ngIf='hostApp.platform == Platform.macOS \
|
||||
&& !hostApp.isFullScreen \
|
||||
&& !hostWindow.isFullScreen \
|
||||
&& config.store.appearance.frame == "thin" \
|
||||
&& (config.store.appearance.tabsLocation == "top" || config.store.appearance.tabsLocation == "left")')
|
||||
.tabs(
|
||||
|
@@ -12,7 +12,7 @@ import { UpdaterService } from '../services/updater.service'
|
||||
|
||||
import { BaseTabComponent } from './baseTab.component'
|
||||
import { SafeModeModalComponent } from './safeModeModal.component'
|
||||
import { AppService, PlatformService, ToolbarButton, ToolbarButtonProvider } from '../api'
|
||||
import { AppService, HostWindowService, PlatformService, ToolbarButton, ToolbarButtonProvider } from '../api'
|
||||
|
||||
/** @hidden */
|
||||
@Component({
|
||||
@@ -66,6 +66,7 @@ export class AppRootComponent {
|
||||
private constructor (
|
||||
private hotkeys: HotkeysService,
|
||||
private updater: UpdaterService,
|
||||
public hostWindow: HostWindowService,
|
||||
public hostApp: HostAppService,
|
||||
public config: ConfigService,
|
||||
public app: AppService,
|
||||
@@ -78,9 +79,6 @@ export class AppRootComponent {
|
||||
this.logger = log.create('main')
|
||||
this.logger.info('v', platform.getAppVersion())
|
||||
|
||||
this.leftToolbarButtons = this.getToolbarButtons(false)
|
||||
this.rightToolbarButtons = this.getToolbarButtons(true)
|
||||
|
||||
this.updateIcon = require('../icons/gift.svg')
|
||||
|
||||
this.hotkeys.matchedHotkey.subscribe((hotkey: string) => {
|
||||
@@ -114,7 +112,7 @@ export class AppRootComponent {
|
||||
}
|
||||
}
|
||||
if (hotkey === 'toggle-fullscreen') {
|
||||
this.hostApp.toggleFullscreen()
|
||||
hostWindow.toggleFullscreen()
|
||||
}
|
||||
})
|
||||
|
||||
@@ -126,14 +124,6 @@ export class AppRootComponent {
|
||||
ngbModal.open(SafeModeModalComponent)
|
||||
}
|
||||
|
||||
setInterval(() => {
|
||||
if (this.config.store.enableAutomaticUpdates) {
|
||||
this.updater.check().then(available => {
|
||||
this.updatesAvailable = available
|
||||
})
|
||||
}
|
||||
}, 3600 * 12 * 1000)
|
||||
|
||||
this.app.tabOpened$.subscribe(tab => {
|
||||
this.unsortedTabs.push(tab)
|
||||
this.noTabs = false
|
||||
@@ -143,12 +133,26 @@ export class AppRootComponent {
|
||||
this.unsortedTabs = this.unsortedTabs.filter(x => x !== tab)
|
||||
this.noTabs = app.tabs.length === 0
|
||||
})
|
||||
|
||||
config.ready$.toPromise().then(() => {
|
||||
this.leftToolbarButtons = this.getToolbarButtons(false)
|
||||
this.rightToolbarButtons = this.getToolbarButtons(true)
|
||||
|
||||
setInterval(() => {
|
||||
if (this.config.store.enableAutomaticUpdates) {
|
||||
this.updater.check().then(available => {
|
||||
this.updatesAvailable = available
|
||||
})
|
||||
}
|
||||
}, 3600 * 12 * 1000)
|
||||
})
|
||||
}
|
||||
|
||||
async ngOnInit () {
|
||||
this.ready = true
|
||||
|
||||
this.app.emitReady()
|
||||
this.config.ready$.toPromise().then(() => {
|
||||
this.ready = true
|
||||
this.app.emitReady()
|
||||
})
|
||||
}
|
||||
|
||||
@HostListener('dragover')
|
||||
|
@@ -2,7 +2,7 @@
|
||||
import { Component } from '@angular/core'
|
||||
import { BaseTabComponent } from './baseTab.component'
|
||||
import { ConfigService } from '../services/config.service'
|
||||
import { HostAppService } from '../services/hostApp.service'
|
||||
import { HostWindowService } from '../api/hostWindow'
|
||||
|
||||
/** @hidden */
|
||||
@Component({
|
||||
@@ -16,7 +16,7 @@ export class WelcomeTabComponent extends BaseTabComponent {
|
||||
enableGlobalHotkey = true
|
||||
|
||||
constructor (
|
||||
private hostApp: HostAppService,
|
||||
private hostWindow: HostWindowService,
|
||||
public config: ConfigService,
|
||||
) {
|
||||
super()
|
||||
@@ -38,6 +38,6 @@ export class WelcomeTabComponent extends BaseTabComponent {
|
||||
this.config.store.hotkeys['toggle-window'] = []
|
||||
}
|
||||
this.config.save()
|
||||
this.hostApp.getWindow().reload()
|
||||
this.hostWindow.reload()
|
||||
}
|
||||
}
|
||||
|
@@ -1,4 +1,4 @@
|
||||
import { NgModule, ModuleWithProviders, APP_INITIALIZER } from '@angular/core'
|
||||
import { NgModule, ModuleWithProviders } from '@angular/core'
|
||||
import { BrowserModule } from '@angular/platform-browser'
|
||||
import { BrowserAnimationsModule } from '@angular/platform-browser/animations'
|
||||
import { FormsModule } from '@angular/forms'
|
||||
@@ -38,10 +38,6 @@ import { LastCLIHandler } from './cli'
|
||||
import 'perfect-scrollbar/css/perfect-scrollbar.css'
|
||||
import 'ng2-dnd/bundles/style.css'
|
||||
|
||||
function initialize (config: ConfigService) {
|
||||
return () => config.ready$.toPromise()
|
||||
}
|
||||
|
||||
const PROVIDERS = [
|
||||
{ provide: HotkeyProvider, useClass: AppHotkeyProvider, multi: true },
|
||||
{ provide: Theme, useClass: StandardTheme, multi: true },
|
||||
@@ -54,7 +50,6 @@ const PROVIDERS = [
|
||||
{ provide: TabRecoveryProvider, useClass: SplitTabRecoveryProvider, multi: true },
|
||||
{ provide: CLIHandler, useClass: LastCLIHandler, multi: true },
|
||||
{ provide: PERFECT_SCROLLBAR_CONFIG, useValue: { suppressScrollX: true } },
|
||||
{ provide: APP_INITIALIZER, useFactory: initialize, deps: [ConfigService], multi: true },
|
||||
]
|
||||
|
||||
/** @hidden */
|
||||
|
@@ -10,6 +10,7 @@ import { SelectorModalComponent } from '../components/selectorModal.component'
|
||||
import { SelectorOption } from '../api/selector'
|
||||
import { RecoveryToken } from '../api/tabRecovery'
|
||||
import { BootstrapData, BOOTSTRAP_DATA } from '../api/mainProcess'
|
||||
import { HostWindowService } from '../api/hostWindow'
|
||||
|
||||
import { ConfigService } from './config.service'
|
||||
import { HostAppService } from './hostApp.service'
|
||||
@@ -73,6 +74,7 @@ export class AppService {
|
||||
private constructor (
|
||||
private config: ConfigService,
|
||||
private hostApp: HostAppService,
|
||||
private hostWindow: HostWindowService,
|
||||
private tabRecovery: TabRecoveryService,
|
||||
private tabsService: TabsService,
|
||||
private ngbModal: NgbModal,
|
||||
@@ -127,7 +129,7 @@ export class AppService {
|
||||
|
||||
tab.titleChange$.subscribe(title => {
|
||||
if (tab === this._activeTab) {
|
||||
this.hostApp.setTitle(title)
|
||||
this.hostWindow.setTitle(title)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -205,7 +207,7 @@ export class AppService {
|
||||
setImmediate(() => {
|
||||
this._activeTab?.emitFocused()
|
||||
})
|
||||
this.hostApp.setTitle(this._activeTab?.title)
|
||||
this.hostWindow.setTitle(this._activeTab?.title)
|
||||
}
|
||||
|
||||
getParentTab (tab: BaseTabComponent): SplitTabComponent|null {
|
||||
@@ -332,7 +334,7 @@ export class AppService {
|
||||
this.tabRecovery.enabled = false
|
||||
await this.tabRecovery.saveTabs(this.tabs)
|
||||
if (await this.closeAllTabs()) {
|
||||
this.hostApp.closeWindow()
|
||||
this.hostWindow.close()
|
||||
} else {
|
||||
this.tabRecovery.enabled = true
|
||||
}
|
||||
|
@@ -89,9 +89,9 @@ export class ConfigService {
|
||||
restartRequested: boolean
|
||||
|
||||
/** Fires once when the config is loaded */
|
||||
get ready$ (): Observable<void> { return this.ready }
|
||||
get ready$ (): Observable<boolean> { return this.ready }
|
||||
|
||||
private ready = new AsyncSubject<void>()
|
||||
private ready = new AsyncSubject<boolean>()
|
||||
private changed = new Subject<void>()
|
||||
private _store: any
|
||||
private defaults: any
|
||||
@@ -213,7 +213,7 @@ export class ConfigService {
|
||||
|
||||
private async init () {
|
||||
await this.load()
|
||||
this.ready.next()
|
||||
this.ready.next(true)
|
||||
this.ready.complete()
|
||||
|
||||
this.hostApp.configChangeBroadcast$.subscribe(() => {
|
||||
|
@@ -1,5 +1,5 @@
|
||||
import { Injectable } from '@angular/core'
|
||||
import { App, IpcRenderer, Shell, Dialog, Clipboard, GlobalShortcut, Screen, Remote, AutoUpdater, TouchBar, BrowserWindow, Menu, MenuItem, NativeImage, MessageBoxOptions } from 'electron'
|
||||
import { App, IpcRenderer, Shell, Dialog, Clipboard, GlobalShortcut, Screen, Remote, AutoUpdater, TouchBar, BrowserWindow, Menu, MenuItem, NativeImage } from 'electron'
|
||||
import * as remote from '@electron/remote'
|
||||
|
||||
export interface MessageBoxResponse {
|
||||
@@ -44,11 +44,4 @@ export class ElectronService {
|
||||
this.Menu = remote.Menu
|
||||
this.MenuItem = remote.MenuItem
|
||||
}
|
||||
|
||||
async showMessageBox (
|
||||
browserWindow: BrowserWindow,
|
||||
options: MessageBoxOptions
|
||||
): Promise<MessageBoxResponse> {
|
||||
return this.dialog.showMessageBox(browserWindow, options)
|
||||
}
|
||||
}
|
||||
|
@@ -33,7 +33,6 @@ export class HostAppService {
|
||||
* Fired once the window is visible
|
||||
*/
|
||||
shown = new EventEmitter<any>()
|
||||
isFullScreen = false
|
||||
isPortable = !!process.env.PORTABLE_EXECUTABLE_FILE
|
||||
|
||||
private preferencesMenu = new Subject<void>()
|
||||
@@ -92,14 +91,6 @@ export class HostAppService {
|
||||
this.logger.error('Unhandled exception:', err)
|
||||
})
|
||||
|
||||
electron.ipcRenderer.on('host:window-enter-full-screen', () => this.zone.run(() => {
|
||||
this.isFullScreen = true
|
||||
}))
|
||||
|
||||
electron.ipcRenderer.on('host:window-leave-full-screen', () => this.zone.run(() => {
|
||||
this.isFullScreen = false
|
||||
}))
|
||||
|
||||
electron.ipcRenderer.on('host:window-shown', () => {
|
||||
this.zone.run(() => this.shown.emit())
|
||||
})
|
||||
@@ -163,11 +154,6 @@ export class HostAppService {
|
||||
this.electron.ipcRenderer.send('app:new-window')
|
||||
}
|
||||
|
||||
toggleFullscreen (): void {
|
||||
const window = this.getWindow()
|
||||
window.setFullScreen(!this.isFullScreen)
|
||||
}
|
||||
|
||||
openDevTools (): void {
|
||||
this.getWindow().webContents.openDevTools({ mode: 'undocked' })
|
||||
}
|
||||
@@ -176,22 +162,6 @@ export class HostAppService {
|
||||
this.electron.ipcRenderer.send('window-focus')
|
||||
}
|
||||
|
||||
minimize (): void {
|
||||
this.electron.ipcRenderer.send('window-minimize')
|
||||
}
|
||||
|
||||
maximize (): void {
|
||||
this.electron.ipcRenderer.send('window-maximize')
|
||||
}
|
||||
|
||||
unmaximize (): void {
|
||||
this.electron.ipcRenderer.send('window-unmaximize')
|
||||
}
|
||||
|
||||
toggleMaximize (): void {
|
||||
this.electron.ipcRenderer.send('window-toggle-maximize')
|
||||
}
|
||||
|
||||
setBounds (bounds: Bounds): void {
|
||||
this.electron.ipcRenderer.send('window-set-bounds', bounds)
|
||||
}
|
||||
@@ -200,10 +170,6 @@ export class HostAppService {
|
||||
this.electron.ipcRenderer.send('window-set-always-on-top', flag)
|
||||
}
|
||||
|
||||
setTitle (title?: string): void {
|
||||
this.electron.ipcRenderer.send('window-set-title', title ?? 'Terminus')
|
||||
}
|
||||
|
||||
setTouchBar (touchBar: TouchBar): void {
|
||||
this.getWindow().setTouchBar(touchBar)
|
||||
}
|
||||
@@ -223,10 +189,6 @@ export class HostAppService {
|
||||
this.electron.ipcRenderer.send('window-bring-to-front')
|
||||
}
|
||||
|
||||
closeWindow (): void {
|
||||
this.electron.ipcRenderer.send('window-close')
|
||||
}
|
||||
|
||||
registerGlobalHotkey (specs: string[]): void {
|
||||
this.electron.ipcRenderer.send('app:register-global-hotkey', specs)
|
||||
}
|
||||
|
Reference in New Issue
Block a user