This commit is contained in:
tamaina 2019-04-19 13:27:34 +09:00 committed by Satsuki Yanagi
parent 0335f2a4cb
commit 9b3e54ce82
3 changed files with 18 additions and 17 deletions

View file

@ -640,8 +640,8 @@ common/views/components/emoji-picker.vue:
flags: "旗" flags: "旗"
common/views/components/settings/client-mode.vue: common/views/components/settings/client-mode.vue:
title: "クライアント" title: "モード"
select-app-type: "利用するクライアントのモード" intro: "デスクトップ版とモバイル版のどちらを使うかを指定できます。"
choices: choices:
auto: "自動で選択" auto: "自動で選択"
desktop: "デスクトップ版に固定" desktop: "デスクトップ版に固定"

View file

@ -35,12 +35,12 @@
const url = new URL(location.href); const url = new URL(location.href);
//#region Detect app name //#region Detect app name
var appType = null; window.appType = null;
if (`${url.pathname}/`.startsWith('/docs/')) appType = 'docs'; if (`${url.pathname}/`.startsWith('/docs/')) window.appType = 'docs';
if (`${url.pathname}/`.startsWith('/dev/')) appType = 'dev'; if (`${url.pathname}/`.startsWith('/dev/')) window.appType = 'dev';
if (`${url.pathname}/`.startsWith('/auth/')) appType = 'auth'; if (`${url.pathname}/`.startsWith('/auth/')) window.appType = 'auth';
if (`${url.pathname}/`.startsWith('/admin/')) appType = 'admin'; if (`${url.pathname}/`.startsWith('/admin/')) window.appType = 'admin';
//#endregion //#endregion
// Script version // Script version
@ -84,7 +84,9 @@
// Detect the user agent // Detect the user agent
const ua = navigator.userAgent.toLowerCase(); const ua = navigator.userAgent.toLowerCase();
const isMobile = /mobile|iphone|ipad|android/.test(ua) || window.innerWidth < 576; const isMobile = settings.device.appTypeForce === 'mobile' ||
(settings.device.appTypeForce !== 'desktop'
&& (/mobile|iphone|ipad|android/.test(ua) || window.innerWidth < 576));
// Get the <head> element // Get the <head> element
const head = document.getElementsByTagName('head')[0]; const head = document.getElementsByTagName('head')[0];
@ -103,15 +105,15 @@
} }
// Switch desktop or mobile version // Switch desktop or mobile version
if (appType == null) { if (window.appType == null) {
appType = isMobile ? 'mobile' : 'desktop'; window.appType = isMobile ? 'mobile' : 'desktop';
} }
// Load an app script // Load an app script
// Note: 'async' make it possible to load the script asyncly. // Note: 'async' make it possible to load the script asyncly.
// 'defer' make it possible to run the script when the dom loaded. // 'defer' make it possible to run the script when the dom loaded.
const script = document.createElement('script'); const script = document.createElement('script');
script.setAttribute('src', `/assets/${appType}.${ver}.js`); script.setAttribute('src', `/assets/${window.appType}.${ver}.js`);
script.setAttribute('async', 'true'); script.setAttribute('async', 'true');
script.setAttribute('defer', 'true'); script.setAttribute('defer', 'true');
head.appendChild(script); head.appendChild(script);

View file

@ -1,9 +1,10 @@
<template> <template>
<ui-card> <ui-card>
<template #title><fa :icon="faMobile"/> {{ $t('title') }}</template> <template #title><fa :icon="faMobileAlt"/> {{ $t('title') }}</template>
<section class="fit-top"> <section class="fit-top">
<ui-select v-model="lang" :placeholder="$t('select-app-type')"> <p>{{ $t('intro') }}</p>
<ui-select v-model="appTypeForce" :placeholder="$t('intro')">
<option v-for="x in ['auto', 'desktop', 'mobile']" :value="x" :key="x">{{ $t(`choices.${x}`) }}</option> <option v-for="x in ['auto', 'desktop', 'mobile']" :value="x" :key="x">{{ $t(`choices.${x}`) }}</option>
</ui-select> </ui-select>
<ui-info>Current: <i>{{ $t(currentAppType) }}</i></ui-info> <ui-info>Current: <i>{{ $t(currentAppType) }}</i></ui-info>
@ -15,18 +16,16 @@
<script lang="ts"> <script lang="ts">
import Vue from 'vue'; import Vue from 'vue';
import i18n from '../../../../i18n'; import i18n from '../../../../i18n';
import { langs } from '../../../../config'; import { faMobileAlt } from '@fortawesome/free-solid-svg-icons'
import { faMobile } from '@fortawesome/free-solid-svg-icons'
export default Vue.extend({ export default Vue.extend({
i18n: i18n('common/views/components/settings/client-mode.vue'), i18n: i18n('common/views/components/settings/client-mode.vue'),
data() { data() {
return { return {
langs,
currentAppType: (window as any).appType, currentAppType: (window as any).appType,
faMobile faMobileAlt
}; };
}, },