mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
use async / await.
This commit is contained in:
parent
aae55ea585
commit
b808530f0c
@ -143,23 +143,27 @@
|
|||||||
return this.$accessor.client.about_page
|
return this.$accessor.client.about_page
|
||||||
}
|
}
|
||||||
|
|
||||||
mounted() {
|
async Load() {
|
||||||
if (this.about === '') {
|
|
||||||
this.loading = true
|
this.loading = true
|
||||||
this.$http
|
|
||||||
.get<string>('https://raw.githubusercontent.com/m1k1o/neko/dev/README.md')
|
try {
|
||||||
.then((res) => {
|
const res = await this.$http.get<string>('https://raw.githubusercontent.com/m1k1o/neko/dev/README.md')
|
||||||
return this.$http.post('https://api.github.com/markdown', {
|
const res2 = await this.$http.post('https://api.github.com/markdown', {
|
||||||
text: res.data,
|
text: res.data,
|
||||||
mode: 'gfm',
|
mode: 'gfm',
|
||||||
context: 'github/gollum',
|
context: 'github/gollum',
|
||||||
})
|
})
|
||||||
})
|
this.$accessor.client.setAbout(res2.data)
|
||||||
.then((res) => {
|
} catch (err) {
|
||||||
this.$accessor.client.setAbout(res.data)
|
console.error(err)
|
||||||
|
} finally {
|
||||||
this.loading = false
|
this.loading = false
|
||||||
})
|
}
|
||||||
.catch((err) => console.error(err))
|
}
|
||||||
|
|
||||||
|
mounted() {
|
||||||
|
if (this.about === '') {
|
||||||
|
this.Load()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -204,23 +204,23 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async login() {
|
login() {
|
||||||
let password = this.password
|
let password = this.password
|
||||||
if (this.autoPassword !== null) {
|
if (this.autoPassword !== null) {
|
||||||
password = this.autoPassword
|
password = this.autoPassword
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
if (this.displayname == '') {
|
||||||
await this.$accessor.login({ displayname: this.displayname, password })
|
|
||||||
|
|
||||||
this.autoPassword = null
|
|
||||||
} catch (err) {
|
|
||||||
this.$swal({
|
this.$swal({
|
||||||
title: this.$t('connect.error') as string,
|
title: this.$t('connect.error') as string,
|
||||||
text: err.message,
|
text: 'Display Name cannot be empty.' as string, // TODO: Add to i18n.
|
||||||
icon: 'error',
|
icon: 'error',
|
||||||
})
|
})
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.$accessor.login({ displayname: this.displayname, password })
|
||||||
|
this.autoPassword = null
|
||||||
}
|
}
|
||||||
|
|
||||||
about() {
|
about() {
|
||||||
|
@ -165,64 +165,64 @@
|
|||||||
this.context.open(event, data)
|
this.context.open(event, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
kick(member: Member) {
|
async kick(member: Member) {
|
||||||
this.$swal({
|
const value = await this.$swal({
|
||||||
title: this.$t('context.confirm.kick_title', { name: member.displayname }) as string,
|
title: this.$t('context.confirm.kick_title', { name: member.displayname }) as string,
|
||||||
text: this.$t('context.confirm.kick_text', { name: member.displayname }) as string,
|
text: this.$t('context.confirm.kick_text', { name: member.displayname }) as string,
|
||||||
icon: 'warning',
|
icon: 'warning',
|
||||||
showCancelButton: true,
|
showCancelButton: true,
|
||||||
confirmButtonText: this.$t('context.confirm.button_yes') as string,
|
confirmButtonText: this.$t('context.confirm.button_yes') as string,
|
||||||
cancelButtonText: this.$t('context.confirm.button_cancel') as string,
|
cancelButtonText: this.$t('context.confirm.button_cancel') as string,
|
||||||
}).then(({ value }) => {
|
})
|
||||||
|
|
||||||
if (value) {
|
if (value) {
|
||||||
this.$accessor.user.kick(member)
|
this.$accessor.user.kick(member)
|
||||||
}
|
}
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ban(member: Member) {
|
async ban(member: Member) {
|
||||||
this.$swal({
|
const value = await this.$swal({
|
||||||
title: this.$t('context.confirm.ban_title', { name: member.displayname }) as string,
|
title: this.$t('context.confirm.ban_title', { name: member.displayname }) as string,
|
||||||
text: this.$t('context.confirm.ban_text', { name: member.displayname }) as string,
|
text: this.$t('context.confirm.ban_text', { name: member.displayname }) as string,
|
||||||
icon: 'warning',
|
icon: 'warning',
|
||||||
showCancelButton: true,
|
showCancelButton: true,
|
||||||
confirmButtonText: this.$t('context.confirm.button_yes') as string,
|
confirmButtonText: this.$t('context.confirm.button_yes') as string,
|
||||||
cancelButtonText: this.$t('context.confirm.button_cancel') as string,
|
cancelButtonText: this.$t('context.confirm.button_cancel') as string,
|
||||||
}).then(({ value }) => {
|
})
|
||||||
|
|
||||||
if (value) {
|
if (value) {
|
||||||
this.$accessor.user.ban(member)
|
this.$accessor.user.ban(member)
|
||||||
}
|
}
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mute(member: Member) {
|
async mute(member: Member) {
|
||||||
this.$swal({
|
const value = await this.$swal({
|
||||||
title: this.$t('context.confirm.mute_title', { name: member.displayname }) as string,
|
title: this.$t('context.confirm.mute_title', { name: member.displayname }) as string,
|
||||||
text: this.$t('context.confirm.mute_text', { name: member.displayname }) as string,
|
text: this.$t('context.confirm.mute_text', { name: member.displayname }) as string,
|
||||||
icon: 'warning',
|
icon: 'warning',
|
||||||
showCancelButton: true,
|
showCancelButton: true,
|
||||||
confirmButtonText: this.$t('context.confirm.button_yes') as string,
|
confirmButtonText: this.$t('context.confirm.button_yes') as string,
|
||||||
cancelButtonText: this.$t('context.confirm.button_cancel') as string,
|
cancelButtonText: this.$t('context.confirm.button_cancel') as string,
|
||||||
}).then(({ value }) => {
|
})
|
||||||
|
|
||||||
if (value) {
|
if (value) {
|
||||||
this.$accessor.user.mute(member)
|
this.$accessor.user.mute(member)
|
||||||
}
|
}
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
unmute(member: Member) {
|
async unmute(member: Member) {
|
||||||
this.$swal({
|
const value = await this.$swal({
|
||||||
title: this.$t('context.confirm.unmute_title', { name: member.displayname }) as string,
|
title: this.$t('context.confirm.unmute_title', { name: member.displayname }) as string,
|
||||||
text: this.$t('context.confirm.unmute_text', { name: member.displayname }) as string,
|
text: this.$t('context.confirm.unmute_text', { name: member.displayname }) as string,
|
||||||
icon: 'warning',
|
icon: 'warning',
|
||||||
showCancelButton: true,
|
showCancelButton: true,
|
||||||
confirmButtonText: this.$t('context.confirm.button_yes') as string,
|
confirmButtonText: this.$t('context.confirm.button_yes') as string,
|
||||||
cancelButtonText: this.$t('context.confirm.button_cancel') as string,
|
cancelButtonText: this.$t('context.confirm.button_cancel') as string,
|
||||||
}).then(({ value }) => {
|
})
|
||||||
|
|
||||||
if (value) {
|
if (value) {
|
||||||
this.$accessor.user.unmute(member)
|
this.$accessor.user.unmute(member)
|
||||||
}
|
}
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
adminRelease(member: Member) {
|
adminRelease(member: Member) {
|
||||||
|
@ -482,18 +482,14 @@
|
|||||||
return key
|
return key
|
||||||
}
|
}
|
||||||
|
|
||||||
play() {
|
async play() {
|
||||||
if (!this._video.paused || !this.playable) {
|
if (!this._video.paused || !this.playable) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
this._video
|
await this._video.play()
|
||||||
.play()
|
|
||||||
.then(() => {
|
|
||||||
this.onResise()
|
this.onResise()
|
||||||
})
|
|
||||||
.catch((err) => this.$log.error)
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.$log.error(err)
|
this.$log.error(err)
|
||||||
}
|
}
|
||||||
@ -569,21 +565,21 @@
|
|||||||
this.onResise()
|
this.onResise()
|
||||||
}
|
}
|
||||||
|
|
||||||
onFocus() {
|
async onFocus() {
|
||||||
if (!document.hasFocus() || !this.$accessor.active) {
|
if (!document.hasFocus() || !this.$accessor.active) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.hosting && this.clipboard_read_available) {
|
if (this.hosting && this.clipboard_read_available) {
|
||||||
navigator.clipboard
|
try {
|
||||||
.readText()
|
const text = await navigator.clipboard.readText()
|
||||||
.then((text) => {
|
|
||||||
if (this.clipboard !== text) {
|
if (this.clipboard !== text) {
|
||||||
this.$accessor.remote.setClipboard(text)
|
this.$accessor.remote.setClipboard(text)
|
||||||
this.$accessor.remote.sendClipboard(text)
|
this.$accessor.remote.sendClipboard(text)
|
||||||
}
|
}
|
||||||
})
|
} catch (err) {
|
||||||
.catch(this.$log.error)
|
this.$log.error(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,10 +52,6 @@ export abstract class BaseClient extends EventEmitter<BaseEvents> {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (displayname === '') {
|
|
||||||
throw new Error('Display Name cannot be empty.')
|
|
||||||
}
|
|
||||||
|
|
||||||
this._displayname = displayname
|
this._displayname = displayname
|
||||||
this[EVENT.CONNECTING]()
|
this[EVENT.CONNECTING]()
|
||||||
|
|
||||||
@ -184,7 +180,7 @@ export abstract class BaseClient extends EventEmitter<BaseEvents> {
|
|||||||
this._ws!.send(JSON.stringify({ event, ...payload }))
|
this._ws!.send(JSON.stringify({ event, ...payload }))
|
||||||
}
|
}
|
||||||
|
|
||||||
public createPeer(sdp: string, lite: boolean, servers: RTCIceServer[]) {
|
public async createPeer(sdp: string, lite: boolean, servers: RTCIceServer[]) {
|
||||||
this.emit('debug', `creating peer`)
|
this.emit('debug', `creating peer`)
|
||||||
if (!this.socketOpen) {
|
if (!this.socketOpen) {
|
||||||
this.emit(
|
this.emit(
|
||||||
@ -262,10 +258,10 @@ export abstract class BaseClient extends EventEmitter<BaseEvents> {
|
|||||||
}
|
}
|
||||||
this._candidates = []
|
this._candidates = []
|
||||||
|
|
||||||
this._peer
|
try {
|
||||||
.createAnswer()
|
const d = await this._peer.createAnswer()
|
||||||
.then((d) => {
|
|
||||||
this._peer!.setLocalDescription(d)
|
this._peer!.setLocalDescription(d)
|
||||||
|
|
||||||
this._ws!.send(
|
this._ws!.send(
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
event: EVENT.SIGNAL.ANSWER,
|
event: EVENT.SIGNAL.ANSWER,
|
||||||
@ -273,8 +269,9 @@ export abstract class BaseClient extends EventEmitter<BaseEvents> {
|
|||||||
displayname: this._displayname,
|
displayname: this._displayname,
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
})
|
} catch (err) {
|
||||||
.catch((err) => this.emit('error', err))
|
this.emit('error', err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private onMessage(e: MessageEvent) {
|
private onMessage(e: MessageEvent) {
|
||||||
|
@ -58,17 +58,17 @@ export const mutations = mutationTree(state, {
|
|||||||
export const actions = actionTree(
|
export const actions = actionTree(
|
||||||
{ state, getters, mutations },
|
{ state, getters, mutations },
|
||||||
{
|
{
|
||||||
initialise() {
|
async initialise() {
|
||||||
$http
|
try {
|
||||||
.get<Emojis>('emoji.json')
|
const req = await $http.get<Emojis>('emoji.json')
|
||||||
.then((req) => {
|
|
||||||
for (const group of req.data.groups) {
|
for (const group of req.data.groups) {
|
||||||
accessor.emoji.addGroup(group)
|
accessor.emoji.addGroup(group)
|
||||||
}
|
}
|
||||||
accessor.emoji.setList(req.data.list)
|
accessor.emoji.setList(req.data.list)
|
||||||
accessor.emoji.setKeywords(req.data.keywords)
|
accessor.emoji.setKeywords(req.data.keywords)
|
||||||
})
|
} catch (err) {
|
||||||
.catch(console.error)
|
console.error(err)
|
||||||
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -70,13 +70,13 @@ export const mutations = mutationTree(state, {
|
|||||||
export const actions = actionTree(
|
export const actions = actionTree(
|
||||||
{ state, getters, mutations },
|
{ state, getters, mutations },
|
||||||
{
|
{
|
||||||
initialise() {
|
async initialise() {
|
||||||
$http
|
try {
|
||||||
.get<KeyboardLayouts>('keyboard_layouts.json')
|
const req = await $http.get<KeyboardLayouts>('keyboard_layouts.json')
|
||||||
.then((req) => {
|
|
||||||
accessor.settings.setKeyboardLayoutsList(req.data)
|
accessor.settings.setKeyboardLayoutsList(req.data)
|
||||||
})
|
} catch (err) {
|
||||||
.catch(console.error)
|
console.error(err)
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
broadcastStatus({ getters }, { url, isActive }) {
|
broadcastStatus({ getters }, { url, isActive }) {
|
||||||
|
Loading…
Reference in New Issue
Block a user