mirror of
https://github.com/MrUnknownDE/VRCX.git
synced 2026-04-30 20:23:46 +02:00
Open instance in-game
This commit is contained in:
@@ -64,50 +64,87 @@ export const useLaunchStore = defineStore('Launch', () => {
|
||||
*
|
||||
* @param {string} location
|
||||
* @param {string} shortName
|
||||
* @param {boolean} desktopMode
|
||||
* @returns {Promise<void>}
|
||||
* @returns {Promise<string>} launchUrl
|
||||
*/
|
||||
async function launchGame(location, shortName, desktopMode) {
|
||||
async function getLaunchUrl(location, shortName) {
|
||||
const L = parseLocation(location);
|
||||
const args = [];
|
||||
if (
|
||||
shortName &&
|
||||
L.instanceType !== 'public' &&
|
||||
L.groupAccessType !== 'public'
|
||||
) {
|
||||
args.push(
|
||||
`vrchat://launch?ref=vrcx.app&id=${location}&shortName=${shortName}`
|
||||
);
|
||||
} else {
|
||||
// fetch shortName
|
||||
let newShortName = '';
|
||||
const response = await instanceRequest.getInstanceShortName({
|
||||
worldId: L.worldId,
|
||||
instanceId: L.instanceId
|
||||
});
|
||||
if (response.json) {
|
||||
if (response.json.shortName) {
|
||||
newShortName = response.json.shortName;
|
||||
} else {
|
||||
newShortName = response.json.secureName;
|
||||
}
|
||||
}
|
||||
if (newShortName) {
|
||||
args.push(
|
||||
`vrchat://launch?ref=vrcx.app&id=${location}&shortName=${newShortName}`
|
||||
);
|
||||
} else {
|
||||
args.push(`vrchat://launch?ref=vrcx.app&id=${location}`);
|
||||
}
|
||||
return `vrchat://launch?ref=vrcx.app&id=${location}&shortName=${shortName}`;
|
||||
}
|
||||
|
||||
// fetch shortName
|
||||
let newShortName = '';
|
||||
const response = await instanceRequest.getInstanceShortName({
|
||||
worldId: L.worldId,
|
||||
instanceId: L.instanceId
|
||||
});
|
||||
if (response.json) {
|
||||
if (response.json.shortName) {
|
||||
newShortName = response.json.shortName;
|
||||
} else {
|
||||
newShortName = response.json.secureName;
|
||||
}
|
||||
}
|
||||
if (newShortName) {
|
||||
return `vrchat://launch?ref=vrcx.app&id=${location}&shortName=${newShortName}`;
|
||||
}
|
||||
return `vrchat://launch?ref=vrcx.app&id=${location}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* launch.exe &attach=1
|
||||
* @param {string} location
|
||||
* @param {string} shortName
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async function tryOpenInstanceInVrc(location, shortName) {
|
||||
const launchUrl = await getLaunchUrl(location, shortName);
|
||||
let result = false;
|
||||
try {
|
||||
result = await AppApi.TryOpenInstanceInVrc(launchUrl);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
console.log('Attach Game', launchUrl, result);
|
||||
if (!result) {
|
||||
$app.$message({
|
||||
message:
|
||||
'Failed open instance in VRChat, falling back to self invite',
|
||||
type: 'warning'
|
||||
});
|
||||
// self invite fallback
|
||||
const L = parseLocation(location);
|
||||
await instanceRequest.selfInvite({
|
||||
instanceId: L.instanceId,
|
||||
worldId: L.worldId,
|
||||
shortName
|
||||
});
|
||||
$app.$message({
|
||||
message: 'Self invite sent',
|
||||
type: 'success'
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {string} location
|
||||
* @param {string} shortName
|
||||
* @param {boolean} desktopMode
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async function launchGame(location, shortName, desktopMode) {
|
||||
const launchUrl = await getLaunchUrl(location, shortName);
|
||||
const args = [launchUrl];
|
||||
const launchArguments =
|
||||
await configRepository.getString('launchArguments');
|
||||
|
||||
const vrcLaunchPathOverride = await configRepository.getString(
|
||||
'vrcLaunchPathOverride'
|
||||
);
|
||||
|
||||
if (launchArguments) {
|
||||
args.push(launchArguments);
|
||||
}
|
||||
@@ -157,6 +194,7 @@ export const useLaunchStore = defineStore('Launch', () => {
|
||||
launchDialogData,
|
||||
showLaunchOptions,
|
||||
showLaunchDialog,
|
||||
launchGame
|
||||
launchGame,
|
||||
tryOpenInstanceInVrc
|
||||
};
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user