Skip to content

Commit 63d51e9

Browse files
committed
Introduce vibrateIfPossible into the utils package. This will check if the browser
has support for vibrating. This fixes a number of bugs for iOS safari & friends.
1 parent 6f02912 commit 63d51e9

12 files changed

+34
-24
lines changed

src/lib/components/AccordionContainer.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import {cubicIn} from 'svelte/easing';
1313
import { flip } from 'svelte/animate';
1414
import { type ContainerLayout, type WidgetLayout, type IDragItem } from "$lib/stores/layoutStates";
15-
import { startDrag, stopDrag } from "$lib/utils"
15+
import { startDrag, stopDrag, vibrateIfPossible } from "$lib/utils"
1616
import { writable, type Writable } from "svelte/store";
1717
import { isHidden } from "$lib/widgets/utils";
1818
import { handleContainerConsider, handleContainerFinalize } from "./utils";
@@ -56,7 +56,7 @@
5656
};
5757
5858
function handleClick(e: CustomEvent<boolean>) {
59-
navigator.vibrate(20)
59+
vibrateIfPossible(20)
6060
$isOpen = e.detail
6161
}
6262

src/lib/components/TabsContainer.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import {cubicIn} from 'svelte/easing';
1313
import { flip } from 'svelte/animate';
1414
import { type ContainerLayout, type WidgetLayout, type IDragItem, type WritableLayoutStateStore } from "$lib/stores/layoutStates";
15-
import { startDrag, stopDrag } from "$lib/utils"
15+
import { startDrag, stopDrag, vibrateIfPossible } from "$lib/utils"
1616
import type { Writable } from "svelte/store";
1717
import { isHidden } from "$lib/widgets/utils";
1818
import { handleContainerConsider, handleContainerFinalize } from "./utils";
@@ -62,7 +62,7 @@
6262
}
6363
6464
function handleSelect() {
65-
navigator.vibrate(20)
65+
vibrateIfPossible(20)
6666
}
6767
6868
function _startDrag(e: MouseEvent | TouchEvent) {

src/lib/utils.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -828,3 +828,9 @@ const MOBILE_USER_AGENTS = ["iPhone", "iPad", "Android", "BlackBerry", "WebOs"].
828828
export function isMobileBrowser(userAgent: string): boolean {
829829
return MOBILE_USER_AGENTS.some(a => userAgent.match(a))
830830
}
831+
832+
export function vibrateIfPossible(strength: number | Array<number>) {
833+
if (window.navigator.vibrate) {
834+
window.navigator.vibrate(strength);
835+
}
836+
}

src/lib/widgets/ButtonWidget.svelte

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import { Button } from "@gradio/button";
44
import { get, type Writable, writable } from "svelte/store";
55
import { isDisabled } from "./utils"
6+
import { vibrateIfPossible } from "$lib/utils";
67
import type { ComfyButtonNode } from "$lib/nodes/widgets";
78
89
export let widget: WidgetLayout | null = null;
@@ -24,7 +25,7 @@
2425
2526
function onClick(e: MouseEvent) {
2627
node.onClick();
27-
navigator.vibrate(20)
28+
vibrateIfPossible(20)
2829
}
2930
3031
const style = {

src/lib/widgets/CheckboxWidget.svelte

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@
44
import { Checkbox } from "@gradio/form";
55
import { get, type Writable, writable } from "svelte/store";
66
import { isDisabled } from "./utils"
7+
import { vibrateIfPossible } from "$lib/utils";
78
import type { SelectData } from "@gradio/utils";
89
import type { ComfyCheckboxNode } from "$lib/nodes/widgets";
910
1011
export let widget: WidgetLayout | null = null;
1112
export let isMobile: boolean = false;
1213
let node: ComfyCheckboxNode | null = null;
1314
let nodeValue: Writable<boolean> | null = null;
14-
let attrsChanged: Writable<number> | null = null;
15+
let attrsChanged: Wrivtable<number> | null = null;
1516
1617
$: widget && setNodeValue(widget);
1718
@@ -25,7 +26,7 @@
2526
2627
function onSelect(e: CustomEvent<SelectData>) {
2728
$nodeValue = e.detail.selected
28-
navigator.vibrate(20)
29+
vibrateIfPossible(20)
2930
}
3031
</script>
3132

src/lib/widgets/ComboWidget.svelte

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import { type WidgetLayout } from "$lib/stores/layoutStates";
99
import { get, writable, type Writable } from "svelte/store";
1010
import { isDisabled } from "./utils"
11-
import { clamp, getSafetensorsMetadata } from '$lib/utils';
11+
import { clamp, getSafetensorsMetadata, vibrateIfPossible } from '$lib/utils';
1212
export let widget: WidgetLayout | null = null;
1313
export let isMobile: boolean = false;
1414
let node: ComfyComboNode | null = null;
@@ -70,7 +70,7 @@
7070
function onFocus() {
7171
// console.warn("FOCUS")
7272
if (listOpen) {
73-
navigator.vibrate(20)
73+
vibrateIfPossible(20)
7474
}
7575
}
7676
@@ -86,7 +86,7 @@
8686
8787
function handleSelect(index: number) {
8888
// console.warn("SEL", index)
89-
navigator.vibrate(20)
89+
vibrateIfPossible(20)
9090
const item = $valuesForCombo[index]
9191
activeIndex = index;
9292
$nodeValue = item.value

src/lib/widgets/NumberWidget.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import { type WidgetLayout } from "$lib/stores/layoutStates";
44
import { Range } from "$lib/components/gradio/form";
55
import { get, type Writable } from "svelte/store";
6-
import { debounce } from "$lib/utils";
6+
import { debounce, vibrateIfPossible } from "$lib/utils";
77
import interfaceState from "$lib/stores/interfaceState";
88
import { isDisabled } from "./utils"
99
export let widget: WidgetLayout | null = null;
@@ -96,7 +96,7 @@
9696
lastDisplayValue = option;
9797
canVibrate = false;
9898
setTimeout(() => { canVibrate = true }, 30)
99-
navigator.vibrate(10)
99+
vibrateIfPossible(10)
100100
}
101101
}
102102
</script>

src/lib/widgets/RadioWidget.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import { get, type Writable, writable } from "svelte/store";
66
import { isDisabled } from "./utils"
77
import type { SelectData } from "@gradio/utils";
8-
import { clamp } from "$lib/utils";
8+
import { clamp, vibrateIfPossible } from "$lib/utils";
99
import type { ComfyRadioNode } from "$lib/nodes/widgets";
1010
1111
export let widget: WidgetLayout | null = null;
@@ -34,7 +34,7 @@
3434
function onSelect(e: CustomEvent<SelectData>) {
3535
node.setValue(e.detail.value)
3636
node.index = e.detail.index as number
37-
navigator.vibrate(20)
37+
vibrateIfPossible(20)
3838
}
3939
</script>
4040

src/mobile/GenToolbar.svelte

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<script lang="ts">
22
import ComfyApp, { type SerializedAppState } from "$lib/components/ComfyApp";
33
import workflowState, { ComfyBoxWorkflow } from "$lib/stores/workflowState";
4+
import { vibrateIfPossible } from "$lib/utils";
45
56
import { Link, Toolbar } from "framework7-svelte"
67
@@ -11,7 +12,7 @@
1112
$: workflow = $workflowState.activeWorkflow;
1213
1314
function queuePrompt() {
14-
navigator.vibrate(20)
15+
vibrateIfPossible(20)
1516
app.runDefaultQueueAction()
1617
}
1718
</script>

src/mobile/MainToolbar.svelte

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import ComfyApp, { type SerializedAppState } from "$lib/components/ComfyApp";
33
import queueState from "$lib/stores/queueState";
44
import workflowState, { ComfyBoxWorkflow } from "$lib/stores/workflowState";
5-
import { getNodeInfo } from "$lib/utils"
5+
import { getNodeInfo, vibrateIfPossible } from "$lib/utils"
66
import { LayoutTextSidebarReverse, Image, Grid } from "svelte-bootstrap-icons";
77
88
import { Link, Toolbar } from "framework7-svelte"
@@ -21,28 +21,28 @@
2121
$: workflow = $workflowState.activeWorkflow;
2222
2323
function queuePrompt() {
24-
navigator.vibrate(20)
24+
vibrateIfPossible(20)
2525
app.runDefaultQueueAction()
2626
}
2727
2828
async function refreshCombos() {
29-
navigator.vibrate(20)
29+
vibrateIfPossible(20)
3030
await app.refreshComboInNodes()
3131
}
3232
3333
function doSave(): void {
3434
if (!fileInput)
3535
return;
3636
37-
navigator.vibrate(20)
37+
vibrateIfPossible(20)
3838
app.querySave()
3939
}
4040
4141
function doLoad(): void {
4242
if (!fileInput)
4343
return;
4444
45-
navigator.vibrate(20)
45+
vibrateIfPossible(20)
4646
fileInput.value = null;
4747
fileInput.click();
4848
}
@@ -52,7 +52,7 @@
5252
}
5353
5454
function doSaveLocal(): void {
55-
navigator.vibrate(20)
55+
vibrateIfPossible(20)
5656
app.saveStateToLocalStorage();
5757
}
5858

src/mobile/routes/workflow.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@
3434
}
3535
3636
async function refreshCombos() {
37-
navigator.vibrate(20)
37+
vibrateIfPossible(20)
3838
await app.refreshComboInNodes()
3939
}
4040
4141
function doSaveLocal(): void {
42-
navigator.vibrate(20)
42+
vibrateIfPossible(20)
4343
app.saveStateToLocalStorage();
4444
}
4545

src/mobile/routes/workflows.svelte

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import workflowState, { ComfyBoxWorkflow, type WorkflowInstID } from "$lib/stores/workflowState";
44
import { onMount } from "svelte";
55
import interfaceState from "$lib/stores/interfaceState";
6+
import { vibrateIfPossible } from "$lib/utils";
67
import { f7 } from 'framework7-svelte';
78
import { XCircle } from 'svelte-bootstrap-icons';
89
@@ -31,7 +32,7 @@
3132
if (!fileInput)
3233
return;
3334
34-
navigator.vibrate(20)
35+
vibrateIfPossible(20);
3536
fileInput.value = null;
3637
fileInput.click();
3738
}

0 commit comments

Comments
 (0)