Files
VRCX/src/views/Settings/dialogs/RegistryBackupDialog.vue
T
Natsumi 3324d0d279 Upgrade to Vue3 and Element Plus (#1374)
* Update Vue devtools

* upgrade vue pinia element-plus vue-i18n, add vite

* fix: i18n

* global components

* change v-deep

* upgrade vue-lazyload

* data table

* update enlint and safe-dialog

* package.json and vite.config.js

* el-icon

* el-message

* vue 2 -> vue3 migration changes

* $pinia

* dialog

* el-popover slot

* lint

* chore

* slot

* scss

* remote state access

* misc

* jsconfig

* el-button size mini -> small

* :model-value

* ElMessageBox

* datatable

* remove v-lazyload

* template #dropdown

* mini -> small

* css

* byebye hideTooltips

* use sass-embedded

* Update SQLite, remove unneeded libraries

* Fix shift remove local avatar favorites

* Electron arm64

* arm64 support

* bye pug

* f-word vite hah

* misc

* remove safe dialog component

* Add self invite to launch dialog

* Fix errors

* Icons 1

* improve localfavorite loading performance

* improve favorites world item performance

* dialog visibility changes for Element Plus

* clear element plus error

* import performance

* revert App.vue hah

* hah

* Revert "Add self invite to launch dialog"

This reverts commit 4801cfad58.

* Toggle self invite/open in-game

* Self invite on launch dialog

* el-button icon

* el-icon

* fix user dialog tab switching logic

* fix PlayerList

* Formatting changes

* More icons

* Fix friend log table

* loading margin

* fix markdown

* fix world dialog tab switching issue

* Fixes and formatting

* fix: global i18n.t export

* fix favorites world tab not working

* Create instance, displayName

* Remove group members sort by userId

* Fix loading dialog tabs on swtich

* Star

* charts console.warn

* wip: fix charts

* wip: fix charts

* wip: charts composables

* fix favorite item tooltip warning

* Fixes and formatting

* Clean up image dialogs

* Remove unused method

* Fix platform/size border

* Fix platform/size border

* $vr

* fix friendExportDialogVisible binding

* ElMessageBox and Settings

* Login formatting

* Rename VR overlay query

* Fix image popover and userdialog badges

* Formatting

* Big buttons

* Fixes, update Cef

* Fix gameLog table nav buttons jumping around while using nav buttons

* Fix z-index

* vr overlay

* vite input add theme

* defineAsyncComponent

* ISO 639-1

* fix i18n

* clean t

* Formatting, fix calendar, rotate arrows

* Show user status when user is offline

* Fix VR overlay

* fix theme and clean up

* split InstanceActivity

* tweak

* Fix VR overlay formatting

* fix scss var

* AppDebug hahahaha

* Years

* remove reactive

* improve perf

* state hah…

* fix user rendering poblems when user object is not yet loaded

* improve perf

* Update avatar/world image uploader, licenses, remove previous images dialog (old images are now deleted)

* improve perf 1

* Suppress stray errors

* fix traveling location display issue

* Fix empty instance creator

* improve friend list refresh performance

* fix main charts

* fix chart

* Fix darkmode

* Fix avatar dialog tags

---------

Co-authored-by: pa <maplenagisa@gmail.com>
2025-09-12 10:45:24 +12:00

291 lines
11 KiB
Vue

<template>
<el-dialog
class="x-dialog"
:model-value="isRegistryBackupDialogVisible"
:title="t('dialog.registry_backup.header')"
width="600px"
@close="closeDialog"
@closed="clearVrcRegistryDialog">
<div style="margin-top: 10px">
<div style="display: flex; align-items: center; justify-content: space-between; font-size: 12px">
<span class="name" style="margin-right: 24px">{{ t('dialog.registry_backup.auto_backup') }}</span>
<el-switch v-model="vrcRegistryAutoBackup" @change="setVrcRegistryAutoBackup"></el-switch>
</div>
<div
style="
display: flex;
align-items: center;
justify-content: space-between;
font-size: 12px;
margin-top: 5px;
">
<span class="name" style="margin-right: 24px">{{ t('dialog.registry_backup.ask_to_restore') }}</span>
<el-switch v-model="vrcRegistryAskRestore" @change="setVrcRegistryAskRestore"></el-switch>
</div>
<DataTable v-bind="registryBackupTable" style="margin-top: 10px">
<el-table-column :label="t('dialog.registry_backup.name')" prop="name"></el-table-column>
<el-table-column :label="t('dialog.registry_backup.date')" prop="date">
<template #default="scope">
<span>{{ formatDateFilter(scope.row.date, 'long') }}</span>
</template>
</el-table-column>
<el-table-column :label="t('dialog.registry_backup.action')" width="90" align="right">
<template #default="scope">
<el-tooltip placement="top" :content="t('dialog.registry_backup.restore')">
<el-button
type="text"
:icon="Upload"
size="small"
class="button-pd-0"
@click="restoreVrcRegistryBackup(scope.row)"></el-button>
</el-tooltip>
<el-tooltip placement="top" :content="t('dialog.registry_backup.save_to_file')">
<el-button
type="text"
:icon="Download"
size="small"
class="button-pd-0"
@click="saveVrcRegistryBackupToFile(scope.row)"></el-button>
</el-tooltip>
<el-tooltip placement="top" :content="t('dialog.registry_backup.delete')">
<el-button
type="text"
:icon="Delete"
size="small"
class="button-pd-0"
@click="deleteVrcRegistryBackup(scope.row)"></el-button>
</el-tooltip>
</template>
</el-table-column>
</DataTable>
<div style="display: flex; align-items: center; justify-content: space-between; margin-top: 10px">
<el-button type="danger" size="small" @click="deleteVrcRegistry">{{
t('dialog.registry_backup.reset')
}}</el-button>
<div>
<el-button size="small" @click="promptVrcRegistryBackupName">{{
t('dialog.registry_backup.backup')
}}</el-button>
<el-button size="small" @click="restoreVrcRegistryFromFile">{{
t('dialog.registry_backup.restore_from_file')
}}</el-button>
</div>
</div>
</div>
</el-dialog>
</template>
<script setup>
import { ElMessage, ElMessageBox } from 'element-plus';
import { Upload, Download, Delete } from '@element-plus/icons-vue';
import { storeToRefs } from 'pinia';
import { ref, watch } from 'vue';
import { useI18n } from 'vue-i18n';
import configRepository from '../../../service/config';
import { downloadAndSaveJson, removeFromArray, formatDateFilter } from '../../../shared/utils';
import { useVrcxStore, useAdvancedSettingsStore } from '../../../stores';
const { backupVrcRegistry } = useVrcxStore();
const { isRegistryBackupDialogVisible } = storeToRefs(useVrcxStore());
const { vrcRegistryAutoBackup, vrcRegistryAskRestore } = storeToRefs(useAdvancedSettingsStore());
const { setVrcRegistryAutoBackup, setVrcRegistryAskRestore } = useAdvancedSettingsStore();
const { t } = useI18n();
const registryBackupTable = ref({
data: [],
tableProps: {
stripe: true,
size: 'small',
defaultSort: {
prop: 'date',
order: 'descending'
}
},
layout: 'table'
});
watch(
() => isRegistryBackupDialogVisible.value,
(newVal) => {
if (newVal) {
updateRegistryBackupDialog();
}
}
);
async function updateRegistryBackupDialog() {
const backupsJson = await configRepository.getString('VRCX_VRChatRegistryBackups');
registryBackupTable.value.data = JSON.parse(backupsJson || '[]');
}
function restoreVrcRegistryBackup(row) {
ElMessageBox.confirm('Continue? Restore Backup', 'Confirm', {
confirmButtonText: 'Confirm',
cancelButtonText: 'Cancel',
type: 'warning'
})
.then((action) => {
if (action !== 'confirm') {
return;
}
const data = JSON.stringify(row.data);
AppApi.SetVRChatRegistry(data)
.then(() => {
ElMessage({
message: 'VRC registry settings restored',
type: 'success'
});
})
.catch((e) => {
console.error(e);
ElMessage({
message: `Failed to restore VRC registry settings, check console for full error: ${e}`,
type: 'error'
});
});
})
.catch(() => {});
}
function saveVrcRegistryBackupToFile(row) {
downloadAndSaveJson(row.name, row.data);
}
async function deleteVrcRegistryBackup(row) {
const backups = registryBackupTable.value.data;
removeFromArray(backups, row);
await configRepository.setString('VRCX_VRChatRegistryBackups', JSON.stringify(backups));
await updateRegistryBackupDialog();
}
function deleteVrcRegistry() {
ElMessageBox.confirm('Continue? Delete VRC Registry Settings', 'Confirm', {
confirmButtonText: 'Confirm',
cancelButtonText: 'Cancel',
type: 'warning'
})
.then((action) => {
if (action !== 'confirm') {
return;
}
AppApi.DeleteVRChatRegistryFolder().then(() => {
ElMessage({
message: 'VRC registry settings deleted',
type: 'success'
});
});
})
.catch(() => {});
}
async function handleBackupVrcRegistry(name) {
await backupVrcRegistry(name);
await updateRegistryBackupDialog();
}
async function promptVrcRegistryBackupName() {
try {
const { value } = await ElMessageBox.prompt('Enter a name for the backup', 'Backup Name', {
confirmButtonText: 'Confirm',
cancelButtonText: 'Cancel',
inputPattern: /\S+/,
inputErrorMessage: 'Name is required',
inputValue: 'Backup'
});
await handleBackupVrcRegistry(value);
} catch (error) {}
}
async function 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 function restoreVrcRegistryFromFile() {
const filePath = await AppApi.OpenFileSelectorDialog(null, '.json', 'JSON Files (*.json)|*.json');
if (WINDOWS) {
if (filePath === '') {
return;
}
}
let json;
if (LINUX) {
json = await openJsonFileSelectorDialogElectron();
} else {
json = await AppApi.ReadVrcRegJsonFile(filePath);
}
try {
const 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 (const key in data) {
const value = data[key];
if (typeof value !== 'object' || typeof value.type !== 'number' || typeof value.data === 'undefined') {
throw new Error('Invalid JSON');
}
}
AppApi.SetVRChatRegistry(json)
.then(() => {
ElMessage({
message: 'VRC registry settings restored',
type: 'success'
});
})
.catch((e) => {
console.error(e);
ElMessage({
message: `Failed to restore VRC registry settings, check console for full error: ${e}`,
type: 'error'
});
});
} catch {
ElMessage({
message: 'Invalid JSON',
type: 'error'
});
}
}
function clearVrcRegistryDialog() {
registryBackupTable.value.data = [];
}
function closeDialog() {
isRegistryBackupDialogVisible.value = false;
}
</script>
<style scoped>
.button-pd-0 {
padding: 0;
}
</style>