Skip to content

Commit

Permalink
TimeBarAllActivities: Fix timestamp component
Browse files Browse the repository at this point in the history
  • Loading branch information
Nuckyz committed Sep 11, 2024
1 parent a765212 commit f27361f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 28 deletions.
9 changes: 1 addition & 8 deletions src/plugins/ignoreActivities/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -266,21 +266,14 @@ 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: {
match: /\.activityTitleText.+?children:(\i)\.name.*?}\),/,
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: {
Expand Down
11 changes: 1 addition & 10 deletions src/plugins/noPendingCount/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
28 changes: 18 additions & 10 deletions src/plugins/timeBarAllActivities/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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: {
Expand All @@ -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)
{
Expand All @@ -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 })
});

0 comments on commit f27361f

Please sign in to comment.