refactor: dialogs (#1216)

This commit is contained in:
pa
2025-04-18 20:11:07 +09:00
committed by GitHub
parent 30d54a74dd
commit ef7f33e131
34 changed files with 3227 additions and 2716 deletions

View File

@@ -1,5 +1,4 @@
import * as workerTimers from 'worker-timers';
import configRepository from '../service/config.js';
import { baseClass, $app, API } from './baseClass.js';
import { worldRequest, groupRequest } from '../api';
@@ -573,28 +572,6 @@ export default class extends baseClass {
}
this.sharedFeed.moderationAgainstTable.wrist = wristArr;
this.sharedFeed.pendingUpdate = true;
},
saveSharedFeedFilters() {
configRepository.setString(
'sharedFeedFilters',
JSON.stringify(this.sharedFeedFilters)
);
this.updateSharedFeed(true);
},
async resetNotyFeedFilters() {
this.sharedFeedFilters.noty = {
...this.sharedFeedFiltersDefaults.noty
};
this.saveSharedFeedFilters();
},
async resetWristFeedFilters() {
this.sharedFeedFilters.wrist = {
...this.sharedFeedFiltersDefaults.wrist
};
this.saveSharedFeedFilters();
}
};
}

View File

@@ -1,5 +1,5 @@
import configRepository from '../service/config.js';
import { baseClass, $app, API, $t, $utils } from './baseClass.js';
import { baseClass, $t, $utils } from './baseClass.js';
export default class extends baseClass {
constructor(_app, _API, _t) {
@@ -8,67 +8,9 @@ export default class extends baseClass {
init() {}
_data = {
registryBackupDialog: {
visible: false
},
registryBackupTable: {
data: [],
tableProps: {
stripe: true,
size: 'mini',
defaultSort: {
prop: 'date',
order: 'descending'
}
},
layout: 'table'
}
};
_data = {};
_methods = {
showRegistryBackupDialog() {
this.$nextTick(() =>
$app.adjustDialogZ(this.$refs.registryBackupDialog.$el)
);
var D = this.registryBackupDialog;
D.visible = true;
this.updateRegistryBackupDialog();
},
async updateRegistryBackupDialog() {
var D = this.registryBackupDialog;
this.registryBackupTable.data = [];
if (!D.visible) {
return;
}
var backupsJson = await configRepository.getString(
'VRCX_VRChatRegistryBackups'
);
if (!backupsJson) {
backupsJson = JSON.stringify([]);
}
this.registryBackupTable.data = JSON.parse(backupsJson);
},
async promptVrcRegistryBackupName() {
var name = await this.$prompt(
'Enter a name for the backup',
'Backup Name',
{
confirmButtonText: 'Confirm',
cancelButtonText: 'Cancel',
inputPattern: /\S+/,
inputErrorMessage: 'Name is required',
inputValue: 'Backup'
}
);
if (name.action === 'confirm') {
this.backupVrcRegistry(name.value);
}
},
async backupVrcRegistry(name) {
var regJson;
if (LINUX) {
@@ -94,158 +36,11 @@ export default class extends baseClass {
'VRCX_VRChatRegistryBackups',
JSON.stringify(backups)
);
await this.updateRegistryBackupDialog();
},
async deleteVrcRegistryBackup(row) {
var backups = this.registryBackupTable.data;
$app.removeFromArray(backups, row);
await configRepository.setString(
'VRCX_VRChatRegistryBackups',
JSON.stringify(backups)
);
await this.updateRegistryBackupDialog();
},
restoreVrcRegistryBackup(row) {
this.$confirm('Continue? Restore Backup', 'Confirm', {
confirmButtonText: 'Confirm',
cancelButtonText: 'Cancel',
type: 'warning',
callback: (action) => {
if (action !== 'confirm') {
return;
}
var data = JSON.stringify(row.data);
AppApi.SetVRChatRegistry(data)
.then(() => {
this.$message({
message: 'VRC registry settings restored',
type: 'success'
});
})
.catch((e) => {
console.error(e);
this.$message({
message: `Failed to restore VRC registry settings, check console for full error: ${e}`,
type: 'error'
});
});
}
});
},
saveVrcRegistryBackupToFile(row) {
$utils.downloadAndSaveJson(row.name, row.data);
},
async openJsonFileSelectorDialogElectron() {
return new Promise((resolve) => {
const fileInput = document.createElement('input');
fileInput.type = 'file';
fileInput.accept = '.json';
fileInput.style.display = 'none';
document.body.appendChild(fileInput);
fileInput.onchange = function (event) {
const file = event.target.files[0];
if (file) {
const reader = new FileReader();
reader.onload = function () {
fileInput.remove();
resolve(reader.result);
};
reader.readAsText(file);
} else {
fileInput.remove();
resolve(null);
}
};
fileInput.click();
});
},
async restoreVrcRegistryFromFile() {
if (WINDOWS) {
var filePath = await AppApi.OpenFileSelectorDialog(
null,
'.json',
'JSON Files (*.json)|*.json'
);
if (filePath === '') {
return;
}
}
var json;
if (LINUX) {
json = await this.openJsonFileSelectorDialogElectron();
} else {
json = await AppApi.ReadVrcRegJsonFile(filePath);
}
try {
var data = JSON.parse(json);
if (!data || typeof data !== 'object') {
throw new Error('Invalid JSON');
}
// quick check to make sure it's a valid registry backup
for (var key in data) {
var value = data[key];
if (
typeof value !== 'object' ||
typeof value.type !== 'number' ||
typeof value.data === 'undefined'
) {
throw new Error('Invalid JSON');
}
}
AppApi.SetVRChatRegistry(json)
.then(() => {
this.$message({
message: 'VRC registry settings restored',
type: 'success'
});
})
.catch((e) => {
console.error(e);
this.$message({
message: `Failed to restore VRC registry settings, check console for full error: ${e}`,
type: 'error'
});
});
} catch {
this.$message({
message: 'Invalid JSON',
type: 'error'
});
}
},
deleteVrcRegistry() {
this.$confirm('Continue? Delete VRC Registry Settings', 'Confirm', {
confirmButtonText: 'Confirm',
cancelButtonText: 'Cancel',
type: 'warning',
callback: (action) => {
if (action !== 'confirm') {
return;
}
AppApi.DeleteVRChatRegistryFolder().then(() => {
this.$message({
message: 'VRC registry settings deleted',
type: 'success'
});
});
}
});
},
clearVrcRegistryDialog() {
this.registryBackupTable.data = [];
// await this.updateRegistryBackupDialog();
},
// Because it is a startup func, it is not integrated into RegistryBackupDialog.vue now
// func backupVrcRegistry is also split up
async checkAutoBackupRestoreVrcRegistry() {
if (!this.vrcRegistryAutoBackup) {
return;
@@ -309,7 +104,7 @@ export default class extends baseClass {
backups.forEach((backup) => {
if (backup.name === 'Auto Backup') {
// remove old auto backup
$app.removeFromArray(backups, backup);
$utils.removeFromArray(backups, backup);
}
});
await configRepository.setString(

View File

@@ -44,9 +44,6 @@ export default class extends baseClass {
_methods = {
async showVRCXUpdateDialog() {
this.$nextTick(() =>
$app.adjustDialogZ(this.$refs.VRCXUpdateDialog.$el)
);
var D = this.VRCXUpdateDialog;
D.visible = true;
D.updatePendingIsLatest = false;