Skip to content

Commit

Permalink
[desktop]: Support image fullscreen
Browse files Browse the repository at this point in the history
  • Loading branch information
tiagohm committed Apr 24, 2024
1 parent d597fd2 commit 27f9b6a
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 2 deletions.
8 changes: 8 additions & 0 deletions desktop/app/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,14 @@ try {
return true
})

ipcMain.handle('WINDOW.FULLSCREEN', (event, enabled?: boolean) => {
const window = findWindowById(event.sender.id)?.window
if (!window) return false
const flag = enabled ?? !window.isFullScreen()
window.setFullScreen(flag)
return flag
})

ipcMain.handle('WINDOW.CLOSE', (event, data: CloseWindow<any>) => {
if (data.id) {
for (const [key, value] of browserWindows) {
Expand Down
2 changes: 1 addition & 1 deletion desktop/src/app/app.component.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<section id="titlebar" class="flex flex-row align-items-center justify-content-end gap-2 sticky pr-1"
<section *ngIf="showTopBar" id="titlebar" class="flex flex-row align-items-center justify-content-end gap-2 sticky pr-1"
[style]="{ height: '42px', zIndex: '1000', backgroundColor }">
<span class="align-items-center draggable-region flex flex-column flex-1 font-bold justify-content-center min-h-full text-center">
<div>{{ title }}</div>
Expand Down
1 change: 1 addition & 0 deletions desktop/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export class AppComponent implements AfterViewInit {
subTitle? = ''
backgroundColor = '#212121'
topMenu: ExtendedMenuItem[] = []
showTopBar = true

get title() {
return this.windowTitle.getTitle()
Expand Down
15 changes: 15 additions & 0 deletions desktop/src/app/image/image.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,11 @@ export class ImageComponent implements AfterViewInit, OnDestroy {
) {
app.title = 'Image'

app.topMenu.push({
icon: 'mdi mdi-fullscreen',
command: () => this.enterFullscreen(),
})

this.stretchShadow.subscribe(value => {
this.stretch.shadow = value / 65536
})
Expand Down Expand Up @@ -490,6 +495,8 @@ export class ImageComponent implements AfterViewInit, OnDestroy {
hotkeys('ctrl+-', (event) => { event.preventDefault(); this.zoomOut() })
hotkeys('ctrl+=', (event) => { event.preventDefault(); this.zoomIn() })
hotkeys('ctrl+0', (event) => { event.preventDefault(); this.resetZoom() })
hotkeys('f12', (event) => { if (this.app.showTopBar) { event.preventDefault(); this.enterFullscreen() } })
hotkeys('escape', (event) => { if (!this.app.showTopBar) { event.preventDefault(); this.exitFullscreen() } })

this.loadPreference()
}
Expand Down Expand Up @@ -837,6 +844,14 @@ export class ImageComponent implements AfterViewInit, OnDestroy {
this.panZoom.smoothZoomAbs(window.innerWidth / 2, window.innerHeight / 2, 1.0)
}

async enterFullscreen() {
this.app.showTopBar = !await this.electron.fullscreenWindow(true)
}

async exitFullscreen() {
this.app.showTopBar = !await this.electron.fullscreenWindow(false)
}

private async retrieveCoordinateInterpolation() {
const coordinate = await this.api.coordinateInterpolation(this.imageData.path!)

Expand Down
4 changes: 4 additions & 0 deletions desktop/src/shared/services/electron.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,10 @@ export class ElectronService {
this.send('WINDOW.MAXIMIZE')
}

fullscreenWindow(enabled?: boolean): Promise<boolean> {
return this.send('WINDOW.FULLSCREEN', enabled)
}

closeWindow<T>(data: CloseWindow<T>) {
return this.send('WINDOW.CLOSE', data)
}
Expand Down
2 changes: 1 addition & 1 deletion desktop/src/shared/types/app.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const INTERNAL_EVENT_TYPES = [
'DIRECTORY.OPEN', 'FILE.OPEN', 'FILE.SAVE', 'WINDOW.OPEN', 'WINDOW.CLOSE',
'WINDOW.PIN', 'WINDOW.UNPIN', 'WINDOW.MINIMIZE', 'WINDOW.MAXIMIZE', 'WINDOW.RESIZE',
'WHEEL.RENAMED', 'LOCATION.CHANGED', 'JSON.WRITE', 'JSON.READ',
'CALIBRATION.CHANGED'
'CALIBRATION.CHANGED', 'WINDOW.FULLSCREEN'
] as const

export type InternalEventType = (typeof INTERNAL_EVENT_TYPES)[number]
Expand Down

0 comments on commit 27f9b6a

Please sign in to comment.