Skip to content

Commit d1762e2

Browse files
committed
add linux support for SpotifyEnableDevMode
1 parent fc69822 commit d1762e2

File tree

1 file changed

+46
-13
lines changed

1 file changed

+46
-13
lines changed

src/test/java/SpotifyEnableDevMode.java

Lines changed: 46 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,30 +13,52 @@
1313
public class SpotifyEnableDevMode {
1414

1515
public static void main(String[] args) throws IOException {
16-
enableDevTools(Paths.get(System.getenv("LOCALAPPDATA"), "Spotify"));
17-
enableEmployeeMode(Paths.get(System.getenv("APPDATA"), "Spotify"));
16+
boolean isWindows = System.getProperty("os.name").toLowerCase().contains("win");
17+
18+
Path spotifyApp = isWindows
19+
? Paths.get(System.getenv("APPDATA"), "Spotify")
20+
: Paths.get("/opt/spotify");
21+
if (!Files.exists(spotifyApp)) {
22+
System.err.println("Spotify application directory not found: " + spotifyApp);
23+
return;
24+
}
25+
enableEmployeeMode(spotifyApp);
26+
27+
Path spotifyCache = isWindows
28+
? Paths.get(System.getenv("LOCALAPPDATA"), "Spotify")
29+
: Paths.get("/home", System.getProperty("user.name"), ".cache", "spotify");
30+
if (!Files.exists(spotifyCache)) {
31+
System.err.println("Spotify cache directory not found: " + spotifyCache);
32+
return;
33+
}
34+
35+
enableDevTools(spotifyCache);
1836
}
1937

2038
private static void enableDevTools(Path spotifyLocal) throws IOException {
2139
Path file = spotifyLocal.resolve("offline.bnk");
2240
TextPatcher patcher = (fileName, content) -> {
23-
return content.replaceAll("(?<=app-developer..|app-developer>)0", "2");
41+
content = content.replaceAll("(?<=app-developer..|app-developer>)0", "2");
42+
System.out.println("Patched " + fileName + " to enable developer tools.");
43+
return content;
2444
};
2545
patchFile(file, patcher);
2646
}
2747

2848
private static void enableEmployeeMode(Path spotifyAppData) throws IOException {
2949
Path appsDir = spotifyAppData.resolve("Apps");
3050
Path xpuiSpa = appsDir.resolve("xpui.spa");
31-
3251
patchArchive(xpuiSpa, (TextPatcher) (fileName, content) -> {
33-
if (!fileName.equals("xpui.js")) {
34-
return content;
52+
if (!fileName.endsWith(".js")) {
53+
return content; // Only patch JavaScript files
54+
}
55+
if (content.contains(".employee.isEmployee")) {
56+
content = content.replace(
57+
".employee.isEmployee",
58+
".autoPlay"
59+
);
60+
System.out.println("Patched " + fileName + " to enable employee mode.");
3561
}
36-
37-
content = content.replaceAll("\"1\"===e.employee", " true"); // Minified
38-
content = content.replaceAll("\"1\" === e.employee", " true"); // Formatted
39-
4062
return content;
4163
});
4264
}
@@ -46,12 +68,20 @@ private static void patchFile(Path archive, Patcher patcher) throws IOException
4668
}
4769

4870
private static void patchArchive(Path archive, Patcher patcher) throws IOException {
49-
// Move archive to temp location
50-
Path tempArchive = archive.getParent().resolve(archive.getFileName() + ".tmp");
5171
if (!Files.exists(archive)) {
52-
Files.move(archive, tempArchive);
72+
System.err.println("Archive not found: " + archive);
73+
return;
74+
}
75+
76+
if (!Files.isWritable(archive)) {
77+
System.err.println("No write permission for archive: " + archive);
78+
return;
5379
}
5480

81+
// Move archive to temp location
82+
Path tempArchive = Paths.get(System.getProperty("java.io.tmpdir"), "spotify-temp-" + archive.getFileName());
83+
Files.copy(archive, tempArchive);
84+
5585
// Write patched archive to original location
5686
try (
5787
ZipFile zipFile = new ZipFile(tempArchive.toFile());
@@ -77,6 +107,9 @@ private static void patchArchive(Path archive, Patcher patcher) throws IOExcepti
77107
zos.write(outputBytes);
78108
}
79109
}
110+
} finally {
111+
// Delete temp archive
112+
Files.deleteIfExists(tempArchive);
80113
}
81114
}
82115

0 commit comments

Comments
 (0)