Electron support for Linux (#1074)

* init

* SQLite changes

* Move html folder, edit build scripts

* AppApi interface

* Build flags

* AppApi inheritance

* Finishing touches

* Merge upstream changes

* Test CI

* Fix class inits

* Rename AppApi

* Merge upstream changes

* Fix SQLiteLegacy on Linux, Add Linux interop, build tools

* Linux specific localisation strings

* Make it run

* Bring back most of Linux functionality

* Clean up

* Fix TTS voices

* Fix UI var

* Changes

* Electron minimise to tray

* Remove separate toggle for WlxOverlay

* Fixes

* Touchups

* Move csproj

* Window zoom, Desktop Notifications, VR check on Linux

* Fix desktop notifications, VR check spam

* Fix building on Linux

* Clean up

* Fix WebApi headers

* Rewrite VRCX updater

* Clean up

* Linux updater

* Add Linux to build action

* init

* SQLite changes

* Move html folder, edit build scripts

* AppApi interface

* Build flags

* AppApi inheritance

* Finishing touches

* Merge upstream changes

* Test CI

* Fix class inits

* Rename AppApi

* Merge upstream changes

* Fix SQLiteLegacy on Linux, Add Linux interop, build tools

* Linux specific localisation strings

* Make it run

* Bring back most of Linux functionality

* Clean up

* Fix TTS voices

* Changes

* Electron minimise to tray

* Remove separate toggle for WlxOverlay

* Fixes

* Touchups

* Move csproj

* Window zoom, Desktop Notifications, VR check on Linux

* Fix desktop notifications, VR check spam

* Fix building on Linux

* Clean up

* Fix WebApi headers

* Rewrite VRCX updater

* Clean up

* Linux updater

* Add Linux to build action

* Test updater

* Rebase and handle merge conflicts

* Fix Linux updater

* Fix Linux app restart

* Fix friend order

* Handle AppImageInstaller, show an install message on Linux

* Updates to the AppImage installer

* Fix Linux updater, fix set version, check for .NET, copy wine prefix

* Handle random errors

* Rotate tall prints

* try fix Linux restart bug

* Final

---------

Co-authored-by: rs189 <35667100+rs189@users.noreply.github.com>
This commit is contained in:
Natsumi
2025-01-11 13:09:44 +13:00
committed by GitHub
parent a39eb9d5ed
commit 938fff63d0
223 changed files with 15841 additions and 9562 deletions

37
src/classes/API/config.js Normal file
View File

@@ -0,0 +1,37 @@
import { baseClass, $app, API, $t, $utils } from '../baseClass.js';
export default class extends baseClass {
constructor(_app, _API, _t) {
super(_app, _API, _t);
}
init() {
API.getConfig = function () {
return this.call('config', {
method: 'GET'
}).then((json) => {
var args = {
json
};
this.$emit('CONFIG', args);
return args;
});
};
API.$on('CONFIG', function (args) {
args.ref = this.applyConfig(args.json);
});
API.applyConfig = function (json) {
var ref = {
...json
};
this.cachedConfig = ref;
return ref;
};
}
_data = {};
_methods = {};
}

View File

@@ -0,0 +1,16 @@
import * as workerTimers from 'worker-timers';
import configRepository from '../repository/config.js';
import database from '../repository/database.js';
import { baseClass, $app, API, $t, $utils } from './baseClass.js';
export default class extends baseClass {
constructor(_app, _API, _t) {
super(_app, _API, _t);
}
init() {}
_data = {};
_methods = {};
}

53
src/classes/apiInit.js Normal file
View File

@@ -0,0 +1,53 @@
import { baseClass, $app, API, $t } from './baseClass.js';
export default class extends baseClass {
constructor(_app) {
super(_app);
}
eventHandlers = new Map();
$emit = function (name, ...args) {
if ($app.debug) {
console.log(name, ...args);
}
var handlers = this.eventHandlers.get(name);
if (typeof handlers === 'undefined') {
return;
}
try {
for (var handler of handlers) {
handler.apply(this, args);
}
} catch (err) {
console.error(err);
}
};
$on = function (name, handler) {
var handlers = this.eventHandlers.get(name);
if (typeof handlers === 'undefined') {
handlers = [];
this.eventHandlers.set(name, handlers);
}
handlers.push(handler);
};
$off = function (name, handler) {
var handlers = this.eventHandlers.get(name);
if (typeof handlers === 'undefined') {
return;
}
var { length } = handlers;
for (var i = 0; i < length; ++i) {
if (handlers[i] === handler) {
if (length > 1) {
handlers.splice(i, 1);
} else {
this.eventHandlers.delete(name);
}
break;
}
}
};
}

419
src/classes/apiLogin.js Normal file
View File

@@ -0,0 +1,419 @@
import Noty from 'noty';
import security from '../security.js';
import configRepository from '../repository/config.js';
import { baseClass, $app, API, $t } from './baseClass.js';
/* eslint-disable no-unused-vars */
let webApiService = {};
/* eslint-enable no-unused-vars */
export default class extends baseClass {
constructor(_app, _API, _t, _webApiService) {
super(_app, _API, _t);
webApiService = _webApiService;
}
async init() {
API.isLoggedIn = false;
API.attemptingAutoLogin = false;
/**
* @param {{ username: string, password: string }} params credential to login
* @returns {Promise<{origin: boolean, json: any, params}>}
*/
API.login = function (params) {
var { username, password, saveCredentials, cipher } = params;
username = encodeURIComponent(username);
password = encodeURIComponent(password);
var auth = btoa(`${username}:${password}`);
if (saveCredentials) {
delete params.saveCredentials;
if (cipher) {
params.password = cipher;
delete params.cipher;
}
$app.saveCredentials = params;
}
return this.call('auth/user', {
method: 'GET',
headers: {
Authorization: `Basic ${auth}`
}
}).then((json) => {
var args = {
json,
params,
origin: true
};
if (
json.requiresTwoFactorAuth &&
json.requiresTwoFactorAuth.includes('emailOtp')
) {
this.$emit('USER:EMAILOTP', args);
} else if (json.requiresTwoFactorAuth) {
this.$emit('USER:2FA', args);
} else {
this.$emit('USER:CURRENT', args);
}
return args;
});
};
/**
* @param {{ code: string }} params One-time password
* @returns {Promise<{json: any, params}>}
*/
API.verifyOTP = function (params) {
return this.call('auth/twofactorauth/otp/verify', {
method: 'POST',
params
}).then((json) => {
var args = {
json,
params
};
this.$emit('OTP', args);
return args;
});
};
/**
* @param {{ code: string }} params One-time token
* @returns {Promise<{json: any, params}>}
*/
API.verifyTOTP = function (params) {
return this.call('auth/twofactorauth/totp/verify', {
method: 'POST',
params
}).then((json) => {
var args = {
json,
params
};
this.$emit('TOTP', args);
return args;
});
};
/**
* @param {{ code: string }} params One-time token
* @returns {Promise<{json: any, params}>}
*/
API.verifyEmailOTP = function (params) {
return this.call('auth/twofactorauth/emailotp/verify', {
method: 'POST',
params
}).then((json) => {
var args = {
json,
params
};
this.$emit('EMAILOTP', args);
return args;
});
};
API.$on('AUTOLOGIN', function () {
if (this.attemptingAutoLogin) {
return;
}
this.attemptingAutoLogin = true;
var user =
$app.loginForm.savedCredentials[
$app.loginForm.lastUserLoggedIn
];
if (typeof user === 'undefined') {
this.attemptingAutoLogin = false;
return;
}
if ($app.enablePrimaryPassword) {
this.logout();
return;
}
$app.relogin(user)
.then(() => {
if (this.errorNoty) {
this.errorNoty.close();
}
this.errorNoty = new Noty({
type: 'success',
text: 'Automatically logged in.'
}).show();
console.log('Automatically logged in.');
})
.catch((err) => {
if (this.errorNoty) {
this.errorNoty.close();
}
this.errorNoty = new Noty({
type: 'error',
text: 'Failed to login automatically.'
}).show();
console.error('Failed to login automatically.', err);
})
.finally(() => {
if (!navigator.onLine) {
this.errorNoty = new Noty({
type: 'error',
text: `You're offline.`
}).show();
console.error(`You're offline.`);
}
});
});
API.$on('USER:CURRENT', function () {
this.attemptingAutoLogin = false;
});
API.$on('LOGOUT', function () {
this.attemptingAutoLogin = false;
});
API.logout = function () {
this.$emit('LOGOUT');
// return this.call('logout', {
// method: 'PUT'
// }).finally(() => {
// this.$emit('LOGOUT');
// });
};
}
_data = {
loginForm: {
loading: true,
username: '',
password: '',
endpoint: '',
websocket: '',
saveCredentials: false,
savedCredentials: {},
lastUserLoggedIn: '',
rules: {
username: [
{
required: true,
trigger: 'blur'
}
],
password: [
{
required: true,
trigger: 'blur'
}
]
}
}
};
_methods = {
async relogin(user) {
var { loginParmas } = user;
if (user.cookies) {
await webApiService.setCookies(user.cookies);
}
this.loginForm.lastUserLoggedIn = user.user.id; // for resend email 2fa
if (loginParmas.endpoint) {
API.endpointDomain = loginParmas.endpoint;
API.websocketDomain = loginParmas.websocket;
} else {
API.endpointDomain = API.endpointDomainVrchat;
API.websocketDomain = API.websocketDomainVrchat;
}
return new Promise((resolve, reject) => {
if (this.enablePrimaryPassword) {
this.checkPrimaryPassword(loginParmas)
.then((pwd) => {
this.loginForm.loading = true;
return API.getConfig()
.catch((err) => {
this.loginForm.loading = false;
reject(err);
})
.then(() => {
API.login({
username: loginParmas.username,
password: pwd,
cipher: loginParmas.password,
endpoint: loginParmas.endpoint,
websocket: loginParmas.websocket
})
.catch((err2) => {
this.loginForm.loading = false;
// API.logout();
reject(err2);
})
.then(() => {
this.loginForm.loading = false;
resolve();
});
});
})
.catch((_) => {
this.$message({
message: 'Incorrect primary password',
type: 'error'
});
reject(_);
});
} else {
API.getConfig()
.catch((err) => {
this.loginForm.loading = false;
reject(err);
})
.then(() => {
API.login({
username: loginParmas.username,
password: loginParmas.password,
endpoint: loginParmas.endpoint,
websocket: loginParmas.websocket
})
.catch((err2) => {
this.loginForm.loading = false;
API.logout();
reject(err2);
})
.then(() => {
this.loginForm.loading = false;
resolve();
});
});
}
});
},
async deleteSavedLogin(userId) {
var savedCredentials = JSON.parse(
await configRepository.getString('savedCredentials')
);
delete savedCredentials[userId];
// Disable primary password when no account is available.
if (Object.keys(savedCredentials).length === 0) {
this.enablePrimaryPassword = false;
await configRepository.setBool('enablePrimaryPassword', false);
}
this.loginForm.savedCredentials = savedCredentials;
var jsonCredentials = JSON.stringify(savedCredentials);
await configRepository.setString(
'savedCredentials',
jsonCredentials
);
new Noty({
type: 'success',
text: 'Account removed.'
}).show();
},
async login() {
await webApiService.clearCookies();
this.$refs.loginForm.validate((valid) => {
if (valid && !this.loginForm.loading) {
this.loginForm.loading = true;
if (this.loginForm.endpoint) {
API.endpointDomain = this.loginForm.endpoint;
API.websocketDomain = this.loginForm.websocket;
} else {
API.endpointDomain = API.endpointDomainVrchat;
API.websocketDomain = API.websocketDomainVrchat;
}
API.getConfig()
.catch((err) => {
this.loginForm.loading = false;
throw err;
})
.then((args) => {
if (
this.loginForm.saveCredentials &&
this.enablePrimaryPassword
) {
$app.$prompt(
$t('prompt.primary_password.description'),
$t('prompt.primary_password.header'),
{
inputType: 'password',
inputPattern: /[\s\S]{1,32}/
}
)
.then(({ value }) => {
let saveCredential =
this.loginForm.savedCredentials[
Object.keys(
this.loginForm
.savedCredentials
)[0]
];
security
.decrypt(
saveCredential.loginParmas
.password,
value
)
.then(() => {
security
.encrypt(
this.loginForm.password,
value
)
.then((pwd) => {
API.login({
username:
this.loginForm
.username,
password:
this.loginForm
.password,
endpoint:
this.loginForm
.endpoint,
websocket:
this.loginForm
.websocket,
saveCredentials:
this.loginForm
.saveCredentials,
cipher: pwd
}).then(() => {
this.$refs.loginForm.resetFields();
});
});
});
})
.finally(() => {
this.loginForm.loading = false;
});
return args;
}
API.login({
username: this.loginForm.username,
password: this.loginForm.password,
endpoint: this.loginForm.endpoint,
websocket: this.loginForm.websocket,
saveCredentials: this.loginForm.saveCredentials
})
.then(() => {
this.$refs.loginForm.resetFields();
})
.finally(() => {
this.loginForm.loading = false;
});
return args;
});
}
});
},
logout() {
this.$confirm('Continue? Logout', 'Confirm', {
confirmButtonText: 'Confirm',
cancelButtonText: 'Cancel',
type: 'info',
callback: (action) => {
if (action === 'confirm') {
API.logout();
}
}
});
}
};
}

View File

@@ -0,0 +1,385 @@
import Noty from 'noty';
import { baseClass, $app, API, $t } from './baseClass.js';
/* eslint-disable no-unused-vars */
let webApiService = {};
/* eslint-enable no-unused-vars */
export default class extends baseClass {
constructor(_app, _API, _t, _webApiService) {
super(_app, _API, _t);
webApiService = _webApiService;
}
init() {
API.cachedConfig = {};
API.pendingGetRequests = new Map();
API.failedGetRequests = new Map();
API.endpointDomainVrchat = 'https://api.vrchat.cloud/api/1';
API.websocketDomainVrchat = 'wss://pipeline.vrchat.cloud';
API.endpointDomain = 'https://api.vrchat.cloud/api/1';
API.websocketDomain = 'wss://pipeline.vrchat.cloud';
API.call = function (endpoint, options) {
var init = {
url: `${API.endpointDomain}/${endpoint}`,
method: 'GET',
...options
};
var { params } = init;
if (init.method === 'GET') {
// don't retry recent 404/403
if (this.failedGetRequests.has(endpoint)) {
var lastRun = this.failedGetRequests.get(endpoint);
if (lastRun >= Date.now() - 900000) {
// 15mins
throw new Error(
`${$t('api.error.message.403_404_bailing_request')}, ${endpoint}`
);
}
this.failedGetRequests.delete(endpoint);
}
// transform body to url
if (params === Object(params)) {
var url = new URL(init.url);
var { searchParams } = url;
for (var key in params) {
searchParams.set(key, params[key]);
}
init.url = url.toString();
}
// merge requests
var req = this.pendingGetRequests.get(init.url);
if (typeof req !== 'undefined') {
if (req.time >= Date.now() - 10000) {
// 10s
return req.req;
}
this.pendingGetRequests.delete(init.url);
}
} else if (
init.uploadImage ||
init.uploadFilePUT ||
init.uploadImageLegacy
) {
// nothing
} else {
init.headers = {
'Content-Type': 'application/json;charset=utf-8',
...init.headers
};
init.body =
params === Object(params) ? JSON.stringify(params) : '{}';
}
var req = webApiService
.execute(init)
.catch((err) => {
this.$throw(0, err, endpoint);
})
.then((response) => {
if (!response.data) {
return response;
}
try {
response.data = JSON.parse(response.data);
if ($app.debugWebRequests) {
console.log(init, response.data);
}
return response;
} catch (e) {}
if (response.status === 200) {
this.$throw(
0,
$t('api.error.message.invalid_json_response'),
endpoint
);
}
if (
response.status === 429 &&
init.url.endsWith('/instances/groups')
) {
$app.nextGroupInstanceRefresh = 120; // 1min
throw new Error(
`${response.status}: rate limited ${endpoint}`
);
}
if (response.status === 504 || response.status === 502) {
// ignore expected API errors
throw new Error(
`${response.status}: ${response.data} ${endpoint}`
);
}
this.$throw(response.status, endpoint);
return {};
})
.then(({ data, status }) => {
if (status === 200) {
if (!data) {
return data;
}
var text = '';
if (data.success === Object(data.success)) {
text = data.success.message;
} else if (data.OK === String(data.OK)) {
text = data.OK;
}
if (text) {
new Noty({
type: 'success',
text: $app.escapeTag(text)
}).show();
}
return data;
}
if (
status === 401 &&
data.error.message === '"Missing Credentials"'
) {
this.$emit('AUTOLOGIN');
throw new Error(
`401 ${$t('api.error.message.missing_credentials')}`
);
}
if (
status === 401 &&
data.error.message === '"Unauthorized"' &&
endpoint !== 'auth/user'
) {
// trigger 2FA dialog
if (!$app.twoFactorAuthDialogVisible) {
$app.API.getCurrentUser();
}
throw new Error(`401 ${$t('api.status_code.401')}`);
}
if (status === 403 && endpoint === 'config') {
$app.$alert(
$t('api.error.message.vpn_in_use'),
`403 ${$t('api.error.message.login_error')}`
);
this.logout();
throw new Error(`403 ${endpoint}`);
}
if (
init.method === 'GET' &&
status === 404 &&
endpoint.startsWith('avatars/')
) {
$app.$message({
message: $t(
'message.api_handler.avatar_private_or_deleted'
),
type: 'error'
});
$app.avatarDialog.visible = false;
throw new Error(
`404: ${data.error.message} ${endpoint}`
);
}
if (
status === 404 &&
endpoint.endsWith('/persist/exists')
) {
return false;
}
if (
init.method === 'GET' &&
(status === 404 || status === 403) &&
!endpoint.startsWith('auth/user')
) {
this.failedGetRequests.set(endpoint, Date.now());
}
if (
init.method === 'GET' &&
status === 404 &&
endpoint.startsWith('users/') &&
endpoint.split('/').length - 1 === 1
) {
throw new Error(
`404: ${data.error.message} ${endpoint}`
);
}
if (
status === 404 &&
endpoint.startsWith('invite/') &&
init.inviteId
) {
this.expireNotification(init.inviteId);
}
if (
status === 403 &&
endpoint.startsWith('invite/myself/to/')
) {
throw new Error(
`403: ${data.error.message} ${endpoint}`
);
}
if (data && data.error === Object(data.error)) {
this.$throw(
data.error.status_code || status,
data.error.message,
endpoint
);
} else if (data && typeof data.error === 'string') {
this.$throw(
data.status_code || status,
data.error,
endpoint
);
}
this.$throw(status, data, endpoint);
return data;
});
if (init.method === 'GET') {
req.finally(() => {
this.pendingGetRequests.delete(init.url);
});
this.pendingGetRequests.set(init.url, {
req,
time: Date.now()
});
}
return req;
};
// FIXME : extra를 없애줘
API.$throw = function (code, error, endpoint) {
var text = [];
if (code > 0) {
const status = this.statusCodes[code];
if (typeof status === 'undefined') {
text.push(`${code}`);
} else {
const codeText = $t(`api.status_code.${code}`);
text.push(`${code} ${codeText}`);
}
}
if (typeof error !== 'undefined') {
text.push(
`${$t('api.error.message.error_message')}: ${typeof error === 'string' ? error : JSON.stringify(error)}`
);
}
if (typeof endpoint !== 'undefined') {
text.push(
`${$t('api.error.message.endpoint')}: "${typeof endpoint === 'string' ? endpoint : JSON.stringify(endpoint)}"`
);
}
text = text.map((s) => $app.escapeTag(s)).join('<br>');
if (text.length) {
if (this.errorNoty) {
this.errorNoty.close();
}
this.errorNoty = new Noty({
type: 'error',
text
}).show();
}
throw new Error(text);
};
API.$bulk = function (options, args) {
if ('handle' in options) {
options.handle.call(this, args, options);
}
if (
args.json.length > 0 &&
((options.params.offset += args.json.length),
// eslint-disable-next-line no-nested-ternary
options.N > 0
? options.N > options.params.offset
: options.N < 0
? args.json.length
: options.params.n === args.json.length)
) {
this.bulk(options);
} else if ('done' in options) {
options.done.call(this, true, options);
}
return args;
};
API.bulk = function (options) {
this[options.fn](options.params)
.catch((err) => {
if ('done' in options) {
options.done.call(this, false, options);
}
throw err;
})
.then((args) => this.$bulk(options, args));
};
API.statusCodes = {
100: 'Continue',
101: 'Switching Protocols',
102: 'Processing',
103: 'Early Hints',
200: 'OK',
201: 'Created',
202: 'Accepted',
203: 'Non-Authoritative Information',
204: 'No Content',
205: 'Reset Content',
206: 'Partial Content',
207: 'Multi-Status',
208: 'Already Reported',
226: 'IM Used',
300: 'Multiple Choices',
301: 'Moved Permanently',
302: 'Found',
303: 'See Other',
304: 'Not Modified',
305: 'Use Proxy',
306: 'Switch Proxy',
307: 'Temporary Redirect',
308: 'Permanent Redirect',
400: 'Bad Request',
401: 'Unauthorized',
402: 'Payment Required',
403: 'Forbidden',
404: 'Not Found',
405: 'Method Not Allowed',
406: 'Not Acceptable',
407: 'Proxy Authentication Required',
408: 'Request Timeout',
409: 'Conflict',
410: 'Gone',
411: 'Length Required',
412: 'Precondition Failed',
413: 'Payload Too Large',
414: 'URI Too Long',
415: 'Unsupported Media Type',
416: 'Range Not Satisfiable',
417: 'Expectation Failed',
418: "I'm a teapot",
421: 'Misdirected Request',
422: 'Unprocessable Entity',
423: 'Locked',
424: 'Failed Dependency',
425: 'Too Early',
426: 'Upgrade Required',
428: 'Precondition Required',
429: 'Too Many Requests',
431: 'Request Header Fields Too Large',
451: 'Unavailable For Legal Reasons',
500: 'Internal Server Error',
501: 'Not Implemented',
502: 'Bad Gateway',
503: 'Service Unavailable',
504: 'Gateway Timeout',
505: 'HTTP Version Not Supported',
506: 'Variant Also Negotiates',
507: 'Insufficient Storage',
508: 'Loop Detected',
510: 'Not Extended',
511: 'Network Authentication Required',
// CloudFlare Error
520: 'Web server returns an unknown error',
521: 'Web server is down',
522: 'Connection timed out',
523: 'Origin is unreachable',
524: 'A timeout occurred',
525: 'SSL handshake failed',
526: 'Invalid SSL certificate',
527: 'Railgun Listener to origin error'
};
}
}

28
src/classes/baseClass.js Normal file
View File

@@ -0,0 +1,28 @@
import $utils from './utils';
/* eslint-disable no-unused-vars */
let $app = {};
let API = {};
let $t = {};
/* eslint-enable no-unused-vars */
class baseClass {
constructor(_app, _API, _t) {
$app = _app;
API = _API;
$t = _t;
this.init();
}
updateRef(_app) {
$app = _app;
}
init() {}
_data = {};
_methods = {};
}
export { baseClass, $app, API, $t, $utils };

103
src/classes/booping.js Normal file
View File

@@ -0,0 +1,103 @@
import { baseClass, $app, API, $t, $utils } from './baseClass.js';
export default class extends baseClass {
constructor(_app, _API, _t) {
super(_app, _API, _t);
}
init() {
/**
* @params {{
userId: string,
emojiId: string
}} params
* @returns {Promise<{json: any, params}>}
*/
API.sendBoop = function (params) {
return this.call(`users/${params.userId}/boop`, {
method: 'POST',
params
}).then((json) => {
var args = {
json,
params
};
this.$emit('BOOP:SEND', args);
return args;
});
};
}
_data = {
sendBoopDialog: {
visible: false,
userId: '',
fileId: ''
}
};
_methods = {
sendBoop() {
var D = this.sendBoopDialog;
this.dismissBoop(D.userId);
var params = {
userId: D.userId
};
if (D.fileId) {
params.emojiId = D.fileId;
}
API.sendBoop(params);
D.visible = false;
},
dismissBoop(userId) {
// JANK: This is a hack to remove boop notifications when responding
var array = this.notificationTable.data;
for (var i = array.length - 1; i >= 0; i--) {
var ref = array[i];
if (
ref.type !== 'boop' ||
ref.$isExpired ||
ref.senderUserId !== userId
) {
continue;
}
API.sendNotificationResponse({
notificationId: ref.id,
responseType: 'delete',
responseData: ''
});
}
},
showSendBoopDialog(userId) {
this.$nextTick(() =>
$app.adjustDialogZ(this.$refs.sendBoopDialog.$el)
);
var D = this.sendBoopDialog;
D.userId = userId;
D.visible = true;
if (this.emojiTable.length === 0 && API.currentUser.$isVRCPlus) {
this.refreshEmojiTable();
}
},
getEmojiValue(emojiName) {
if (!emojiName) {
return '';
}
return `vrchat_${emojiName.replace(/ /g, '_').toLowerCase()}`;
},
getEmojiName(emojiValue) {
// uppercase first letter of each word
if (!emojiValue) {
return '';
}
return emojiValue
.replace('vrchat_', '')
.replace(/_/g, ' ')
.replace(/\b\w/g, (l) => l.toUpperCase());
}
};
}

341
src/classes/currentUser.js Normal file
View File

@@ -0,0 +1,341 @@
import { baseClass, $app, API, $t, $utils } from './baseClass.js';
export default class extends baseClass {
constructor(_app, _API, _t) {
super(_app, _API, _t);
}
init() {
API.currentUser = {
$userColour: ''
};
API.getCurrentUser = function () {
return this.call('auth/user', {
method: 'GET'
}).then((json) => {
var args = {
json,
fromGetCurrentUser: true
};
if (
json.requiresTwoFactorAuth &&
json.requiresTwoFactorAuth.includes('emailOtp')
) {
this.$emit('USER:EMAILOTP', args);
} else if (json.requiresTwoFactorAuth) {
this.$emit('USER:2FA', args);
} else {
if ($app.debugCurrentUserDiff) {
var ref = args.json;
var $ref = this.currentUser;
var props = {};
for (var prop in $ref) {
if ($ref[prop] !== Object($ref[prop])) {
props[prop] = true;
}
}
for (var prop in ref) {
if (
Array.isArray(ref[prop]) &&
Array.isArray($ref[prop])
) {
if (!$app.arraysMatch(ref[prop], $ref[prop])) {
props[prop] = true;
}
} else if (ref[prop] !== Object(ref[prop])) {
props[prop] = true;
}
}
var has = false;
for (var prop in props) {
var asis = $ref[prop];
var tobe = ref[prop];
if (asis === tobe) {
delete props[prop];
} else {
if (
prop.startsWith('$') ||
prop === 'offlineFriends' ||
prop === 'onlineFriends' ||
prop === 'activeFriends'
) {
delete props[prop];
continue;
}
props[prop] = [tobe, asis];
has = true;
}
}
if (has) {
console.log('API.getCurrentUser diff', props);
}
}
$app.nextCurrentUserRefresh = 420; // 7mins
this.$emit('USER:CURRENT', args);
}
return args;
});
};
API.$on('USER:CURRENT', function (args) {
var { json } = args;
args.ref = this.applyCurrentUser(json);
// when isGameRunning use gameLog instead of API
var $location = $app.parseLocation($app.lastLocation.location);
var $travelingLocation = $app.parseLocation(
$app.lastLocationDestination
);
var location = $app.lastLocation.location;
var instanceId = $location.instanceId;
var worldId = $location.worldId;
var travelingToLocation = $app.lastLocationDestination;
var travelingToWorld = $travelingLocation.worldId;
var travelingToInstance = $travelingLocation.instanceId;
if (!$app.isGameRunning && json.presence) {
if ($app.isRealInstance(json.presence.world)) {
location = `${json.presence.world}:${json.presence.instance}`;
travelingToLocation = `${json.presence.travelingToWorld}:${json.presence.travelingToInstance}`;
} else {
location = json.presence.world;
travelingToLocation = json.presence.travelingToWorld;
}
instanceId = json.presence.instance;
worldId = json.presence.world;
travelingToInstance = json.presence.travelingToInstance;
travelingToWorld = json.presence.travelingToWorld;
}
this.applyUser({
allowAvatarCopying: json.allowAvatarCopying,
badges: json.badges,
bio: json.bio,
bioLinks: json.bioLinks,
currentAvatarImageUrl: json.currentAvatarImageUrl,
currentAvatarTags: json.currentAvatarTags,
currentAvatarThumbnailImageUrl:
json.currentAvatarThumbnailImageUrl,
date_joined: json.date_joined,
developerType: json.developerType,
displayName: json.displayName,
friendKey: json.friendKey,
// json.friendRequestStatus - missing from currentUser
id: json.id,
// instanceId - missing from currentUser
isFriend: json.isFriend,
last_activity: json.last_activity,
last_login: json.last_login,
last_mobile: json.last_mobile,
last_platform: json.last_platform,
// location - missing from currentUser
// platform - missing from currentUser
// note - missing from currentUser
profilePicOverride: json.profilePicOverride,
// profilePicOverrideThumbnail - missing from currentUser
pronouns: json.pronouns,
state: json.state,
status: json.status,
statusDescription: json.statusDescription,
tags: json.tags,
// travelingToInstance - missing from currentUser
// travelingToLocation - missing from currentUser
// travelingToWorld - missing from currentUser
userIcon: json.userIcon,
// worldId - missing from currentUser
fallbackAvatar: json.fallbackAvatar,
// Location from gameLog/presence
location,
instanceId,
worldId,
travelingToLocation,
travelingToInstance,
travelingToWorld,
// set VRCX online/offline timers
$online_for: this.currentUser.$online_for,
$offline_for: this.currentUser.$offline_for,
$location_at: this.currentUser.$location_at,
$travelingToTime: this.currentUser.$travelingToTime
});
});
API.applyCurrentUser = function (json) {
var ref = this.currentUser;
if (this.isLoggedIn) {
if (json.currentAvatar !== ref.currentAvatar) {
$app.addAvatarToHistory(json.currentAvatar);
}
Object.assign(ref, json);
if (ref.homeLocation !== ref.$homeLocation.tag) {
ref.$homeLocation = $app.parseLocation(ref.homeLocation);
// apply home location name to user dialog
if (
$app.userDialog.visible &&
$app.userDialog.id === ref.id
) {
$app.getWorldName(API.currentUser.homeLocation).then(
(worldName) => {
$app.userDialog.$homeLocationName = worldName;
}
);
}
}
ref.$isVRCPlus = ref.tags.includes('system_supporter');
this.applyUserTrustLevel(ref);
this.applyUserLanguage(ref);
this.applyPresenceLocation(ref);
this.applyQueuedInstance(ref.queuedInstance);
this.applyPresenceGroups(ref);
} else {
ref = {
acceptedPrivacyVersion: 0,
acceptedTOSVersion: 0,
accountDeletionDate: null,
accountDeletionLog: null,
activeFriends: [],
ageVerificationStatus: '',
ageVerified: false,
allowAvatarCopying: false,
badges: [],
bio: '',
bioLinks: [],
currentAvatar: '',
currentAvatarAssetUrl: '',
currentAvatarImageUrl: '',
currentAvatarTags: [],
currentAvatarThumbnailImageUrl: '',
date_joined: '',
developerType: '',
displayName: '',
emailVerified: false,
fallbackAvatar: '',
friendGroupNames: [],
friendKey: '',
friends: [],
googleId: '',
hasBirthday: false,
hasEmail: false,
hasLoggedInFromClient: false,
hasPendingEmail: false,
hideContentFilterSettings: false,
homeLocation: '',
id: '',
isBoopingEnabled: false,
isFriend: false,
last_activity: '',
last_login: '',
last_mobile: null,
last_platform: '',
obfuscatedEmail: '',
obfuscatedPendingEmail: '',
oculusId: '',
offlineFriends: [],
onlineFriends: [],
pastDisplayNames: [],
picoId: '',
presence: {
avatarThumbnail: '',
currentAvatarTags: '',
displayName: '',
groups: [],
id: '',
instance: '',
instanceType: '',
platform: '',
profilePicOverride: '',
status: '',
travelingToInstance: '',
travelingToWorld: '',
userIcon: '',
world: '',
...json.presence
},
profilePicOverride: '',
pronouns: '',
queuedInstance: '',
state: '',
status: '',
statusDescription: '',
statusFirstTime: false,
statusHistory: [],
steamDetails: {},
steamId: '',
tags: [],
twoFactorAuthEnabled: false,
twoFactorAuthEnabledDate: null,
unsubscribe: false,
updated_at: '',
userIcon: '',
userLanguage: '',
userLanguageCode: '',
username: '',
viveId: '',
// VRCX
$online_for: Date.now(),
$offline_for: '',
$location_at: Date.now(),
$travelingToTime: Date.now(),
$homeLocation: {},
$isVRCPlus: false,
$isModerator: false,
$isTroll: false,
$isProbableTroll: false,
$trustLevel: 'Visitor',
$trustClass: 'x-tag-untrusted',
$userColour: '',
$trustSortNum: 1,
$languages: [],
$locationTag: '',
$travelingToLocation: '',
$vrchatcredits: null,
...json
};
ref.$homeLocation = $app.parseLocation(ref.homeLocation);
ref.$isVRCPlus = ref.tags.includes('system_supporter');
this.applyUserTrustLevel(ref);
this.applyUserLanguage(ref);
this.applyPresenceLocation(ref);
this.applyPresenceGroups(ref);
this.currentUser = ref;
this.isLoggedIn = true;
this.$emit('LOGIN', {
json,
ref
});
}
return ref;
};
/**
* @typedef {{
* status: 'active' | 'offline' | 'busy' | 'ask me' | 'join me',
* statusDescription: string
* }} SaveCurrentUserParameters
*/
/**
* Updates current user's status.
* @param params {SaveCurrentUserParameters} new status to be set
* @returns {Promise<{json: any, params}>}
*/
API.saveCurrentUser = function (params) {
return this.call(`users/${this.currentUser.id}`, {
method: 'PUT',
params
}).then((json) => {
var args = {
json,
params
};
this.$emit('USER:CURRENT:SAVE', args);
return args;
});
};
}
_data = {};
_methods = {};
}

285
src/classes/discordRpc.js Normal file
View File

@@ -0,0 +1,285 @@
import configRepository from '../repository/config.js';
import { baseClass, $app, API, $t, $utils } from './baseClass.js';
export default class extends baseClass {
constructor(_app, _API, _t) {
super(_app, _API, _t);
}
_data = {
isDiscordActive: false,
discordActive: false,
discordInstance: true,
discordJoinButton: false,
discordHideInvite: true,
discordHideImage: false
};
_methods = {
updateDiscord() {
var currentLocation = this.lastLocation.location;
var timeStamp = this.lastLocation.date;
if (this.lastLocation.location === 'traveling') {
currentLocation = this.lastLocationDestination;
timeStamp = this.lastLocationDestinationTime;
}
if (
!this.discordActive ||
(!this.isGameRunning && !this.gameLogDisabled) ||
(!currentLocation && !this.lastLocation$.tag)
) {
this.setDiscordActive(false);
return;
}
this.setDiscordActive(true);
var L = this.lastLocation$;
if (currentLocation !== this.lastLocation$.tag) {
Discord.SetTimestamps(timeStamp, 0);
L = $app.parseLocation(currentLocation);
L.worldName = '';
L.thumbnailImageUrl = '';
L.worldCapacity = 0;
L.joinUrl = '';
L.accessName = '';
if (L.worldId) {
var ref = API.cachedWorlds.get(L.worldId);
if (ref) {
L.worldName = ref.name;
L.thumbnailImageUrl = ref.thumbnailImageUrl;
L.worldCapacity = ref.capacity;
} else {
API.getWorld({
worldId: L.worldId
}).then((args) => {
L.worldName = args.ref.name;
L.thumbnailImageUrl = args.ref.thumbnailImageUrl;
L.worldCapacity = args.ref.capacity;
return args;
});
}
if (this.isGameNoVR) {
var platform = 'Desktop';
} else {
var platform = 'VR';
}
var groupAccessType = '';
if (L.groupAccessType) {
if (L.groupAccessType === 'public') {
groupAccessType = 'Public';
} else if (L.groupAccessType === 'plus') {
groupAccessType = 'Plus';
}
}
switch (L.accessType) {
case 'public':
L.joinUrl = this.getLaunchURL(L);
L.accessName = `Public #${L.instanceName} (${platform})`;
break;
case 'invite+':
L.accessName = `Invite+ #${L.instanceName} (${platform})`;
break;
case 'invite':
L.accessName = `Invite #${L.instanceName} (${platform})`;
break;
case 'friends':
L.accessName = `Friends #${L.instanceName} (${platform})`;
break;
case 'friends+':
L.accessName = `Friends+ #${L.instanceName} (${platform})`;
break;
case 'group':
L.accessName = `Group #${L.instanceName} (${platform})`;
this.getGroupName(L.groupId).then((groupName) => {
if (groupName) {
L.accessName = `Group${groupAccessType}(${groupName}) #${L.instanceName} (${platform})`;
}
});
break;
}
}
this.lastLocation$ = L;
}
var hidePrivate = false;
if (
this.discordHideInvite &&
(L.accessType === 'invite' ||
L.accessType === 'invite+' ||
L.groupAccessType === 'members')
) {
hidePrivate = true;
}
switch (API.currentUser.status) {
case 'active':
L.statusName = 'Online';
L.statusImage = 'active';
break;
case 'join me':
L.statusName = 'Join Me';
L.statusImage = 'joinme';
break;
case 'ask me':
L.statusName = 'Ask Me';
L.statusImage = 'askme';
if (this.discordHideInvite) {
hidePrivate = true;
}
break;
case 'busy':
L.statusName = 'Do Not Disturb';
L.statusImage = 'busy';
hidePrivate = true;
break;
}
var appId = '883308884863901717';
var bigIcon = 'vrchat';
var partyId = `${L.worldId}:${L.instanceName}`;
var partySize = this.lastLocation.playerList.size;
var partyMaxSize = L.worldCapacity;
if (partySize > partyMaxSize) {
partyMaxSize = partySize;
}
var buttonText = 'Join';
var buttonUrl = L.joinUrl;
if (!this.discordJoinButton) {
buttonText = '';
buttonUrl = '';
}
if (!this.discordInstance) {
partySize = 0;
partyMaxSize = 0;
}
if (hidePrivate) {
partyId = '';
partySize = 0;
partyMaxSize = 0;
buttonText = '';
buttonUrl = '';
} else if (this.isRpcWorld(L.tag)) {
// custom world rpc
if (
L.worldId === 'wrld_f20326da-f1ac-45fc-a062-609723b097b1' ||
L.worldId === 'wrld_10e5e467-fc65-42ed-8957-f02cace1398c' ||
L.worldId === 'wrld_04899f23-e182-4a8d-b2c7-2c74c7c15534'
) {
appId = '784094509008551956';
bigIcon = 'pypy';
} else if (
L.worldId === 'wrld_42377cf1-c54f-45ed-8996-5875b0573a83' ||
L.worldId === 'wrld_dd6d2888-dbdc-47c2-bc98-3d631b2acd7c'
) {
appId = '846232616054030376';
bigIcon = 'vr_dancing';
} else if (
L.worldId === 'wrld_52bdcdab-11cd-4325-9655-0fb120846945' ||
L.worldId === 'wrld_2d40da63-8f1f-4011-8a9e-414eb8530acd'
) {
appId = '939473404808007731';
bigIcon = 'zuwa_zuwa_dance';
} else if (
L.worldId === 'wrld_74970324-58e8-4239-a17b-2c59dfdf00db' ||
L.worldId === 'wrld_db9d878f-6e76-4776-8bf2-15bcdd7fc445' ||
L.worldId === 'wrld_435bbf25-f34f-4b8b-82c6-cd809057eb8e' ||
L.worldId === 'wrld_f767d1c8-b249-4ecc-a56f-614e433682c8'
) {
appId = '968292722391785512';
bigIcon = 'ls_media';
} else if (
L.worldId === 'wrld_266523e8-9161-40da-acd0-6bd82e075833'
) {
appId = '1095440531821170820';
bigIcon = 'movie_and_chill';
}
if (this.nowPlaying.name) {
L.worldName = this.nowPlaying.name;
}
if (this.nowPlaying.playing) {
Discord.SetTimestamps(
Date.now(),
(this.nowPlaying.startTime -
this.nowPlaying.offset +
this.nowPlaying.length) *
1000
);
}
} else if (!this.discordHideImage && L.thumbnailImageUrl) {
bigIcon = L.thumbnailImageUrl;
}
Discord.SetAssets(
bigIcon, // big icon
'Powered by VRCX', // big icon hover text
L.statusImage, // small icon
L.statusName, // small icon hover text
partyId, // party id
partySize, // party size
partyMaxSize, // party max size
buttonText, // button text
buttonUrl, // button url
appId // app id
);
// NOTE
// 글자 수가 짧으면 업데이트가 안된다..
if (L.worldName.length < 2) {
L.worldName += '\uFFA0'.repeat(2 - L.worldName.length);
}
if (hidePrivate) {
Discord.SetText('Private', '');
Discord.SetTimestamps(0, 0);
} else if (this.discordInstance) {
Discord.SetText(L.worldName, L.accessName);
} else {
Discord.SetText(L.worldName, '');
}
},
async setDiscordActive(active) {
if (active !== this.isDiscordActive) {
this.isDiscordActive = await Discord.SetActive(active);
}
},
async saveDiscordOption(configLabel = '') {
if (configLabel === 'discordActive') {
this.discordActive = !this.discordActive;
await configRepository.setBool(
'discordActive',
this.discordActive
);
}
if (configLabel === 'discordInstance') {
this.discordInstance = !this.discordInstance;
await configRepository.setBool(
'discordInstance',
this.discordInstance
);
}
if (configLabel === 'discordJoinButton') {
this.discordJoinButton = !this.discordJoinButton;
await configRepository.setBool(
'discordJoinButton',
this.discordJoinButton
);
}
if (configLabel === 'discordHideInvite') {
this.discordHideInvite = !this.discordHideInvite;
await configRepository.setBool(
'discordHideInvite',
this.discordHideInvite
);
}
if (configLabel === 'discordHideImage') {
this.discordHideImage = !this.discordHideImage;
await configRepository.setBool(
'discordHideImage',
this.discordHideImage
);
}
this.lastLocation$.tag = '';
this.nextDiscordUpdate = 3;
this.updateDiscord();
}
};
}

179
src/classes/feed.js Normal file
View File

@@ -0,0 +1,179 @@
import { baseClass, $app, API, $t, $utils } from './baseClass.js';
import configRepository from '../repository/config.js';
import database from '../repository/database.js';
export default class extends baseClass {
constructor(_app, _API, _t) {
super(_app, _API, _t);
}
_data = {
feedTable: {
data: [],
search: '',
vip: false,
loading: false,
filter: [],
tableProps: {
stripe: true,
size: 'mini',
defaultSort: {
prop: 'created_at',
order: 'descending'
}
},
pageSize: 15,
paginationProps: {
small: true,
layout: 'sizes,prev,pager,next,total',
pageSizes: [10, 15, 25, 50, 100]
}
},
feedSessionTable: []
};
_methods = {
feedSearch(row) {
var value = this.feedTable.search.toUpperCase();
if (!value) {
return true;
}
if (
value.startsWith('wrld_') &&
String(row.location).toUpperCase().includes(value)
) {
return true;
}
switch (row.type) {
case 'GPS':
if (String(row.displayName).toUpperCase().includes(value)) {
return true;
}
if (String(row.worldName).toUpperCase().includes(value)) {
return true;
}
return false;
case 'Online':
if (String(row.displayName).toUpperCase().includes(value)) {
return true;
}
if (String(row.worldName).toUpperCase().includes(value)) {
return true;
}
return false;
case 'Offline':
if (String(row.displayName).toUpperCase().includes(value)) {
return true;
}
if (String(row.worldName).toUpperCase().includes(value)) {
return true;
}
return false;
case 'Status':
if (String(row.displayName).toUpperCase().includes(value)) {
return true;
}
if (String(row.status).toUpperCase().includes(value)) {
return true;
}
if (
String(row.statusDescription)
.toUpperCase()
.includes(value)
) {
return true;
}
return false;
case 'Avatar':
if (String(row.displayName).toUpperCase().includes(value)) {
return true;
}
if (String(row.avatarName).toUpperCase().includes(value)) {
return true;
}
return false;
case 'Bio':
if (String(row.displayName).toUpperCase().includes(value)) {
return true;
}
if (String(row.bio).toUpperCase().includes(value)) {
return true;
}
if (String(row.previousBio).toUpperCase().includes(value)) {
return true;
}
return false;
}
return true;
},
async feedTableLookup() {
await configRepository.setString(
'VRCX_feedTableFilters',
JSON.stringify(this.feedTable.filter)
);
await configRepository.setBool(
'VRCX_feedTableVIPFilter',
this.feedTable.vip
);
this.feedTable.loading = true;
var vipList = [];
if (this.feedTable.vip) {
vipList = Array.from(this.localFavoriteFriends.values());
}
this.feedTable.data = await database.lookupFeedDatabase(
this.feedTable.search,
this.feedTable.filter,
vipList
);
this.feedTable.loading = false;
},
addFeed(feed) {
this.queueFeedNoty(feed);
this.feedSessionTable.push(feed);
this.updateSharedFeed(false);
if (
this.feedTable.filter.length > 0 &&
!this.feedTable.filter.includes(feed.type)
) {
return;
}
if (
this.feedTable.vip &&
!this.localFavoriteFriends.has(feed.userId)
) {
return;
}
if (!this.feedSearch(feed)) {
return;
}
this.feedTable.data.push(feed);
this.sweepFeed();
this.notifyMenu('feed');
},
sweepFeed() {
var { data } = this.feedTable;
var j = data.length;
if (j > this.maxTableSize) {
data.splice(0, j - this.maxTableSize);
}
var date = new Date();
date.setDate(date.getDate() - 1); // 24 hour limit
var limit = date.toJSON();
var i = 0;
var k = this.feedSessionTable.length;
while (i < k && this.feedSessionTable[i].created_at < limit) {
++i;
}
if (i === k) {
this.feedSessionTable = [];
} else if (i) {
this.feedSessionTable.splice(0, i);
}
}
};
}

1129
src/classes/gameLog.js Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

3569
src/classes/groups.js Normal file

File diff suppressed because it is too large Load Diff

162
src/classes/languages.js Normal file
View File

@@ -0,0 +1,162 @@
import { baseClass, $app, API, $t, $utils } from './baseClass.js';
export default class extends baseClass {
constructor(_app, _API, _t) {
super(_app, _API, _t);
}
init() {
API.$on('CONFIG', function (args) {
var languages =
args.ref?.constants?.LANGUAGE?.SPOKEN_LANGUAGE_OPTIONS;
if (!languages) {
return;
}
$app.subsetOfLanguages = languages;
var data = [];
for (var key in languages) {
var value = languages[key];
data.push({
key,
value
});
}
$app.languageDialog.languages = data;
});
API.$on('LOGOUT', function () {
$app.languageDialog.visible = false;
});
}
_data = {
// vrchat to famfamfam language mappings
languageMappings: {
eng: 'us',
kor: 'kr',
rus: 'ru',
spa: 'es',
por: 'pt',
zho: 'cn',
deu: 'de',
jpn: 'jp',
fra: 'fr',
swe: 'se',
nld: 'nl',
pol: 'pl',
dan: 'dk',
nor: 'no',
ita: 'it',
tha: 'th',
fin: 'fi',
hun: 'hu',
ces: 'cz',
tur: 'tr',
ara: 'ae',
ron: 'ro',
vie: 'vn',
ukr: 'ua',
ase: 'us',
bfi: 'gb',
dse: 'nl',
fsl: 'fr',
jsl: 'jp',
kvk: 'kr',
mlt: 'mt',
ind: 'id',
hrv: 'hr',
heb: 'he',
afr: 'af',
ben: 'be',
bul: 'bg',
cmn: 'cn',
cym: 'cy',
ell: 'el',
est: 'et',
fil: 'ph',
gla: 'gd',
gle: 'ga',
hin: 'hi',
hmn: 'cn',
hye: 'hy',
isl: 'is',
lav: 'lv',
lit: 'lt',
ltz: 'lb',
mar: 'hi',
mkd: 'mk',
msa: 'my',
sco: 'gd',
slk: 'sk',
slv: 'sl',
tel: 'hi',
mri: 'nz',
wuu: 'cn',
yue: 'cn',
tws: 'cn',
asf: 'au',
nzs: 'nz',
gsg: 'de',
epo: 'eo',
tok: 'tok'
},
subsetOfLanguages: [],
languageDialog: {
visible: false,
loading: false,
languageChoice: false,
languageValue: '',
languages: []
}
};
_methods = {
languageClass(language) {
var style = {};
var mapping = this.languageMappings[language];
if (typeof mapping !== 'undefined') {
style[mapping] = true;
} else {
style.unknown = true;
}
return style;
},
addUserLanguage(language) {
if (language !== String(language)) {
return;
}
var D = this.languageDialog;
D.loading = true;
API.addUserTags({
tags: [`language_${language}`]
}).finally(function () {
D.loading = false;
});
},
removeUserLanguage(language) {
if (language !== String(language)) {
return;
}
var D = this.languageDialog;
D.loading = true;
API.removeUserTags({
tags: [`language_${language}`]
}).finally(function () {
D.loading = false;
});
},
showLanguageDialog() {
this.$nextTick(() =>
$app.adjustDialogZ(this.$refs.languageDialog.$el)
);
var D = this.languageDialog;
D.visible = true;
}
};
}

147
src/classes/memos.js Normal file
View File

@@ -0,0 +1,147 @@
import { baseClass, $app, API, $t, $utils } from './baseClass.js';
import database from '../repository/database.js';
export default class extends baseClass {
constructor(_app, _API, _t) {
super(_app, _API, _t);
}
init() {}
_data = {
hideUserMemos: false
};
_methods = {
async migrateMemos() {
var json = JSON.parse(await VRCXStorage.GetAll());
database.begin();
for (var line in json) {
if (line.substring(0, 8) === 'memo_usr') {
var userId = line.substring(5);
var memo = json[line];
if (memo) {
await this.saveUserMemo(userId, memo);
VRCXStorage.Remove(`memo_${userId}`);
}
}
}
database.commit();
},
onUserMemoChange() {
var D = this.userDialog;
this.saveUserMemo(D.id, D.memo);
},
async getUserMemo(userId) {
try {
return await database.getUserMemo(userId);
} catch (err) {
console.error(err);
return {
userId: '',
editedAt: '',
memo: ''
};
}
},
saveUserMemo(id, memo) {
if (memo) {
database.setUserMemo({
userId: id,
editedAt: new Date().toJSON(),
memo
});
} else {
database.deleteUserMemo(id);
}
var ref = this.friends.get(id);
if (ref) {
ref.memo = String(memo || '');
if (memo) {
var array = memo.split('\n');
ref.$nickName = array[0];
} else {
ref.$nickName = '';
}
}
},
async getAllUserMemos() {
var memos = await database.getAllUserMemos();
memos.forEach((memo) => {
var ref = $app.friends.get(memo.userId);
if (typeof ref !== 'undefined') {
ref.memo = memo.memo;
ref.$nickName = '';
if (memo.memo) {
var array = memo.memo.split('\n');
ref.$nickName = array[0];
}
}
});
},
onWorldMemoChange() {
var D = this.worldDialog;
this.saveWorldMemo(D.id, D.memo);
},
async getWorldMemo(worldId) {
try {
return await database.getWorldMemo(worldId);
} catch (err) {
console.error(err);
return {
worldId: '',
editedAt: '',
memo: ''
};
}
},
saveWorldMemo(worldId, memo) {
if (memo) {
database.setWorldMemo({
worldId,
editedAt: new Date().toJSON(),
memo
});
} else {
database.deleteWorldMemo(worldId);
}
},
onAvatarMemoChange() {
var D = this.avatarDialog;
this.saveAvatarMemo(D.id, D.memo);
},
async getAvatarMemo(avatarId) {
try {
return await database.getAvatarMemoDB(avatarId);
} catch (err) {
console.error(err);
return {
avatarId: '',
editedAt: '',
memo: ''
};
}
},
saveAvatarMemo(avatarId, memo) {
if (memo) {
database.setAvatarMemo({
avatarId,
editedAt: new Date().toJSON(),
memo
});
} else {
database.deleteAvatarMemo(avatarId);
}
}
};
}

809
src/classes/prompts.js Normal file
View File

@@ -0,0 +1,809 @@
import * as workerTimers from 'worker-timers';
import configRepository from '../repository/config.js';
import database from '../repository/database.js';
import { baseClass, $app, API, $t, $utils } from './baseClass.js';
export default class extends baseClass {
constructor(_app, _API, _t) {
super(_app, _API, _t);
}
_methods = {
promptTOTP() {
if (this.twoFactorAuthDialogVisible) {
return;
}
AppApi.FlashWindow();
this.twoFactorAuthDialogVisible = true;
this.$prompt(
$t('prompt.totp.description'),
$t('prompt.totp.header'),
{
distinguishCancelAndClose: true,
cancelButtonText: $t('prompt.totp.use_otp'),
confirmButtonText: $t('prompt.totp.verify'),
inputPlaceholder: $t('prompt.totp.input_placeholder'),
inputPattern: /^[0-9]{6}$/,
inputErrorMessage: $t('prompt.totp.input_error'),
callback: (action, instance) => {
if (action === 'confirm') {
API.verifyTOTP({
code: instance.inputValue.trim()
})
.catch((err) => {
this.promptTOTP();
throw err;
})
.then((args) => {
API.getCurrentUser();
return args;
});
} else if (action === 'cancel') {
this.promptOTP();
}
},
beforeClose: (action, instance, done) => {
this.twoFactorAuthDialogVisible = false;
done();
}
}
);
},
promptOTP() {
if (this.twoFactorAuthDialogVisible) {
return;
}
this.twoFactorAuthDialogVisible = true;
this.$prompt(
$t('prompt.otp.description'),
$t('prompt.otp.header'),
{
distinguishCancelAndClose: true,
cancelButtonText: $t('prompt.otp.use_totp'),
confirmButtonText: $t('prompt.otp.verify'),
inputPlaceholder: $t('prompt.otp.input_placeholder'),
inputPattern: /^[a-z0-9]{4}-[a-z0-9]{4}$/,
inputErrorMessage: $t('prompt.otp.input_error'),
callback: (action, instance) => {
if (action === 'confirm') {
API.verifyOTP({
code: instance.inputValue.trim()
})
.catch((err) => {
this.promptOTP();
throw err;
})
.then((args) => {
API.getCurrentUser();
return args;
});
} else if (action === 'cancel') {
this.promptTOTP();
}
},
beforeClose: (action, instance, done) => {
this.twoFactorAuthDialogVisible = false;
done();
}
}
);
},
promptEmailOTP() {
if (this.twoFactorAuthDialogVisible) {
return;
}
AppApi.FlashWindow();
this.twoFactorAuthDialogVisible = true;
this.$prompt(
$t('prompt.email_otp.description'),
$t('prompt.email_otp.header'),
{
distinguishCancelAndClose: true,
cancelButtonText: $t('prompt.email_otp.resend'),
confirmButtonText: $t('prompt.email_otp.verify'),
inputPlaceholder: $t('prompt.email_otp.input_placeholder'),
inputPattern: /^[0-9]{6}$/,
inputErrorMessage: $t('prompt.email_otp.input_error'),
callback: (action, instance) => {
if (action === 'confirm') {
API.verifyEmailOTP({
code: instance.inputValue.trim()
})
.catch((err) => {
this.promptEmailOTP();
throw err;
})
.then((args) => {
API.getCurrentUser();
return args;
});
} else if (action === 'cancel') {
this.resendEmail2fa();
}
},
beforeClose: (action, instance, done) => {
this.twoFactorAuthDialogVisible = false;
done();
}
}
);
},
promptUserIdDialog() {
this.$prompt(
$t('prompt.direct_access_user_id.description'),
$t('prompt.direct_access_user_id.header'),
{
distinguishCancelAndClose: true,
confirmButtonText: $t('prompt.direct_access_user_id.ok'),
cancelButtonText: $t('prompt.direct_access_user_id.cancel'),
inputPattern: /\S+/,
inputErrorMessage: $t(
'prompt.direct_access_user_id.input_error'
),
callback: (action, instance) => {
if (action === 'confirm' && instance.inputValue) {
var testUrl = instance.inputValue.substring(0, 15);
if (testUrl === 'https://vrchat.') {
var userId = this.parseUserUrl(
instance.inputValue
);
if (userId) {
this.showUserDialog(userId);
} else {
this.$message({
message: $t(
'prompt.direct_access_user_id.message.error'
),
type: 'error'
});
}
} else {
this.showUserDialog(instance.inputValue);
}
}
}
}
);
},
promptUsernameDialog() {
this.$prompt(
$t('prompt.direct_access_username.description'),
$t('prompt.direct_access_username.header'),
{
distinguishCancelAndClose: true,
confirmButtonText: $t('prompt.direct_access_username.ok'),
cancelButtonText: $t(
'prompt.direct_access_username.cancel'
),
inputPattern: /\S+/,
inputErrorMessage: $t(
'prompt.direct_access_username.input_error'
),
callback: (action, instance) => {
if (action === 'confirm' && instance.inputValue) {
this.lookupUser({
displayName: instance.inputValue
});
}
}
}
);
},
promptWorldDialog() {
this.$prompt(
$t('prompt.direct_access_world_id.description'),
$t('prompt.direct_access_world_id.header'),
{
distinguishCancelAndClose: true,
confirmButtonText: $t('prompt.direct_access_world_id.ok'),
cancelButtonText: $t(
'prompt.direct_access_world_id.cancel'
),
inputPattern: /\S+/,
inputErrorMessage: $t(
'prompt.direct_access_world_id.input_error'
),
callback: (action, instance) => {
if (action === 'confirm' && instance.inputValue) {
if (!this.directAccessWorld(instance.inputValue)) {
this.$message({
message: $t(
'prompt.direct_access_world_id.message.error'
),
type: 'error'
});
}
}
}
}
);
},
promptAvatarDialog() {
this.$prompt(
$t('prompt.direct_access_avatar_id.description'),
$t('prompt.direct_access_avatar_id.header'),
{
distinguishCancelAndClose: true,
confirmButtonText: $t('prompt.direct_access_avatar_id.ok'),
cancelButtonText: $t(
'prompt.direct_access_avatar_id.cancel'
),
inputPattern: /\S+/,
inputErrorMessage: $t(
'prompt.direct_access_avatar_id.input_error'
),
callback: (action, instance) => {
if (action === 'confirm' && instance.inputValue) {
var testUrl = instance.inputValue.substring(0, 15);
if (testUrl === 'https://vrchat.') {
var avatarId = this.parseAvatarUrl(
instance.inputValue
);
if (avatarId) {
this.showAvatarDialog(avatarId);
} else {
this.$message({
message: $t(
'prompt.direct_access_avatar_id.message.error'
),
type: 'error'
});
}
} else {
this.showAvatarDialog(instance.inputValue);
}
}
}
}
);
},
promptOmniDirectDialog() {
this.$prompt(
$t('prompt.direct_access_omni.description'),
$t('prompt.direct_access_omni.header'),
{
distinguishCancelAndClose: true,
confirmButtonText: $t('prompt.direct_access_omni.ok'),
cancelButtonText: $t('prompt.direct_access_omni.cancel'),
inputPattern: /\S+/,
inputErrorMessage: $t(
'prompt.direct_access_omni.input_error'
),
callback: (action, instance) => {
if (action === 'confirm' && instance.inputValue) {
var input = instance.inputValue.trim();
if (!this.directAccessParse(input)) {
this.$message({
message: $t(
'prompt.direct_access_omni.message.error'
),
type: 'error'
});
}
}
}
}
);
},
changeFavoriteGroupName(ctx) {
this.$prompt(
$t('prompt.change_favorite_group_name.description'),
$t('prompt.change_favorite_group_name.header'),
{
distinguishCancelAndClose: true,
cancelButtonText: $t(
'prompt.change_favorite_group_name.cancel'
),
confirmButtonText: $t(
'prompt.change_favorite_group_name.change'
),
inputPlaceholder: $t(
'prompt.change_favorite_group_name.input_placeholder'
),
inputValue: ctx.displayName,
inputPattern: /\S+/,
inputErrorMessage: $t(
'prompt.change_favorite_group_name.input_error'
),
callback: (action, instance) => {
if (action === 'confirm') {
API.saveFavoriteGroup({
type: ctx.type,
group: ctx.name,
displayName: instance.inputValue
}).then((args) => {
this.$message({
message: $t(
'prompt.change_favorite_group_name.message.success'
),
type: 'success'
});
return args;
});
}
}
}
);
},
promptNotificationTimeout() {
this.$prompt(
$t('prompt.notification_timeout.description'),
$t('prompt.notification_timeout.header'),
{
distinguishCancelAndClose: true,
confirmButtonText: $t('prompt.notification_timeout.ok'),
cancelButtonText: $t('prompt.notification_timeout.cancel'),
inputValue: this.notificationTimeout / 1000,
inputPattern: /\d+$/,
inputErrorMessage: $t(
'prompt.notification_timeout.input_error'
),
callback: async (action, instance) => {
if (
action === 'confirm' &&
instance.inputValue &&
!isNaN(instance.inputValue)
) {
this.notificationTimeout = Math.trunc(
Number(instance.inputValue) * 1000
);
await configRepository.setString(
'VRCX_notificationTimeout',
this.notificationTimeout
);
this.updateVRConfigVars();
}
}
}
);
},
promptPhotonOverlayMessageTimeout() {
this.$prompt(
$t('prompt.overlay_message_timeout.description'),
$t('prompt.overlay_message_timeout.header'),
{
distinguishCancelAndClose: true,
confirmButtonText: $t('prompt.overlay_message_timeout.ok'),
cancelButtonText: $t(
'prompt.overlay_message_timeout.cancel'
),
inputValue: this.photonOverlayMessageTimeout / 1000,
inputPattern: /\d+$/,
inputErrorMessage: $t(
'prompt.overlay_message_timeout.input_error'
),
callback: async (action, instance) => {
if (
action === 'confirm' &&
instance.inputValue &&
!isNaN(instance.inputValue)
) {
this.photonOverlayMessageTimeout = Math.trunc(
Number(instance.inputValue) * 1000
);
await configRepository.setString(
'VRCX_photonOverlayMessageTimeout',
this.photonOverlayMessageTimeout
);
this.updateVRConfigVars();
}
}
}
);
},
promptRenameAvatar(avatar) {
this.$prompt(
$t('prompt.rename_avatar.description'),
$t('prompt.rename_avatar.header'),
{
distinguishCancelAndClose: true,
confirmButtonText: $t('prompt.rename_avatar.ok'),
cancelButtonText: $t('prompt.rename_avatar.cancel'),
inputValue: avatar.ref.name,
inputErrorMessage: $t('prompt.rename_avatar.input_error'),
callback: (action, instance) => {
if (
action === 'confirm' &&
instance.inputValue !== avatar.ref.name
) {
API.saveAvatar({
id: avatar.id,
name: instance.inputValue
}).then((args) => {
this.$message({
message: $t(
'prompt.rename_avatar.message.success'
),
type: 'success'
});
return args;
});
}
}
}
);
},
promptChangeAvatarDescription(avatar) {
this.$prompt(
$t('prompt.change_avatar_description.description'),
$t('prompt.change_avatar_description.header'),
{
distinguishCancelAndClose: true,
confirmButtonText: $t(
'prompt.change_avatar_description.ok'
),
cancelButtonText: $t(
'prompt.change_avatar_description.cancel'
),
inputValue: avatar.ref.description,
inputErrorMessage: $t(
'prompt.change_avatar_description.input_error'
),
callback: (action, instance) => {
if (
action === 'confirm' &&
instance.inputValue !== avatar.ref.description
) {
API.saveAvatar({
id: avatar.id,
description: instance.inputValue
}).then((args) => {
this.$message({
message: $t(
'prompt.change_avatar_description.message.success'
),
type: 'success'
});
return args;
});
}
}
}
);
},
promptRenameWorld(world) {
this.$prompt(
$t('prompt.rename_world.description'),
$t('prompt.rename_world.header'),
{
distinguishCancelAndClose: true,
confirmButtonText: $t('prompt.rename_world.ok'),
cancelButtonText: $t('prompt.rename_world.cancel'),
inputValue: world.ref.name,
inputErrorMessage: $t('prompt.rename_world.input_error'),
callback: (action, instance) => {
if (
action === 'confirm' &&
instance.inputValue !== world.ref.name
) {
API.saveWorld({
id: world.id,
name: instance.inputValue
}).then((args) => {
this.$message({
message: $t(
'prompt.rename_world.message.success'
),
type: 'success'
});
return args;
});
}
}
}
);
},
promptChangeWorldDescription(world) {
this.$prompt(
$t('prompt.change_world_description.description'),
$t('prompt.change_world_description.header'),
{
distinguishCancelAndClose: true,
confirmButtonText: $t('prompt.change_world_description.ok'),
cancelButtonText: $t(
'prompt.change_world_description.cancel'
),
inputValue: world.ref.description,
inputErrorMessage: $t(
'prompt.change_world_description.input_error'
),
callback: (action, instance) => {
if (
action === 'confirm' &&
instance.inputValue !== world.ref.description
) {
API.saveWorld({
id: world.id,
description: instance.inputValue
}).then((args) => {
this.$message({
message: $t(
'prompt.change_world_description.message.success'
),
type: 'success'
});
return args;
});
}
}
}
);
},
promptChangeWorldCapacity(world) {
this.$prompt(
$t('prompt.change_world_capacity.description'),
$t('prompt.change_world_capacity.header'),
{
distinguishCancelAndClose: true,
confirmButtonText: $t('prompt.change_world_capacity.ok'),
cancelButtonText: $t('prompt.change_world_capacity.cancel'),
inputValue: world.ref.capacity,
inputPattern: /\d+$/,
inputErrorMessage: $t(
'prompt.change_world_capacity.input_error'
),
callback: (action, instance) => {
if (
action === 'confirm' &&
instance.inputValue !== world.ref.capacity
) {
API.saveWorld({
id: world.id,
capacity: instance.inputValue
}).then((args) => {
this.$message({
message: $t(
'prompt.change_world_capacity.message.success'
),
type: 'success'
});
return args;
});
}
}
}
);
},
promptChangeWorldRecommendedCapacity(world) {
this.$prompt(
$t('prompt.change_world_recommended_capacity.description'),
$t('prompt.change_world_recommended_capacity.header'),
{
distinguishCancelAndClose: true,
confirmButtonText: $t('prompt.change_world_capacity.ok'),
cancelButtonText: $t('prompt.change_world_capacity.cancel'),
inputValue: world.ref.recommendedCapacity,
inputPattern: /\d+$/,
inputErrorMessage: $t(
'prompt.change_world_recommended_capacity.input_error'
),
callback: (action, instance) => {
if (
action === 'confirm' &&
instance.inputValue !==
world.ref.recommendedCapacity
) {
API.saveWorld({
id: world.id,
recommendedCapacity: instance.inputValue
}).then((args) => {
this.$message({
message: $t(
'prompt.change_world_recommended_capacity.message.success'
),
type: 'success'
});
return args;
});
}
}
}
);
},
promptChangeWorldYouTubePreview(world) {
this.$prompt(
$t('prompt.change_world_preview.description'),
$t('prompt.change_world_preview.header'),
{
distinguishCancelAndClose: true,
confirmButtonText: $t('prompt.change_world_preview.ok'),
cancelButtonText: $t('prompt.change_world_preview.cancel'),
inputValue: world.ref.previewYoutubeId,
inputErrorMessage: $t(
'prompt.change_world_preview.input_error'
),
callback: (action, instance) => {
if (
action === 'confirm' &&
instance.inputValue !== world.ref.previewYoutubeId
) {
if (instance.inputValue.length > 11) {
try {
var url = new URL(instance.inputValue);
var id1 = url.pathname;
var id2 = url.searchParams.get('v');
if (id1 && id1.length === 12) {
instance.inputValue = id1.substring(
1,
12
);
}
if (id2 && id2.length === 11) {
instance.inputValue = id2;
}
} catch {
this.$message({
message: $t(
'prompt.change_world_preview.message.error'
),
type: 'error'
});
return;
}
}
if (
instance.inputValue !==
world.ref.previewYoutubeId
) {
API.saveWorld({
id: world.id,
previewYoutubeId: instance.inputValue
}).then((args) => {
this.$message({
message: $t(
'prompt.change_world_preview.message.success'
),
type: 'success'
});
return args;
});
}
}
}
}
);
},
promptMaxTableSizeDialog() {
this.$prompt(
$t('prompt.change_table_size.description'),
$t('prompt.change_table_size.header'),
{
distinguishCancelAndClose: true,
confirmButtonText: $t('prompt.change_table_size.save'),
cancelButtonText: $t('prompt.change_table_size.cancel'),
inputValue: this.maxTableSize,
inputPattern: /\d+$/,
inputErrorMessage: $t(
'prompt.change_table_size.input_error'
),
callback: async (action, instance) => {
if (action === 'confirm' && instance.inputValue) {
if (instance.inputValue > 10000) {
instance.inputValue = 10000;
}
this.maxTableSize = instance.inputValue;
await configRepository.setString(
'VRCX_maxTableSize',
this.maxTableSize
);
database.setmaxTableSize(this.maxTableSize);
this.feedTableLookup();
this.gameLogTableLookup();
}
}
}
);
},
promptProxySettings() {
this.$prompt(
$t('prompt.proxy_settings.description'),
$t('prompt.proxy_settings.header'),
{
distinguishCancelAndClose: true,
confirmButtonText: $t('prompt.proxy_settings.restart'),
cancelButtonText: $t('prompt.proxy_settings.close'),
inputValue: this.proxyServer,
inputPlaceholder: $t('prompt.proxy_settings.placeholder'),
callback: async (action, instance) => {
this.proxyServer = instance.inputValue;
await VRCXStorage.Set(
'VRCX_ProxyServer',
this.proxyServer
);
await VRCXStorage.Flush();
await new Promise((resolve) => {
workerTimers.setTimeout(resolve, 100);
});
if (action === 'confirm') {
var isUpgrade = false;
this.restartVRCX(isUpgrade);
}
}
}
);
},
promptPhotonLobbyTimeoutThreshold() {
this.$prompt(
$t('prompt.photon_lobby_timeout.description'),
$t('prompt.photon_lobby_timeout.header'),
{
distinguishCancelAndClose: true,
confirmButtonText: $t('prompt.photon_lobby_timeout.ok'),
cancelButtonText: $t('prompt.photon_lobby_timeout.cancel'),
inputValue: this.photonLobbyTimeoutThreshold / 1000,
inputPattern: /\d+$/,
inputErrorMessage: $t(
'prompt.photon_lobby_timeout.input_error'
),
callback: async (action, instance) => {
if (
action === 'confirm' &&
instance.inputValue &&
!isNaN(instance.inputValue)
) {
this.photonLobbyTimeoutThreshold = Math.trunc(
Number(instance.inputValue) * 1000
);
await configRepository.setString(
'VRCX_photonLobbyTimeoutThreshold',
this.photonLobbyTimeoutThreshold
);
}
}
}
);
},
promptAutoClearVRCXCacheFrequency() {
this.$prompt(
$t('prompt.auto_clear_cache.description'),
$t('prompt.auto_clear_cache.header'),
{
distinguishCancelAndClose: true,
confirmButtonText: $t('prompt.auto_clear_cache.ok'),
cancelButtonText: $t('prompt.auto_clear_cache.cancel'),
inputValue: this.clearVRCXCacheFrequency / 3600 / 2,
inputPattern: /\d+$/,
inputErrorMessage: $t(
'prompt.auto_clear_cache.input_error'
),
callback: async (action, instance) => {
if (
action === 'confirm' &&
instance.inputValue &&
!isNaN(instance.inputValue)
) {
this.clearVRCXCacheFrequency = Math.trunc(
Number(instance.inputValue) * 3600 * 2
);
await configRepository.setString(
'VRCX_clearVRCXCacheFrequency',
this.clearVRCXCacheFrequency
);
}
}
}
);
}
};
}

View File

@@ -0,0 +1,284 @@
import * as workerTimers from 'worker-timers';
import configRepository from '../repository/config.js';
import database from '../repository/database.js';
import { baseClass, $app, API, $t, $utils } from './baseClass.js';
export default class extends baseClass {
constructor(_app, _API, _t) {
super(_app, _API, _t);
}
init() {}
_data = {};
_methods = {
async tryRestoreFriendNumber() {
var lastUpdate = await configRepository.getString(
`VRCX_lastStoreTime_${API.currentUser.id}`
);
if (lastUpdate == -4) {
// this means the backup was already applied
return;
}
var status = false;
this.friendNumber = 0;
for (var ref of this.friendLog.values()) {
ref.friendNumber = 0;
}
try {
if (lastUpdate) {
// backup ready to try apply
status = await this.restoreFriendNumber();
}
// needs to be in reverse because we don't know the starting number
this.applyFriendLogFriendOrderInReverse();
} catch (err) {
console.error(err);
}
// if (status) {
// this.$message({
// message: 'Friend order restored from backup',
// type: 'success',
// duration: 0,
// showClose: true
// });
// } else if (this.friendLogTable.data.length > 0) {
// this.$message({
// message:
// 'No backup found, friend order partially restored from friendLog',
// type: 'success',
// duration: 0,
// showClose: true
// });
// }
await configRepository.setString(
`VRCX_lastStoreTime_${API.currentUser.id}`,
-4
);
},
async restoreFriendNumber() {
var storedData = null;
try {
var data = await configRepository.getString(
`VRCX_friendOrder_${API.currentUser.id}`
);
if (data) {
var storedData = JSON.parse(data);
}
} catch (err) {
console.error(err);
}
if (!storedData || storedData.length === 0) {
var message = 'whomp whomp, no friend order backup found';
console.error(message);
return false;
}
var friendLogTable = this.getFriendLogFriendOrder();
// for storedData
var machList = [];
for (var i = 0; i < Object.keys(storedData).length; i++) {
var key = Object.keys(storedData)[i];
var value = storedData[key];
var item = this.parseFriendOrderBackup(
friendLogTable,
key,
value
);
machList.push(item);
}
machList.sort((a, b) => b.matches - a.matches);
console.log(
`friendLog: ${friendLogTable.length} friendOrderBackups:`,
machList
);
var bestBackup = machList[0];
if (!bestBackup?.isValid) {
var message = 'whomp whomp, no valid backup found';
console.error(message);
return false;
}
this.applyFriendOrderBackup(bestBackup.table);
this.applyFriendLogFriendOrder();
await configRepository.setInt(
`VRCX_friendNumber_${API.currentUser.id}`,
this.friendNumber
);
return true;
},
getFriendLogFriendOrder() {
var friendLogTable = [];
for (var i = 0; i < this.friendLogTable.data.length; i++) {
var ref = this.friendLogTable.data[i];
if (ref.type !== 'Friend') {
continue;
}
if (
friendLogTable.findIndex((x) => x.id === ref.userId) !== -1
) {
// console.log(
// 'ignoring duplicate friend',
// ref.displayName,
// ref.created_at
// );
continue;
}
friendLogTable.push({
id: ref.userId,
displayName: ref.displayName,
created_at: ref.created_at
});
}
var compareByCreatedAt = function (a, b) {
var A = a.created_at;
var B = b.created_at;
if (A < B) {
return -1;
}
if (A > B) {
return 1;
}
return 0;
};
friendLogTable.sort(compareByCreatedAt);
return friendLogTable;
},
applyFriendLogFriendOrder() {
var friendLogTable = this.getFriendLogFriendOrder();
if (this.friendNumber === 0) {
console.log(
'No backup applied, applying friend log in reverse'
);
// this means no FriendOrderBackup was applied
// will need to apply in reverse order instead
return;
}
for (var friendLog of friendLogTable) {
var ref = this.friendLog.get(friendLog.id);
if (!ref || ref.friendNumber) {
continue;
}
ref.friendNumber = ++this.friendNumber;
this.friendLog.set(ref.userId, ref);
database.setFriendLogCurrent(ref);
var friendRef = this.friends.get(friendLog.id);
if (friendRef?.ref) {
friendRef.ref.$friendNumber = ref.friendNumber;
}
}
},
applyFriendLogFriendOrderInReverse() {
this.friendNumber = this.friends.size + 1;
var friendLogTable = this.getFriendLogFriendOrder();
for (var i = friendLogTable.length - 1; i > -1; i--) {
var friendLog = friendLogTable[i];
var ref = this.friendLog.get(friendLog.id);
if (!ref) {
continue;
}
if (ref.friendNumber) {
break;
}
ref.friendNumber = --this.friendNumber;
this.friendLog.set(ref.userId, ref);
database.setFriendLogCurrent(ref);
var friendRef = this.friends.get(friendLog.id);
if (friendRef?.ref) {
friendRef.ref.$friendNumber = ref.friendNumber;
}
}
this.friendNumber = this.friends.size;
console.log('Applied friend order from friendLog');
},
parseFriendOrderBackup(friendLogTable, created_at, backupUserIds) {
var backupTable = [];
for (var i = 0; i < backupUserIds.length; i++) {
var userId = backupUserIds[i];
var ctx = this.friends.get(userId);
if (ctx) {
backupTable.push({
id: ctx.id,
displayName: ctx.name
});
}
}
// var compareTable = [];
// compare 2 tables, find max amount of id's in same order
var maxMatches = 0;
var currentMatches = 0;
var backupIndex = 0;
for (var i = 0; i < friendLogTable.length; i++) {
var isMatch = false;
var ref = friendLogTable[i];
if (backupIndex <= 0) {
backupIndex = backupTable.findIndex((x) => x.id === ref.id);
if (backupIndex !== -1) {
currentMatches = 1;
}
} else if (backupTable[backupIndex].id === ref.id) {
currentMatches++;
isMatch = true;
} else {
var backupIndex = backupTable.findIndex(
(x) => x.id === ref.id
);
if (backupIndex !== -1) {
currentMatches = 1;
}
}
if (backupIndex === backupTable.length - 1) {
backupIndex = 0;
} else {
backupIndex++;
}
if (currentMatches > maxMatches) {
maxMatches = currentMatches;
}
// compareTable.push({
// id: ref.id,
// displayName: ref.displayName,
// match: isMatch
// });
}
var lerp = (a, b, alpha) => {
return a + alpha * (b - a);
};
return {
matches: parseFloat(`${maxMatches}.${created_at}`),
table: backupUserIds,
isValid: maxMatches > lerp(4, 10, backupTable.length / 1000) // pls no collisions
};
},
applyFriendOrderBackup(userIdOrder) {
for (var i = 0; i < userIdOrder.length; i++) {
var userId = userIdOrder[i];
var ctx = this.friends.get(userId);
var ref = ctx?.ref;
if (!ref || ref.$friendNumber) {
continue;
}
var friendLogCurrent = {
userId,
displayName: ref.displayName,
trustLevel: ref.$trustLevel,
friendNumber: i + 1
};
this.friendLog.set(userId, friendLogCurrent);
database.setFriendLogCurrent(friendLogCurrent);
this.friendNumber = i + 1;
}
}
};
}

596
src/classes/sharedFeed.js Normal file
View File

@@ -0,0 +1,596 @@
import * as workerTimers from 'worker-timers';
import configRepository from '../repository/config.js';
import { baseClass, $app, API, $t, $utils } from './baseClass.js';
export default class extends baseClass {
constructor(_app, _API, _t) {
super(_app, _API, _t);
}
_data = {
sharedFeed: {
gameLog: {
wrist: [],
lastEntryDate: ''
},
feedTable: {
wrist: [],
lastEntryDate: ''
},
notificationTable: {
wrist: [],
lastEntryDate: ''
},
friendLogTable: {
wrist: [],
lastEntryDate: ''
},
moderationAgainstTable: {
wrist: [],
lastEntryDate: ''
},
pendingUpdate: false
},
updateSharedFeedTimer: null,
updateSharedFeedPending: false,
updateSharedFeedPendingForceUpdate: false
};
_methods = {
updateSharedFeed(forceUpdate) {
if (!this.friendLogInitStatus) {
return;
}
if (this.updateSharedFeedTimer) {
if (forceUpdate) {
this.updateSharedFeedPendingForceUpdate = true;
}
this.updateSharedFeedPending = true;
} else {
this.updateSharedExecute(forceUpdate);
this.updateSharedFeedTimer = setTimeout(() => {
if (this.updateSharedFeedPending) {
this.updateSharedExecute(
this.updateSharedFeedPendingForceUpdate
);
}
this.updateSharedFeedTimer = null;
}, 150);
}
},
updateSharedExecute(forceUpdate) {
try {
this.updateSharedFeedDebounce(forceUpdate);
} catch (err) {
console.error(err);
}
this.updateSharedFeedTimer = null;
this.updateSharedFeedPending = false;
this.updateSharedFeedPendingForceUpdate = false;
},
updateSharedFeedDebounce(forceUpdate) {
this.updateSharedFeedGameLog(forceUpdate);
this.updateSharedFeedFeedTable(forceUpdate);
this.updateSharedFeedNotificationTable(forceUpdate);
this.updateSharedFeedFriendLogTable(forceUpdate);
this.updateSharedFeedModerationAgainstTable(forceUpdate);
var feeds = this.sharedFeed;
if (!feeds.pendingUpdate) {
return;
}
var wristFeed = [];
wristFeed = wristFeed.concat(
feeds.gameLog.wrist,
feeds.feedTable.wrist,
feeds.notificationTable.wrist,
feeds.friendLogTable.wrist,
feeds.moderationAgainstTable.wrist
);
// OnPlayerJoining/Traveling
API.currentTravelers.forEach((ref) => {
var isFavorite = this.localFavoriteFriends.has(ref.id);
if (
(this.sharedFeedFilters.wrist.OnPlayerJoining ===
'Friends' ||
(this.sharedFeedFilters.wrist.OnPlayerJoining ===
'VIP' &&
isFavorite)) &&
!$app.lastLocation.playerList.has(ref.id)
) {
if (ref.$location.tag === $app.lastLocation.location) {
var feedEntry = {
...ref,
isFavorite,
isFriend: true,
type: 'OnPlayerJoining'
};
wristFeed.unshift(feedEntry);
} else {
var worldRef = API.cachedWorlds.get(
ref.$location.worldId
);
var groupName = '';
if (ref.$location.groupId) {
var groupRef = API.cachedGroups.get(
ref.$location.groupId
);
if (typeof groupRef !== 'undefined') {
groupName = groupRef.name;
} else {
// no group cache, fetch group and try again
API.getGroup({
groupId: ref.$location.groupId
})
.then((args) => {
workerTimers.setTimeout(() => {
// delay to allow for group cache to update
$app.sharedFeed.pendingUpdate = true;
$app.updateSharedFeed(false);
}, 100);
return args;
})
.catch((err) => {
console.error(err);
});
}
}
if (typeof worldRef !== 'undefined') {
var feedEntry = {
created_at: ref.created_at,
type: 'GPS',
userId: ref.id,
displayName: ref.displayName,
location: ref.$location.tag,
worldName: worldRef.name,
groupName,
previousLocation: '',
isFavorite,
time: 0,
isFriend: true,
isTraveling: true
};
wristFeed.unshift(feedEntry);
} else {
// no world cache, fetch world and try again
API.getWorld({
worldId: ref.$location.worldId
})
.then((args) => {
workerTimers.setTimeout(() => {
// delay to allow for world cache to update
$app.sharedFeed.pendingUpdate = true;
$app.updateSharedFeed(false);
}, 100);
return args;
})
.catch((err) => {
console.error(err);
});
}
}
}
});
wristFeed.sort(function (a, b) {
if (a.created_at < b.created_at) {
return 1;
}
if (a.created_at > b.created_at) {
return -1;
}
return 0;
});
wristFeed.splice(16);
AppApi.ExecuteVrFeedFunction(
'wristFeedUpdate',
JSON.stringify(wristFeed)
);
this.applyUserDialogLocation();
this.applyWorldDialogInstances();
this.applyGroupDialogInstances();
feeds.pendingUpdate = false;
},
updateSharedFeedGameLog(forceUpdate) {
// Location, OnPlayerJoined, OnPlayerLeft
var sessionTable = this.gameLogSessionTable;
var i = sessionTable.length;
if (i > 0) {
if (
sessionTable[i - 1].created_at ===
this.sharedFeed.gameLog.lastEntryDate &&
forceUpdate === false
) {
return;
}
this.sharedFeed.gameLog.lastEntryDate =
sessionTable[i - 1].created_at;
} else {
return;
}
var bias = new Date(Date.now() - 86400000).toJSON(); // 24 hours
var wristArr = [];
var w = 0;
var wristFilter = this.sharedFeedFilters.wrist;
var currentUserLeaveTime = 0;
var locationJoinTime = 0;
for (var i = sessionTable.length - 1; i > -1; i--) {
var ctx = sessionTable[i];
if (ctx.created_at < bias) {
break;
}
if (ctx.type === 'Notification') {
continue;
}
// on Location change remove OnPlayerLeft
if (ctx.type === 'LocationDestination') {
currentUserLeaveTime = Date.parse(ctx.created_at);
var currentUserLeaveTimeOffset =
currentUserLeaveTime + 5 * 1000;
for (var k = w - 1; k > -1; k--) {
var feedItem = wristArr[k];
if (
(feedItem.type === 'OnPlayerLeft' ||
feedItem.type === 'BlockedOnPlayerLeft' ||
feedItem.type === 'MutedOnPlayerLeft') &&
Date.parse(feedItem.created_at) >=
currentUserLeaveTime &&
Date.parse(feedItem.created_at) <=
currentUserLeaveTimeOffset
) {
wristArr.splice(k, 1);
w--;
}
}
}
// on Location change remove OnPlayerJoined
if (ctx.type === 'Location') {
locationJoinTime = Date.parse(ctx.created_at);
var locationJoinTimeOffset = locationJoinTime + 20 * 1000;
for (var k = w - 1; k > -1; k--) {
var feedItem = wristArr[k];
if (
(feedItem.type === 'OnPlayerJoined' ||
feedItem.type === 'BlockedOnPlayerJoined' ||
feedItem.type === 'MutedOnPlayerJoined') &&
Date.parse(feedItem.created_at) >=
locationJoinTime &&
Date.parse(feedItem.created_at) <=
locationJoinTimeOffset
) {
wristArr.splice(k, 1);
w--;
}
}
}
// remove current user
if (
(ctx.type === 'OnPlayerJoined' ||
ctx.type === 'OnPlayerLeft' ||
ctx.type === 'PortalSpawn') &&
ctx.displayName === API.currentUser.displayName
) {
continue;
}
var isFriend = false;
var isFavorite = false;
if (ctx.userId) {
isFriend = this.friends.has(ctx.userId);
isFavorite = this.localFavoriteFriends.has(ctx.userId);
} else if (ctx.displayName) {
for (var ref of API.cachedUsers.values()) {
if (ref.displayName === ctx.displayName) {
isFriend = this.friends.has(ref.id);
isFavorite = this.localFavoriteFriends.has(ref.id);
break;
}
}
}
// add tag colour
var tagColour = '';
if (ctx.userId) {
var tagRef = this.customUserTags.get(ctx.userId);
if (typeof tagRef !== 'undefined') {
tagColour = tagRef.colour;
}
}
// BlockedOnPlayerJoined, BlockedOnPlayerLeft, MutedOnPlayerJoined, MutedOnPlayerLeft
if (
ctx.type === 'OnPlayerJoined' ||
ctx.type === 'OnPlayerLeft'
) {
for (var ref of API.cachedPlayerModerations.values()) {
if (
ref.targetDisplayName !== ctx.displayName &&
ref.sourceUserId !== ctx.userId
) {
continue;
}
if (ref.type === 'block') {
var type = `Blocked${ctx.type}`;
} else if (ref.type === 'mute') {
var type = `Muted${ctx.type}`;
} else {
continue;
}
var entry = {
created_at: ctx.created_at,
type,
displayName: ref.targetDisplayName,
userId: ref.targetUserId,
isFriend,
isFavorite
};
if (
wristFilter[type] &&
(wristFilter[type] === 'Everyone' ||
(wristFilter[type] === 'Friends' && isFriend) ||
(wristFilter[type] === 'VIP' && isFavorite))
) {
wristArr.unshift(entry);
}
this.queueGameLogNoty(entry);
}
}
// when too many user joins happen at once when switching instances
// the "w" counter maxes out and wont add any more entries
// until the onJoins are cleared by "Location"
// e.g. if a "VideoPlay" occurs between "OnPlayerJoined" and "Location" it wont be added
if (
w < 50 &&
wristFilter[ctx.type] &&
(wristFilter[ctx.type] === 'On' ||
wristFilter[ctx.type] === 'Everyone' ||
(wristFilter[ctx.type] === 'Friends' && isFriend) ||
(wristFilter[ctx.type] === 'VIP' && isFavorite))
) {
wristArr.push({
...ctx,
tagColour,
isFriend,
isFavorite
});
++w;
}
}
this.sharedFeed.gameLog.wrist = wristArr;
this.sharedFeed.pendingUpdate = true;
},
updateSharedFeedFeedTable(forceUpdate) {
// GPS, Online, Offline, Status, Avatar
var feedSession = this.feedSessionTable;
var i = feedSession.length;
if (i > 0) {
if (
feedSession[i - 1].created_at ===
this.sharedFeed.feedTable.lastEntryDate &&
forceUpdate === false
) {
return;
}
this.sharedFeed.feedTable.lastEntryDate =
feedSession[i - 1].created_at;
} else {
return;
}
var bias = new Date(Date.now() - 86400000).toJSON(); // 24 hours
var wristArr = [];
var w = 0;
var wristFilter = this.sharedFeedFilters.wrist;
for (var i = feedSession.length - 1; i > -1; i--) {
var ctx = feedSession[i];
if (ctx.created_at < bias) {
break;
}
if (ctx.type === 'Avatar') {
continue;
}
// hide private worlds from feed
if (
this.hidePrivateFromFeed &&
ctx.type === 'GPS' &&
ctx.location === 'private'
) {
continue;
}
var isFriend = this.friends.has(ctx.userId);
var isFavorite = this.localFavoriteFriends.has(ctx.userId);
if (
w < 20 &&
wristFilter[ctx.type] &&
(wristFilter[ctx.type] === 'Friends' ||
(wristFilter[ctx.type] === 'VIP' && isFavorite))
) {
wristArr.push({
...ctx,
isFriend,
isFavorite
});
++w;
}
}
this.sharedFeed.feedTable.wrist = wristArr;
this.sharedFeed.pendingUpdate = true;
},
updateSharedFeedNotificationTable(forceUpdate) {
// invite, requestInvite, requestInviteResponse, inviteResponse, friendRequest
var notificationTable = this.notificationTable;
var i = notificationTable.length;
if (i > 0) {
if (
notificationTable[i - 1].created_at ===
this.sharedFeed.notificationTable.lastEntryDate &&
forceUpdate === false
) {
return;
}
this.sharedFeed.notificationTable.lastEntryDate =
notificationTable[i - 1].created_at;
} else {
return;
}
var bias = new Date(Date.now() - 86400000).toJSON(); // 24 hours
var wristArr = [];
var w = 0;
var wristFilter = this.sharedFeedFilters.wrist;
for (var i = notificationTable.length - 1; i > -1; i--) {
var ctx = notificationTable[i];
if (ctx.created_at < bias) {
break;
}
if (ctx.senderUserId === API.currentUser.id) {
continue;
}
var isFriend = this.friends.has(ctx.senderUserId);
var isFavorite = this.localFavoriteFriends.has(
ctx.senderUserId
);
if (
w < 20 &&
wristFilter[ctx.type] &&
(wristFilter[ctx.type] === 'On' ||
wristFilter[ctx.type] === 'Friends' ||
(wristFilter[ctx.type] === 'VIP' && isFavorite))
) {
wristArr.push({
...ctx,
isFriend,
isFavorite
});
++w;
}
}
this.sharedFeed.notificationTable.wrist = wristArr;
this.sharedFeed.pendingUpdate = true;
},
updateSharedFeedFriendLogTable(forceUpdate) {
// TrustLevel, Friend, FriendRequest, Unfriend, DisplayName
var friendLog = this.friendLogTable;
var i = friendLog.length;
if (i > 0) {
if (
friendLog[i - 1].created_at ===
this.sharedFeed.friendLogTable.lastEntryDate &&
forceUpdate === false
) {
return;
}
this.sharedFeed.friendLogTable.lastEntryDate =
friendLog[i - 1].created_at;
} else {
return;
}
var bias = new Date(Date.now() - 86400000).toJSON(); // 24 hours
var wristArr = [];
var w = 0;
var wristFilter = this.sharedFeedFilters.wrist;
for (var i = friendLog.length - 1; i > -1; i--) {
var ctx = friendLog[i];
if (ctx.created_at < bias) {
break;
}
if (ctx.type === 'FriendRequest') {
continue;
}
var isFriend = this.friends.has(ctx.userId);
var isFavorite = this.localFavoriteFriends.has(ctx.userId);
if (
w < 20 &&
wristFilter[ctx.type] &&
(wristFilter[ctx.type] === 'On' ||
wristFilter[ctx.type] === 'Friends' ||
(wristFilter[ctx.type] === 'VIP' && isFavorite))
) {
wristArr.push({
...ctx,
isFriend,
isFavorite
});
++w;
}
}
this.sharedFeed.friendLogTable.wrist = wristArr;
this.sharedFeed.pendingUpdate = true;
},
updateSharedFeedModerationAgainstTable(forceUpdate) {
// Unblocked, Blocked, Muted, Unmuted
var moderationAgainst = this.moderationAgainstTable;
var i = moderationAgainst.length;
if (i > 0) {
if (
moderationAgainst[i - 1].created_at ===
this.sharedFeed.moderationAgainstTable.lastEntryDate &&
forceUpdate === false
) {
return;
}
this.sharedFeed.moderationAgainstTable.lastEntryDate =
moderationAgainst[i - 1].created_at;
} else {
return;
}
var bias = new Date(Date.now() - 86400000).toJSON(); // 24 hours
var wristArr = [];
var w = 0;
var wristFilter = this.sharedFeedFilters.wrist;
for (var i = moderationAgainst.length - 1; i > -1; i--) {
var ctx = moderationAgainst[i];
if (ctx.created_at < bias) {
break;
}
var isFriend = this.friends.has(ctx.userId);
var isFavorite = this.localFavoriteFriends.has(ctx.userId);
// add tag colour
var tagColour = '';
var tagRef = this.customUserTags.get(ctx.userId);
if (typeof tagRef !== 'undefined') {
tagColour = tagRef.colour;
}
if (
w < 20 &&
wristFilter[ctx.type] &&
wristFilter[ctx.type] === 'On'
) {
wristArr.push({
...ctx,
isFriend,
isFavorite,
tagColour
});
++w;
}
}
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();
}
};
}

618
src/classes/uiComponents.js Normal file
View File

@@ -0,0 +1,618 @@
import Vue from 'vue';
import VueMarkdown from 'vue-markdown';
import { baseClass, $app, API, $t, $utils } from './baseClass.js';
export default class extends baseClass {
constructor(_app, _API, _t) {
super(_app, _API, _t);
}
init() {
Vue.component('vue-markdown', VueMarkdown);
Vue.component('launch', {
template:
'<el-button @click="confirm" size="mini" icon="el-icon-info" circle></el-button>',
props: {
location: String
},
methods: {
parse() {
this.$el.style.display = $app.checkCanInviteSelf(
this.location
)
? ''
: 'none';
},
confirm() {
API.$emit('SHOW_LAUNCH_DIALOG', this.location);
}
},
watch: {
location() {
this.parse();
}
},
mounted() {
this.parse();
}
});
Vue.component('invite-yourself', {
template:
'<el-button @click="confirm" size="mini" icon="el-icon-message" circle></el-button>',
props: {
location: String,
shortname: String
},
methods: {
parse() {
this.$el.style.display = $app.checkCanInviteSelf(
this.location
)
? ''
: 'none';
},
confirm() {
$app.selfInvite(this.location, this.shortname);
}
},
watch: {
location() {
this.parse();
}
},
mounted() {
this.parse();
}
});
Vue.component('location', {
template:
"<span><span @click=\"showWorldDialog\" :class=\"{ 'x-link': link && this.location !== 'private' && this.location !== 'offline'}\">" +
'<i v-if="isTraveling" class="el-icon el-icon-loading" style="display:inline-block;margin-right:5px"></i>' +
'<span>{{ text }}</span></span>' +
'<span v-if="groupName" @click="showGroupDialog" :class="{ \'x-link\': link}">({{ groupName }})</span>' +
'<span v-if="region" class="flags" :class="region" style="display:inline-block;margin-left:5px"></span>' +
'<i v-if="strict" class="el-icon el-icon-lock" style="display:inline-block;margin-left:5px"></i></span>',
props: {
location: String,
traveling: String,
hint: {
type: String,
default: ''
},
grouphint: {
type: String,
default: ''
},
link: {
type: Boolean,
default: true
}
},
data() {
return {
text: this.location,
region: this.region,
strict: this.strict,
isTraveling: this.isTraveling,
groupName: this.groupName
};
},
methods: {
parse() {
this.isTraveling = false;
this.groupName = '';
var instanceId = this.location;
if (
typeof this.traveling !== 'undefined' &&
this.location === 'traveling'
) {
instanceId = this.traveling;
this.isTraveling = true;
}
this.text = instanceId;
var L = $utils.parseLocation(instanceId);
if (L.isOffline) {
this.text = 'Offline';
} else if (L.isPrivate) {
this.text = 'Private';
} else if (L.isTraveling) {
this.text = 'Traveling';
} else if (
typeof this.hint === 'string' &&
this.hint !== ''
) {
if (L.instanceId) {
this.text = `${this.hint} #${L.instanceName} ${L.accessTypeName}`;
} else {
this.text = this.hint;
}
} else if (L.worldId) {
var ref = API.cachedWorlds.get(L.worldId);
if (typeof ref === 'undefined') {
$app.getWorldName(L.worldId).then((worldName) => {
if (L.tag === instanceId) {
if (L.instanceId) {
this.text = `${worldName} #${L.instanceName} ${L.accessTypeName}`;
} else {
this.text = worldName;
}
}
});
} else if (L.instanceId) {
this.text = `${ref.name} #${L.instanceName} ${L.accessTypeName}`;
} else {
this.text = ref.name;
}
}
if (this.grouphint) {
this.groupName = this.grouphint;
} else if (L.groupId) {
this.groupName = L.groupId;
$app.getGroupName(instanceId).then((groupName) => {
if (L.tag === instanceId) {
this.groupName = groupName;
}
});
}
this.region = '';
if (!L.isOffline && !L.isPrivate && !L.isTraveling) {
this.region = L.region;
if (!L.region && L.instanceId) {
this.region = 'us';
}
}
this.strict = L.strict;
},
showWorldDialog() {
if (this.link) {
var instanceId = this.location;
if (this.traveling && this.location === 'traveling') {
instanceId = this.traveling;
}
if (!instanceId && this.hint.length === 8) {
// shortName
API.$emit('SHOW_WORLD_DIALOG_SHORTNAME', this.hint);
return;
}
API.$emit('SHOW_WORLD_DIALOG', instanceId);
}
},
showGroupDialog() {
var location = this.location;
if (this.isTraveling) {
location = this.traveling;
}
if (!location || !this.link) {
return;
}
var L = $utils.parseLocation(location);
if (!L.groupId) {
return;
}
API.$emit('SHOW_GROUP_DIALOG', L.groupId);
}
},
watch: {
location() {
this.parse();
}
},
created() {
this.parse();
}
});
Vue.component('location-world', {
template:
'<span><span @click="showLaunchDialog" class="x-link">' +
'<i v-if="isUnlocked" class="el-icon el-icon-unlock" style="display:inline-block;margin-right:5px"></i>' +
'<span>#{{ instanceName }} {{ accessTypeName }}</span></span>' +
'<span v-if="groupName" @click="showGroupDialog" class="x-link">({{ groupName }})</span>' +
'<span class="flags" :class="region" style="display:inline-block;margin-left:5px"></span>' +
'<i v-if="strict" class="el-icon el-icon-lock" style="display:inline-block;margin-left:5px"></i></span>',
props: {
locationobject: Object,
currentuserid: String,
worlddialogshortname: String,
grouphint: {
type: String,
default: ''
}
},
data() {
return {
location: this.location,
instanceName: this.instanceName,
accessTypeName: this.accessTypeName,
region: this.region,
shortName: this.shortName,
isUnlocked: this.isUnlocked,
strict: this.strict,
groupName: this.groupName
};
},
methods: {
parse() {
this.location = this.locationobject.tag;
this.instanceName = this.locationobject.instanceName;
this.accessTypeName = this.locationobject.accessTypeName;
this.strict = this.locationobject.strict;
this.shortName = this.locationobject.shortName;
this.isUnlocked = false;
if (
(this.worlddialogshortname &&
this.locationobject.shortName &&
this.worlddialogshortname ===
this.locationobject.shortName) ||
this.currentuserid === this.locationobject.userId
) {
this.isUnlocked = true;
}
this.region = this.locationobject.region;
if (!this.region) {
this.region = 'us';
}
this.groupName = '';
if (this.grouphint) {
this.groupName = this.grouphint;
} else if (this.locationobject.groupId) {
this.groupName = this.locationobject.groupId;
$app.getGroupName(this.locationobject.groupId).then(
(groupName) => {
this.groupName = groupName;
}
);
}
},
showLaunchDialog() {
API.$emit(
'SHOW_LAUNCH_DIALOG',
this.location,
this.shortName
);
},
showGroupDialog() {
if (!this.location) {
return;
}
var L = $utils.parseLocation(this.location);
if (!L.groupId) {
return;
}
API.$emit('SHOW_GROUP_DIALOG', L.groupId);
}
},
watch: {
locationobject() {
this.parse();
}
},
created() {
this.parse();
}
});
Vue.component('last-join', {
template:
'<span>' +
'<el-tooltip placement="top" style="margin-left:5px" v-if="lastJoin">' +
'<div slot="content">' +
'<span>{{ $t("dialog.user.info.last_join") }} <timer :epoch="lastJoin"></timer></span>' +
'</div>' +
'<i v-if="lastJoin" class="el-icon el-icon-location-outline" style="display:inline-block"></i>' +
'</el-tooltip>' +
'</span>',
props: {
location: String,
currentlocation: String
},
data() {
return {
lastJoin: this.lastJoin
};
},
methods: {
parse() {
this.lastJoin = $app.instanceJoinHistory.get(this.location);
}
},
watch: {
location() {
this.parse();
},
currentlocation() {
this.parse();
}
},
created() {
this.parse();
}
});
Vue.component('instance-info', {
template:
'<div style="display:inline-block;margin-left:5px">' +
'<el-tooltip v-if="isValidInstance" placement="bottom">' +
'<div slot="content">' +
'<template v-if="isClosed"><span>Closed At: {{ closedAt | formatDate(\'long\') }}</span></br></template>' +
'<template v-if="canCloseInstance"><el-button :disabled="isClosed" size="mini" type="primary" @click="$app.closeInstance(location)">{{ $t("dialog.user.info.close_instance") }}</el-button></br></br></template>' +
'<span><span style="color:#409eff">PC: </span>{{ platforms.standalonewindows }}</span></br>' +
'<span><span style="color:#67c23a">Android: </span>{{ platforms.android }}</span></br>' +
'<span>{{ $t("dialog.user.info.instance_game_version") }} {{ gameServerVersion }}</span></br>' +
'<span v-if="queueEnabled">{{ $t("dialog.user.info.instance_queuing_enabled") }}</br></span>' +
'<span v-if="userList.length">{{ $t("dialog.user.info.instance_users") }}</br></span>' +
'<template v-for="user in userList"><span style="cursor:pointer;margin-right:5px" @click="showUserDialog(user.id)" v-text="user.displayName"></span></template>' +
'</div>' +
'<i class="el-icon-caret-bottom"></i>' +
'</el-tooltip>' +
'<span v-if="occupants" style="margin-left:5px">{{ occupants }}/{{ capacity }}</span>' +
'<span v-if="friendcount" style="margin-left:5px">({{ friendcount }})</span>' +
'<span v-if="isFull" style="margin-left:5px;color:lightcoral">{{ $t("dialog.user.info.instance_full") }}</span>' +
'<span v-if="isHardClosed" style="margin-left:5px;color:lightcoral">{{ $t("dialog.user.info.instance_hard_closed") }}</span>' +
'<span v-else-if="isClosed" style="margin-left:5px;color:lightcoral">{{ $t("dialog.user.info.instance_closed") }}</span>' +
'<span v-if="queueSize" style="margin-left:5px">{{ $t("dialog.user.info.instance_queue") }} {{ queueSize }}</span>' +
'<span v-if="isAgeGated" style="margin-left:5px;color:lightcoral">{{ $t("dialog.user.info.instance_age_gated") }}</span>' +
'</div>',
props: {
location: String,
instance: Object,
friendcount: Number,
updateelement: Number
},
data() {
return {
isValidInstance: this.isValidInstance,
isFull: this.isFull,
isClosed: this.isClosed,
isHardClosed: this.isHardClosed,
closedAt: this.closedAt,
occupants: this.occupants,
capacity: this.capacity,
queueSize: this.queueSize,
queueEnabled: this.queueEnabled,
platforms: this.platforms,
userList: this.userList,
gameServerVersion: this.gameServerVersion,
canCloseInstance: this.canCloseInstance
};
},
methods: {
parse() {
this.isValidInstance = false;
this.isFull = false;
this.isClosed = false;
this.isHardClosed = false;
this.closedAt = '';
this.occupants = 0;
this.capacity = 0;
this.queueSize = 0;
this.queueEnabled = false;
this.platforms = [];
this.userList = [];
this.gameServerVersion = '';
this.canCloseInstance = false;
this.isAgeGated = false;
if (
!this.location ||
!this.instance ||
Object.keys(this.instance).length === 0
) {
return;
}
this.isValidInstance = true;
this.isFull =
typeof this.instance.hasCapacityForYou !==
'undefined' && !this.instance.hasCapacityForYou;
if (this.instance.closedAt) {
this.isClosed = true;
this.closedAt = this.instance.closedAt;
}
this.isHardClosed = this.instance.hardClose === true;
this.occupants = this.instance.userCount;
if (this.location === $app.lastLocation.location) {
// use gameLog for occupants when in same location
this.occupants = $app.lastLocation.playerList.size;
}
this.capacity = this.instance.capacity;
this.gameServerVersion = this.instance.gameServerVersion;
this.queueSize = this.instance.queueSize;
if (this.instance.platforms) {
this.platforms = this.instance.platforms;
}
if (this.instance.users) {
this.userList = this.instance.users;
}
if (this.instance.ownerId === API.currentUser.id) {
this.canCloseInstance = true;
} else if (this.instance?.ownerId?.startsWith('grp_')) {
// check group perms
var groupId = this.instance.ownerId;
var group = API.cachedGroups.get(groupId);
this.canCloseInstance = $app.hasGroupPermission(
group,
'group-instance-moderate'
);
}
this.isAgeGated = this.instance.ageGate === true;
if (this.location && this.location.includes('~ageGate')) {
// dumb workaround for API not returning `ageGate`
this.isAgeGated = true;
}
},
showUserDialog(userId) {
API.$emit('SHOW_USER_DIALOG', userId);
}
},
watch: {
updateelement() {
this.parse();
},
location() {
this.parse();
},
friendcount() {
this.parse();
}
},
created() {
this.parse();
}
});
Vue.component('avatar-info', {
template:
'<div @click="confirm" class="avatar-info">' +
'<span style="margin-right:5px">{{ avatarName }}</span>' +
'<span style="margin-right:5px" :class="color">{{ avatarType }}</span>' +
'<span style="color:#909399;font-family:monospace;font-size:12px;">{{ avatarTags }}</span>' +
'</div>',
props: {
imageurl: String,
userid: String,
hintownerid: String,
hintavatarname: String,
avatartags: Array
},
data() {
return {
avatarName: this.avatarName,
avatarType: this.avatarType,
avatarTags: this.avatarTags,
color: this.color
};
},
methods: {
async parse() {
this.ownerId = '';
this.avatarName = '';
this.avatarType = '';
this.color = '';
this.avatarTags = '';
if (!this.imageurl) {
this.avatarName = '-';
} else if (this.hintownerid) {
this.avatarName = this.hintavatarname;
this.ownerId = this.hintownerid;
} else {
try {
var avatarInfo = await $app.getAvatarName(
this.imageurl
);
this.avatarName = avatarInfo.avatarName;
this.ownerId = avatarInfo.ownerId;
} catch (err) {}
}
if (typeof this.userid === 'undefined' || !this.ownerId) {
this.color = '';
this.avatarType = '';
} else if (this.ownerId === this.userid) {
this.color = 'avatar-info-own';
this.avatarType = '(own)';
} else {
this.color = 'avatar-info-public';
this.avatarType = '(public)';
}
if (typeof this.avatartags === 'object') {
var tagString = '';
for (var i = 0; i < this.avatartags.length; i++) {
var tagName = this.avatartags[i].replace(
'content_',
''
);
tagString += tagName;
if (i < this.avatartags.length - 1) {
tagString += ', ';
}
}
this.avatarTags = tagString;
}
},
confirm() {
if (!this.imageurl) {
return;
}
$app.showAvatarAuthorDialog(
this.userid,
this.ownerId,
this.imageurl
);
}
},
watch: {
imageurl() {
this.parse();
},
userid() {
this.parse();
},
avatartags() {
this.parse();
}
},
mounted() {
this.parse();
}
});
Vue.component('display-name', {
template:
'<span @click="showUserDialog" class="x-link">{{ username }}</span>',
props: {
userid: String,
location: String,
key: Number,
hint: {
type: String,
default: ''
}
},
data() {
return {
username: this.username
};
},
methods: {
async parse() {
this.username = this.userid;
if (this.hint) {
this.username = this.hint;
} else if (this.userid) {
var args = await API.getCachedUser({
userId: this.userid
});
}
if (
typeof args !== 'undefined' &&
typeof args.json !== 'undefined' &&
typeof args.json.displayName !== 'undefined'
) {
this.username = args.json.displayName;
}
},
showUserDialog() {
$app.showUserDialog(this.userid);
}
},
watch: {
location() {
this.parse();
},
key() {
this.parse();
},
userid() {
this.parse();
}
},
mounted() {
this.parse();
}
});
}
}

112
src/classes/updateLoop.js Normal file
View File

@@ -0,0 +1,112 @@
import * as workerTimers from 'worker-timers';
import { baseClass, $app, API, $t, $utils } from './baseClass.js';
export default class extends baseClass {
constructor(_app, _API, _t) {
super(_app, _API, _t);
}
init() {
API.$on('LOGIN', function () {
$app.nextCurrentUserRefresh = 300;
$app.nextFriendsRefresh = 3600;
$app.nextGroupInstanceRefresh = 0;
});
}
_data = {
nextCurrentUserRefresh: 300,
nextFriendsRefresh: 3600,
nextGroupInstanceRefresh: 0,
nextAppUpdateCheck: 3600,
ipcTimeout: 0,
nextClearVRCXCacheCheck: 0,
nextDiscordUpdate: 0,
nextAutoStateChange: 0,
nextGetLogCheck: 0,
nextGameRunningCheck: 0
};
_methods = {
async updateLoop() {
try {
if (API.isLoggedIn === true) {
if (--this.nextCurrentUserRefresh <= 0) {
this.nextCurrentUserRefresh = 300; // 5min
API.getCurrentUser();
}
if (--this.nextFriendsRefresh <= 0) {
this.nextFriendsRefresh = 3600; // 1hour
this.refreshFriendsList();
this.updateStoredUser(API.currentUser);
if (this.isGameRunning) {
API.refreshPlayerModerations();
}
}
if (--this.nextGroupInstanceRefresh <= 0) {
if (this.friendLogInitStatus) {
this.nextGroupInstanceRefresh = 300; // 5min
API.getUsersGroupInstances();
}
AppApi.CheckGameRunning();
}
if (--this.nextAppUpdateCheck <= 0) {
this.nextAppUpdateCheck = 3600; // 1hour
if (this.autoUpdateVRCX !== 'Off') {
this.checkForVRCXUpdate();
}
}
if (--this.ipcTimeout <= 0) {
this.ipcEnabled = false;
}
if (
--this.nextClearVRCXCacheCheck <= 0 &&
this.clearVRCXCacheFrequency > 0
) {
this.nextClearVRCXCacheCheck =
this.clearVRCXCacheFrequency / 2;
this.clearVRCXCache();
}
if (--this.nextDiscordUpdate <= 0) {
this.nextDiscordUpdate = 3;
if (this.discordActive) {
this.updateDiscord();
}
}
if (--this.nextAutoStateChange <= 0) {
this.nextAutoStateChange = 3;
this.updateAutoStateChange();
}
if (
(this.isRunningUnderWine || LINUX) &&
--this.nextGetLogCheck <= 0
) {
this.nextGetLogCheck = 0.5;
const logLines = await LogWatcher.GetLogLines();
if (logLines) {
logLines.forEach((logLine) => {
$app.addGameLogEvent(logLine);
});
}
}
if (
(this.isRunningUnderWine || LINUX) &&
--this.nextGameRunningCheck <= 0
) {
if (LINUX) {
this.nextGameRunningCheck = 1;
$app.updateIsGameRunning(await AppApi.IsGameRunning(), await AppApi.IsSteamVRRunning(), false);
} else {
this.nextGameRunningCheck = 3;
AppApi.CheckGameRunning();
}
}
}
} catch (err) {
API.isRefreshFriendsLoading = false;
console.error(err);
}
workerTimers.setTimeout(() => this.updateLoop(), 1000);
}
};
}

303
src/classes/utils.js Normal file
View File

@@ -0,0 +1,303 @@
export default {
removeFromArray(array, item) {
var { length } = array;
for (var i = 0; i < length; ++i) {
if (array[i] === item) {
array.splice(i, 1);
return true;
}
}
return false;
},
arraysMatch(a, b) {
if (!Array.isArray(a) || !Array.isArray(b)) {
return false;
}
return (
a.length === b.length &&
a.every(
(element, index) =>
JSON.stringify(element) === JSON.stringify(b[index])
)
);
},
escapeTag(tag) {
var s = String(tag);
return s.replace(/["&'<>]/g, (c) => `&#${c.charCodeAt(0)};`);
},
escapeTagRecursive(obj) {
if (typeof obj === 'string') {
return this.escapeTag(obj);
}
if (typeof obj === 'object') {
for (var key in obj) {
obj[key] = this.escapeTagRecursive(obj[key]);
}
}
return obj;
},
timeToText(sec) {
var n = Number(sec);
if (isNaN(n)) {
return this.escapeTag(sec);
}
n = Math.floor(n / 1000);
var arr = [];
if (n < 0) {
n = -n;
}
if (n >= 86400) {
arr.push(`${Math.floor(n / 86400)}d`);
n %= 86400;
}
if (n >= 3600) {
arr.push(`${Math.floor(n / 3600)}h`);
n %= 3600;
}
if (n >= 60) {
arr.push(`${Math.floor(n / 60)}m`);
n %= 60;
}
if (arr.length === 0 && n < 60) {
arr.push(`${n}s`);
}
return arr.join(' ');
},
textToHex(text) {
var s = String(text);
return s
.split('')
.map((c) => c.charCodeAt(0).toString(16))
.join(' ');
},
commaNumber(num) {
if (!num) {
return '0';
}
var s = String(Number(num));
return s.replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1,');
},
parseLocation(tag) {
var _tag = String(tag || '');
var ctx = {
tag: _tag,
isOffline: false,
isPrivate: false,
isTraveling: false,
worldId: '',
instanceId: '',
instanceName: '',
accessType: '',
accessTypeName: '',
region: '',
shortName: '',
userId: null,
hiddenId: null,
privateId: null,
friendsId: null,
groupId: null,
groupAccessType: null,
canRequestInvite: false,
strict: false,
ageGate: false
};
if (_tag === 'offline' || _tag === 'offline:offline') {
ctx.isOffline = true;
} else if (_tag === 'private' || _tag === 'private:private') {
ctx.isPrivate = true;
} else if (_tag === 'traveling' || _tag === 'traveling:traveling') {
ctx.isTraveling = true;
} else if (_tag.startsWith('local') === false) {
var sep = _tag.indexOf(':');
// technically not part of instance id, but might be there when coping id from url so why not support it
var shortNameQualifier = '&shortName=';
var shortNameIndex = _tag.indexOf(shortNameQualifier);
if (shortNameIndex >= 0) {
ctx.shortName = _tag.substr(
shortNameIndex + shortNameQualifier.length
);
_tag = _tag.substr(0, shortNameIndex);
}
if (sep >= 0) {
ctx.worldId = _tag.substr(0, sep);
ctx.instanceId = _tag.substr(sep + 1);
ctx.instanceId.split('~').forEach((s, i) => {
if (i) {
var A = s.indexOf('(');
var Z = A >= 0 ? s.lastIndexOf(')') : -1;
var key = Z >= 0 ? s.substr(0, A) : s;
var value = A < Z ? s.substr(A + 1, Z - A - 1) : '';
if (key === 'hidden') {
ctx.hiddenId = value;
} else if (key === 'private') {
ctx.privateId = value;
} else if (key === 'friends') {
ctx.friendsId = value;
} else if (key === 'canRequestInvite') {
ctx.canRequestInvite = true;
} else if (key === 'region') {
ctx.region = value;
} else if (key === 'group') {
ctx.groupId = value;
} else if (key === 'groupAccessType') {
ctx.groupAccessType = value;
} else if (key === 'strict') {
ctx.strict = true;
} else if (key === 'ageGate') {
ctx.ageGate = true;
}
} else {
ctx.instanceName = s;
}
});
ctx.accessType = 'public';
if (ctx.privateId !== null) {
if (ctx.canRequestInvite) {
// InvitePlus
ctx.accessType = 'invite+';
} else {
// InviteOnly
ctx.accessType = 'invite';
}
ctx.userId = ctx.privateId;
} else if (ctx.friendsId !== null) {
// FriendsOnly
ctx.accessType = 'friends';
ctx.userId = ctx.friendsId;
} else if (ctx.hiddenId !== null) {
// FriendsOfGuests
ctx.accessType = 'friends+';
ctx.userId = ctx.hiddenId;
} else if (ctx.groupId !== null) {
// Group
ctx.accessType = 'group';
}
ctx.accessTypeName = ctx.accessType;
if (ctx.groupAccessType !== null) {
if (ctx.groupAccessType === 'public') {
ctx.accessTypeName = 'groupPublic';
} else if (ctx.groupAccessType === 'plus') {
ctx.accessTypeName = 'groupPlus';
}
}
} else {
ctx.worldId = _tag;
}
}
return ctx;
},
displayLocation(location, worldName, groupName) {
var text = worldName;
var L = this.parseLocation(location);
if (L.isOffline) {
text = 'Offline';
} else if (L.isPrivate) {
text = 'Private';
} else if (L.isTraveling) {
text = 'Traveling';
} else if (L.worldId) {
if (groupName) {
text = `${worldName} ${L.accessTypeName}(${groupName})`;
} else if (L.instanceId) {
text = `${worldName} ${L.accessTypeName}`;
}
}
return text;
},
extractFileId(s) {
var match = String(s).match(/file_[0-9A-Za-z-]+/);
return match ? match[0] : '';
},
extractFileVersion(s) {
var match = /(?:\/file_[0-9A-Za-z-]+\/)([0-9]+)/gi.exec(s);
return match ? match[1] : '';
},
extractVariantVersion(url) {
if (!url) {
return '0';
}
try {
const params = new URLSearchParams(new URL(url).search);
const version = params.get('v');
if (version) {
return version;
}
return '0';
} catch {
return '0';
}
},
buildTreeData(json) {
var node = [];
for (var key in json) {
if (key[0] === '$') {
continue;
}
var value = json[key];
if (Array.isArray(value) && value.length === 0) {
node.push({
key,
value: '[]'
});
} else if (
value === Object(value) &&
Object.keys(value).length === 0
) {
node.push({
key,
value: '{}'
});
} else if (Array.isArray(value)) {
node.push({
children: value.map((val, idx) => {
if (val === Object(val)) {
return {
children: this.buildTreeData(val),
key: idx
};
}
return {
key: idx,
value: val
};
}),
key
});
} else if (value === Object(value)) {
node.push({
children: this.buildTreeData(value),
key
});
} else {
node.push({
key,
value: String(value)
});
}
}
node.sort(function (a, b) {
var A = String(a.key).toUpperCase();
var B = String(b.key).toUpperCase();
if (A < B) {
return -1;
}
if (A > B) {
return 1;
}
return 0;
});
return node;
}
};

322
src/classes/vrcRegistry.js Normal file
View File

@@ -0,0 +1,322 @@
import configRepository from '../repository/config.js';
import { baseClass, $app, API, $t, $utils } from './baseClass.js';
export default class extends baseClass {
constructor(_app, _API, _t) {
super(_app, _API, _t);
}
init() {}
_data = {
registryBackupDialog: {
visible: false
},
registryBackupTable: {
data: [],
tableProps: {
stripe: true,
size: 'mini',
defaultSort: {
prop: 'date',
order: 'descending'
}
},
layout: 'table'
}
};
_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) {
regJson = await AppApi.GetVRChatRegistryJson();
regJson = JSON.parse(regJson);
} else {
regJson = await AppApi.GetVRChatRegistry();
}
var newBackup = {
name,
date: new Date().toJSON(),
data: regJson
};
var backupsJson = await configRepository.getString(
'VRCX_VRChatRegistryBackups'
);
if (!backupsJson) {
backupsJson = JSON.stringify([]);
}
var backups = JSON.parse(backupsJson);
backups.push(newBackup);
await configRepository.setString(
'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) {
this.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 = [];
},
async checkAutoBackupRestoreVrcRegistry() {
if (!this.vrcRegistryAutoBackup) {
return;
}
// check for auto restore
var hasVRChatRegistryFolder =
await AppApi.HasVRChatRegistryFolder();
if (!hasVRChatRegistryFolder) {
var lastBackupDate = await configRepository.getString(
'VRCX_VRChatRegistryLastBackupDate'
);
var lastRestoreCheck = await configRepository.getString(
'VRCX_VRChatRegistryLastRestoreCheck'
);
if (
!lastBackupDate ||
(lastRestoreCheck &&
lastBackupDate &&
lastRestoreCheck === lastBackupDate)
) {
// only ask to restore once and when backup is present
return;
}
// popup message about auto restore
this.$alert(
$t('dialog.registry_backup.restore_prompt'),
$t('dialog.registry_backup.header')
);
this.showRegistryBackupDialog();
await AppApi.FocusWindow();
await configRepository.setString(
'VRCX_VRChatRegistryLastRestoreCheck',
lastBackupDate
);
} else {
await this.autoBackupVrcRegistry();
}
},
async autoBackupVrcRegistry() {
var date = new Date();
var lastBackupDate = await configRepository.getString(
'VRCX_VRChatRegistryLastBackupDate'
);
if (lastBackupDate) {
var lastBackup = new Date(lastBackupDate);
var diff = date.getTime() - lastBackup.getTime();
var diffDays = Math.floor(diff / (1000 * 60 * 60 * 24));
if (diffDays < 7) {
return;
}
}
var backupsJson = await configRepository.getString(
'VRCX_VRChatRegistryBackups'
);
if (!backupsJson) {
backupsJson = JSON.stringify([]);
}
var backups = JSON.parse(backupsJson);
backups.forEach((backup) => {
if (backup.name === 'Auto Backup') {
// remove old auto backup
$app.removeFromArray(backups, backup);
}
});
await configRepository.setString(
'VRCX_VRChatRegistryBackups',
JSON.stringify(backups)
);
this.backupVrcRegistry('Auto Backup');
await configRepository.setString(
'VRCX_VRChatRegistryLastBackupDate',
date.toJSON()
);
}
};
}

View File

@@ -0,0 +1,52 @@
import * as workerTimers from 'worker-timers';
/* eslint-disable no-unused-vars */
let VRCXStorage = {};
/* eslint-enable no-unused-vars */
export default class {
constructor(_VRCXStorage) {
VRCXStorage = _VRCXStorage;
this.init();
}
init() {
VRCXStorage.GetArray = async function (key) {
try {
var array = JSON.parse(await this.Get(key));
if (Array.isArray(array)) {
return array;
}
} catch (err) {
console.error(err);
}
return [];
};
VRCXStorage.SetArray = function (key, value) {
this.Set(key, JSON.stringify(value));
};
VRCXStorage.GetObject = async function (key) {
try {
var object = JSON.parse(await this.Get(key));
if (object === Object(object)) {
return object;
}
} catch (err) {
console.error(err);
}
return {};
};
VRCXStorage.SetObject = function (key, value) {
this.Set(key, JSON.stringify(value));
};
workerTimers.setInterval(
() => {
VRCXStorage.Flush();
},
5 * 60 * 1000
);
}
}

File diff suppressed because it is too large Load Diff

348
src/classes/vrcxUpdater.js Normal file
View File

@@ -0,0 +1,348 @@
import { baseClass, $app, API, $t, $utils } from './baseClass.js';
import * as workerTimers from 'worker-timers';
export default class extends baseClass {
constructor(_app, _API, _t) {
super(_app, _API, _t);
}
_data = {
VRCXUpdateDialog: {
visible: false,
updatePending: false,
updatePendingIsLatest: false,
release: '',
releases: [],
json: {}
},
branch: 'Stable',
autoUpdateVRCX: 'Auto Download',
checkingForVRCXUpdate: false,
pendingVRCXInstall: '',
pendingVRCXUpdate: false,
branches: {
Stable: {
name: 'Stable',
urlReleases: 'https://api0.vrcx.app/releases/stable',
urlLatest: 'https://api0.vrcx.app/releases/stable/latest'
},
Nightly: {
name: 'Nightly',
urlReleases: 'https://api0.vrcx.app/releases/nightly',
urlLatest: 'https://api0.vrcx.app/releases/nightly/latest'
}
// LinuxTest: {
// name: 'LinuxTest',
// urlReleases: 'https://api.github.com/repos/rs189/VRCX/releases',
// urlLatest:
// 'https://api.github.com/repos/rs189/VRCX/releases/latest'
// }
},
updateProgress: 0,
updateInProgress: false
};
_methods = {
async showVRCXUpdateDialog() {
this.$nextTick(() =>
$app.adjustDialogZ(this.$refs.VRCXUpdateDialog.$el)
);
var D = this.VRCXUpdateDialog;
D.visible = true;
D.updatePendingIsLatest = false;
D.updatePending = await AppApi.CheckForUpdateExe();
this.loadBranchVersions();
},
async downloadVRCXUpdate(
downloadUrl,
downloadName,
hashUrl,
size,
releaseName,
type
) {
if (this.updateInProgress) {
return;
}
try {
this.updateInProgress = true;
this.downloadFileProgress();
await AppApi.DownloadUpdate(
downloadUrl,
downloadName,
hashUrl,
size
);
this.pendingVRCXInstall = releaseName;
} catch (err) {
console.error(err);
this.$message({
message: `${$t('message.vrcx_updater.failed_install')} ${err}`,
type: 'error'
});
} finally {
this.updateInProgress = false;
this.updateProgress = 0;
}
},
async cancelUpdate() {
await AppApi.CancelUpdate();
this.updateInProgress = false;
this.updateProgress = 0;
},
async downloadFileProgress() {
this.updateProgress = await AppApi.CheckUpdateProgress();
if (this.updateInProgress) {
workerTimers.setTimeout(() => this.downloadFileProgress(), 150);
}
},
updateProgressText() {
if (this.updateProgress === 100) {
return $t('message.vrcx_updater.checking_hash');
}
return `${this.updateProgress}%`;
},
installVRCXUpdate() {
for (var release of this.VRCXUpdateDialog.releases) {
if (release.name !== this.VRCXUpdateDialog.release) {
continue;
}
var downloadUrl = '';
var downloadName = '';
var hashUrl = '';
var size = 0;
for (var asset of release.assets) {
if (asset.state !== 'uploaded') {
continue;
}
if (
WINDOWS &&
(asset.content_type === 'application/x-msdownload' ||
asset.content_type ===
'application/x-msdos-program')
) {
downloadUrl = asset.browser_download_url;
downloadName = asset.name;
size = asset.size;
continue;
}
if (
LINUX &&
asset.content_type === 'application/octet-stream'
) {
downloadUrl = asset.browser_download_url;
downloadName = asset.name;
size = asset.size;
continue;
}
if (
asset.name === 'SHA256SUMS.txt' &&
asset.content_type === 'text/plain'
) {
hashUrl = asset.browser_download_url;
continue;
}
}
if (!downloadUrl) {
return;
}
var releaseName = release.name;
var type = 'Manual';
this.downloadVRCXUpdate(
downloadUrl,
downloadName,
hashUrl,
size,
releaseName,
type
);
break;
}
},
async loadBranchVersions() {
var D = this.VRCXUpdateDialog;
var url = this.branches[this.branch].urlReleases;
this.checkingForVRCXUpdate = true;
try {
var response = await webApiService.execute({
url,
method: 'GET'
});
} finally {
this.checkingForVRCXUpdate = false;
}
var json = JSON.parse(response.data);
if (this.debugWebRequests) {
console.log(json, response);
}
var releases = [];
if (typeof json !== 'object' || json.message) {
$app.$message({
message: $t('message.vrcx_updater.failed', {
message: json.message
}),
type: 'error'
});
return;
}
for (var release of json) {
for (var asset of release.assets) {
if (
(asset.content_type === 'application/x-msdownload' ||
asset.content_type ===
'application/x-msdos-program') &&
asset.state === 'uploaded'
) {
releases.push(release);
}
}
}
D.releases = releases;
D.release = json[0].name;
this.VRCXUpdateDialog.updatePendingIsLatest = false;
if (D.release === this.pendingVRCXInstall) {
// update already downloaded and latest version
this.VRCXUpdateDialog.updatePendingIsLatest = true;
}
if (
(await configRepository.getString('VRCX_branch')) !==
this.branch
) {
await configRepository.setString('VRCX_branch', this.branch);
}
},
async checkForVRCXUpdate() {
var currentVersion = this.appVersion.replace(' (Linux)', '');
if (
!currentVersion ||
currentVersion === 'VRCX Nightly Build' ||
currentVersion === 'VRCX Build'
) {
// ignore custom builds
return;
}
if (this.branch === 'Beta') {
// move Beta users to stable
this.branch = 'Stable';
await configRepository.setString('VRCX_branch', this.branch);
}
if (typeof this.branches[this.branch] === 'undefined') {
// handle invalid branch
this.branch = 'Stable';
await configRepository.setString('VRCX_branch', this.branch);
}
var url = this.branches[this.branch].urlLatest;
this.checkingForVRCXUpdate = true;
try {
var response = await webApiService.execute({
url,
method: 'GET'
});
} finally {
this.checkingForVRCXUpdate = false;
}
this.pendingVRCXUpdate = false;
var json = JSON.parse(response.data);
if (this.debugWebRequests) {
console.log(json, response);
}
if (json === Object(json) && json.name && json.published_at) {
this.VRCXUpdateDialog.updateJson = json;
this.changeLogDialog.buildName = json.name;
this.changeLogDialog.changeLog = this.changeLogRemoveLinks(
json.body
);
var releaseName = json.name;
this.latestAppVersion = releaseName;
this.VRCXUpdateDialog.updatePendingIsLatest = false;
if (releaseName === this.pendingVRCXInstall) {
// update already downloaded
this.VRCXUpdateDialog.updatePendingIsLatest = true;
} else if (releaseName > currentVersion) {
var downloadUrl = '';
var downloadName = '';
var hashUrl = '';
var size = 0;
for (var asset of json.assets) {
if (asset.state !== 'uploaded') {
continue;
}
if (
!LINUX &&
(asset.content_type ===
'application/x-msdownload' ||
asset.content_type ===
'application/x-msdos-program')
) {
downloadUrl = asset.browser_download_url;
downloadName = asset.name;
size = asset.size;
continue;
}
if (
LINUX &&
asset.content_type === 'application/octet-stream'
) {
downloadUrl = asset.browser_download_url;
downloadName = asset.name;
size = asset.size;
continue;
}
if (
asset.name === 'SHA256SUMS.txt' &&
asset.content_type === 'text/plain'
) {
hashUrl = asset.browser_download_url;
continue;
}
}
if (!downloadUrl) {
return;
}
this.pendingVRCXUpdate = true;
this.notifyMenu('settings');
var type = 'Auto';
if (!API.isLoggedIn) {
this.showVRCXUpdateDialog();
} else if (this.autoUpdateVRCX === 'Notify') {
// this.showVRCXUpdateDialog();
} else if (this.autoUpdateVRCX === 'Auto Download') {
this.downloadVRCXUpdate(
downloadUrl,
downloadName,
hashUrl,
size,
releaseName,
type
);
}
}
}
},
restartVRCX(isUpgrade) {
if (!LINUX) {
AppApi.RestartApplication(isUpgrade);
} else {
window.electron.restartApp();
}
},
async saveAutoUpdateVRCX() {
if (this.autoUpdateVRCX === 'Off') {
this.pendingVRCXUpdate = false;
}
await configRepository.setString(
'VRCX_autoUpdateVRCX',
this.autoUpdateVRCX
);
}
};
}

588
src/classes/websocket.js Normal file
View File

@@ -0,0 +1,588 @@
import * as workerTimers from 'worker-timers';
import Noty from 'noty';
import { baseClass, $app, API, $t, $utils } from './baseClass.js';
export default class extends baseClass {
constructor(_app, _API, _t) {
super(_app, _API, _t);
}
init() {
API.webSocket = null;
API.lastWebSocketMessage = '';
API.$on('USER:CURRENT', function () {
if ($app.friendLogInitStatus && this.webSocket === null) {
this.getAuth();
}
});
API.getAuth = function () {
return this.call('auth', {
method: 'GET'
}).then((json) => {
var args = {
json
};
this.$emit('AUTH', args);
return args;
});
};
API.$on('AUTH', function (args) {
if (args.json.ok) {
this.connectWebSocket(args.json.token);
}
});
API.connectWebSocket = function (token) {
if (this.webSocket !== null) {
return;
}
var socket = new WebSocket(`${API.websocketDomain}/?auth=${token}`);
socket.onopen = () => {
if ($app.debugWebSocket) {
console.log('WebSocket connected');
}
};
socket.onclose = () => {
if (this.webSocket === socket) {
this.webSocket = null;
}
try {
socket.close();
} catch (err) {}
if ($app.debugWebSocket) {
console.log('WebSocket closed');
}
workerTimers.setTimeout(() => {
if (
this.isLoggedIn &&
$app.friendLogInitStatus &&
this.webSocket === null
) {
this.getAuth();
}
}, 5000);
};
socket.onerror = () => {
if (this.errorNoty) {
this.errorNoty.close();
}
this.errorNoty = new Noty({
type: 'error',
text: 'WebSocket Error'
}).show();
socket.onclose();
};
socket.onmessage = ({ data }) => {
try {
if (this.lastWebSocketMessage === data) {
// pls no spam
return;
}
this.lastWebSocketMessage = data;
var json = JSON.parse(data);
try {
json.content = JSON.parse(json.content);
} catch (err) {}
this.$emit('PIPELINE', {
json
});
if ($app.debugWebSocket && json.content) {
var displayName = '';
var user = this.cachedUsers.get(json.content.userId);
if (user) {
displayName = user.displayName;
}
console.log(
'WebSocket',
json.type,
displayName,
json.content
);
}
} catch (err) {
console.error(err);
}
};
this.webSocket = socket;
};
API.$on('LOGOUT', function () {
this.closeWebSocket();
});
API.closeWebSocket = function () {
var socket = this.webSocket;
if (socket === null) {
return;
}
this.webSocket = null;
try {
socket.close();
} catch (err) {}
};
API.reconnectWebSocket = function () {
if (!this.isLoggedIn || !$app.friendLogInitStatus) {
return;
}
this.closeWebSocket();
this.getAuth();
};
API.$on('PIPELINE', function (args) {
var { type, content, err } = args.json;
if (typeof err !== 'undefined') {
console.error('PIPELINE: error', args);
if (this.errorNoty) {
this.errorNoty.close();
}
this.errorNoty = new Noty({
type: 'error',
text: $app.escapeTag(`WebSocket Error: ${err}`)
}).show();
return;
}
if (typeof content === 'undefined') {
console.error('PIPELINE: missing content', args);
return;
}
if (typeof content.user !== 'undefined') {
// I forgot about this...
delete content.user.state;
}
switch (type) {
case 'notification':
this.$emit('NOTIFICATION', {
json: content,
params: {
notificationId: content.id
}
});
this.$emit('PIPELINE:NOTIFICATION', {
json: content,
params: {
notificationId: content.id
}
});
break;
case 'notification-v2':
console.log('notification-v2', content);
this.$emit('NOTIFICATION:V2', {
json: content,
params: {
notificationId: content.id
}
});
break;
case 'notification-v2-delete':
console.log('notification-v2-delete', content);
for (var id of content.ids) {
this.$emit('NOTIFICATION:HIDE', {
params: {
notificationId: id
}
});
this.$emit('NOTIFICATION:SEE', {
params: {
notificationId: id
}
});
}
break;
case 'notification-v2-update':
console.log('notification-v2-update', content);
this.$emit('NOTIFICATION:V2:UPDATE', {
json: content.updates,
params: {
notificationId: content.id
}
});
break;
case 'see-notification':
this.$emit('NOTIFICATION:SEE', {
params: {
notificationId: content
}
});
break;
case 'hide-notification':
this.$emit('NOTIFICATION:HIDE', {
params: {
notificationId: content
}
});
this.$emit('NOTIFICATION:SEE', {
params: {
notificationId: content
}
});
break;
case 'response-notification':
this.$emit('NOTIFICATION:HIDE', {
params: {
notificationId: content.notificationId
}
});
this.$emit('NOTIFICATION:SEE', {
params: {
notificationId: content.notificationId
}
});
break;
case 'friend-add':
this.$emit('USER', {
json: content.user,
params: {
userId: content.userId
}
});
this.$emit('FRIEND:ADD', {
params: {
userId: content.userId
}
});
break;
case 'friend-delete':
this.$emit('FRIEND:DELETE', {
params: {
userId: content.userId
}
});
break;
case 'friend-online':
// Where is instanceId, travelingToWorld, travelingToInstance?
// More JANK, what a mess
var $location = $utils.parseLocation(content.location);
var $travelingToLocation = $utils.parseLocation(
content.travelingToLocation
);
if (content?.user?.id) {
this.$emit('USER', {
json: {
id: content.userId,
platform: content.platform,
state: 'online',
location: content.location,
worldId: content.worldId,
instanceId: $location.instanceId,
travelingToLocation:
content.travelingToLocation,
travelingToWorld: $travelingToLocation.worldId,
travelingToInstance:
$travelingToLocation.instanceId,
...content.user
},
params: {
userId: content.userId
}
});
} else {
this.$emit('FRIEND:STATE', {
json: {
state: 'online'
},
params: {
userId: content.userId
}
});
}
break;
case 'friend-active':
if (content?.user?.id) {
this.$emit('USER', {
json: {
id: content.userId,
platform: content.platform,
state: 'active',
location: 'offline',
worldId: 'offline',
instanceId: 'offline',
travelingToLocation: 'offline',
travelingToWorld: 'offline',
travelingToInstance: 'offline',
...content.user
},
params: {
userId: content.userId
}
});
} else {
this.$emit('FRIEND:STATE', {
json: {
state: 'active'
},
params: {
userId: content.userId
}
});
}
break;
case 'friend-offline':
// more JANK, hell yeah
this.$emit('USER', {
json: {
id: content.userId,
platform: content.platform,
state: 'offline',
location: 'offline',
worldId: 'offline',
instanceId: 'offline',
travelingToLocation: 'offline',
travelingToWorld: 'offline',
travelingToInstance: 'offline'
},
params: {
userId: content.userId
}
});
break;
case 'friend-update':
this.$emit('USER', {
json: content.user,
params: {
userId: content.userId
}
});
break;
case 'friend-location':
var $location = $utils.parseLocation(content.location);
var $travelingToLocation = $utils.parseLocation(
content.travelingToLocation
);
if (!content?.user?.id) {
var ref = this.cachedUsers.get(content.userId);
if (typeof ref !== 'undefined') {
this.$emit('USER', {
json: {
...ref,
location: content.location,
worldId: content.worldId,
instanceId: $location.instanceId,
travelingToLocation:
content.travelingToLocation,
travelingToWorld:
$travelingToLocation.worldId,
travelingToInstance:
$travelingToLocation.instanceId
},
params: {
userId: content.userId
}
});
}
break;
}
this.$emit('USER', {
json: {
location: content.location,
worldId: content.worldId,
instanceId: $location.instanceId,
travelingToLocation: content.travelingToLocation,
travelingToWorld: $travelingToLocation.worldId,
travelingToInstance:
$travelingToLocation.instanceId,
...content.user,
state: 'online' // JANK
},
params: {
userId: content.userId
}
});
break;
case 'user-update':
this.$emit('USER:CURRENT', {
json: content.user,
params: {
userId: content.userId
}
});
break;
case 'user-location':
// update current user location
if (content.userId !== this.currentUser.id) {
console.error('user-location wrong userId', content);
break;
}
// content.user: {}
// content.world: {}
this.currentUser.presence.instance = content.instance;
this.currentUser.presence.world = content.worldId;
$app.setCurrentUserLocation(content.location);
break;
case 'group-joined':
// var groupId = content.groupId;
// $app.onGroupJoined(groupId);
break;
case 'group-left':
// var groupId = content.groupId;
// $app.onGroupLeft(groupId);
break;
case 'group-role-updated':
var groupId = content.role.groupId;
API.getGroup({ groupId, includeRoles: true });
console.log('group-role-updated', content);
// content {
// role: {
// createdAt: string,
// description: string,
// groupId: string,
// id: string,
// isManagementRole: boolean,
// isSelfAssignable: boolean,
// name: string,
// order: number,
// permissions: string[],
// requiresPurchase: boolean,
// requiresTwoFactor: boolean
break;
case 'group-member-updated':
var member = content.member;
if (!member) {
console.error(
'group-member-updated missing member',
content
);
break;
}
var groupId = member.groupId;
if (
$app.groupDialog.visible &&
$app.groupDialog.id === groupId
) {
$app.getGroupDialogGroup(groupId);
}
this.$emit('GROUP:MEMBER', {
json: member,
params: {
groupId
}
});
console.log('group-member-updated', member);
break;
case 'instance-queue-joined':
case 'instance-queue-position':
var instanceId = content.instanceLocation;
var position = content.position ?? 0;
var queueSize = content.queueSize ?? 0;
$app.instanceQueueUpdate(instanceId, position, queueSize);
break;
case 'instance-queue-ready':
var instanceId = content.instanceLocation;
// var expiry = Date.parse(content.expiry);
$app.instanceQueueReady(instanceId);
break;
case 'instance-queue-left':
var instanceId = content.instanceLocation;
$app.removeQueuedInstance(instanceId);
// $app.instanceQueueClear();
break;
case 'content-refresh':
var contentType = content.contentType;
console.log('content-refresh', content);
if (contentType === 'icon') {
if (
$app.galleryDialogVisible &&
!$app.galleryDialogIconsLoading
) {
$app.refreshVRCPlusIconsTable();
}
} else if (contentType === 'gallery') {
if (
$app.galleryDialogVisible &&
!$app.galleryDialogGalleryLoading
) {
$app.refreshGalleryTable();
}
} else if (contentType === 'emoji') {
if (
$app.galleryDialogVisible &&
!$app.galleryDialogEmojisLoading
) {
$app.refreshEmojiTable();
}
} else if (
contentType === 'print' ||
contentType === 'prints'
) {
if (
$app.galleryDialogVisible &&
!$app.galleryDialogPrintsLoading
) {
$app.refreshPrintTable();
}
} else if (contentType === 'avatar') {
// hmm, utilizing this might be too spamy and cause UI to move around
} else if (contentType === 'world') {
// hmm
} else if (contentType === 'created') {
// on avatar upload
} else {
console.log('Unknown content-refresh', content);
}
break;
case 'instance-closed':
// TODO: get worldName, groupName, hardClose
var noty = {
type: 'instance.closed',
location: content.instanceLocation,
message: 'Instance Closed',
created_at: new Date().toJSON()
};
if (
$app.notificationTable.filters[0].value.length === 0 ||
$app.notificationTable.filters[0].value.includes(
noty.type
)
) {
$app.notifyMenu('notification');
}
$app.queueNotificationNoty(noty);
$app.notificationTable.data.push(noty);
$app.updateSharedFeed(true);
break;
default:
console.log('Unknown pipeline type', args.json);
}
});
}
_data = {};
_methods = {};
}