Skip to content

Commit

Permalink
but here's the changer
Browse files Browse the repository at this point in the history
  • Loading branch information
nyakowint committed May 12, 2024
1 parent bbec51f commit b1ab4f1
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions src/plugins/xsOverlay.desktop/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ interface Call {
ringing: string[];
}

const MuteStore = findByPropsLazy("isSuppressEveryoneEnabled");
const Notifs = findByPropsLazy("makeTextChatNotification");
const XSLog = new Logger("XSOverlay");

Expand Down Expand Up @@ -115,13 +114,13 @@ const settings = definePluginSettings({
},
timeout: {
type: OptionType.NUMBER,
description: "Notif duration (secs)",
default: 1.0,
description: "Notification duration (secs)",
default: 3,
},
timeoutPerCharacter: {
type: OptionType.NUMBER,
description: "Duration multiplier per character",
default: 0.5
lengthBasedTimeout: {
type: OptionType.BOOLEAN,
description: "Extend duration with message length",
default: true
},
opacity: {
type: OptionType.SLIDER,
Expand Down Expand Up @@ -261,13 +260,14 @@ function shouldIgnoreForChannelType(channel: Channel) {
else return !settings.store.serverNotifications;
}

const useLengthTimeout = settings.store.lengthBasedTimeout;

function sendMsgNotif(titleString: string, content: string, message: Message) {
const timeout = Math.max(settings.store.timeout, content.length * settings.store.timeoutPerCharacter);
fetch(`https://cdn.discordapp.com/avatars/${message.author.id}/${message.author.avatar}.png?size=128`).then(response => response.arrayBuffer()).then(result => {
const msgData = {
messageType: 1,
index: 0,
timeout,
timeout: useLengthTimeout ? settings.store.timeout : calculateTimeout(content),
height: calculateHeight(content),
opacity: settings.store.opacity,
volume: settings.store.volume,
Expand All @@ -286,7 +286,7 @@ function sendOtherNotif(content: string, titleString: string) {
const msgData = {
messageType: 1,
index: 0,
timeout: settings.store.timeout,
timeout: useLengthTimeout ? settings.store.timeout : calculateTimeout(content),
height: calculateHeight(content),
opacity: settings.store.opacity,
volume: settings.store.volume,
Expand All @@ -313,3 +313,10 @@ function calculateHeight(content: string) {
if (content.length <= 300) return 200;
return 250;
}

function calculateTimeout(content: string) {
if (content.length <= 100) return 3;
if (content.length <= 200) return 4;
if (content.length <= 300) return 5;
return 6;
}

0 comments on commit b1ab4f1

Please sign in to comment.