summaryrefslogtreecommitdiff
path: root/src/web/app/desktop/script.ts
diff options
context:
space:
mode:
authorha-dai <contact@haradai.net>2017-11-27 03:41:47 +0900
committerha-dai <contact@haradai.net>2017-11-27 03:41:47 +0900
commit6c75bc6d5188cbbf80fe1086fa0e8828f4edb873 (patch)
tree3ffedcc3a06e53269e92d2990cf0b3bb247ac04a /src/web/app/desktop/script.ts
parentMerge branch 'master' of https://github.com/syuilo/misskey (diff)
parentUpdate dependencies :rocket: (diff)
downloadmisskey-6c75bc6d5188cbbf80fe1086fa0e8828f4edb873.tar.gz
misskey-6c75bc6d5188cbbf80fe1086fa0e8828f4edb873.tar.bz2
misskey-6c75bc6d5188cbbf80fe1086fa0e8828f4edb873.zip
Merge branch 'master' of github.com:syuilo/misskey
Diffstat (limited to 'src/web/app/desktop/script.ts')
-rw-r--r--src/web/app/desktop/script.ts108
1 files changed, 108 insertions, 0 deletions
diff --git a/src/web/app/desktop/script.ts b/src/web/app/desktop/script.ts
new file mode 100644
index 0000000000..b06cb180e1
--- /dev/null
+++ b/src/web/app/desktop/script.ts
@@ -0,0 +1,108 @@
+/**
+ * Desktop Client
+ */
+
+// Style
+import './style.styl';
+
+require('./tags');
+require('./mixins');
+import * as riot from 'riot';
+import init from '../init';
+import route from './router';
+import fuckAdBlock from './scripts/fuck-ad-block';
+import MiOS from '../common/mios';
+import HomeStreamManager from '../common/scripts/streaming/home-stream-manager';
+import composeNotification from '../common/scripts/compose-notification';
+
+/**
+ * init
+ */
+init(async (mios: MiOS) => {
+ /**
+ * Fuck AD Block
+ */
+ fuckAdBlock();
+
+ /**
+ * Init Notification
+ */
+ if ('Notification' in window) {
+ // 許可を得ていなかったらリクエスト
+ if ((Notification as any).permission == 'default') {
+ await Notification.requestPermission();
+ }
+
+ if ((Notification as any).permission == 'granted') {
+ registerNotifications(mios.stream);
+ }
+ }
+
+ // Start routing
+ route(mios);
+}, true);
+
+function registerNotifications(stream: HomeStreamManager) {
+ if (stream == null) return;
+
+ if (stream.hasConnection) {
+ attach(stream.borrow());
+ }
+
+ stream.on('connected', connection => {
+ attach(connection);
+ });
+
+ function attach(connection) {
+ connection.on('drive_file_created', file => {
+ const _n = composeNotification('drive_file_created', file);
+ const n = new Notification(_n.title, {
+ body: _n.body,
+ icon: _n.icon
+ });
+ setTimeout(n.close.bind(n), 5000);
+ });
+
+ connection.on('mention', post => {
+ const _n = composeNotification('mention', post);
+ const n = new Notification(_n.title, {
+ body: _n.body,
+ icon: _n.icon
+ });
+ setTimeout(n.close.bind(n), 6000);
+ });
+
+ connection.on('reply', post => {
+ const _n = composeNotification('reply', post);
+ const n = new Notification(_n.title, {
+ body: _n.body,
+ icon: _n.icon
+ });
+ setTimeout(n.close.bind(n), 6000);
+ });
+
+ connection.on('quote', post => {
+ const _n = composeNotification('quote', post);
+ const n = new Notification(_n.title, {
+ body: _n.body,
+ icon: _n.icon
+ });
+ setTimeout(n.close.bind(n), 6000);
+ });
+
+ connection.on('unread_messaging_message', message => {
+ const _n = composeNotification('unread_messaging_message', message);
+ const n = new Notification(_n.title, {
+ body: _n.body,
+ icon: _n.icon
+ });
+ n.onclick = () => {
+ n.close();
+ (riot as any).mount(document.body.appendChild(document.createElement('mk-messaging-room-window')), {
+ user: message.user
+ });
+ };
+ setTimeout(n.close.bind(n), 7000);
+ });
+ }
+}