-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathspotify-preload.c
More file actions
73 lines (52 loc) · 2.07 KB
/
spotify-preload.c
File metadata and controls
73 lines (52 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// SPDX-License: BSD-3-Clause
#define _GNU_SOURCE
#include <stdlib.h>
#include <stdio.h>
#include <dlfcn.h>
#include <pthread.h>
static const char *ICON_NAME_OVERRIDE = "com.spotify.Client-symbolic";
/* Electron currently uses app_indicator_set_icon_full() but this covers all options in-case. */
static void (*original_set_icon_full) (void *, const char *, const char *);
static void (*original_set_icon) (void *, const char *);
static void* (*original_indicator_new) (const char *, const char *, int);
static void* (*original_indicator_new_with_path) (const char *, const char *, int, const char*);
static pthread_once_t resolve_once = PTHREAD_ONCE_INIT;
static void resolve_symbols (void)
{
original_set_icon_full = dlsym (RTLD_NEXT, "app_indicator_set_icon_full");
original_set_icon = dlsym (RTLD_NEXT, "app_indicator_set_icon");
original_indicator_new = dlsym (RTLD_NEXT, "app_indicator_new");
original_indicator_new_with_path = dlsym (RTLD_NEXT, "app_indicator_new_with_path");
if (!original_set_icon_full ||
!original_set_icon ||
!original_indicator_new ||
!original_indicator_new_with_path)
{
fprintf(stderr, "[spotify-icon-override] failed to resolve symbols\n");
abort();
}
}
static inline void ensure_resolved (void)
{
pthread_once (&resolve_once, resolve_symbols);
}
void *app_indicator_new (const char *id, const char *icon_name, int category)
{
ensure_resolved();
return original_indicator_new (id, ICON_NAME_OVERRIDE, category);
}
void *app_indicator_new_with_path (const char *id, const char *icon_name, int category, const char *icon_theme_path)
{
ensure_resolved();
return original_indicator_new_with_path (id, ICON_NAME_OVERRIDE, category, NULL);
}
void app_indicator_set_icon (void *indicator, const char *icon_name)
{
ensure_resolved();
original_set_icon (indicator, ICON_NAME_OVERRIDE);
}
void app_indicator_set_icon_full (void *indicator, const char *icon_name, const char *icon_desc)
{
ensure_resolved();
original_set_icon_full (indicator, ICON_NAME_OVERRIDE, icon_desc);
}