fix(music-together): fix ? operator

This commit is contained in:
JellyBrick
2024-09-17 21:09:30 +09:00
parent 178bfa483f
commit 216e76f4a1

View File

@ -166,13 +166,13 @@ export default createPlugin<
this.profiles = {}; this.profiles = {};
this.connection.onConnections((connection) => { this.connection.onConnections((connection) => {
if (!connection) { if (!connection) {
this.api?.toastService.show(t('plugins.music-together.toast.disconnected')); this.api?.toastService?.show(t('plugins.music-together.toast.disconnected'));
this.onStop(); this.onStop();
return; return;
} }
if (!connection.open) { if (!connection.open) {
this.api?.toastService.show(t('plugins.music-together.toast.user-disconnected', { this.api?.toastService?.show(t('plugins.music-together.toast.user-disconnected', {
name: this.profiles[connection.peer]?.name name: this.profiles[connection.peer]?.name
})); }));
this.putProfile(connection.peer, undefined); this.putProfile(connection.peer, undefined);
@ -219,7 +219,7 @@ export default createPlugin<
break; break;
} }
this.api?.toastService.show(t('plugins.music-together.toast.user-connected', { name: event.payload.profile.name })); this.api?.toastService?.show(t('plugins.music-together.toast.user-connected', { name: event.payload.profile.name }));
this.putProfile(conn.peer, event.payload.profile); this.putProfile(conn.peer, event.payload.profile);
break; break;
} }
@ -307,7 +307,7 @@ export default createPlugin<
if (!connection) return false; if (!connection) return false;
this.connection.onConnections((connection) => { this.connection.onConnections((connection) => {
if (!connection?.open) { if (!connection?.open) {
this.api?.toastService.show(t('plugins.music-together.toast.disconnected')); this.api?.toastService?.show(t('plugins.music-together.toast.disconnected'));
this.onStop(); this.onStop();
} }
}); });
@ -381,7 +381,7 @@ export default createPlugin<
const permissionLabel = t(`plugins.music-together.menu.permission.${this.permission}`); const permissionLabel = t(`plugins.music-together.menu.permission.${this.permission}`);
this.api?.toastService.show(t('plugins.music-together.toast.permission-changed', { permission: permissionLabel })); this.api?.toastService?.show(t('plugins.music-together.toast.permission-changed', { permission: permissionLabel }));
break; break;
} }
default: { default: {
@ -593,18 +593,18 @@ export default createPlugin<
onItemClick: (id) => { onItemClick: (id) => {
if (id === 'music-together-close') { if (id === 'music-together-close') {
this.onStop(); this.onStop();
this.api?.toastService.show(t('plugins.music-together.toast.closed')); this.api?.toastService?.show(t('plugins.music-together.toast.closed'));
hostPopup.dismiss(); hostPopup.dismiss();
} }
if (id === 'music-together-copy-id') { if (id === 'music-together-copy-id') {
navigator.clipboard.writeText(this.connection?.id ?? '') navigator.clipboard.writeText(this.connection?.id ?? '')
.then(() => { .then(() => {
this.api?.toastService.show(t('plugins.music-together.toast.id-copied')); this.api?.toastService?.show(t('plugins.music-together.toast.id-copied'));
hostPopup.dismiss(); hostPopup.dismiss();
}) })
.catch(() => { .catch(() => {
this.api?.toastService.show(t('plugins.music-together.toast.id-copy-failed')); this.api?.toastService?.show(t('plugins.music-together.toast.id-copy-failed'));
hostPopup.dismiss(); hostPopup.dismiss();
}); });
} }
@ -620,7 +620,7 @@ export default createPlugin<
settingPopup.setPermission(this.permission); settingPopup.setPermission(this.permission);
const permissionLabel = t(`plugins.music-together.menu.permission.${this.permission}`); const permissionLabel = t(`plugins.music-together.menu.permission.${this.permission}`);
this.api?.toastService.show(t('plugins.music-together.toast.permission-changed', { permission: permissionLabel })); this.api?.toastService?.show(t('plugins.music-together.toast.permission-changed', { permission: permissionLabel }));
const item = hostPopup.items.find((it) => it?.element.id === id); const item = hostPopup.items.find((it) => it?.element.id === id);
if (item?.type === 'item') { if (item?.type === 'item') {
item.setText(t('plugins.music-together.menu.set-permission')); item.setText(t('plugins.music-together.menu.set-permission'));
@ -632,7 +632,7 @@ export default createPlugin<
onItemClick: (id) => { onItemClick: (id) => {
if (id === 'music-together-disconnect') { if (id === 'music-together-disconnect') {
this.onStop(); this.onStop();
this.api?.toastService.show(t('plugins.music-together.toast.disconnected')); this.api?.toastService?.show(t('plugins.music-together.toast.disconnected'));
guestPopup.dismiss(); guestPopup.dismiss();
} }
} }
@ -648,14 +648,14 @@ export default createPlugin<
if (result) { if (result) {
navigator.clipboard.writeText(this.connection?.id ?? '') navigator.clipboard.writeText(this.connection?.id ?? '')
.then(() => { .then(() => {
this.api?.toastService.show(t('plugins.music-together.toast.id-copied')); this.api?.toastService?.show(t('plugins.music-together.toast.id-copied'));
hostPopup.showAtAnchor(setting); hostPopup.showAtAnchor(setting);
}).catch(() => { }).catch(() => {
this.api?.toastService.show(t('plugins.music-together.toast.id-copy-failed')); this.api?.toastService?.show(t('plugins.music-together.toast.id-copy-failed'));
hostPopup.showAtAnchor(setting); hostPopup.showAtAnchor(setting);
}); });
} else { } else {
this.api?.toastService.show(t('plugins.music-together.toast.host-failed')); this.api?.toastService?.show(t('plugins.music-together.toast.host-failed'));
} }
} }
@ -666,10 +666,10 @@ export default createPlugin<
this.hideSpinner(); this.hideSpinner();
if (result) { if (result) {
this.api?.toastService.show(t('plugins.music-together.toast.joined')); this.api?.toastService?.show(t('plugins.music-together.toast.joined'));
guestPopup.showAtAnchor(setting); guestPopup.showAtAnchor(setting);
} else { } else {
this.api?.toastService.show(t('plugins.music-together.toast.join-failed')); this.api?.toastService?.show(t('plugins.music-together.toast.join-failed'));
} }
} }
} }