Skip to content

Commit

Permalink
Touch ups
Browse files Browse the repository at this point in the history
  • Loading branch information
Natsumi-sama committed Jan 21, 2025
1 parent 9321f74 commit 7eae915
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 21 deletions.
45 changes: 28 additions & 17 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,6 @@ console.log(`isLinux: ${LINUX}`);
this.checkForVRCXUpdate();
}
await AppApi.CheckGameRunning();
this.isSidebarGroupByInstance =
(await configRepository.getBool(
'VRCX_sidebarGroupByInstance'
)) ?? true;
this.isGameNoVR = await configRepository.getBool('isGameNoVR');
await AppApi.SetAppLauncherSettings(
this.enableAppLauncher,
Expand Down Expand Up @@ -3785,6 +3781,7 @@ console.log(`isLinux: ${LINUX}`);
if (isGameRunning) {
API.currentUser.$online_for = Date.now();
API.currentUser.$offline_for = '';
API.currentUser.$previousAvatarSwapTime = Date.now();
} else {
await configRepository.setBool('isGameNoVR', this.isGameNoVR);
API.currentUser.$online_for = '';
Expand All @@ -3793,6 +3790,8 @@ console.log(`isLinux: ${LINUX}`);
this.autoVRChatCacheManagement();
this.checkIfGameCrashed();
this.ipcTimeout = 0;
this.addAvatarWearTime(API.currentUser.currentAvatar);
API.currentUser.$previousAvatarSwapTime = '';
}
this.lastLocationReset();
this.clearNowPlaying();
Expand All @@ -3805,13 +3804,6 @@ console.log(`isLinux: ${LINUX}`);
console.log(new Date(), 'isGameRunning', isGameRunning);
}

if (isGameRunning) {
API.currentUser.$previousAvatarSwapTime = Date.now();
} else if (API.currentUser.$previousAvatarSwapTime) {
this.addAvatarWearTime(API.currentUser.currentAvatar);
API.currentUser.$previousAvatarSwapTime = '';
}

if (isSteamVRRunning !== this.isSteamVRRunning) {
this.isSteamVRRunning = isSteamVRRunning;
console.log('isSteamVRRunning:', isSteamVRRunning);
Expand Down Expand Up @@ -12173,7 +12165,16 @@ console.log(`isLinux: ${LINUX}`);
}
}
database.getAvatarTimeSpent(avatarId).then((aviTime) => {
D.timeSpent = aviTime.timeSpent;
if (D.id === aviTime.avatarId) {
D.timeSpent = aviTime.timeSpent;
if (
D.id === API.currentUser.currentAvatar &&
API.currentUser.$previousAvatarSwapTime
) {
D.timeSpent +=
Date.now() - API.currentUser.$previousAvatarSwapTime;
}
}
});
API.getAvatar({ avatarId })
.then((args) => {
Expand Down Expand Up @@ -19870,8 +19871,12 @@ console.log(`isLinux: ${LINUX}`);
var historyArray = await database.getAvatarHistory(API.currentUser.id);
this.avatarHistoryArray = historyArray;
for (var i = 0; i < historyArray.length; i++) {
this.avatarHistory.add(historyArray[i].id);
API.applyAvatar(historyArray[i]);
var avatar = historyArray[i];
if (avatar.authorId === API.currentUser.id) {
continue;
}
this.avatarHistory.add(avatar.id);
API.applyAvatar(avatar);
}
};

Expand Down Expand Up @@ -19899,9 +19904,12 @@ console.log(`isLinux: ${LINUX}`);
});
};

$app.methods.addAvatarWearTime = function (avatar) {
$app.methods.addAvatarWearTime = function (avatarId) {
if (!API.currentUser.$previousAvatarSwapTime || !avatarId) {
return;
}
const timeSpent = Date.now() - API.currentUser.$previousAvatarSwapTime;
database.addAvatarTimeSpent(avatar, timeSpent);
database.addAvatarTimeSpent(avatarId, timeSpent);
};

$app.methods.promptClearAvatarHistory = function () {
Expand Down Expand Up @@ -23124,7 +23132,10 @@ console.log(`isLinux: ${LINUX}`);
// friendsListSidebar
// - SidebarGroupByInstance

$app.data.isSidebarGroupByInstance = true;
$app.data.isSidebarGroupByInstance = await configRepository.getBool(
'VRCX_sidebarGroupByInstance',
true
);
$app.computed.onlineFriendsInSameInstance = function () {
const groupedItems = {};

Expand Down
11 changes: 8 additions & 3 deletions src/classes/currentUser.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,10 @@ export default class extends baseClass {
if (this.isLoggedIn) {
if (json.currentAvatar !== ref.currentAvatar) {
$app.addAvatarToHistory(json.currentAvatar);
$app.addAvatarWearTime(ref.currentAvatar);
this.currentUser.$previousAvatarSwapTime = Date.now();
if ($app.isGameRunning) {
$app.addAvatarWearTime(ref.currentAvatar);
ref.$previousAvatarSwapTime = Date.now();
}
}
Object.assign(ref, json);
if (ref.homeLocation !== ref.$homeLocation.tag) {
Expand Down Expand Up @@ -278,7 +280,7 @@ export default class extends baseClass {
$offline_for: '',
$location_at: Date.now(),
$travelingToTime: Date.now(),
$previousAvatarSwapTime: Date.now(),
$previousAvatarSwapTime: '',
$homeLocation: {},
$isVRCPlus: false,
$isModerator: false,
Expand All @@ -294,6 +296,9 @@ export default class extends baseClass {
$vrchatcredits: null,
...json
};
if ($app.isGameRunning) {
ref.$previousAvatarSwapTime = Date.now();
}
ref.$homeLocation = $app.parseLocation(ref.homeLocation);
ref.$isVRCPlus = ref.tags.includes('system_supporter');
this.applyUserTrustLevel(ref);
Expand Down
2 changes: 2 additions & 0 deletions src/mixins/dialogs/avatarDialog.pug
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ mixin avatarDialog()
.x-friend-item(style="cursor:default")
.detail
span.name {{ $t('dialog.avatar.info.time_spent') }}
el-tooltip(v-if="!hideTooltips" placement="top" style="margin-left:5px" :content="$t('dialog.world.info.accuracy_notice')")
i.el-icon-warning
span.extra(v-if="avatarDialog.timeSpent === 0") -
span.extra(v-else) {{ timeToText(avatarDialog.timeSpent) }}
.x-friend-item(style="width:100%;cursor:default")
Expand Down
2 changes: 1 addition & 1 deletion src/repository/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -2710,7 +2710,7 @@ class Database {
const columnExists = dbRow.some((row) => row.name === 'time');
if (!columnExists) {
sqliteService.executeNonQuery(
`ALTER TABLE ${Database.userPrefix}_avatar_history ADD COLUMN 'time' INTEGER DEFAULT 0;`
`ALTER TABLE ${Database.userPrefix}_avatar_history ADD time INTEGER DEFAULT 0`
);
}
}, `PRAGMA table_info(${Database.userPrefix}_avatar_history);`);
Expand Down

0 comments on commit 7eae915

Please sign in to comment.