Skip to content

Sync-in · Sovereign platform for file storage, sharing, synchronization, and collaboration.

fix(frontend:files): prevent unintended browsing during mobile selection

johaven717d080d9fa1
diff --git a/frontend/src/app/applications/spaces/components/spaces-browser.component.html b/frontend/src/app/applications/spaces/components/spaces-browser.component.html
index 330dc3c9..17faf798 100644
--- a/frontend/src/app/applications/spaces/components/spaces-browser.component.html
+++ b/frontend/src/app/applications/spaces/components/spaces-browser.component.html
@@ -290,7 +290,7 @@
@for (f of scrollView?.viewPortItems; track f.id) {
<div (click)="onSelect($event, f)"
(contextmenu)="onTargetContextMenu($event, f)"
- (appTap)="onFileActivate(f)"
+ (appTap)="onFileActivate(f, $event.sourceEvent)"
[singleTapOnTouch]="true"
[class.disabled]="f.isDisabled"
[class.deleted]="f.isBeingDeleted"
@@ -463,7 +463,7 @@
@for (f of scrollView?.viewPortItems; track f.id) {
<tr (click)="onSelect($event, f)"
(contextmenu)="onTargetContextMenu($event, f)"
- (appTap)="onFileActivate(f)"
+ (appTap)="onFileActivate(f, $event.sourceEvent)"
[singleTapOnTouch]="true"
[class.disabled]="f.isDisabled"
[class.deleted]="f.isBeingDeleted"
diff --git a/frontend/src/app/applications/spaces/components/spaces-browser.component.ts b/frontend/src/app/applications/spaces/components/spaces-browser.component.ts
index 80d1d951..4f8da285 100644
--- a/frontend/src/app/applications/spaces/components/spaces-browser.component.ts
+++ b/frontend/src/app/applications/spaces/components/spaces-browser.component.ts
@@ -436,14 +436,26 @@ export class SpacesBrowserComponent implements OnInit, AfterViewInit, OnDestroy
this.layout.openContextMenu(ev, this.fileContextMenu)
}
- onFileActivate(file: FileModel) {
- this.layout.closeContextMenu()
- if (this.selection.length !== 1 || this.selection[0] !== file) {
+ onFileActivate(file: FileModel, sourceEvent?: PointerEvent) {
+ const multiSelectionWasActive = this.showSelectionChecks
+ const selectOnly = this.closeOpenContextMenu() || multiSelectionWasActive
+ if (multiSelectionWasActive || this.selection[0] !== file) {
this.setSelection([file], file, file)
}
+ if (selectOnly) return
+ if (sourceEvent?.pointerType === 'touch') {
+ setTimeout(() => this.browse(file), 100)
+ return
+ }
this.browse(file)
}
+ private closeOpenContextMenu(): boolean {
+ if (!this.mainContextMenu.isOpen && !this.mainReadOnlyContextMenu.isOpen && !this.fileContextMenu.isOpen) return false
+ this.layout.closeContextMenu()
+ return true
+ }
+
browse(file: FileModel) {
if (file.isDisabled) {
this.layout.sendNotification('warning', file.name, 'Share is disabled')
diff --git a/frontend/src/app/common/directives/tap.directive.ts b/frontend/src/app/common/directives/tap.directive.ts
index 94480bce..8ce236f9 100644
--- a/frontend/src/app/common/directives/tap.directive.ts
+++ b/frontend/src/app/common/directives/tap.directive.ts
@@ -1,4 +1,5 @@
-import { Directive, ElementRef, EventEmitter, inject, Input, NgZone, OnDestroy, Output } from '@angular/core'
+import { DOCUMENT, isPlatformBrowser } from '@angular/common'
+import { DestroyRef, Directive, ElementRef, EventEmitter, inject, Injectable, Input, NgZone, OnDestroy, Output, PLATFORM_ID } from '@angular/core'
type TapKind = 'single' | 'double'
interface TapEvent {
@@ -8,6 +9,41 @@ interface TapEvent {
sourceEvent?: PointerEvent
}
+@Injectable({ providedIn: 'root' })
+class TapGhostClickGuard {
+ private readonly document = inject(DOCUMENT)
+ private readonly destroyRef = inject(DestroyRef)
+ private readonly zone = inject(NgZone)
+ private readonly isBrowser = isPlatformBrowser(inject(PLATFORM_ID))
+ private readonly duration = 400
+ private readonly slop = 24
+ private blockedUntil = 0
+ private x = 0
+ private y = 0
+
+ constructor() {
+ if (!this.isBrowser) return
+ this.zone.runOutsideAngular(() => {
+ this.document.addEventListener('click', this.onClick, { capture: true, passive: false })
+ })
+ this.destroyRef.onDestroy(() => this.document.removeEventListener('click', this.onClick, true))
+ }
+
+ arm(event: PointerEvent) {
+ this.blockedUntil = performance.now() + this.duration
+ this.x = event.clientX
+ this.y = event.clientY
+ }
+
+ private onClick = (event: MouseEvent) => {
+ if (performance.now() >= this.blockedUntil || Math.hypot(event.clientX - this.x, event.clientY - this.y) > this.slop) return
+
+ this.blockedUntil = 0
+ event.preventDefault()
+ event.stopImmediatePropagation()
+ }
+}
+
@Directive({
selector: '[appTap]',
standalone: true,
@@ -47,6 +83,7 @@ export class TapDirective implements OnDestroy {
private readonly elRef = inject<ElementRef<HTMLElement>>(ElementRef as any)
private readonly zone = inject(NgZone)
+ private readonly ghostClickGuard = inject(TapGhostClickGuard)
private el: HTMLElement
private removeFns: (() => void)[] = []
private active = false
@@ -233,6 +270,9 @@ export class TapDirective implements OnDestroy {
}
private emit(type: TapKind, x: number, y: number, sourceEvent?: PointerEvent) {
+ if (this.preventGhostClick && sourceEvent?.pointerType === 'touch') {
+ this.ghostClickGuard.arm(sourceEvent)
+ }
this.lastEmitTs = performance.now()
this.zone.run(() => this.appTap.emit({ x, y, type, sourceEvent }))
}