TimeBarAllActivities: Fix timestamp component
This commit is contained in:
parent
a765212cfe
commit
f27361f017
|
@ -266,7 +266,7 @@ export default definePlugin({
|
|||
replace: (m, props, nowPlaying) => `${m}$self.renderToggleGameActivityButton(${props},${nowPlaying}),`
|
||||
}
|
||||
},
|
||||
// Discord has 3 different components for activities. Currently, the last is the one being used
|
||||
// Discord has 2 different components for activities. Currently, the last is the one being used
|
||||
{
|
||||
find: ".activityTitleText,variant",
|
||||
replacement: {
|
||||
|
@ -274,13 +274,6 @@ export default definePlugin({
|
|||
replace: (m, props) => `${m}$self.renderToggleActivityButton(${props}),`
|
||||
},
|
||||
},
|
||||
{
|
||||
find: ".activityCardDetails,children",
|
||||
replacement: {
|
||||
match: /\.activityCardDetails.+?children:(\i\.application)\.name.*?}\),/,
|
||||
replace: (m, props) => `${m}$self.renderToggleActivityButton(${props}),`
|
||||
}
|
||||
},
|
||||
{
|
||||
find: ".promotedLabelWrapperNonBanner,children",
|
||||
replacement: {
|
||||
|
|
|
@ -62,16 +62,7 @@ export default definePlugin({
|
|||
replace: "return 0;"
|
||||
}
|
||||
},
|
||||
// New message requests hook
|
||||
{
|
||||
find: 'location:"use-message-requests-count"',
|
||||
predicate: () => settings.store.hideMessageRequestsCount,
|
||||
replacement: {
|
||||
match: /getNonChannelAckId\(\i\.\i\.MESSAGE_REQUESTS\).+?return /,
|
||||
replace: "$&0;"
|
||||
}
|
||||
},
|
||||
// Old message requests hook
|
||||
// Message requests hook
|
||||
{
|
||||
find: "getMessageRequestsCount(){",
|
||||
predicate: () => settings.store.hideMessageRequestsCount,
|
||||
|
|
|
@ -5,9 +5,11 @@
|
|||
*/
|
||||
|
||||
import { definePluginSettings } from "@api/Settings";
|
||||
import ErrorBoundary from "@components/ErrorBoundary";
|
||||
import { Devs } from "@utils/constants";
|
||||
import definePlugin, { OptionType } from "@utils/types";
|
||||
import { findComponentByCodeLazy } from "@webpack";
|
||||
import { RequiredDeep } from "type-fest";
|
||||
|
||||
interface Activity {
|
||||
timestamps?: ActivityTimestamps;
|
||||
|
@ -18,7 +20,15 @@ interface ActivityTimestamps {
|
|||
end?: string;
|
||||
}
|
||||
|
||||
const ActivityTimeBar = findComponentByCodeLazy<ActivityTimestamps>(".Millis.HALF_SECOND", ".bar", ".progress");
|
||||
interface TimebarComponentProps {
|
||||
activity: Activity;
|
||||
}
|
||||
|
||||
const ActivityTimeBar = findComponentByCodeLazy<ActivityTimestamps>(".bar", ".progress", "(100*");
|
||||
|
||||
function isActivityTimestamped(activity: Activity): activity is RequiredDeep<Activity> {
|
||||
return activity.timestamps != null && activity.timestamps.start != null && activity.timestamps.end != null;
|
||||
}
|
||||
|
||||
export const settings = definePluginSettings({
|
||||
hideActivityDetailText: {
|
||||
|
@ -45,7 +55,7 @@ export default definePlugin({
|
|||
// Insert Spotify time bar component
|
||||
{
|
||||
match: /\(0,.{0,30}activity:(\i),className:\i\.badges\}\)/g,
|
||||
replace: "$&,$self.getTimeBar($1)"
|
||||
replace: "$&,$self.TimebarComponent({activity:$1})"
|
||||
},
|
||||
// Hide the large title on listening activities, to make them look more like Spotify (also visible from hovering over the large icon)
|
||||
{
|
||||
|
@ -64,13 +74,11 @@ export default definePlugin({
|
|||
}
|
||||
],
|
||||
|
||||
isActivityTimestamped(activity: Activity) {
|
||||
return activity.timestamps != null && activity.timestamps.start != null && activity.timestamps.end != null;
|
||||
},
|
||||
isActivityTimestamped,
|
||||
|
||||
getTimeBar(activity: Activity) {
|
||||
if (this.isActivityTimestamped(activity)) {
|
||||
return <ActivityTimeBar start={activity.timestamps!.start} end={activity.timestamps!.end} />;
|
||||
}
|
||||
}
|
||||
TimebarComponent: ErrorBoundary.wrap(({ activity }: TimebarComponentProps) => {
|
||||
if (!isActivityTimestamped(activity)) return null;
|
||||
|
||||
return <ActivityTimeBar start={activity.timestamps.start} end={activity.timestamps.end} />;
|
||||
}, { noop: true })
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue