forked from mirror/misskey
embedページの判定をconfig.tsに移行
This commit is contained in:
parent
1926fa304b
commit
237605d6b8
@ -7,11 +7,11 @@
|
|||||||
// よって、devモードとして起動されるときはビルド時に組み込む形としておく。
|
// よって、devモードとして起動されるときはビルド時に組み込む形としておく。
|
||||||
// (pnpm start時はpugファイルの中で静的リソースとして読み込むようになっており、この問題は起こっていない)
|
// (pnpm start時はpugファイルの中で静的リソースとして読み込むようになっており、この問題は起こっていない)
|
||||||
import '@tabler/icons-webfont/dist/tabler-icons.scss';
|
import '@tabler/icons-webfont/dist/tabler-icons.scss';
|
||||||
import { isEmbedPage } from '@/scripts/embed-page.js';
|
import { embedPage } from '@/config.js';
|
||||||
|
|
||||||
await main();
|
await main();
|
||||||
|
|
||||||
if (isEmbedPage()) {
|
if (embedPage) {
|
||||||
import('@/_embed_boot_.js');
|
import('@/_embed_boot_.js');
|
||||||
} else {
|
} else {
|
||||||
import('@/_boot_.js');
|
import('@/_boot_.js');
|
||||||
|
@ -14,7 +14,7 @@ import { apiUrl } from '@/config.js';
|
|||||||
import { waiting, popup, popupMenu, success, alert } from '@/os.js';
|
import { waiting, popup, popupMenu, success, alert } from '@/os.js';
|
||||||
import { misskeyApi } from '@/scripts/misskey-api.js';
|
import { misskeyApi } from '@/scripts/misskey-api.js';
|
||||||
import { unisonReload, reloadChannel } from '@/scripts/unison-reload.js';
|
import { unisonReload, reloadChannel } from '@/scripts/unison-reload.js';
|
||||||
import { isEmbedPage } from '@/scripts/embed-page.js';
|
import { embedPage } from '@/config.js';
|
||||||
|
|
||||||
// TODO: 他のタブと永続化されたstateを同期
|
// TODO: 他のタブと永続化されたstateを同期
|
||||||
|
|
||||||
@ -23,7 +23,7 @@ type Account = Misskey.entities.MeDetailed & { token: string };
|
|||||||
const accountData = miLocalStorage.getItem('account');
|
const accountData = miLocalStorage.getItem('account');
|
||||||
|
|
||||||
function initAccount() {
|
function initAccount() {
|
||||||
if (isEmbedPage()) return null;
|
if (embedPage) return null;
|
||||||
if (accountData) return reactive(JSON.parse(accountData) as Account);
|
if (accountData) return reactive(JSON.parse(accountData) as Account);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -85,13 +85,13 @@ export async function signout() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function getAccounts(): Promise<{ id: Account['id'], token: Account['token'] }[]> {
|
export async function getAccounts(): Promise<{ id: Account['id'], token: Account['token'] }[]> {
|
||||||
if (isEmbedPage()) return [];
|
if (embedPage) return [];
|
||||||
|
|
||||||
return (await get('accounts')) || [];
|
return (await get('accounts')) || [];
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function addAccount(id: Account['id'], token: Account['token']) {
|
export async function addAccount(id: Account['id'], token: Account['token']) {
|
||||||
if (isEmbedPage()) return;
|
if (embedPage) return;
|
||||||
|
|
||||||
const accounts = await getAccounts();
|
const accounts = await getAccounts();
|
||||||
if (!accounts.some(x => x.id === id)) {
|
if (!accounts.some(x => x.id === id)) {
|
||||||
@ -194,7 +194,7 @@ export async function refreshAccount() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function login(token: Account['token'], redirect?: string) {
|
export async function login(token: Account['token'], redirect?: string) {
|
||||||
if (isEmbedPage()) return;
|
if (embedPage) return;
|
||||||
|
|
||||||
const showing = ref(true);
|
const showing = ref(true);
|
||||||
popup(defineAsyncComponent(() => import('@/components/MkWaitingDialog.vue')), {
|
popup(defineAsyncComponent(() => import('@/components/MkWaitingDialog.vue')), {
|
||||||
|
@ -21,6 +21,7 @@ export const version = _VERSION_;
|
|||||||
export const instanceName = siteName === 'Misskey' || siteName == null ? host : siteName;
|
export const instanceName = siteName === 'Misskey' || siteName == null ? host : siteName;
|
||||||
export const ui = miLocalStorage.getItem('ui');
|
export const ui = miLocalStorage.getItem('ui');
|
||||||
export const debug = miLocalStorage.getItem('debug') === 'true';
|
export const debug = miLocalStorage.getItem('debug') === 'true';
|
||||||
|
export const embedPage = location.pathname.startsWith('/embed');
|
||||||
|
|
||||||
export function updateLocale(newLocale): void {
|
export function updateLocale(newLocale): void {
|
||||||
locale = newLocale;
|
locale = newLocale;
|
||||||
|
@ -47,20 +47,20 @@ const safeSessionStorage = new Map<Keys, string>();
|
|||||||
|
|
||||||
export const miLocalStorage = {
|
export const miLocalStorage = {
|
||||||
getItem: (key: Keys): string | null => {
|
getItem: (key: Keys): string | null => {
|
||||||
if (isEmbedPage()) {
|
if (embedPage) {
|
||||||
return safeSessionStorage.get(key) ?? null;
|
return safeSessionStorage.get(key) ?? null;
|
||||||
}
|
}
|
||||||
return window.localStorage.getItem(key);
|
return window.localStorage.getItem(key);
|
||||||
},
|
},
|
||||||
setItem: (key: Keys, value: string): void => {
|
setItem: (key: Keys, value: string): void => {
|
||||||
if (isEmbedPage()) {
|
if (embedPage) {
|
||||||
safeSessionStorage.set(key, value);
|
safeSessionStorage.set(key, value);
|
||||||
} else {
|
} else {
|
||||||
window.localStorage.setItem(key, value);
|
window.localStorage.setItem(key, value);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
removeItem: (key: Keys): void => {
|
removeItem: (key: Keys): void => {
|
||||||
if (isEmbedPage()) {
|
if (embedPage) {
|
||||||
safeSessionStorage.delete(key);
|
safeSessionStorage.delete(key);
|
||||||
} else {
|
} else {
|
||||||
window.localStorage.removeItem(key);
|
window.localStorage.removeItem(key);
|
||||||
@ -78,7 +78,7 @@ export const miLocalStorage = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
if (isEmbedPage()) {
|
if (embedPage) {
|
||||||
initEmbedPageLocalStorage();
|
initEmbedPageLocalStorage();
|
||||||
if (_DEV_) console.warn('Using safeSessionStorage as localStorage alternative');
|
if (_DEV_) console.warn('Using safeSessionStorage as localStorage alternative');
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@ import MkContextMenu from '@/components/MkContextMenu.vue';
|
|||||||
import { MenuItem } from '@/types/menu.js';
|
import { MenuItem } from '@/types/menu.js';
|
||||||
import copyToClipboard from '@/scripts/copy-to-clipboard.js';
|
import copyToClipboard from '@/scripts/copy-to-clipboard.js';
|
||||||
import { showMovedDialog } from '@/scripts/show-moved-dialog.js';
|
import { showMovedDialog } from '@/scripts/show-moved-dialog.js';
|
||||||
import { isEmbedPage } from '@/scripts/embed-page.js';
|
import { embedPage } from '@/config.js';
|
||||||
|
|
||||||
export const openingWindowsCount = ref(0);
|
export const openingWindowsCount = ref(0);
|
||||||
|
|
||||||
@ -173,7 +173,7 @@ export async function popup<T extends Component>(
|
|||||||
events: ComponentEmit<T> = {} as ComponentEmit<T>,
|
events: ComponentEmit<T> = {} as ComponentEmit<T>,
|
||||||
disposeEvent?: keyof ComponentEmit<T>,
|
disposeEvent?: keyof ComponentEmit<T>,
|
||||||
): Promise<{ dispose: () => void }> {
|
): Promise<{ dispose: () => void }> {
|
||||||
if (isEmbedPage()) return { dispose: () => {} };
|
if (embedPage) return { dispose: () => {} };
|
||||||
|
|
||||||
markRaw(component);
|
markRaw(component);
|
||||||
|
|
||||||
@ -633,7 +633,7 @@ export function popupMenu(items: MenuItem[], src?: HTMLElement | EventTarget | n
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function contextMenu(items: MenuItem[], ev: MouseEvent): Promise<void> {
|
export function contextMenu(items: MenuItem[], ev: MouseEvent): Promise<void> {
|
||||||
if (isEmbedPage()) return Promise.resolve();
|
if (embedPage) return Promise.resolve();
|
||||||
|
|
||||||
ev.preventDefault();
|
ev.preventDefault();
|
||||||
return new Promise(resolve => {
|
return new Promise(resolve => {
|
||||||
|
@ -4,17 +4,14 @@
|
|||||||
*/
|
*/
|
||||||
import { miLocalStorage } from "@/local-storage.js";
|
import { miLocalStorage } from "@/local-storage.js";
|
||||||
import type { Keys } from "@/local-storage.js";
|
import type { Keys } from "@/local-storage.js";
|
||||||
|
import { embedPage } from "@/config.js";
|
||||||
export function isEmbedPage() {
|
|
||||||
return location.pathname.startsWith('/embed');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* EmbedページではlocalStorageを使用できないようにしているが、
|
* EmbedページではlocalStorageを使用できないようにしているが、
|
||||||
* 動作に必要な値はsafeSessionStorage(miLocalStorage内のやつ)に移動する
|
* 動作に必要な値はsafeSessionStorage(miLocalStorage内のやつ)に移動する
|
||||||
*/
|
*/
|
||||||
export function initEmbedPageLocalStorage() {
|
export function initEmbedPageLocalStorage() {
|
||||||
if (!isEmbedPage()) {
|
if (!embedPage) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,12 +10,12 @@ import {
|
|||||||
set as iset,
|
set as iset,
|
||||||
del as idel,
|
del as idel,
|
||||||
} from 'idb-keyval';
|
} from 'idb-keyval';
|
||||||
import { isEmbedPage } from './embed-page.js';
|
import { embedPage } from '@/config.js';
|
||||||
import { miLocalStorage } from '@/local-storage.js';
|
import { miLocalStorage } from '@/local-storage.js';
|
||||||
|
|
||||||
const PREFIX = 'idbfallback::';
|
const PREFIX = 'idbfallback::';
|
||||||
|
|
||||||
let idbAvailable = typeof window !== 'undefined' ? !!(window.indexedDB && typeof window.indexedDB.open === 'function' && !isEmbedPage()) : true;
|
let idbAvailable = typeof window !== 'undefined' ? !!(window.indexedDB && typeof window.indexedDB.open === 'function' && !embedPage) : true;
|
||||||
|
|
||||||
// iframe.contentWindow.indexedDB.deleteDatabase() がchromeのバグで使用できないため、indexedDBを無効化している。
|
// iframe.contentWindow.indexedDB.deleteDatabase() がchromeのバグで使用できないため、indexedDBを無効化している。
|
||||||
// バグが治って再度有効化するのであれば、cypressのコマンド内のコメントアウトを外すこと
|
// バグが治って再度有効化するのであれば、cypressのコマンド内のコメントアウトを外すこと
|
||||||
|
@ -11,7 +11,7 @@ import { globalEvents } from '@/events.js';
|
|||||||
import lightTheme from '@/themes/_light.json5';
|
import lightTheme from '@/themes/_light.json5';
|
||||||
import darkTheme from '@/themes/_dark.json5';
|
import darkTheme from '@/themes/_dark.json5';
|
||||||
import { miLocalStorage } from '@/local-storage.js';
|
import { miLocalStorage } from '@/local-storage.js';
|
||||||
import { isEmbedPage } from '@/scripts/embed-page.js';
|
import { embedPage } from '@/config.js';
|
||||||
|
|
||||||
export type Theme = {
|
export type Theme = {
|
||||||
id: string;
|
id: string;
|
||||||
@ -96,7 +96,7 @@ export function applyTheme(theme: Theme, persist = true) {
|
|||||||
document.documentElement.style.setProperty(`--${k}`, v.toString());
|
document.documentElement.style.setProperty(`--${k}`, v.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isEmbedPage()) {
|
if (!embedPage) {
|
||||||
document.documentElement.style.setProperty('color-scheme', colorScheme);
|
document.documentElement.style.setProperty('color-scheme', colorScheme);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ import { markRaw } from 'vue';
|
|||||||
import { $i } from '@/account.js';
|
import { $i } from '@/account.js';
|
||||||
import { wsOrigin } from '@/config.js';
|
import { wsOrigin } from '@/config.js';
|
||||||
import { StreamMock } from '@/scripts/stream-mock.js';
|
import { StreamMock } from '@/scripts/stream-mock.js';
|
||||||
import { isEmbedPage } from '@/scripts/embed-page.js';
|
import { embedPage } from '@/config.js';
|
||||||
|
|
||||||
// heart beat interval in ms
|
// heart beat interval in ms
|
||||||
const HEART_BEAT_INTERVAL = 1000 * 60;
|
const HEART_BEAT_INTERVAL = 1000 * 60;
|
||||||
@ -21,7 +21,7 @@ export function useStream(): Misskey.IStream {
|
|||||||
if (stream) return stream;
|
if (stream) return stream;
|
||||||
|
|
||||||
// TODO: No Websocketモードもここで判定
|
// TODO: No Websocketモードもここで判定
|
||||||
if (isEmbedPage()) {
|
if (embedPage) {
|
||||||
stream = markRaw(new StreamMock(wsOrigin, null));
|
stream = markRaw(new StreamMock(wsOrigin, null));
|
||||||
return stream;
|
return stream;
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user