summaryrefslogtreecommitdiff
path: root/src/web/app
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2017-05-18 05:06:55 +0900
committersyuilo <syuilotan@yahoo.co.jp>2017-05-18 05:06:55 +0900
commitc72a07187a6cebeb343fa52201577478cd2c6a6a (patch)
treee6d50b8a986a655f16ecac43e802be4a1cbd9e59 /src/web/app
parentMerge branch 'master' of https://github.com/syuilo/misskey (diff)
downloadsharkey-c72a07187a6cebeb343fa52201577478cd2c6a6a.tar.gz
sharkey-c72a07187a6cebeb343fa52201577478cd2c6a6a.tar.bz2
sharkey-c72a07187a6cebeb343fa52201577478cd2c6a6a.zip
なんかもうめっちゃ変えた
Diffstat (limited to 'src/web/app')
-rw-r--r--src/web/app/auth/script.js6
-rw-r--r--src/web/app/auth/view.pug5
-rw-r--r--src/web/app/base.pug6
-rw-r--r--src/web/app/boot.js197
-rw-r--r--src/web/app/client/script.js29
-rw-r--r--src/web/app/client/view.pug5
-rw-r--r--src/web/app/desktop/script.js6
-rw-r--r--src/web/app/dev/script.js6
-rw-r--r--src/web/app/dev/view.pug4
-rw-r--r--src/web/app/init.js186
-rw-r--r--src/web/app/mobile/script.js6
11 files changed, 226 insertions, 230 deletions
diff --git a/src/web/app/auth/script.js b/src/web/app/auth/script.js
index 19391b2b9e..fe7f9befe8 100644
--- a/src/web/app/auth/script.js
+++ b/src/web/app/auth/script.js
@@ -7,14 +7,14 @@ import './style.styl';
import * as riot from 'riot';
require('./tags');
-import boot from '../boot';
+import init from '../init';
document.title = 'Misskey | アプリの連携';
/**
- * Boot
+ * init
*/
-boot(me => {
+init(me => {
mount(document.createElement('mk-index'));
});
diff --git a/src/web/app/auth/view.pug b/src/web/app/auth/view.pug
deleted file mode 100644
index afa1e408f8..0000000000
--- a/src/web/app/auth/view.pug
+++ /dev/null
@@ -1,5 +0,0 @@
-extends ../base
-
-block head
- meta(name='viewport' content='width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no')
- script(src=`/assets/auth.${version}.ja.js` async defer)
diff --git a/src/web/app/base.pug b/src/web/app/base.pug
index 912157a2e8..fd57f55931 100644
--- a/src/web/app/base.pug
+++ b/src/web/app/base.pug
@@ -9,11 +9,15 @@ html
meta(name='application-name' content='Misskey')
meta(name='theme-color' content=themeColor)
meta(name='referrer' content='origin')
+
title Misskey
+
style
include ./../../../built/web/assets/init.css
+ script
+ include ./../../../built/web/assets/boot.js
+
script(src='https://use.fontawesome.com/22aba0df4f.js' async)
- block head
body
noscript: p
diff --git a/src/web/app/boot.js b/src/web/app/boot.js
index 242df13c77..4df44ed793 100644
--- a/src/web/app/boot.js
+++ b/src/web/app/boot.js
@@ -1,186 +1,35 @@
/**
- * boot loader
+ * MISSKEY ENTRY POINT
*/
-"use strict";
+const Url = new URL(location.href);
-import * as riot from 'riot';
-import api from './common/scripts/api';
-import signout from './common/scripts/signout';
-import checkForUpdate from './common/scripts/check-for-update';
-import mixin from './common/mixins';
-import generateDefaultUserdata from './common/scripts/generate-default-userdata';
-import CONFIG from './common/scripts/config';
-require('./common/tags');
+let app = Url.host.split('.')[0];
-/**
- * MISSKEY ENTRY POINT!
- */
-
-console.info(`Misskey v${VERSION}`);
-
-document.domain = CONFIG.host;
+// Detect user language
+let lang = navigator.language.split('-')[0];
+if (!/^(en|ja)$/.test(lang)) lang = 'en';
-// Set global configuration
-riot.mixin({ CONFIG });
-
-// ↓ NodeList、HTMLCollection、FileList、DataTransferItemListで forEach を使えるようにする
-if (NodeList.prototype.forEach === undefined) {
- NodeList.prototype.forEach = Array.prototype.forEach;
-}
-if (HTMLCollection.prototype.forEach === undefined) {
- HTMLCollection.prototype.forEach = Array.prototype.forEach;
-}
-if (FileList.prototype.forEach === undefined) {
- FileList.prototype.forEach = Array.prototype.forEach;
-}
-if (window.DataTransferItemList && DataTransferItemList.prototype.forEach === undefined) {
- DataTransferItemList.prototype.forEach = Array.prototype.forEach;
-}
+// Detect user agent
+const ua = navigator.userAgent.toLowerCase();
+const isMobile = /mobile|iphone|ipad|android/.test(ua);
-// iOSでプライベートモードだとlocalStorageが使えないので既存のメソッドを上書きする
-try {
- localStorage.setItem('kyoppie', 'yuppie');
-} catch (e) {
- Storage.prototype.setItem = () => { }; // noop
-}
+const head = document.getElementsByTagName('head')[0];
-// クライアントを更新すべきならする
-if (localStorage.getItem('should-refresh') == 'true') {
- localStorage.removeItem('should-refresh');
- location.reload(true);
+if (isMobile) {
+ const meta = document.createElement('meta');
+ meta.setAttribute('name', 'viewport');
+ meta.setAttribute('content', 'width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no');
+ head.appendChild(meta);
}
-// 更新チェック
-setTimeout(checkForUpdate, 3000);
-
-// ユーザーをフェッチしてコールバックする
-export default callback => {
- // Get cached account data
- let cachedMe = JSON.parse(localStorage.getItem('me'));
-
- if (cachedMe) {
- fetched(cachedMe);
-
- // 後から新鮮なデータをフェッチ
- fetchme(cachedMe.token, freshData => {
- Object.assign(cachedMe, freshData);
- cachedMe.trigger('updated');
- });
- } else {
- // Get token from cookie
- const i = (document.cookie.match(/i=(!\w+)/) || [null, null])[1];
-
- fetchme(i, fetched);
- }
-
- // フェッチが完了したとき
- function fetched(me) {
- if (me) {
- riot.observable(me);
-
- // この me オブジェクトを更新するメソッド
- me.update = data => {
- if (data) Object.assign(me, data);
- me.trigger('updated');
- };
-
- // ローカルストレージにキャッシュ
- localStorage.setItem('me', JSON.stringify(me));
-
- me.on('updated', () => {
- // キャッシュ更新
- localStorage.setItem('me', JSON.stringify(me));
- });
- }
-
- // ミックスイン初期化
- mixin(me);
-
- // ローディング画面クリア
- const ini = document.getElementById('ini');
- ini.parentNode.removeChild(ini);
-
- // アプリ基底要素マウント
- const app = document.createElement('div');
- app.setAttribute('id', 'app');
- document.body.appendChild(app);
-
- try {
- callback(me);
- } catch (e) {
- panic(e);
- }
- }
-};
-
-// ユーザーをフェッチしてコールバックする
-function fetchme(token, cb) {
- let me = null;
-
- // Return when not signed in
- if (token == null) {
- return done();
- }
-
- // Fetch user
- fetch(`${CONFIG.apiUrl}/i`, {
- method: 'POST',
- body: JSON.stringify({
- i: token
- })
- }).then(res => { // When success
- // When failed to authenticate user
- if (res.status !== 200) {
- return signout();
- }
-
- res.json().then(i => {
- me = i;
- me.token = token;
-
- // initialize it if user data is empty
- me.data ? done() : init();
- });
- }, () => { // When failure
- // Display error screen
- riot.mount(document.body.appendChild(
- document.createElement('mk-error')));
- });
-
- function done() {
- if (cb) cb(me);
- }
-
- // Initialize user data
- function init() {
- const data = generateDefaultUserdata();
- api(token, 'i/appdata/set', {
- data
- }).then(() => {
- me.data = data;
- done();
- });
- }
+if (app == 'misskey') {
+ app = isMobile ? 'mobile' : 'desktop';
}
-// BSoD
-function panic(e) {
- console.error(e);
-
- // Display blue screen
- document.body.innerHTML =
- `<div id="error">
- <h1>:( 致命的な問題が発生しました。</h1>
- <p>お使いのブラウザ(またはOS)のバージョンを更新すると解決する可能性があります。</p>
- <hr>
- <p>エラーコード: ${e.toString()}</p>
- <p>ブラウザ バージョン: ${navigator.userAgent}</p>
- <p>クライアント バージョン: ${VERSION}</p>
- <hr>
- <p>問題が解決しない場合は、上記の情報をお書き添えの上 syuilotan@yahoo.co.jp までご連絡ください。</p>
- <p>Thank you for using Misskey.</p>
- </div>`;
-
- // TODO: Report the bug
-}
+// Load app script
+const script = document.createElement('script');
+script.setAttribute('src', `/assets/${app}.${VERSION}.${lang}.js`);
+script.setAttribute('async', 'true');
+script.setAttribute('defer', 'true');
+head.appendChild(script);
diff --git a/src/web/app/client/script.js b/src/web/app/client/script.js
deleted file mode 100644
index 465d3edb38..0000000000
--- a/src/web/app/client/script.js
+++ /dev/null
@@ -1,29 +0,0 @@
-/**
- * MISSKEY CLIENT ENTRY POINT
- */
-
-const head = document.getElementsByTagName('head')[0];
-
-// Detect user language
-let lang = navigator.language.split('-')[0];
-if (!/^(en|ja)$/.test(lang)) lang = 'en';
-
-// Detect user agent
-const ua = navigator.userAgent.toLowerCase();
-const isMobile = /mobile|iphone|ipad|android/.test(ua);
-
-const app = isMobile ? 'mobile' : 'desktop';
-
-// Load app script
-const script = document.createElement('script');
-script.setAttribute('src', `/assets/${app}.${VERSION}.${lang}.js`);
-script.setAttribute('async', 'true');
-script.setAttribute('defer', 'true');
-head.appendChild(script);
-
-if (isMobile) {
- const meta = document.createElement('meta');
- meta.setAttribute('name', 'viewport');
- meta.setAttribute('content', 'width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no');
- head.appendChild(meta);
-}
diff --git a/src/web/app/client/view.pug b/src/web/app/client/view.pug
deleted file mode 100644
index 3441631cd7..0000000000
--- a/src/web/app/client/view.pug
+++ /dev/null
@@ -1,5 +0,0 @@
-extends ../base
-
-block head
- script
- include ./../../../../built/web/assets/client/script.js
diff --git a/src/web/app/desktop/script.js b/src/web/app/desktop/script.js
index af986b53bd..b3691f7ff2 100644
--- a/src/web/app/desktop/script.js
+++ b/src/web/app/desktop/script.js
@@ -8,14 +8,14 @@ import './style.styl';
require('./tags');
require('./mixins');
import * as riot from 'riot';
-import boot from '../boot';
+import init from '../init';
import route from './router';
import fuckAdBlock from './scripts/fuck-ad-block';
/**
- * Boot
+ * init
*/
-boot(me => {
+init(me => {
/**
* Fuck AD Block
*/
diff --git a/src/web/app/dev/script.js b/src/web/app/dev/script.js
index 38e864af0b..32f0285e17 100644
--- a/src/web/app/dev/script.js
+++ b/src/web/app/dev/script.js
@@ -6,13 +6,13 @@
import './style.styl';
require('./tags');
-import boot from '../boot';
+import init from '../init';
const route = require('./router');
/**
- * Boot
+ * init
*/
-boot(me => {
+init(me => {
// Start routing
route(me);
});
diff --git a/src/web/app/dev/view.pug b/src/web/app/dev/view.pug
deleted file mode 100644
index 1a9a0e5bbd..0000000000
--- a/src/web/app/dev/view.pug
+++ /dev/null
@@ -1,4 +0,0 @@
-extends ../base
-
-block head
- script(src=`/assets/dev.${version}.js` async defer)
diff --git a/src/web/app/init.js b/src/web/app/init.js
new file mode 100644
index 0000000000..e480b2b774
--- /dev/null
+++ b/src/web/app/init.js
@@ -0,0 +1,186 @@
+/**
+ * App initializer
+ */
+
+"use strict";
+
+import * as riot from 'riot';
+import api from './common/scripts/api';
+import signout from './common/scripts/signout';
+import checkForUpdate from './common/scripts/check-for-update';
+import mixin from './common/mixins';
+import generateDefaultUserdata from './common/scripts/generate-default-userdata';
+import CONFIG from './common/scripts/config';
+require('./common/tags');
+
+/**
+ * APP ENTRY POINT!
+ */
+
+console.info(`Misskey v${VERSION}`);
+
+document.domain = CONFIG.host;
+
+// Set global configuration
+riot.mixin({ CONFIG });
+
+// ↓ NodeList、HTMLCollection、FileList、DataTransferItemListで forEach を使えるようにする
+if (NodeList.prototype.forEach === undefined) {
+ NodeList.prototype.forEach = Array.prototype.forEach;
+}
+if (HTMLCollection.prototype.forEach === undefined) {
+ HTMLCollection.prototype.forEach = Array.prototype.forEach;
+}
+if (FileList.prototype.forEach === undefined) {
+ FileList.prototype.forEach = Array.prototype.forEach;
+}
+if (window.DataTransferItemList && DataTransferItemList.prototype.forEach === undefined) {
+ DataTransferItemList.prototype.forEach = Array.prototype.forEach;
+}
+
+// iOSでプライベートモードだとlocalStorageが使えないので既存のメソッドを上書きする
+try {
+ localStorage.setItem('kyoppie', 'yuppie');
+} catch (e) {
+ Storage.prototype.setItem = () => { }; // noop
+}
+
+// クライアントを更新すべきならする
+if (localStorage.getItem('should-refresh') == 'true') {
+ localStorage.removeItem('should-refresh');
+ location.reload(true);
+}
+
+// 更新チェック
+setTimeout(checkForUpdate, 3000);
+
+// ユーザーをフェッチしてコールバックする
+export default callback => {
+ // Get cached account data
+ let cachedMe = JSON.parse(localStorage.getItem('me'));
+
+ if (cachedMe) {
+ fetched(cachedMe);
+
+ // 後から新鮮なデータをフェッチ
+ fetchme(cachedMe.token, freshData => {
+ Object.assign(cachedMe, freshData);
+ cachedMe.trigger('updated');
+ });
+ } else {
+ // Get token from cookie
+ const i = (document.cookie.match(/i=(!\w+)/) || [null, null])[1];
+
+ fetchme(i, fetched);
+ }
+
+ // フェッチが完了したとき
+ function fetched(me) {
+ if (me) {
+ riot.observable(me);
+
+ // この me オブジェクトを更新するメソッド
+ me.update = data => {
+ if (data) Object.assign(me, data);
+ me.trigger('updated');
+ };
+
+ // ローカルストレージにキャッシュ
+ localStorage.setItem('me', JSON.stringify(me));
+
+ me.on('updated', () => {
+ // キャッシュ更新
+ localStorage.setItem('me', JSON.stringify(me));
+ });
+ }
+
+ // ミックスイン初期化
+ mixin(me);
+
+ // ローディング画面クリア
+ const ini = document.getElementById('ini');
+ ini.parentNode.removeChild(ini);
+
+ // アプリ基底要素マウント
+ const app = document.createElement('div');
+ app.setAttribute('id', 'app');
+ document.body.appendChild(app);
+
+ try {
+ callback(me);
+ } catch (e) {
+ panic(e);
+ }
+ }
+};
+
+// ユーザーをフェッチしてコールバックする
+function fetchme(token, cb) {
+ let me = null;
+
+ // Return when not signed in
+ if (token == null) {
+ return done();
+ }
+
+ // Fetch user
+ fetch(`${CONFIG.apiUrl}/i`, {
+ method: 'POST',
+ body: JSON.stringify({
+ i: token
+ })
+ }).then(res => { // When success
+ // When failed to authenticate user
+ if (res.status !== 200) {
+ return signout();
+ }
+
+ res.json().then(i => {
+ me = i;
+ me.token = token;
+
+ // initialize it if user data is empty
+ me.data ? done() : init();
+ });
+ }, () => { // When failure
+ // Display error screen
+ riot.mount(document.body.appendChild(
+ document.createElement('mk-error')));
+ });
+
+ function done() {
+ if (cb) cb(me);
+ }
+
+ // Initialize user data
+ function init() {
+ const data = generateDefaultUserdata();
+ api(token, 'i/appdata/set', {
+ data
+ }).then(() => {
+ me.data = data;
+ done();
+ });
+ }
+}
+
+// BSoD
+function panic(e) {
+ console.error(e);
+
+ // Display blue screen
+ document.body.innerHTML =
+ `<div id="error">
+ <h1>:( 致命的な問題が発生しました。</h1>
+ <p>お使いのブラウザ(またはOS)のバージョンを更新すると解決する可能性があります。</p>
+ <hr>
+ <p>エラーコード: ${e.toString()}</p>
+ <p>ブラウザ バージョン: ${navigator.userAgent}</p>
+ <p>クライアント バージョン: ${VERSION}</p>
+ <hr>
+ <p>問題が解決しない場合は、上記の情報をお書き添えの上 syuilotan@yahoo.co.jp までご連絡ください。</p>
+ <p>Thank you for using Misskey.</p>
+ </div>`;
+
+ // TODO: Report the bug
+}
diff --git a/src/web/app/mobile/script.js b/src/web/app/mobile/script.js
index 22150f46ad..503e0fd673 100644
--- a/src/web/app/mobile/script.js
+++ b/src/web/app/mobile/script.js
@@ -6,13 +6,13 @@
import './style.styl';
require('./tags');
-import boot from '../boot';
+import init from '../init';
import route from './router';
/**
- * Boot
+ * init
*/
-boot(me => {
+init(me => {
// http://qiita.com/junya/items/3ff380878f26ca447f85
document.body.setAttribute('ontouchstart', '');