TimeBarAllActivities: Fix timestamp component
This commit is contained in:
parent
a765212cfe
commit
f27361f017
3 changed files with 20 additions and 28 deletions
|
@ -266,7 +266,7 @@ export default definePlugin({
|
||||||
replace: (m, props, nowPlaying) => `${m}$self.renderToggleGameActivityButton(${props},${nowPlaying}),`
|
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",
|
find: ".activityTitleText,variant",
|
||||||
replacement: {
|
replacement: {
|
||||||
|
@ -274,13 +274,6 @@ export default definePlugin({
|
||||||
replace: (m, props) => `${m}$self.renderToggleActivityButton(${props}),`
|
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",
|
find: ".promotedLabelWrapperNonBanner,children",
|
||||||
replacement: {
|
replacement: {
|
||||||
|
|
|
@ -62,16 +62,7 @@ export default definePlugin({
|
||||||
replace: "return 0;"
|
replace: "return 0;"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
// New message requests hook
|
// 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
|
|
||||||
{
|
{
|
||||||
find: "getMessageRequestsCount(){",
|
find: "getMessageRequestsCount(){",
|
||||||
predicate: () => settings.store.hideMessageRequestsCount,
|
predicate: () => settings.store.hideMessageRequestsCount,
|
||||||
|
|
|
@ -5,9 +5,11 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { definePluginSettings } from "@api/Settings";
|
import { definePluginSettings } from "@api/Settings";
|
||||||
|
import ErrorBoundary from "@components/ErrorBoundary";
|
||||||
import { Devs } from "@utils/constants";
|
import { Devs } from "@utils/constants";
|
||||||
import definePlugin, { OptionType } from "@utils/types";
|
import definePlugin, { OptionType } from "@utils/types";
|
||||||
import { findComponentByCodeLazy } from "@webpack";
|
import { findComponentByCodeLazy } from "@webpack";
|
||||||
|
import { RequiredDeep } from "type-fest";
|
||||||
|
|
||||||
interface Activity {
|
interface Activity {
|
||||||
timestamps?: ActivityTimestamps;
|
timestamps?: ActivityTimestamps;
|
||||||
|
@ -18,7 +20,15 @@ interface ActivityTimestamps {
|
||||||
end?: string;
|
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({
|
export const settings = definePluginSettings({
|
||||||
hideActivityDetailText: {
|
hideActivityDetailText: {
|
||||||
|
@ -45,7 +55,7 @@ export default definePlugin({
|
||||||
// Insert Spotify time bar component
|
// Insert Spotify time bar component
|
||||||
{
|
{
|
||||||
match: /\(0,.{0,30}activity:(\i),className:\i\.badges\}\)/g,
|
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)
|
// 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) {
|
isActivityTimestamped,
|
||||||
return activity.timestamps != null && activity.timestamps.start != null && activity.timestamps.end != null;
|
|
||||||
},
|
|
||||||
|
|
||||||
getTimeBar(activity: Activity) {
|
TimebarComponent: ErrorBoundary.wrap(({ activity }: TimebarComponentProps) => {
|
||||||
if (this.isActivityTimestamped(activity)) {
|
if (!isActivityTimestamped(activity)) return null;
|
||||||
return <ActivityTimeBar start={activity.timestamps!.start} end={activity.timestamps!.end} />;
|
|
||||||
}
|
return <ActivityTimeBar start={activity.timestamps.start} end={activity.timestamps.end} />;
|
||||||
}
|
}, { noop: true })
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue