Skip to content

Commit

Permalink
tms(flask): 長押しによるコンテキストメニューイベントの発行を防ぐ
Browse files Browse the repository at this point in the history
  • Loading branch information
taiyme committed May 26, 2024
1 parent bd1825e commit 5870023
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 1 deletion.
10 changes: 10 additions & 0 deletions locales/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10178,6 +10178,16 @@ export interface Locale extends ILocale {
* {x}を開く
*/
readonly "openX": ParameterizedString<"x">;
readonly "_preventLongPressContextMenu": {
/**
* 長押しによるコンテキストメニューイベントの発行を防ぐ
*/
readonly "label": string;
/**
* 長押しを含む操作が中断される問題を解消します。
*/
readonly "caption": string;
};
};
readonly "_admin": {
/**
Expand Down
3 changes: 3 additions & 0 deletions locales/ja-JP.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2713,5 +2713,8 @@ _tms:
warning: "これらの設定を有効にすると、ページの表示や挙動に深刻な影響を及ぼし、{name}が正常に利用できなくなる可能性があります。"
forceFetchX: "{x}を強制取得"
openX: "{x}を開く"
_preventLongPressContextMenu:
label: "長押しによるコンテキストメニューイベントの発行を防ぐ"
caption: "長押しを含む操作が中断される問題を解消します。"
_admin:
repositoryUrlDescription: "ソースコードが公開されているリポジトリがある場合、そのURLを記入します。taiymeを現状のまま(ソースコードにいかなる変更も加えずに)使用している場合は https://github.com/taiyme/misskey と記入します。"
6 changes: 6 additions & 0 deletions packages/frontend/src/boot/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { fetchCustomEmojis } from '@/custom-emojis.js';
import { setupRouter } from '@/router/definition.js';
import { tmsFlaskStore } from '@/tms/flask-store.js';
import { tmsStore } from '@/tms/store.js';
import { preventLongPressContextMenu } from '@/scripts/tms/prevent-longpress-contextmenu.js';

export async function common(createVue: () => App<Element>) {
console.info(`taiyme v${version}`);
Expand Down Expand Up @@ -123,6 +124,11 @@ export async function common(createVue: () => App<Element>) {
await tmsStore.ready;
await tmsFlaskStore.ready;

// 長押しのコンテキストメニューを無効化
if (tmsFlaskStore.state.preventLongPressContextMenu) {
preventLongPressContextMenu();
}

const fetchInstanceMetaPromise = fetchInstance();

fetchInstanceMetaPromise.then(() => {
Expand Down
16 changes: 15 additions & 1 deletion packages/frontend/src/pages/tms/flags/index.main.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ SPDX-License-Identifier: AGPL-3.0-only

<template>
<div class="_gaps_m">
<FormSection>
<div class="_gaps">
<MkSwitch v-model="preventLongPressContextMenu">
<template #label>{{ i18n.ts._tms._flags._preventLongPressContextMenu.label }}</template>
<template #caption>{{ i18n.ts._tms._flags._preventLongPressContextMenu.caption }}</template>
</MkSwitch>
</div>
</FormSection>
<FormSection>
<template #label>For developer</template>
<div class="_gaps_s">
Expand All @@ -27,14 +35,20 @@ SPDX-License-Identifier: AGPL-3.0-only
</template>

<script lang="ts" setup>
import { defineAsyncComponent, readonly, ref, watch } from 'vue';
import { computed, defineAsyncComponent, readonly, ref, watch } from 'vue';
import { commitHash, lang, version } from '@/config.js';
import { i18n } from '@/i18n.js';
import { miLocalStorage } from '@/local-storage.js';
import { confirm, popup, waiting } from '@/os.js';
import { tmsFlaskStore } from '@/tms/flask-store.js';
import FormSection from '@/components/form/section.vue';
import MkButton from '@/components/MkButton.vue';
import MkFolder from '@/components/MkFolder.vue';
import MkSwitch from '@/components/MkSwitch.vue';
//#region 即時変更
const preventLongPressContextMenu = computed(tmsFlaskStore.makeGetterSetter('preventLongPressContextMenu'));
//#endregion
const confirmDialog = async (): Promise<boolean> => {
const { canceled } = await confirm({
Expand Down
39 changes: 39 additions & 0 deletions packages/frontend/src/scripts/tms/prevent-longpress-contextmenu.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* SPDX-FileCopyrightText: syuilo and misskey-project
* SPDX-License-Identifier: AGPL-3.0-only
*/

export const preventLongPressContextMenu = () => {
let touching = false;
let timerId: number | null = null;

const onTouchStart = () => {
if (timerId != null) {
window.clearTimeout(timerId);
timerId = null;
}
timerId = window.setTimeout(() => {
touching = true;
timerId = null;
}, 100);
};

const onTouchEnd = () => {
if (timerId != null) {
window.clearTimeout(timerId);
timerId = null;
}
touching = false;
};

document.addEventListener('touchstart', onTouchStart, { passive: true, capture: true });
document.addEventListener('touchend', onTouchEnd, { passive: true, capture: true });
document.addEventListener('touchcancel', onTouchEnd, { passive: true, capture: true });
document.addEventListener('click', onTouchEnd, { passive: true, capture: true });
document.addEventListener('contextmenu', (ev) => {
if (touching) {
ev.preventDefault();
ev.stopPropagation();
}
}, { passive: false, capture: true });
};
4 changes: 4 additions & 0 deletions packages/frontend/src/tms/flask-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,8 @@ import { Storage } from '@/pizzax.js';
* tmsFlaskStore -- 独自実装した実験的機能についてのデータを格納する
*/
export const tmsFlaskStore = markRaw(new Storage('tmsFlask', {
preventLongPressContextMenu: {
where: 'device',
default: true,
},
}));

0 comments on commit 5870023

Please sign in to comment.