2022-11-21 16:44:30 +02:00
/ *
* Vencord , a modification for Discord ' s desktop app
* Copyright ( c ) 2022 Vendicated and contributors
*
* This program is free software : you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation , either version 3 of the License , or
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program . If not , see < https : //www.gnu.org/licenses/>.
* /
2024-06-26 18:09:21 +02:00
import "./style.css" ;
2026-02-11 12:08:34 -05:00
import { definePluginSettings , migratePluginSetting } from "@api/Settings" ;
2026-03-01 15:14:40 -05:00
import { Devs , EquicordDevs } from "@utils/constants" ;
2025-05-02 21:00:56 -04:00
import { classes } from "@utils/misc" ;
2022-11-28 13:37:55 +01:00
import definePlugin , { OptionType } from "@utils/types" ;
2025-11-15 13:39:36 +01:00
import { DiscordPlatform , User } from "@vencord/discord-types" ;
2025-01-29 01:04:36 -03:00
import { filters , findStoreLazy , mapMangledModuleLazy } from "@webpack" ;
2025-09-23 23:58:38 +02:00
import { AuthenticationStore , PresenceStore , Tooltip , UserStore , useStateFromStores } from "@webpack/common" ;
2022-11-21 16:44:30 +02:00
2024-07-20 04:16:06 -04:00
export interface Session {
sessionId : string ;
status : string ;
active : boolean ;
clientInfo : {
version : number ;
os : string ;
client : string ;
} ;
}
const SessionsStore = findStoreLazy ( "SessionsStore" ) as {
getSessions ( ) : Record < string , Session > ;
} ;
2026-03-01 15:14:40 -05:00
2026-02-05 16:50:16 -05:00
const { useStatusFillColor } = mapMangledModuleLazy ( [ ".5625*" , "translate" ] , {
2025-05-02 21:00:56 -04:00
useStatusFillColor : filters.byCode ( ".hex" )
} ) ;
2026-03-01 15:14:40 -05:00
const platformMap = {
embedded : "Console" ,
vr : "VR"
} ;
2026-01-08 15:11:47 +00:00
function Icon ( path : string , opts ? : { viewBox? : string ; width? : number ; height? : number ; } ) {
2023-10-31 23:56:13 +01:00
return ( { color , tooltip , small } : { color : string ; tooltip : string ; small : boolean ; } ) = > (
2026-01-08 15:11:47 +00:00
< Tooltip text = { tooltip } >
2025-05-02 21:00:56 -04:00
{ tooltipProps = > (
2023-10-31 23:56:13 +01:00
< svg
{ . . . tooltipProps }
height = { ( opts ? . height ? ? 20 ) - ( small ? 3 : 0 ) }
width = { ( opts ? . width ? ? 20 ) - ( small ? 3 : 0 ) }
viewBox = { opts ? . viewBox ? ? "0 0 24 24" }
fill = { color }
>
< path d = { path } / >
< / svg >
) }
< / Tooltip >
) ;
2022-11-21 16:44:30 +02:00
}
const Icons = {
desktop : Icon ( "M4 2.5c-1.103 0-2 .897-2 2v11c0 1.104.897 2 2 2h7v2H7v2h10v-2h-4v-2h7c1.103 0 2-.896 2-2v-11c0-1.103-.897-2-2-2H4Zm16 2v9H4v-9h16Z" ) ,
web : Icon ( "M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2Zm-1 17.93c-3.95-.49-7-3.85-7-7.93 0-.62.08-1.21.21-1.79L9 15v1c0 1.1.9 2 2 2v1.93Zm6.9-2.54c-.26-.81-1-1.39-1.9-1.39h-1v-3c0-.55-.45-1-1-1H8v-2h2c.55 0 1-.45 1-1V7h2c1.1 0 2-.9 2-2v-.41c2.93 1.19 5 4.06 5 7.41 0 2.08-.8 3.97-2.1 5.39Z" ) ,
2023-05-16 23:37:47 -03:00
mobile : Icon ( "M 187 0 L 813 0 C 916.277 0 1000 83.723 1000 187 L 1000 1313 C 1000 1416.277 916.277 1500 813 1500 L 187 1500 C 83.723 1500 0 1416.277 0 1313 L 0 187 C 0 83.723 83.723 0 187 0 Z M 125 1000 L 875 1000 L 875 250 L 125 250 Z M 500 1125 C 430.964 1125 375 1180.964 375 1250 C 375 1319.036 430.964 1375 500 1375 C 569.036 1375 625 1319.036 625 1250 C 625 1180.964 569.036 1125 500 1125 Z" , { viewBox : "0 0 1000 1500" , height : 17 , width : 17 } ) ,
2025-02-02 12:20:00 -05:00
embedded : Icon ( "M3.06 20.4q-1.53 0-2.37-1.065T.06 16.74l1.26-9q.27-1.8 1.605-2.97T6.06 3.6h11.88q1.8 0 3.135 1.17t1.605 2.97l1.26 9q.21 1.53-.63 2.595T20.94 20.4q-.63 0-1.17-.225T18.78 19.5l-2.7-2.7H7.92l-2.7 2.7q-.45.45-.99.675t-1.17.225Zm14.94-7.2q.51 0 .855-.345T19.2 12q0-.51-.345-.855T18 10.8q-.51 0-.855.345T16.8 12q0 .51.345 .855T18 13.2Zm-2.4-3.6q.51 0 .855-.345T16.8 8.4q0-.51-.345-.855T15.6 7.2q-.51 0-.855.345T14.4 8.4q0 .51.345 .855T15.6 9.6ZM6.9 13.2h1.8v-2.1h2.1v-1.8h-2.1v-2.1h-1.8v2.1h-2.1v1.8h2.1v2.1Z" , { viewBox : "0 0 24 24" , height : 20 , width : 20 } ) ,
2026-03-01 15:14:40 -05:00
vr : Icon ( "M8.46 8.64a1 1 0 0 1 1 1c0 .44-.3.8-.72.92l-.11.07c-.08.06-.2.19-.2.41a.99.99 0 0 1-.98.86h-.06a1 1 0 0 1-.94-1.05l.02-.32c.05-1.06.92-1.9 1.99-1.9ZM15.55 5a5.5 5.5 0 0 1 5.15 3.67h.3a2 2 0 0 1 2 2v3.18a2 2 0 0 1-2 1.99h-.2A4.54 4.54 0 0 1 16.55 19a4.45 4.45 0 0 1-3.6-1.83 1.2 1.2 0 0 0-1.9 0 4.44 4.44 0 0 1-3.9 1.82 4.54 4.54 0 0 1-3.94-3.15H3a2 2 0 0 1-2-2v-3.18c0-1.1.9-1.99 2-1.99h.3A5.5 5.5 0 0 1 8.46 5h7.09Zm-7.1 2C6.6 7 5.06 8.5 4.97 10.41l-.02.66v3.18c0 1.43 1.05 2.66 2.34 2.74.85.06 1.63-.32 2.14-1.01a3.2 3.2 0 0 1 2.57-1.3c1 0 1.97.48 2.57 1.3.5.69 1.3 1.08 2.14 1.01 1.3-.08 2.34-1.31 2.34-2.74l-.02-3.84a3.54 3.54 0 0 0-3.49-3.43H8.45Z" , { viewBox : "0 4 24 16" , height : 20 , width : 20 } ) ,
2025-02-02 12:20:00 -05:00
suncord : Icon ( "M7 4a6 6 0 00-6 6v4a6 6 0 006 6h10a6 6 0 006-6v-4a6 6 0 00-6-6H7zm0 11a1 1 0 01-1-1v-1H5a1 1 0 010-2h1v-1a1 1 0 012 0v1h1a1 1 0 010 2H8v1a1 1 0 01-1 1zm10-4a1 1 0 100-2 1 1 0 000 2zm1 3a1 1 0 11-2 0 1 1 0 012 0zm0-2a1 1 0 102 0 1 1 0 00-2 0zm-3 1a1 1 0 110-2 1 1 0 010 2z" , { viewBox : "0 0 24 24" , height : 24 , width : 24 } ) ,
2025-12-29 15:39:07 -05:00
vencord : Icon ( "M14.8 2.7 9 3.1V47h3.3c1.7 0 6.2.3 10 .7l6.7.6V2l-4.2.2c-2.4.1-6.9.3-10 .5zm1.8 6.4c1 1.7-1.3 3.6-2.7 2.2C12.7 10.1 13.5 8 15 8c.5 0 1.2.5 1.6 1.1zM16 33c0 6-.4 10-1 10s-1-4-1-10 .4-10 1-10 1 4 1 10zm15-8v23.3l3.8-.7c2-.3 4.7-.6 6-.6H43V3h-2.2c-1.3 0-4-.3-6-.6L31 1.7V25z" , { viewBox : "0 0 50 50" } ) ,
2022-11-21 16:44:30 +02:00
} ;
2025-05-02 21:00:56 -04:00
2026-01-09 15:16:34 -05:00
const PlatformIcon = ( { platform , status , small } ) = > {
2026-03-01 15:14:40 -05:00
const tooltip = platformMap [ platform ] ? ? platform . charAt ( 0 ) . toUpperCase ( ) + platform . slice ( 1 ) ;
2024-09-23 12:43:30 -04:00
let Icon = Icons [ platform ] ? ? Icons . desktop ;
2025-05-02 21:00:56 -04:00
const { ConsoleIcon } = settings . store ;
2025-11-18 23:48:00 -05:00
if ( platform === "embedded" ) {
switch ( ConsoleIcon ) {
case "equicord" :
Icon = Icons . embedded ;
break ;
case "suncord" :
Icon = Icons . suncord ;
break ;
2025-12-29 15:39:07 -05:00
case "vencord" :
Icon = Icons . vencord ;
2025-11-18 23:48:00 -05:00
break ;
default :
Icon = Icons . embedded ;
break ;
}
2024-09-23 12:43:30 -04:00
}
2022-11-21 16:44:30 +02:00
2025-01-29 01:04:36 -03:00
return < Icon color = { useStatusFillColor ( status ) } tooltip = { tooltip } small = { small } / > ;
2022-11-21 16:44:30 +02:00
} ;
2025-05-02 21:00:56 -04:00
function useEnsureOwnStatus ( user : User ) {
2025-09-25 11:01:23 -04:00
if ( user . id !== AuthenticationStore . getId ( ) ) {
2025-05-02 21:00:56 -04:00
return ;
2022-12-23 04:16:17 +01:00
}
2024-06-26 18:09:21 +02:00
2025-05-02 21:00:56 -04:00
const sessions = useStateFromStores ( [ SessionsStore ] , ( ) = > SessionsStore . getSessions ( ) ) ;
if ( typeof sessions !== "object" ) return null ;
const sortedSessions = Object . values ( sessions ) . sort ( ( { status : a } , { status : b } ) = > {
if ( a === b ) return 0 ;
if ( a === "online" ) return 1 ;
if ( b === "online" ) return - 1 ;
if ( a === "idle" ) return 1 ;
if ( b === "idle" ) return - 1 ;
return 0 ;
} ) ;
2024-06-26 18:09:21 +02:00
2025-05-02 21:00:56 -04:00
const ownStatus = Object . values ( sortedSessions ) . reduce ( ( acc , curr ) = > {
if ( curr . clientInfo . client !== "unknown" )
acc [ curr . clientInfo . client ] = curr . status ;
return acc ;
} , { } ) ;
2024-06-26 18:09:21 +02:00
2025-05-02 21:00:56 -04:00
const { clientStatuses } = PresenceStore . getState ( ) ;
clientStatuses [ UserStore . getCurrentUser ( ) . id ] = ownStatus ;
2024-06-26 18:09:21 +02:00
}
2025-05-02 21:00:56 -04:00
interface PlatformIndicatorProps {
user : User ;
isProfile? : boolean ;
isMessage? : boolean ;
isMemberList? : boolean ;
}
2024-06-26 18:09:21 +02:00
2025-05-02 21:00:56 -04:00
const PlatformIndicator = ( { user , isProfile , isMessage , isMemberList } : PlatformIndicatorProps ) = > {
2026-02-11 12:08:34 -05:00
if ( user == null || ( user . bot && ! settings . store . showBots ) ) return null ;
2025-05-02 21:00:56 -04:00
useEnsureOwnStatus ( user ) ;
2022-12-23 04:16:17 +01:00
2025-11-15 13:39:36 +01:00
const status = useStateFromStores ( [ PresenceStore ] , ( ) = > PresenceStore . getClientStatus ( user . id ) ) ;
2022-11-21 16:44:30 +02:00
if ( ! status ) return null ;
2025-05-02 21:00:56 -04:00
const icons = Array . from ( Object . entries ( status ) , ( [ platform , status ] ) = > (
2022-11-21 16:44:30 +02:00
< PlatformIcon
key = { platform }
2025-11-15 13:39:36 +01:00
platform = { platform as DiscordPlatform }
2022-11-21 16:44:30 +02:00
status = { status }
2025-05-02 21:00:56 -04:00
small = { isProfile || isMemberList }
2022-11-21 16:44:30 +02:00
/ >
) ) ;
2025-05-02 21:00:56 -04:00
if ( ! icons . length ) {
return null ;
}
2022-11-21 20:25:21 +02:00
2022-12-23 04:16:17 +01:00
return (
2025-05-02 21:00:56 -04:00
< div
className = { classes ( "vc-platform-indicator" , isProfile && "vc-platform-indicator-profile" , isMessage && "vc-platform-indicator-message" ) }
style = { { marginLeft : isMemberList ? "4px" : undefined } }
2023-05-12 03:54:57 +02:00
>
2022-11-21 16:44:30 +02:00
{ icons }
2025-05-02 21:00:56 -04:00
< / div >
2022-12-23 04:16:17 +01:00
) ;
2022-12-21 21:16:32 +02:00
} ;
2025-05-31 12:07:51 -04:00
migratePluginSetting ( "PlatformIndicators" , "profiles" , "badges" ) ;
2025-05-02 21:00:56 -04:00
const settings = definePluginSettings ( {
list : {
type : OptionType . BOOLEAN ,
description : "Show indicators in the member list" ,
default : true ,
} ,
profiles : {
type : OptionType . BOOLEAN ,
description : "Show indicators in user profiles" ,
default : true ,
} ,
messages : {
type : OptionType . BOOLEAN ,
description : "Show indicators inside messages" ,
default : true ,
} ,
colorMobileIndicator : {
type : OptionType . BOOLEAN ,
description : "Whether to make the mobile indicator match the color of the user status." ,
default : true ,
restartNeeded : true
} ,
2025-05-19 19:19:50 -04:00
showBots : {
type : OptionType . BOOLEAN ,
description : "Whether to show platform indicators on bots" ,
default : false ,
restartNeeded : false
} ,
2025-05-02 21:00:56 -04:00
ConsoleIcon : {
type : OptionType . SELECT ,
description : "What console icon to use" ,
restartNeeded : true ,
options : [
{
label : "Equicord" ,
value : "equicord" ,
default : true
} ,
{
label : "Suncord" ,
value : "suncord" ,
} ,
{
2025-12-29 15:39:07 -05:00
label : "Vencord" ,
value : "vencord" ,
2025-05-02 21:00:56 -04:00
} ,
] ,
}
} ) ;
2022-11-21 16:44:30 +02:00
export default definePlugin ( {
name : "PlatformIndicators" ,
description : "Adds platform indicators (Desktop, Mobile, Web...) to users" ,
2026-03-01 15:14:40 -05:00
authors : [ Devs . kemo , Devs . TheSun , Devs . Nuckyz , Devs . Ven , EquicordDevs . neoarz ] ,
isModified : true ,
2025-05-02 21:00:56 -04:00
settings ,
2025-11-27 13:47:59 -08:00
renderNicknameIcon ( props ) {
if ( ! settings . store . profiles ) return null ;
return (
< PlatformIndicator user = { UserStore . getUser ( props . userId ) } isProfile / >
) ;
2022-12-21 21:16:32 +02:00
} ,
2025-11-27 13:47:59 -08:00
renderMemberListDecorator ( props ) {
if ( ! settings . store . list ) return null ;
return < PlatformIndicator user = { props . user } isMemberList / > ;
2022-12-21 21:16:32 +02:00
2025-11-27 13:47:59 -08:00
} ,
renderMessageDecoration ( props ) {
if ( ! settings . store . messages ) return null ;
return < PlatformIndicator user = { props . message ? . author } isMessage / > ;
2022-12-21 21:16:32 +02:00
} ,
2022-11-21 16:44:30 +02:00
2023-03-18 00:58:49 -03:00
patches : [
{
find : ".Masks.STATUS_ONLINE_MOBILE" ,
2025-05-02 21:00:56 -04:00
predicate : ( ) = > settings . store . colorMobileIndicator ,
2023-03-18 00:58:49 -03:00
replacement : [
{
// Return the STATUS_ONLINE_MOBILE mask if the user is on mobile, no matter the status
2023-10-26 01:29:52 +02:00
match : /\.STATUS_TYPING;switch(?=.+?(if\(\i\)return \i\.\i\.Masks\.STATUS_ONLINE_MOBILE))/ ,
replace : ".STATUS_TYPING;$1;switch"
2023-03-18 00:58:49 -03:00
} ,
{
// Return the STATUS_ONLINE_MOBILE mask if the user is on mobile, no matter the status
2023-10-26 01:29:52 +02:00
match : /switch\(\i\)\{case \i\.\i\.ONLINE:(if\(\i\)return\{[^}]+\})/ ,
replace : "$1;$&"
2023-03-18 00:58:49 -03:00
}
]
} ,
{
find : ".AVATAR_STATUS_MOBILE_16;" ,
2025-05-02 21:00:56 -04:00
predicate : ( ) = > settings . store . colorMobileIndicator ,
2023-03-18 00:58:49 -03:00
replacement : [
{
// Return the AVATAR_STATUS_MOBILE size mask if the user is on mobile, no matter the status
match : /\i===\i\.\i\.ONLINE&&(?=.{0,70}\.AVATAR_STATUS_MOBILE_16;)/ ,
replace : ""
} ,
{
// Fix sizes for mobile indicators which aren't online
2026-02-02 21:02:28 -05:00
match : /(?<=\(\i\.status,)(\i)(?=,\{.{0,15}isMobile:(\i))/ ,
replace : '$2?"online":$1'
2023-03-18 00:58:49 -03:00
} ,
{
// Make isMobile true no matter the status
match : /(?<=\i&&!\i)&&\i===\i\.\i\.ONLINE/ ,
replace : ""
}
]
} ,
{
2023-10-26 00:03:51 +02:00
find : "}isMobileOnline(" ,
2025-05-02 21:00:56 -04:00
predicate : ( ) = > settings . store . colorMobileIndicator ,
2023-03-18 00:58:49 -03:00
replacement : {
// Make isMobileOnline return true no matter what is the user status
match : /(?<=\i\[\i\.\i\.MOBILE\])===\i\.\i\.ONLINE/ ,
replace : "!= null"
}
}
2025-05-02 21:00:56 -04:00
]
2022-11-21 16:44:30 +02:00
} ) ;