summaryrefslogtreecommitdiff
path: root/src/client/mios.ts
diff options
context:
space:
mode:
authorsyuilo <Syuilotan@yahoo.co.jp>2020-10-17 20:12:00 +0900
committerGitHub <noreply@github.com>2020-10-17 20:12:00 +0900
commit7199e6f4e0b3a2c2bc198e689c3e0cd0d0f0354a (patch)
tree2263a06acec7fa21882366bae26d1a983ce21135 /src/client/mios.ts
parentCW の input でも投稿ショートカットが動作するように (#6690) (diff)
downloadmisskey-7199e6f4e0b3a2c2bc198e689c3e0cd0d0f0354a.tar.gz
misskey-7199e6f4e0b3a2c2bc198e689c3e0cd0d0f0354a.tar.bz2
misskey-7199e6f4e0b3a2c2bc198e689c3e0cd0d0f0354a.zip
Migrate to Vue3 (#6587)
* Update reaction.vue * fix bug * wip * wip * wjio * wip * Revert "wip" This reverts commit e427f2160adf4e8a4147006e25a89854edab0033. * wip * wip * wip * Update init.ts * Update drive-window.vue * wip * wip * Use PascalCase for components * Use PascalCase for components * update dep * wip * wip * wip * Update init.ts * wip * Update paging.ts * Update test.vue * watch deep * wip * lint * wip * wip * wip * wip * wiop * wip * Update webpack.config.ts * alllow null poll * wip * wip * wip * wiop * UI redesign & refactor (#6714) * wip * wip * wip * wip * wip * Update drive.vue * Update word-mute.vue * wip * wip * wip * clean up * wip * Update default.vue * wip * Update notes.vue * Update mfm.ts * Update index.home.vue * Update post-form.vue * Update post-form-attaches.vue * wip * Update post-form.vue * Update sidebar.vue * wip * wip * Update index.vue * wip * Update default.vue * Update index.vue * Update index.vue * wip * Update post-form-attaches.vue * Update note.vue * wip * clean up * Update notes.vue * wip * wip * Update ja-JP.yml * wip * wip * Update index.vue * wip * wip * wip * wip * wip * wip * wip * wip * Update default.vue * wip * Update _dark.json5 * wip * wip * wip * clean up * wip * wip * Update index.vue * Update test.vue * wip * wip * fix * wip * wip * wip * wip * clena yop * wip * wip * Update store.ts * Update messaging-room.vue * Update default.widgets.vue * fix * wip * wip * Update modal.vue * wip * Update os.ts * Update os.ts * Update deck.vue * Update init.ts * wip * Update ja-JP.yml * v-sizeは単にwindowのresizeを監視するだけで良いかもしれない * Update modal.vue * wip * Update tooltip.ts * wip * wip * wip * wip * wip * Update image-viewer.vue * wip * wip * Update style.scss * Update style.scss * Update visitor.vue * wip * Update init.ts * Update init.ts * wip * wip * Update visitor.vue * Update visitor.vue * Update visitor.vue * Update visitor.vue * wip * wip * Update modal.vue * Update header.vue * Update menu.vue * Update about.vue * Update about-misskey.vue * wip * wip * Update visitor.vue * Update tooltip.ts * wip * Update drive.vue * wip * Update style.scss * Update header.vue * wip * wip * Update users.user.vue * Update announcements.vue * wip * wip * wip * Update emojis.vue * wip * Update emojis.vue * Update style.scss * Update users.vue * wip * Update style.scss * wip * Update welcome.entrance.vue * Update radio.vue * Update size.ts * Update emoji-edit-dialog.vue * wip * Update emojis.vue * wip * Update emojis.vue * Update emojis.vue * Update emojis.vue * wip * wip * wip * wip * Update file-dialog.vue * wip * wip * Update token-generate-window.vue * Update notification-setting-window.vue * wip * wip * Update _error_.vue * Update ja-JP.yml * wip * wip * Update store.ts * Update emojis.vue * Update emojis.vue * Update emojis.vue * Update announcements.vue * Update store.ts * wip * Update page-editor.vue * wip * wip * Update modal.vue * wip * Update select-file.ts * Update timeline.vue * Update emojis.vue * Update os.ts * wip * Update user-select.vue * Update mfm.ts * Update get-file-info.ts * Update drive.vue * Update init.ts * Update mfm.ts * wip * wip * Update window.vue * Update note.vue * wip * wip * Update user-info.vue * wip * wip * wip * wip * wip * Update header.vue * Update header.vue * wip * Update explore.vue * wip * wip * wip * Update webpack.config.ts * wip * wip * wip * wip * wip * wip * Update autocomplete.ts * wip * wip * wip * Update toast.vue * wip * Update post-form-dialog.vue * wip * wip * wip * wip * wip * Update users.vue * wip * Update explore.vue * wip * wip * wip * Update package.json * wip * Update icon-dialog.vue * wip * wip * Update user-preview.ts * wip * wip * wip * wip * wip * Update instance.vue * Update user-name.vue * Update federation.vue * Update instance.vue * wip * wip * Update tag.vue * wip * wip * wip * wip * wip * Update instance.vue * wip * Update os.ts * Update os.ts * wip * wip * wip * Update router.ts * wip * Update init.ts * Update note.vue * Update messages.vue * wip * wip * wip * wip * wip * google * wip * wip * wip * wip * Update theme-editor.vue * wip * wip * Update room.vue * Update channel-editor.vue * wip * Update window.vue * Update window.vue * wip * Update window.vue * Update window.vue * wip * Update menu.vue * wip * wip * wip * wip * Update messaging-room.vue * wip * Update post-form.vue * Update default.widgets.vue * Update window.vue * wip
Diffstat (limited to 'src/client/mios.ts')
-rw-r--r--src/client/mios.ts236
1 files changed, 0 insertions, 236 deletions
diff --git a/src/client/mios.ts b/src/client/mios.ts
deleted file mode 100644
index efeb630d7e..0000000000
--- a/src/client/mios.ts
+++ /dev/null
@@ -1,236 +0,0 @@
-// TODO: このファイル消したい
-
-import autobind from 'autobind-decorator';
-import { EventEmitter } from 'eventemitter3';
-
-import { apiUrl, version } from './config';
-import Progress from './scripts/loading';
-
-import Stream from './scripts/stream';
-import store from './store';
-
-/**
- * Misskey Operating System
- */
-export default class MiOS extends EventEmitter {
- public store: ReturnType<typeof store>;
-
- /**
- * A connection manager of home stream
- */
- public stream: Stream;
-
- /**
- * A registration of service worker
- */
- private swRegistration: ServiceWorkerRegistration = null;
-
- constructor(vuex: MiOS['store']) {
- super();
- this.store = vuex;
- }
-
- @autobind
- public signout() {
- this.store.dispatch('logout');
- location.href = '/';
- }
-
- /**
- * Initialize MiOS (boot)
- * @param callback A function that call when initialized
- */
- @autobind
- public async init(callback) {
- const finish = () => {
- callback();
-
- this.store.dispatch('instance/fetch').then(() => {
- // Init service worker
- if (this.store.state.instance.meta.swPublickey) this.registerSw(this.store.state.instance.meta.swPublickey);
- });
- };
-
- // ユーザーをフェッチしてコールバックする
- const fetchme = (token, cb) => {
- let me = null;
-
- // Return when not signed in
- if (token == null || token === 'null') {
- return done();
- }
-
- // Fetch user
- fetch(`${apiUrl}/i`, {
- method: 'POST',
- body: JSON.stringify({
- i: token
- })
- })
- // When success
- .then(res => {
- // When failed to authenticate user
- if (res.status !== 200 && res.status < 500) {
- return this.signout();
- }
-
- // Parse response
- res.json().then(i => {
- me = i;
- me.token = token;
- done();
- });
- })
- // When failure
- .catch(() => {
- // Render the error screen
- document.body.innerHTML = '<div id="err">Oops!</div>';
-
- Progress.done();
- });
-
- function done() {
- if (cb) cb(me);
- }
- };
-
- // フェッチが完了したとき
- const fetched = () => {
- this.emit('signedin');
-
- this.initStream();
-
- // Finish init
- finish();
- };
-
- // キャッシュがあったとき
- if (this.store.state.i != null) {
- if (this.store.state.i.token == null) {
- this.signout();
- return;
- }
-
- // とりあえずキャッシュされたデータでお茶を濁して(?)おいて、
- fetched();
-
- // 後から新鮮なデータをフェッチ
- fetchme(this.store.state.i.token, freshData => {
- this.store.dispatch('mergeMe', freshData);
- });
- } else {
- // Get token from localStorage
- let i = localStorage.getItem('i');
-
- // 連携ログインの場合用にCookieを参照する
- if (i == null || i === 'null') {
- i = (document.cookie.match(/igi=(\w+)/) || [null, null])[1];
- }
-
- fetchme(i, me => {
- if (me) {
- this.store.dispatch('login', me);
- fetched();
- } else {
- this.initStream();
-
- // Finish init
- finish();
- }
- });
- }
- }
-
- @autobind
- private initStream() {
- this.stream = new Stream(this);
- }
-
- /**
- * Register service worker
- */
- @autobind
- private registerSw(swPublickey: string) {
- // Check whether service worker and push manager supported
- const isSwSupported =
- ('serviceWorker' in navigator) && ('PushManager' in window);
-
- // Reject when browser not service worker supported
- if (!isSwSupported) return;
-
- // Reject when not signed in to Misskey
- if (!this.store.getters.isSignedIn) return;
-
- // When service worker activated
- navigator.serviceWorker.ready.then(registration => {
- this.swRegistration = registration;
-
- // Options of pushManager.subscribe
- // SEE: https://developer.mozilla.org/en-US/docs/Web/API/PushManager/subscribe#Parameters
- const opts = {
- // A boolean indicating that the returned push subscription
- // will only be used for messages whose effect is made visible to the user.
- userVisibleOnly: true,
-
- // A public key your push server will use to send
- // messages to client apps via a push server.
- applicationServerKey: urlBase64ToUint8Array(swPublickey)
- };
-
- // Subscribe push notification
- this.swRegistration.pushManager.subscribe(opts).then(subscription => {
- function encode(buffer: ArrayBuffer) {
- return btoa(String.fromCharCode.apply(null, new Uint8Array(buffer)));
- }
-
- // Register
- this.store.dispatch('api', {
- endpoint: 'sw/register',
- data: {
- endpoint: subscription.endpoint,
- auth: encode(subscription.getKey('auth')),
- publickey: encode(subscription.getKey('p256dh'))
- }
- });
- })
- // When subscribe failed
- .catch(async (err: Error) => {
- // 通知が許可されていなかったとき
- if (err.name === 'NotAllowedError') {
- return;
- }
-
- // 違うapplicationServerKey (または gcm_sender_id)のサブスクリプションが
- // 既に存在していることが原因でエラーになった可能性があるので、
- // そのサブスクリプションを解除しておく
- const subscription = await this.swRegistration.pushManager.getSubscription();
- if (subscription) subscription.unsubscribe();
- });
- });
-
- // The path of service worker script
- const sw = `/sw.${version}.js`;
-
- // Register service worker
- navigator.serviceWorker.register(sw);
- }
-}
-
-/**
- * Convert the URL safe base64 string to a Uint8Array
- * @param base64String base64 string
- */
-function urlBase64ToUint8Array(base64String: string): Uint8Array {
- const padding = '='.repeat((4 - base64String.length % 4) % 4);
- const base64 = (base64String + padding)
- .replace(/-/g, '+')
- .replace(/_/g, '/');
-
- const rawData = window.atob(base64);
- const outputArray = new Uint8Array(rawData.length);
-
- for (let i = 0; i < rawData.length; ++i) {
- outputArray[i] = rawData.charCodeAt(i);
- }
- return outputArray;
-}