refactor(client): refactor dialog functions to improve type inference

This commit is contained in:
syuilo
2021-11-18 18:45:58 +09:00
parent 63415f1074
commit ea9aeef9d8
84 changed files with 415 additions and 460 deletions

View File

@ -105,11 +105,9 @@ export default defineComponent({
methods: {
register() {
os.dialog({
os.inputText({
title: this.$ts.password,
input: {
type: 'password'
}
type: 'password'
}).then(({ canceled, result: password }) => {
if (canceled) return;
os.api('i/2fa/register', {
@ -121,11 +119,9 @@ export default defineComponent({
},
unregister() {
os.dialog({
os.inputText({
title: this.$ts.password,
input: {
type: 'password'
}
type: 'password'
}).then(({ canceled, result: password }) => {
if (canceled) return;
os.api('i/2fa/unregister', {
@ -147,7 +143,7 @@ export default defineComponent({
os.success();
this.$i.twoFactorEnabled = true;
}).catch(e => {
os.dialog({
os.alert({
type: 'error',
text: e
});
@ -171,11 +167,9 @@ export default defineComponent({
},
unregisterKey(key) {
os.dialog({
os.inputText({
title: this.$ts.password,
input: {
type: 'password'
}
type: 'password'
}).then(({ canceled, result: password }) => {
if (canceled) return;
return os.api('i/2fa/remove-key', {
@ -191,11 +185,9 @@ export default defineComponent({
},
addSecurityKey() {
os.dialog({
os.inputText({
title: this.$ts.password,
input: {
type: 'password'
}
type: 'password'
}).then(({ canceled, result: password }) => {
if (canceled) return;
os.api('i/2fa/register-key', {

View File

@ -52,7 +52,7 @@ export default defineComponent({
permission: permissions,
});
os.dialog({
os.alert({
type: 'success',
title: this.$ts.token,
text: token

View File

@ -59,10 +59,9 @@ export default defineComponent({
async apply() {
localStorage.setItem('customCss', this.localCustomCss);
const { canceled } = await os.dialog({
const { canceled } = await os.confirm({
type: 'info',
text: this.$ts.reloadToApplySetting,
showCancelButton: true
});
if (canceled) return;

View File

@ -75,10 +75,9 @@ export default defineComponent({
watch: {
async navWindow() {
const { canceled } = await os.dialog({
const { canceled } = await os.confirm({
type: 'info',
text: this.$ts.reloadToApplySetting,
showCancelButton: true
});
if (canceled) return;
@ -92,11 +91,9 @@ export default defineComponent({
methods: {
async setProfile() {
const { canceled, result: name } = await os.dialog({
const { canceled, result: name } = await os.inputText({
title: this.$ts._deck.profile,
input: {
allowEmpty: false
}
allowEmpty: false
});
if (canceled) return;
this.profile = name;

View File

@ -46,19 +46,16 @@ export default defineComponent({
methods: {
async deleteAccount() {
{
const { canceled } = await os.dialog({
const { canceled } = await os.confirm({
type: 'warning',
text: this.$ts.deleteAccountConfirm,
showCancelButton: true
});
if (canceled) return;
}
const { canceled, result: password } = await os.dialog({
const { canceled, result: password } = await os.inputText({
title: this.$ts.password,
input: {
type: 'password'
}
type: 'password'
});
if (canceled) return;
@ -66,7 +63,7 @@ export default defineComponent({
password: password
});
await os.dialog({
await os.alert({
title: this.$ts._accountDelete.started,
});

View File

@ -52,11 +52,9 @@ export default defineComponent({
methods: {
save() {
os.dialog({
os.inputText({
title: this.$ts.password,
input: {
type: 'password'
}
type: 'password'
}).then(({ canceled, result: password }) => {
if (canceled) return;
os.apiWithDialog('i/update-email', {

View File

@ -209,10 +209,9 @@ export default defineComponent({
methods: {
async reloadAsk() {
const { canceled } = await os.dialog({
const { canceled } = await os.confirm({
type: 'info',
text: this.$ts.reloadToApplySetting,
showCancelButton: true
});
if (canceled) return;

View File

@ -67,12 +67,12 @@ export default defineComponent({
target === 'muting' ? 'i/export-mute' :
null, {})
.then(() => {
os.dialog({
os.alert({
type: 'info',
text: this.$ts.exportRequested
});
}).catch((e: any) => {
os.dialog({
os.alert({
type: 'error',
text: e.message
});
@ -90,12 +90,12 @@ export default defineComponent({
null, {
fileId: file.id
}).then(() => {
os.dialog({
os.alert({
type: 'info',
text: this.$ts.importRequested
});
}).catch((e: any) => {
os.dialog({
os.alert({
type: 'error',
text: e.message
});

View File

@ -76,17 +76,13 @@ export default defineComponent({
methods: {
async addItem() {
const menu = Object.keys(this.menuDef).filter(k => !this.$store.state.menu.includes(k));
const { canceled, result: item } = await os.dialog({
type: null,
const { canceled, result: item } = await os.select({
title: this.$ts.addItem,
select: {
items: [...menu.map(k => ({
value: k, text: this.$ts[this.menuDef[k].title]
})), ...[{
value: '-', text: this.$ts.divider
}]]
},
showCancelButton: true
items: [...menu.map(k => ({
value: k, text: this.$ts[this.menuDef[k].title]
})), ...[{
value: '-', text: this.$ts.divider
}]]
});
if (canceled) return;
this.items = [...this.splited, item].join('\n');
@ -103,7 +99,7 @@ export default defineComponent({
},
async reloadAsk() {
const { canceled } = await os.dialog({
const { canceled } = await os.confirm({
type: 'info',
text: this.$ts.reloadToApplySetting,
showCancelButton: true

View File

@ -76,7 +76,7 @@ export default defineComponent({
try {
ast = parse(this.code);
} catch (e) {
os.dialog({
os.alert({
type: 'error',
text: 'Syntax error :('
});
@ -84,7 +84,7 @@ export default defineComponent({
}
const meta = AiScript.collectMetadata(ast);
if (meta == null) {
os.dialog({
os.alert({
type: 'error',
text: 'No metadata found :('
});
@ -92,7 +92,7 @@ export default defineComponent({
}
const data = meta.get(null);
if (data == null) {
os.dialog({
os.alert({
type: 'error',
text: 'No metadata found :('
});
@ -100,7 +100,7 @@ export default defineComponent({
}
const { name, version, author, description, permissions, config } = data;
if (name == null || version == null || author == null) {
os.dialog({
os.alert({
type: 'error',
text: 'Required property not found :('
});

View File

@ -221,7 +221,7 @@ export default defineComponent({
}).then(i => {
os.success();
}).catch(err => {
os.dialog({
os.alert({
type: 'error',
text: err.id
});

View File

@ -111,10 +111,9 @@ export default defineComponent({
},
async setDefault() {
const { canceled } = await os.dialog({
const { canceled } = await os.confirm({
type: 'warning',
text: this.$ts.resetAreYouSure,
showCancelButton: true
});
if (canceled) return;

View File

@ -110,17 +110,16 @@ export default defineComponent({
try {
JSON5.parse(this.valueForEditor);
} catch (e) {
os.dialog({
os.alert({
type: 'error',
text: this.$ts.invalidValue
});
return;
}
os.dialog({
os.confirm({
type: 'warning',
text: this.$ts.saveConfirm,
showCancelButton: true
}).then(({ canceled }) => {
if (canceled) return;
os.apiWithDialog('i/registry/set', {
@ -132,10 +131,9 @@ export default defineComponent({
},
del() {
os.dialog({
os.confirm({
type: 'warning',
text: this.$ts.deleteConfirm,
showCancelButton: true
}).then(({ canceled }) => {
if (canceled) return;
os.apiWithDialog('i/registry/remove', {

View File

@ -64,32 +64,26 @@ export default defineComponent({
methods: {
async change() {
const { canceled: canceled1, result: currentPassword } = await os.dialog({
const { canceled: canceled1, result: currentPassword } = await os.inputText({
title: this.$ts.currentPassword,
input: {
type: 'password'
}
type: 'password'
});
if (canceled1) return;
const { canceled: canceled2, result: newPassword } = await os.dialog({
const { canceled: canceled2, result: newPassword } = await os.inputText({
title: this.$ts.newPassword,
input: {
type: 'password'
}
type: 'password'
});
if (canceled2) return;
const { canceled: canceled3, result: newPassword2 } = await os.dialog({
const { canceled: canceled3, result: newPassword2 } = await os.inputText({
title: this.$ts.newPasswordRetype,
input: {
type: 'password'
}
type: 'password'
});
if (canceled3) return;
if (newPassword !== newPassword2) {
os.dialog({
os.alert({
type: 'error',
text: this.$ts.retypedNotMatch
});
@ -103,11 +97,9 @@ export default defineComponent({
},
regenerateToken() {
os.dialog({
os.inputText({
title: this.$ts.password,
input: {
type: 'password'
}
type: 'password'
}).then(({ canceled, result: password }) => {
if (canceled) return;
os.api('i/regenerate_token', {

View File

@ -62,21 +62,21 @@ export default defineComponent({
try {
theme = JSON5.parse(code);
} catch (e) {
os.dialog({
os.alert({
type: 'error',
text: this.$ts._theme.invalid
});
return false;
}
if (!validateTheme(theme)) {
os.dialog({
os.alert({
type: 'error',
text: this.$ts._theme.invalid
});
return false;
}
if (getThemes().some(t => t.id === theme.id)) {
os.dialog({
os.alert({
type: 'info',
text: this.$ts._theme.alreadyInstalled
});
@ -95,7 +95,7 @@ export default defineComponent({
const theme = this.parseThemeCode(code);
if (!theme) return;
await addTheme(theme);
os.dialog({
os.alert({
type: 'success',
text: this.$t('_theme.installed', { name: theme.name })
});