refactor: app.js (#1291)

* refactor: frontend

* Fix avatar gallery sort

* Update .NET dependencies

* Update npm dependencies

electron v37.1.0

* bulkRefreshFriends

* fix dark theme

* Remove crowdin

* Fix config.json dialog not updating

* VRCX log file fixes & add Cef log

* Remove SharedVariable, fix startup

* Revert init theme change

* Logging date not working? Fix WinformThemer designer error

* Add Cef request hander, no more escaping main page

* clean

* fix

* fix

* clean

* uh

* Apply thememode at startup, fixes random user colours

* Split database into files

* Instance info remove empty lines

* Open external VRC links with VRCX

* Electron fixes

* fix userdialog style

* ohhhh

* fix store

* fix store

* fix: load all group members after kicking a user

* fix: world dialog favorite button style

* fix: Clear VRCX Cache Timer input value

* clean

* Fix VR overlay

* Fix VR overlay 2

* Fix Discord discord rich presence for RPC worlds

* Clean up age verified user tags

* Fix playerList being occupied after program reload

* no `this`

* Fix login stuck loading

* writable: false

* Hide dialogs on logout

* add flush sync option

* rm LOGIN event

* rm LOGOUT event

* remove duplicate event listeners

* remove duplicate event listeners

* clean

* remove duplicate event listeners

* clean

* fix theme style

* fix t

* clearable

* clean

* fix ipcEvent

* Small changes

* Popcorn Palace support

* Remove checkActiveFriends

* Clean up

* Fix dragEnterCef

* Block API requests when not logged in

* Clear state on login & logout

* Fix worldDialog instances not updating

* use <script setup>

* Fix avatar change event, CheckGameRunning at startup

* Fix image dragging

* fix

* Remove PWI

* fix updateLoop

* add webpack-dev-server to dev environment

* rm unnecessary chunks

* use <script setup>

* webpack-dev-server changes

* use <script setup>

* use <script setup>

* Fix UGC text size

* Split login event

* t

* use <script setup>

* fix

* Update .gitignore and enable checkJs in jsconfig

* fix i18n t

* use <script setup>

* use <script setup>

* clean

* global types

* fix

* use checkJs for debugging

* Add watchState for login watchers

* fix .vue template

* type fixes

* rm Vue.filter

* Cef v138.0.170, VC++ 2022

* Settings fixes

* Remove 'USER:CURRENT'

* clean up 2FA callbacks

* remove userApply

* rm i18n import

* notification handling to use notification store methods

* refactor favorite handling to use favorite store methods and clean up event emissions

* refactor moderation handling to use dedicated functions for player moderation events

* refactor friend handling to use dedicated functions for friend events

* Fix program startup, move lang init

* Fix friend state

* Fix status change error

* Fix user notes diff

* fix

* rm group event

* rm auth event

* rm avatar event

* clean

* clean

* getUser

* getFriends

* getFavoriteWorlds, getFavoriteAvatars

* AvatarGalleryUpload btn style & package.json update

* Fix friend requests

* Apply user

* Apply world

* Fix note diff

* Fix VR overlay

* Fixes

* Update build scripts

* Apply avatar

* Apply instance

* Apply group

* update hidden VRC+ badge

* Fix sameInstance "private"

* fix 502/504 API errors

* fix 502/504 API errors

* clean

* Fix friend in same instance on orange showing twice in friends list

* Add back in broken friend state repair methods

* add types

---------

Co-authored-by: Natsumi <cmcooper123@hotmail.com>
This commit is contained in:
pa
2025-07-14 12:00:08 +09:00
committed by GitHub
parent 952fd77ed5
commit f4f78bb5ec
323 changed files with 47745 additions and 43326 deletions
@@ -2,336 +2,332 @@
<div style="width: 100%">
<div style="height: 25px; margin-top: 60px">
<transition name="el-fade-in-linear">
<location
<Location
v-show="!isLoading"
class="location"
:location="activityDetailData[0].location"
is-open-previous-instance-info-dialog
@open-previous-instance-info-dialog="
$emit('open-previous-instance-info-dialog', $event)
"></location>
:location="activityDetailData[0]?.location"
is-open-previous-instance-info-dialog />
</transition>
</div>
<div ref="activityDetailChart"></div>
<div ref="activityDetailChartRef"></div>
</div>
</template>
<script>
<script setup>
import { ref, watch, computed, onDeactivated, onMounted } from 'vue';
import dayjs from 'dayjs';
import utils from '../../../classes/utils';
import Location from '../../../components/Location.vue';
import { storeToRefs } from 'pinia';
export default {
name: 'InstanceActivityDetail',
components: {
Location
import { loadEcharts, timeToText } from '../../../shared/utils';
import { useUserStore, useAppearanceSettingsStore } from '../../../stores';
const { isDarkMode, dtHour12 } = storeToRefs(useAppearanceSettingsStore());
const { showUserDialog } = useUserStore();
const { currentUser } = storeToRefs(useUserStore());
const props = defineProps({
activityDetailData: {
type: Array,
required: true
},
inject: ['API', 'showUserDialog'],
props: {
activityDetailData: {
type: Array,
required: true
},
isDarkMode: {
type: Boolean,
required: true
},
dtHour12: {
type: Boolean,
required: true
},
barWidth: {
type: Number,
required: true,
default: 10
barWidth: {
type: Number,
required: true,
default: 10
}
});
const activityDetailChartRef = ref(null);
const echarts = ref(null);
const isLoading = ref(true);
const echartsInstance = ref(null);
const usersFirstActivity = ref(null);
const resizeObserver = ref(null);
const startTimeStamp = computed(() => {
return props.activityDetailData.find((item) => item.user_id === currentUser.value.id)?.joinTime.valueOf();
});
const endTimeStamp = computed(() => {
return props.activityDetailData.find((item) => item.user_id === currentUser.value.id)?.leaveTime.valueOf();
});
watch(
() => isDarkMode.value,
() => {
if (echartsInstance.value) {
echartsInstance.value.dispose();
echartsInstance.value = null;
initEcharts();
}
},
data() {
return {
echarts: null,
isLoading: true,
echartsInstance: null,
usersFirstActivity: null,
resizeObserver: null
};
},
computed: {
startTimeStamp() {
return this.activityDetailData
.find((item) => item.user_id === this.API.currentUser.id)
?.joinTime.valueOf();
},
endTimeStamp() {
return this.activityDetailData
.find((item) => item.user_id === this.API.currentUser.id)
?.leaveTime.valueOf();
}
);
watch(
() => dtHour12.value,
() => {
if (echartsInstance.value) {
initEcharts();
}
},
watch: {
isDarkMode() {
if (this.echartsInstance) {
this.echartsInstance.dispose();
this.echartsInstance = null;
this.initEcharts();
}
},
dtHour12() {
if (this.echartsInstance) {
this.initEcharts();
}
}
},
created() {
this.resizeObserver = new ResizeObserver((entries) => {
for (const entry of entries) {
this.echartsInstance.resize({
width: entry.contentRect.width,
animation: {
duration: 300
}
});
}
});
},
mounted() {
this.initEcharts(true);
},
deactivated() {
// prevent switch tab play resize animation
this.resizeObserver.disconnect();
},
}
);
methods: {
async initEcharts(isFirstLoad = false) {
if (!this.echarts) {
this.echarts = await utils.loadEcharts();
}
initResizeObserver();
const chartsHeight = this.activityDetailData.length * (this.barWidth + 10) + 200;
const chartDom = this.$refs.activityDetailChart;
if (!this.echartsInstance) {
this.echartsInstance = this.echarts.init(chartDom, `${this.isDarkMode ? 'dark' : null}`, {
height: chartsHeight,
useDirtyRect: this.activityDetailData.length > 80
});
this.resizeObserver.observe(chartDom);
}
onMounted(() => {
initEcharts(true);
});
this.echartsInstance.resize({
height: chartsHeight,
onDeactivated(() => {
// prevent switch tab play resize animation
resizeObserver.value.disconnect();
});
function initResizeObserver() {
resizeObserver.value = new ResizeObserver((entries) => {
for (const entry of entries) {
echartsInstance.value.resize({
width: entry.contentRect.width,
animation: {
duration: 300
}
});
this.echartsInstance.setOption(isFirstLoad ? {} : this.getNewOption(), { lazyUpdate: true });
this.echartsInstance.on('click', 'yAxis', this.handleClickYAxisLabel);
setTimeout(() => {
this.isLoading = false;
}, 200);
},
handleClickYAxisLabel(params) {
const userData = this.usersFirstActivity[params.dataIndex];
if (userData?.user_id) {
this.showUserDialog(userData.user_id);
}
},
getNewOption() {
// grouping player activity entries by user_id and calculate below:
// 1. offset: the time from startTimeStamp or the previous entry's tail to the current entry's joinTime
// 2. time: the time the user spent in the instance
// 3. tail: the time from startTimeStamp to the current entry's leaveTime
// 4. entry: the original activity detail entry
const userGroupedEntries = new Map();
// uniqueUserEntries has each user's first entry and used to keep the order of the users calculated in InstanceActivity.vue
const uniqueUserEntries = [];
for (const entry of this.activityDetailData) {
if (!userGroupedEntries.has(entry.user_id)) {
userGroupedEntries.set(entry.user_id, []);
uniqueUserEntries.push(entry);
}
const elements = userGroupedEntries.get(entry.user_id);
const offset = Math.max(
0,
elements.length === 0
? entry.joinTime.valueOf() - this.startTimeStamp
: entry.joinTime.valueOf() - this.startTimeStamp - elements[elements.length - 1].tail
);
const tail =
elements.length === 0
? offset + entry.time
: elements[elements.length - 1].tail + offset + entry.time;
const element = { offset, time: entry.time, tail, entry };
elements.push(element);
}
this.usersFirstActivity = uniqueUserEntries;
const generateSeries = () => {
const maxEntryCount = Math.max(
...Array.from(userGroupedEntries.values()).map((entries) => entries.length)
);
const placeholderSeries = (data) => {
return {
name: 'Placeholder',
type: 'bar',
stack: 'Total',
itemStyle: {
borderColor: 'transparent',
color: 'transparent'
},
emphasis: {
itemStyle: {
borderColor: 'transparent',
color: 'transparent'
}
},
data
};
};
const timeSeries = (data) => {
return {
name: 'Time',
type: 'bar',
stack: 'Total',
colorBy: 'data',
barWidth: this.barWidth,
emphasis: {
focus: 'self'
},
itemStyle: {
borderRadius: 2,
shadowBlur: 2,
shadowOffsetX: 0.7,
shadowOffsetY: 0.5
},
data
};
};
// generate series having placeholder and time series for each user
const series = Array(maxEntryCount)
.fill(0)
.flatMap((_, index) => {
return [
placeholderSeries(
uniqueUserEntries.map((entry) => {
const element = userGroupedEntries.get(entry.user_id)[index];
return element ? element.offset : 0;
})
),
timeSeries(
uniqueUserEntries.map((entry) => {
const element = userGroupedEntries.get(entry.user_id)[index];
return element ? element.time : 0;
})
)
];
});
return series;
};
const friendOrFavIcon = (display_name) => {
const foundItem = this.activityDetailData.find((item) => item.display_name === display_name);
if (!foundItem) {
return '';
}
if (foundItem.isFavorite) {
return '⭐';
}
if (foundItem.isFriend) {
return '💚';
}
return '';
};
const getTooltip = (params) => {
const activityDetailData = this.activityDetailData;
const param = params;
const userData = uniqueUserEntries[param.dataIndex];
const isTimeSeries = params.seriesIndex % 2 === 1;
if (!isTimeSeries) {
return '';
}
const targetEntryIndex = Math.floor(params.seriesIndex / 2);
if (!activityDetailData || !userData) {
return '';
}
// first, find the user's entries, then get the focused entry
const instanceData = userGroupedEntries.get(userData.user_id)[targetEntryIndex].entry;
const format = this.dtHour12 ? 'hh:mm:ss A' : 'HH:mm:ss';
const formattedLeftDateTime = dayjs(instanceData.leaveTime).format(format);
const formattedJoinDateTime = dayjs(instanceData.joinTime).format(format);
const timeString = utils.timeToText(instanceData.time, true);
const color = param.color;
return `
<div style="display: flex; align-items: center;">
<div style="width: 10px; height: 55px; background-color: ${color}; margin-right: 5px;"></div>
<div>
<div>${instanceData.display_name} ${friendOrFavIcon(instanceData.display_name)}</div>
<div>${formattedJoinDateTime} - ${formattedLeftDateTime}</div>
<div>${timeString}</div>
</div>
</div>
`;
};
const format = this.dtHour12 ? 'hh:mm A' : 'HH:mm';
const echartsOption = {
tooltip: {
trigger: 'item',
axisPointer: {
type: 'shadow'
},
formatter: getTooltip
},
grid: {
top: 50,
left: 160,
right: 90
},
yAxis: {
type: 'category',
axisLabel: {
interval: 0,
formatter: (value) => {
const MAX_LENGTH = 20;
const len = value.length;
return `${friendOrFavIcon(value)} ${len > MAX_LENGTH ? `${value.substring(0, MAX_LENGTH)}...` : value}`;
}
},
inverse: true,
data: uniqueUserEntries.map((item) => item.display_name),
triggerEvent: true
},
xAxis: {
type: 'value',
min: 0,
max: this.endTimeStamp - this.startTimeStamp,
axisLine: { show: true },
axisLabel: {
formatter: (value) => dayjs(value + this.startTimeStamp).format(format)
},
splitLine: { lineStyle: { type: 'dashed' } }
},
series: generateSeries(),
backgroundColor: 'rgba(0, 0, 0, 0)'
};
return echartsOption;
}
});
}
async function initEcharts(isFirstLoad = false) {
if (!echarts.value) {
echarts.value = await loadEcharts();
}
};
const chartsHeight = props.activityDetailData.length * (props.barWidth + 10) + 200;
const chartDom = activityDetailChartRef.value;
if (!echartsInstance.value) {
echartsInstance.value = echarts.value.init(chartDom, `${isDarkMode.value ? 'dark' : null}`, {
height: chartsHeight,
useDirtyRect: props.activityDetailData.length > 80
});
resizeObserver.value.observe(chartDom);
}
echartsInstance.value.resize({
height: chartsHeight,
animation: {
duration: 300
}
});
echartsInstance.value.setOption(isFirstLoad ? {} : getNewOption(), { lazyUpdate: true });
echartsInstance.value.on('click', 'yAxis', handleClickYAxisLabel);
setTimeout(() => {
isLoading.value = false;
}, 200);
}
function handleClickYAxisLabel(params) {
const userData = usersFirstActivity.value[params.dataIndex];
if (userData?.user_id) {
showUserDialog(userData.user_id);
}
}
function getNewOption() {
// grouping player activity entries by user_id and calculate below:
// 1. offset: the time from startTimeStamp or the previous entry's tail to the current entry's joinTime
// 2. time: the time the user spent in the instance
// 3. tail: the time from startTimeStamp to the current entry's leaveTime
// 4. entry: the original activity detail entry
const userGroupedEntries = new Map();
// uniqueUserEntries has each user's first entry and used to keep the order of the users calculated in InstanceActivity.vue
const uniqueUserEntries = [];
for (const entry of props.activityDetailData) {
if (!userGroupedEntries.has(entry.user_id)) {
userGroupedEntries.set(entry.user_id, []);
uniqueUserEntries.push(entry);
}
const elements = userGroupedEntries.get(entry.user_id);
const offset = Math.max(
0,
elements.length === 0
? entry.joinTime.valueOf() - startTimeStamp.value
: entry.joinTime.valueOf() - startTimeStamp.value - elements[elements.length - 1].tail
);
const tail =
elements.length === 0 ? offset + entry.time : elements[elements.length - 1].tail + offset + entry.time;
const element = { offset, time: entry.time, tail, entry };
elements.push(element);
}
usersFirstActivity.value = uniqueUserEntries;
const generateSeries = () => {
const maxEntryCount = Math.max(...Array.from(userGroupedEntries.values()).map((entries) => entries.length));
const placeholderSeries = (data) => {
return {
name: 'Placeholder',
type: 'bar',
stack: 'Total',
itemStyle: {
borderColor: 'transparent',
color: 'transparent'
},
emphasis: {
itemStyle: {
borderColor: 'transparent',
color: 'transparent'
}
},
data
};
};
const timeSeries = (data) => {
return {
name: 'Time',
type: 'bar',
stack: 'Total',
colorBy: 'data',
barWidth: props.barWidth,
emphasis: {
focus: 'self'
},
itemStyle: {
borderRadius: 2,
shadowBlur: 2,
shadowOffsetX: 0.7,
shadowOffsetY: 0.5
},
data
};
};
// generate series having placeholder and time series for each user
const series = Array(maxEntryCount)
.fill(0)
.flatMap((_, index) => {
return [
placeholderSeries(
uniqueUserEntries.map((entry) => {
const element = userGroupedEntries.get(entry.user_id)[index];
return element ? element.offset : 0;
})
),
timeSeries(
uniqueUserEntries.map((entry) => {
const element = userGroupedEntries.get(entry.user_id)[index];
return element ? element.time : 0;
})
)
];
});
return series;
};
const friendOrFavIcon = (display_name) => {
const foundItem = props.activityDetailData.find((item) => item.display_name === display_name);
if (!foundItem) {
return '';
}
if (foundItem.isFavorite) {
return '⭐';
}
if (foundItem.isFriend) {
return '💚';
}
return '';
};
const getTooltip = (params) => {
const activityDetailData = props.activityDetailData;
const param = params;
const userData = uniqueUserEntries[param.dataIndex];
const isTimeSeries = params.seriesIndex % 2 === 1;
if (!isTimeSeries) {
return '';
}
const targetEntryIndex = Math.floor(params.seriesIndex / 2);
if (!activityDetailData || !userData) {
return '';
}
// first, find the user's entries, then get the focused entry
const instanceData = userGroupedEntries.get(userData.user_id)[targetEntryIndex].entry;
const format = dtHour12.value ? 'hh:mm:ss A' : 'HH:mm:ss';
const formattedLeftDateTime = dayjs(instanceData.leaveTime).format(format);
const formattedJoinDateTime = dayjs(instanceData.joinTime).format(format);
const timeString = timeToText(instanceData.time, true);
const color = param.color;
return `
<div style="display: flex; align-items: center;">
<div style="width: 10px; height: 55px; background-color: ${color}; margin-right: 5px;"></div>
<div>
<div>${instanceData.display_name} ${friendOrFavIcon(instanceData.display_name)}</div>
<div>${formattedJoinDateTime} - ${formattedLeftDateTime}</div>
<div>${timeString}</div>
</div>
</div>
`;
};
const format = dtHour12.value ? 'hh:mm A' : 'HH:mm';
const echartsOption = {
tooltip: {
trigger: 'item',
axisPointer: {
type: 'shadow'
},
formatter: getTooltip
},
grid: {
top: 50,
left: 160,
right: 90
},
yAxis: {
type: 'category',
axisLabel: {
interval: 0,
formatter: (value) => {
const MAX_LENGTH = 20;
const len = value.length;
return `${friendOrFavIcon(value)} ${len > MAX_LENGTH ? `${value.substring(0, MAX_LENGTH)}...` : value}`;
}
},
inverse: true,
data: uniqueUserEntries.map((item) => item.display_name),
triggerEvent: true
},
xAxis: {
type: 'value',
min: 0,
max: endTimeStamp.value - startTimeStamp.value,
axisLine: { show: true },
axisLabel: {
formatter: (value) => dayjs(value + startTimeStamp.value).format(format)
},
splitLine: { lineStyle: { type: 'dashed' } }
},
series: generateSeries(),
backgroundColor: 'rgba(0, 0, 0, 0)'
};
return echartsOption;
}
defineExpose({
echartsInstance,
initEcharts
});
</script>
<style scoped>