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