@spicemod/creator 0.0.25 → 0.0.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin.mjs +169 -119
- package/dist/templates/custom-app/shared/spice.config.js +6 -0
- package/dist/templates/custom-app/shared/spice.config.ts +6 -0
- package/dist/templates/custom-app/shared/tsconfig.app.json +33 -0
- package/dist/templates/custom-app/shared/tsconfig.node.json +25 -0
- package/dist/templates/custom-app/ts/react/src/extension/index.tsx +1 -1
- package/dist/templates/extension/js/react/src/app.jsx +1 -1
- package/dist/templates/extension/shared/spice.config.js +6 -0
- package/dist/templates/extension/shared/spice.config.ts +6 -0
- package/dist/templates/extension/shared/tsconfig.app.json +33 -0
- package/dist/templates/extension/shared/tsconfig.node.json +25 -0
- package/dist/templates/extension/ts/react/src/app.tsx +1 -1
- package/dist/templates/hmrCustomApp.js +284 -0
- package/dist/templates/liveReload.js +298 -45
- package/dist/templates/theme/js/react/src/app.jsx +1 -1
- package/dist/templates/theme/shared/spice.config.js +6 -0
- package/dist/templates/theme/shared/spice.config.ts +6 -0
- package/dist/templates/theme/shared/tsconfig.app.json +33 -0
- package/dist/templates/theme/shared/tsconfig.node.json +25 -0
- package/dist/templates/theme/ts/react/src/app.tsx +1 -1
- package/package.json +1 -1
- package/templates/custom-app/shared/spice.config.js +6 -0
- package/templates/custom-app/shared/spice.config.ts +6 -0
- package/templates/custom-app/shared/tsconfig.app.json +33 -0
- package/templates/custom-app/shared/tsconfig.node.json +25 -0
- package/templates/custom-app/ts/react/src/extension/index.tsx +1 -1
- package/templates/extension/js/react/src/app.jsx +1 -1
- package/templates/extension/shared/spice.config.js +6 -0
- package/templates/extension/shared/spice.config.ts +6 -0
- package/templates/extension/shared/tsconfig.app.json +33 -0
- package/templates/extension/shared/tsconfig.node.json +25 -0
- package/templates/extension/ts/react/src/app.tsx +1 -1
- package/templates/hmrCustomApp.js +284 -0
- package/templates/liveReload.js +298 -45
- package/templates/theme/js/react/src/app.jsx +1 -1
- package/templates/theme/shared/spice.config.js +6 -0
- package/templates/theme/shared/spice.config.ts +6 -0
- package/templates/theme/shared/tsconfig.app.json +33 -0
- package/templates/theme/shared/tsconfig.node.json +25 -0
- package/templates/theme/ts/react/src/app.tsx +1 -1
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2023",
|
|
4
|
+
"lib": ["ES2023"],
|
|
5
|
+
"module": "ESNext",
|
|
6
|
+
"types": ["node"],
|
|
7
|
+
"skipLibCheck": true,
|
|
8
|
+
|
|
9
|
+
/* Bundler mode */
|
|
10
|
+
"moduleResolution": "bundler",
|
|
11
|
+
"allowImportingTsExtensions": true,
|
|
12
|
+
"verbatimModuleSyntax": true,
|
|
13
|
+
"moduleDetection": "force",
|
|
14
|
+
"noEmit": true,
|
|
15
|
+
|
|
16
|
+
/* Linting */
|
|
17
|
+
"strict": true,
|
|
18
|
+
"noUnusedLocals": true,
|
|
19
|
+
"noUnusedParameters": true,
|
|
20
|
+
"erasableSyntaxOnly": true,
|
|
21
|
+
"noFallthroughCasesInSwitch": true,
|
|
22
|
+
"noUncheckedSideEffectImports": true
|
|
23
|
+
},
|
|
24
|
+
"include": ["spice.config.ts"]
|
|
25
|
+
}
|
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
const React = Spicetify.React;
|
|
2
|
+
const rc = React.createElement;
|
|
3
|
+
|
|
4
|
+
const waitForImport = async (retryCount = 0) => {
|
|
5
|
+
try {
|
|
6
|
+
const mod = await import(_IMPORT_LINK);
|
|
7
|
+
return mod.default || mod.render;
|
|
8
|
+
} catch (err) {
|
|
9
|
+
console.error("Failed to import app:", err);
|
|
10
|
+
if (retryCount < 3) {
|
|
11
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
12
|
+
return waitForImport(retryCount + 1);
|
|
13
|
+
}
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const styles = {
|
|
19
|
+
container: {
|
|
20
|
+
display: "flex",
|
|
21
|
+
flexDirection: "column",
|
|
22
|
+
alignItems: "center",
|
|
23
|
+
justifyContent: "center",
|
|
24
|
+
height: "100%",
|
|
25
|
+
width: "100%",
|
|
26
|
+
background:
|
|
27
|
+
"radial-gradient(circle at top left, rgba(29, 185, 84, 0.15), transparent 50%), var(--spice-main, #121212)",
|
|
28
|
+
color: "var(--spice-text, #ffffff)",
|
|
29
|
+
fontFamily: "var(--font-family, Circular, Helvetica, Arial, sans-serif)",
|
|
30
|
+
},
|
|
31
|
+
loadingText: {
|
|
32
|
+
marginTop: "24px",
|
|
33
|
+
fontSize: "14px",
|
|
34
|
+
fontWeight: "600",
|
|
35
|
+
color: "rgba(255, 255, 255, 0.8)",
|
|
36
|
+
letterSpacing: "0.05em",
|
|
37
|
+
textTransform: "uppercase",
|
|
38
|
+
},
|
|
39
|
+
errorContainer: {
|
|
40
|
+
display: "flex",
|
|
41
|
+
flexDirection: "column",
|
|
42
|
+
alignItems: "center",
|
|
43
|
+
padding: "48px",
|
|
44
|
+
backgroundColor: "rgba(255, 255, 255, 0.03)",
|
|
45
|
+
backdropFilter: "blur(16px)",
|
|
46
|
+
border: "1px solid rgba(255, 255, 255, 0.08)",
|
|
47
|
+
borderRadius: "24px",
|
|
48
|
+
boxShadow: "0 16px 40px rgba(0, 0, 0, 0.4)",
|
|
49
|
+
maxWidth: "800px",
|
|
50
|
+
width: "90%",
|
|
51
|
+
textAlign: "center",
|
|
52
|
+
},
|
|
53
|
+
iconContainer: {
|
|
54
|
+
display: "flex",
|
|
55
|
+
alignItems: "center",
|
|
56
|
+
justifyContent: "center",
|
|
57
|
+
width: "64px",
|
|
58
|
+
height: "64px",
|
|
59
|
+
borderRadius: "50%",
|
|
60
|
+
backgroundColor: "rgba(241, 94, 108, 0.1)",
|
|
61
|
+
border: "1px solid rgba(241, 94, 108, 0.2)",
|
|
62
|
+
marginBottom: "24px",
|
|
63
|
+
boxShadow: "0 0 20px rgba(241, 94, 108, 0.15)",
|
|
64
|
+
},
|
|
65
|
+
errorTitle: {
|
|
66
|
+
fontSize: "28px",
|
|
67
|
+
fontWeight: "800",
|
|
68
|
+
marginBottom: "16px",
|
|
69
|
+
color: "#ffffff",
|
|
70
|
+
letterSpacing: "-0.04em",
|
|
71
|
+
},
|
|
72
|
+
errorTraceBox: {
|
|
73
|
+
width: "100%",
|
|
74
|
+
backgroundColor: "rgba(0, 0, 0, 0.25)",
|
|
75
|
+
border: "1px solid rgba(255, 255, 255, 0.05)",
|
|
76
|
+
boxShadow: "inset 0 4px 10px rgba(0,0,0,0.3)",
|
|
77
|
+
borderRadius: "12px",
|
|
78
|
+
padding: "16px",
|
|
79
|
+
marginBottom: "32px",
|
|
80
|
+
textAlign: "left",
|
|
81
|
+
overflowX: "auto",
|
|
82
|
+
},
|
|
83
|
+
errorMessage: {
|
|
84
|
+
fontSize: "13px",
|
|
85
|
+
lineHeight: "1.6",
|
|
86
|
+
fontFamily: "monospace",
|
|
87
|
+
color: "rgba(255, 255, 255, 0.7)",
|
|
88
|
+
wordBreak: "break-word",
|
|
89
|
+
margin: 0,
|
|
90
|
+
},
|
|
91
|
+
buttonBase: {
|
|
92
|
+
padding: "14px 36px",
|
|
93
|
+
fontSize: "14px",
|
|
94
|
+
fontWeight: "600",
|
|
95
|
+
color: "#ffffff",
|
|
96
|
+
backgroundColor: "rgba(255, 255, 255, 0.05)",
|
|
97
|
+
backdropFilter: "blur(8px)",
|
|
98
|
+
WebkitBackdropFilter: "blur(8px)",
|
|
99
|
+
border: "1px solid rgba(255, 255, 255, 0.1)",
|
|
100
|
+
borderRadius: "500px",
|
|
101
|
+
cursor: "pointer",
|
|
102
|
+
textTransform: "uppercase",
|
|
103
|
+
letterSpacing: "0.1em",
|
|
104
|
+
transition: "all 0.2s ease",
|
|
105
|
+
},
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
const AlertIcon = () =>
|
|
109
|
+
rc(
|
|
110
|
+
"svg",
|
|
111
|
+
{
|
|
112
|
+
width: "32",
|
|
113
|
+
height: "32",
|
|
114
|
+
viewBox: "0 0 24 24",
|
|
115
|
+
fill: "none",
|
|
116
|
+
stroke: "rgba(241, 94, 108, 0.9)",
|
|
117
|
+
strokeWidth: "2",
|
|
118
|
+
strokeLinecap: "round",
|
|
119
|
+
strokeLinejoin: "round",
|
|
120
|
+
},
|
|
121
|
+
rc("path", {
|
|
122
|
+
d: "M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z",
|
|
123
|
+
}),
|
|
124
|
+
rc("line", { x1: "12", y1: "9", x2: "12", y2: "13" }),
|
|
125
|
+
rc("line", { x1: "12", y1: "17", x2: "12.01", y2: "17" }),
|
|
126
|
+
);
|
|
127
|
+
|
|
128
|
+
const Spinner = () =>
|
|
129
|
+
rc(
|
|
130
|
+
"svg",
|
|
131
|
+
{ width: "48", height: "48", viewBox: "0 0 50 50" },
|
|
132
|
+
rc("circle", {
|
|
133
|
+
cx: "25",
|
|
134
|
+
cy: "25",
|
|
135
|
+
r: "20",
|
|
136
|
+
fill: "none",
|
|
137
|
+
stroke: "rgba(255,255,255,0.1)",
|
|
138
|
+
strokeWidth: "4",
|
|
139
|
+
}),
|
|
140
|
+
rc(
|
|
141
|
+
"circle",
|
|
142
|
+
{
|
|
143
|
+
cx: "25",
|
|
144
|
+
cy: "25",
|
|
145
|
+
r: "20",
|
|
146
|
+
fill: "none",
|
|
147
|
+
stroke: "rgba(255,255,255,0.8)",
|
|
148
|
+
strokeWidth: "4",
|
|
149
|
+
strokeDasharray: "30 100",
|
|
150
|
+
strokeLinecap: "round",
|
|
151
|
+
},
|
|
152
|
+
rc("animateTransform", {
|
|
153
|
+
attributeName: "transform",
|
|
154
|
+
type: "rotate",
|
|
155
|
+
from: "0 25 25",
|
|
156
|
+
to: "360 25 25",
|
|
157
|
+
dur: "1s",
|
|
158
|
+
repeatCount: "indefinite",
|
|
159
|
+
}),
|
|
160
|
+
),
|
|
161
|
+
);
|
|
162
|
+
|
|
163
|
+
const RetryButton = ({ onClick }) => {
|
|
164
|
+
const [isHovered, setIsHovered] = React.useState(false);
|
|
165
|
+
const [isActive, setIsActive] = React.useState(false);
|
|
166
|
+
|
|
167
|
+
const dynamicStyle = {
|
|
168
|
+
...styles.buttonBase,
|
|
169
|
+
backgroundColor: isActive
|
|
170
|
+
? "rgba(255, 255, 255, 0.15)"
|
|
171
|
+
: isHovered
|
|
172
|
+
? "rgba(255, 255, 255, 0.1)"
|
|
173
|
+
: "rgba(255, 255, 255, 0.05)",
|
|
174
|
+
borderColor: isHovered ? "rgba(255, 255, 255, 0.3)" : "rgba(255, 255, 255, 0.1)",
|
|
175
|
+
transform: isActive ? "scale(0.96)" : isHovered ? "scale(1.02)" : "scale(1)",
|
|
176
|
+
boxShadow: isHovered ? "0 4px 12px rgba(0,0,0,0.2)" : "none",
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
return rc(
|
|
180
|
+
"button",
|
|
181
|
+
{
|
|
182
|
+
style: dynamicStyle,
|
|
183
|
+
onClick,
|
|
184
|
+
onMouseEnter: () => setIsHovered(true),
|
|
185
|
+
onMouseLeave: () => {
|
|
186
|
+
setIsHovered(false);
|
|
187
|
+
setIsActive(false);
|
|
188
|
+
},
|
|
189
|
+
onMouseDown: () => setIsActive(true),
|
|
190
|
+
onMouseUp: () => setIsActive(false),
|
|
191
|
+
},
|
|
192
|
+
"Try Again",
|
|
193
|
+
);
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
const Loading = () =>
|
|
197
|
+
rc(
|
|
198
|
+
"div",
|
|
199
|
+
{ style: styles.container },
|
|
200
|
+
rc(Spinner),
|
|
201
|
+
rc("div", { style: styles.loadingText }, "Loading app..."),
|
|
202
|
+
);
|
|
203
|
+
|
|
204
|
+
const ErrorDisplay = ({ message, onRetry }) =>
|
|
205
|
+
rc(
|
|
206
|
+
"div",
|
|
207
|
+
{ style: styles.container },
|
|
208
|
+
rc(
|
|
209
|
+
"div",
|
|
210
|
+
{ style: styles.errorContainer },
|
|
211
|
+
rc("div", { style: styles.iconContainer }, rc(AlertIcon)),
|
|
212
|
+
rc("div", { style: styles.errorTitle }, "Failed to load app"),
|
|
213
|
+
rc("div", { style: styles.errorTraceBox }, rc("p", { style: styles.errorMessage }, message)),
|
|
214
|
+
rc(RetryButton, { onClick: onRetry }),
|
|
215
|
+
),
|
|
216
|
+
);
|
|
217
|
+
|
|
218
|
+
class ErrorBoundary extends React.Component {
|
|
219
|
+
constructor(props) {
|
|
220
|
+
super(props);
|
|
221
|
+
this.state = { hasError: false, errorMessage: null };
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
static getDerivedStateFromError(error) {
|
|
225
|
+
return {
|
|
226
|
+
hasError: true,
|
|
227
|
+
errorMessage:
|
|
228
|
+
error.stack || error.message || "A runtime error occurred in the app component.",
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
componentDidCatch(error, errorInfo) {
|
|
233
|
+
console.error("Caught inside ErrorBoundary:", error, errorInfo);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
render() {
|
|
237
|
+
if (this.state.hasError) {
|
|
238
|
+
return rc(ErrorDisplay, {
|
|
239
|
+
message: this.state.errorMessage,
|
|
240
|
+
onRetry: () => {
|
|
241
|
+
this.setState({ hasError: false, errorMessage: null });
|
|
242
|
+
if (this.props.onRetry) this.props.onRetry();
|
|
243
|
+
},
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
return this.props.children;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
const AppWrapper = () => {
|
|
251
|
+
const [App, setApp] = React.useState(null);
|
|
252
|
+
const [error, setError] = React.useState(null);
|
|
253
|
+
const [isLoading, setIsLoading] = React.useState(true);
|
|
254
|
+
|
|
255
|
+
const loadApp = React.useCallback(() => {
|
|
256
|
+
setIsLoading(true);
|
|
257
|
+
setError(null);
|
|
258
|
+
waitForImport()
|
|
259
|
+
.then((app) => {
|
|
260
|
+
if (app) {
|
|
261
|
+
setApp(() => app);
|
|
262
|
+
} else {
|
|
263
|
+
setError("Unable to load the app. Please check if the development server is running.");
|
|
264
|
+
}
|
|
265
|
+
})
|
|
266
|
+
.catch((err) => {
|
|
267
|
+
setError(err.stack || err.message || "An unexpected error occurred during import.");
|
|
268
|
+
})
|
|
269
|
+
.finally(() => {
|
|
270
|
+
setIsLoading(false);
|
|
271
|
+
});
|
|
272
|
+
}, []);
|
|
273
|
+
|
|
274
|
+
React.useEffect(() => {
|
|
275
|
+
loadApp();
|
|
276
|
+
}, [loadApp]);
|
|
277
|
+
|
|
278
|
+
if (isLoading) return rc(Loading);
|
|
279
|
+
if (error) return rc(ErrorDisplay, { message: error, onRetry: loadApp });
|
|
280
|
+
if (!App) return rc(ErrorDisplay, { message: "App component not found.", onRetry: loadApp });
|
|
281
|
+
|
|
282
|
+
return rc(ErrorBoundary, { onRetry: loadApp }, rc(App));
|
|
283
|
+
};
|
|
284
|
+
var render = () => rc(AppWrapper);
|
|
@@ -1,69 +1,322 @@
|
|
|
1
1
|
(() => {
|
|
2
|
-
const
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
const CONFIG = {
|
|
3
|
+
wsUrl: _HOT_RELOAD_LINK,
|
|
4
|
+
server: _SERVER_URL,
|
|
5
|
+
cssPath: _CSS_PATH,
|
|
6
|
+
jsPath: _JS_PATH,
|
|
7
|
+
removeCmd: _REMOVE_CMD,
|
|
8
|
+
cssId: "sc-css-injected",
|
|
9
|
+
jsId: "sc-js-injected",
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const ICONS = {
|
|
13
|
+
close: `<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M18 6 6 18"/><path d="m6 6 12 12"/></svg>`,
|
|
14
|
+
terminal: `<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 6h18"/><path d="M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6"/><path d="M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2"/></svg>`,
|
|
15
|
+
copy: `<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect width="14" height="14" x="8" y="8" rx="2" ry="2"/><path d="M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2"/></svg>`,
|
|
16
|
+
check: `<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M20 6 9 17l-5-5"/></svg>`,
|
|
17
|
+
warning: `⚠️`,
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
class SpicetifyDevTools {
|
|
21
|
+
constructor() {
|
|
22
|
+
this.state = {
|
|
23
|
+
isConnected: false,
|
|
24
|
+
hasConnectedOnce: false,
|
|
25
|
+
hasError: false,
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
this.socket = null;
|
|
29
|
+
this.reconnectTimeout = null;
|
|
30
|
+
this.shadowRoot = null;
|
|
31
|
+
this.elements = {};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
init() {
|
|
35
|
+
this.setupShadowDOM();
|
|
36
|
+
this.injectUserAssets();
|
|
37
|
+
this.connectWebSocket();
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
setupShadowDOM() {
|
|
41
|
+
const hostEl = document.createElement("div");
|
|
42
|
+
hostEl.id = "sc-devtools-root";
|
|
43
|
+
hostEl.style.cssText = "position: absolute; z-index: 2147483647;";
|
|
44
|
+
document.body.appendChild(hostEl);
|
|
45
|
+
|
|
46
|
+
this.shadowRoot = hostEl.attachShadow({ mode: "open" });
|
|
47
|
+
|
|
48
|
+
const style = document.createElement("style");
|
|
49
|
+
style.textContent = this.getStyles();
|
|
50
|
+
this.shadowRoot.appendChild(style);
|
|
6
51
|
|
|
7
|
-
|
|
8
|
-
|
|
52
|
+
const wrapper = document.createElement("div");
|
|
53
|
+
wrapper.innerHTML = this.getHTMLTemplate();
|
|
54
|
+
this.shadowRoot.appendChild(wrapper);
|
|
9
55
|
|
|
10
|
-
|
|
56
|
+
this.elements = {
|
|
57
|
+
modal: this.shadowRoot.querySelector(".sc-modal"),
|
|
58
|
+
errorContent: this.shadowRoot.querySelector(".sc-modal__content"),
|
|
59
|
+
btnModalClose: this.shadowRoot.querySelector(".sc-modal__close-btn"),
|
|
60
|
+
copyBtns: this.shadowRoot.querySelectorAll(".sc-remove__copy"),
|
|
61
|
+
};
|
|
11
62
|
|
|
12
|
-
|
|
13
|
-
|
|
63
|
+
this.bindEvents();
|
|
64
|
+
}
|
|
14
65
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
});
|
|
66
|
+
bindEvents() {
|
|
67
|
+
this.elements.btnModalClose.addEventListener("click", () => this.hideErrorDialog());
|
|
18
68
|
|
|
19
|
-
|
|
20
|
-
|
|
69
|
+
this.elements.copyBtns.forEach((btn) => {
|
|
70
|
+
btn.addEventListener("click", () => this.handleCopyCommand(btn));
|
|
71
|
+
});
|
|
72
|
+
}
|
|
21
73
|
|
|
74
|
+
connectWebSocket() {
|
|
75
|
+
this.socket = new WebSocket(CONFIG.wsUrl);
|
|
76
|
+
|
|
77
|
+
this.socket.addEventListener("open", () => {
|
|
78
|
+
this.setState({ isConnected: true });
|
|
79
|
+
console.log("[SC] Live reload connected");
|
|
80
|
+
|
|
81
|
+
if (this.state.hasConnectedOnce) {
|
|
82
|
+
Spicetify.showNotification("Reconnected successfully", false);
|
|
83
|
+
}
|
|
84
|
+
this.setState({ hasConnectedOnce: true });
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
this.socket.addEventListener("message", (event) => this.handleMessage(event));
|
|
88
|
+
this.socket.addEventListener("close", () => this.handleDisconnect());
|
|
89
|
+
this.socket.addEventListener("error", () => this.setState({ isConnected: false }));
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
handleMessage(event) {
|
|
93
|
+
let data;
|
|
22
94
|
try {
|
|
23
|
-
|
|
95
|
+
data = JSON.parse(event.data);
|
|
24
96
|
} catch {
|
|
25
97
|
return;
|
|
26
98
|
}
|
|
99
|
+
if (!data) return;
|
|
27
100
|
|
|
28
|
-
if (!Array.isArray(
|
|
101
|
+
if (!Array.isArray(data)) {
|
|
102
|
+
if (data.type === "build-error" && data.errors?.length > 0) {
|
|
103
|
+
this.setState({ hasError: true });
|
|
104
|
+
this.showErrorDialog(data.errors);
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
if (data.type === "build-success") {
|
|
108
|
+
this.setState({ hasError: false });
|
|
109
|
+
this.hideErrorDialog();
|
|
110
|
+
if (data.warnings?.length > 0) {
|
|
111
|
+
Spicetify.showNotification(`${data.warnings.length} warning(s)`, false);
|
|
112
|
+
}
|
|
113
|
+
if (Array.isArray(data.updated) && data.updated.length > 0) {
|
|
114
|
+
data = data.updated;
|
|
115
|
+
} else {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
29
120
|
|
|
30
|
-
|
|
121
|
+
if (Array.isArray(data) && data.length > 0) {
|
|
122
|
+
const isOnlyCSS = data.every((file) => file.endsWith(".css"));
|
|
31
123
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
124
|
+
if (isOnlyCSS && CONFIG.cssPath) {
|
|
125
|
+
this.hotReloadCSS();
|
|
126
|
+
} else {
|
|
127
|
+
window.location.reload();
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
35
131
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
132
|
+
handleDisconnect() {
|
|
133
|
+
this.setState({ isConnected: false });
|
|
134
|
+
clearTimeout(this.reconnectTimeout);
|
|
135
|
+
this.reconnectTimeout = setTimeout(() => this.connectWebSocket(), 1000);
|
|
136
|
+
}
|
|
39
137
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
138
|
+
injectUserAssets() {
|
|
139
|
+
if (CONFIG.cssPath) {
|
|
140
|
+
const link = document.createElement("link");
|
|
141
|
+
link.id = CONFIG.cssId;
|
|
142
|
+
link.rel = "stylesheet";
|
|
143
|
+
link.href = CONFIG.server + CONFIG.cssPath;
|
|
144
|
+
document.head.appendChild(link);
|
|
43
145
|
}
|
|
44
|
-
|
|
146
|
+
const script = document.createElement("script");
|
|
147
|
+
script.id = CONFIG.jsId;
|
|
148
|
+
script.src = CONFIG.server + CONFIG.jsPath;
|
|
149
|
+
script.onerror = () => {
|
|
150
|
+
this.setState({ hasError: true });
|
|
151
|
+
this.showErrorDialog([
|
|
152
|
+
{ text: "Failed to load JavaScript. Ensure the dev server is running." },
|
|
153
|
+
]);
|
|
154
|
+
};
|
|
155
|
+
document.body.appendChild(script);
|
|
156
|
+
}
|
|
45
157
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
158
|
+
hotReloadCSS() {
|
|
159
|
+
const oldLink = document.getElementById(CONFIG.cssId);
|
|
160
|
+
if (!oldLink || !oldLink.parentNode) return;
|
|
49
161
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
162
|
+
const newLink = oldLink.cloneNode(false);
|
|
163
|
+
newLink.href = `${CONFIG.server}${CONFIG.cssPath}?t=${Date.now()}`;
|
|
164
|
+
newLink.onload = () => {
|
|
165
|
+
oldLink.remove();
|
|
166
|
+
Spicetify.showNotification("Styles hot-reloaded", false);
|
|
167
|
+
};
|
|
168
|
+
oldLink.parentNode.insertBefore(newLink, oldLink.nextSibling);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
setState(newState) {
|
|
172
|
+
this.state = { ...this.state, ...newState };
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
showErrorDialog(errors) {
|
|
176
|
+
this.elements.modal.style.display = "flex";
|
|
177
|
+
this.elements.errorContent.innerHTML = "";
|
|
54
178
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
179
|
+
const fragment = document.createDocumentFragment();
|
|
180
|
+
|
|
181
|
+
errors.forEach((err, index) => {
|
|
182
|
+
const msg = err.text || err.message || String(err);
|
|
183
|
+
const item = document.createElement("div");
|
|
184
|
+
item.className = "sc-err-item";
|
|
185
|
+
|
|
186
|
+
let html = `<div class="sc-err-msg">${index + 1}. ${msg}</div>`;
|
|
187
|
+
|
|
188
|
+
if (err.location) {
|
|
189
|
+
const loc = err.location;
|
|
190
|
+
html += `
|
|
191
|
+
<div class="sc-err-loc">
|
|
192
|
+
<div class="sc-err-path">${loc.file}:${loc.line}:${loc.column}</div>
|
|
193
|
+
${loc.lineText ? `<div class="sc-err-code">${loc.lineText}</div>` : ""}
|
|
194
|
+
</div>`;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
if (err.notes?.length) {
|
|
198
|
+
err.notes.forEach((note) => {
|
|
199
|
+
html += `<div class="sc-err-note">${note.text}</div>`;
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
item.innerHTML = html;
|
|
204
|
+
fragment.appendChild(item);
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
this.elements.errorContent.appendChild(fragment);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
hideErrorDialog() {
|
|
211
|
+
this.elements.modal.style.display = "none";
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
handleCopyCommand(btnElement) {
|
|
215
|
+
navigator.clipboard.writeText(CONFIG.removeCmd).then(() => {
|
|
216
|
+
btnElement.classList.add("is-copied");
|
|
217
|
+
btnElement.innerHTML = `${ICONS.check} Copied!`;
|
|
218
|
+
|
|
219
|
+
setTimeout(() => {
|
|
220
|
+
btnElement.classList.remove("is-copied");
|
|
221
|
+
btnElement.innerHTML = `${ICONS.copy} Copy`;
|
|
222
|
+
}, 2000);
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
getHTMLTemplate() {
|
|
227
|
+
const removeSectionHTML = `
|
|
228
|
+
<div class="sc-remove">
|
|
229
|
+
<div class="sc-remove__title">${ICONS.terminal} Remove Extension</div>
|
|
230
|
+
<div class="sc-remove__cmd">
|
|
231
|
+
<code>${CONFIG.removeCmd}</code>
|
|
232
|
+
<button class="sc-remove__copy">${ICONS.copy} Copy</button>
|
|
233
|
+
</div>
|
|
234
|
+
</div>
|
|
235
|
+
`;
|
|
236
|
+
|
|
237
|
+
return `
|
|
238
|
+
<div class="sc-modal" style="display: none;">
|
|
239
|
+
<div class="sc-modal__inner">
|
|
240
|
+
<div class="sc-modal__header">
|
|
241
|
+
<h2 class="sc-modal__title"><span>${ICONS.warning}</span><span>Build Error</span></h2>
|
|
242
|
+
<button class="sc-modal__close-btn">${ICONS.close}</button>
|
|
243
|
+
</div>
|
|
244
|
+
<div class="sc-modal__content"></div>
|
|
245
|
+
${removeSectionHTML}
|
|
246
|
+
</div>
|
|
247
|
+
</div>
|
|
248
|
+
`;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
getStyles() {
|
|
252
|
+
return `
|
|
253
|
+
/* Variables */
|
|
254
|
+
:host {
|
|
255
|
+
--sc-color-bg-modal: #181818;
|
|
256
|
+
--sc-color-bg-elevated: rgba(255, 255, 255, 0.06);
|
|
257
|
+
--sc-color-bg-hover: rgba(255, 255, 255, 0.1);
|
|
258
|
+
--sc-color-text-primary: #ffffff;
|
|
259
|
+
--sc-color-text-secondary: #a7a7a7;
|
|
260
|
+
--sc-color-text-muted: #888888;
|
|
261
|
+
--sc-color-brand: #1ed760;
|
|
262
|
+
--sc-color-error: #e91429;
|
|
263
|
+
--sc-border-light: rgba(255, 255, 255, 0.08);
|
|
264
|
+
--sc-border-error: rgba(233, 20, 41, 0.2);
|
|
265
|
+
--sc-shadow-panel: 0 24px 48px rgba(0, 0, 0, 0.6), 0 0 0 1px var(--sc-border-light);
|
|
266
|
+
--sc-radius-sm: 6px;
|
|
267
|
+
--sc-radius-md: 12px;
|
|
268
|
+
--sc-radius-lg: 16px;
|
|
269
|
+
--sc-radius-circle: 50%;
|
|
270
|
+
--sc-font-sans: "Circular Sp", "Helvetica Neue", Helvetica, Arial, sans-serif;
|
|
271
|
+
--sc-font-mono: Consolas, Monaco, "Courier New", monospace;
|
|
272
|
+
--sc-transition-smooth: all 0.2s ease;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/* Animations */
|
|
276
|
+
@keyframes scModalEnter { from { opacity: 0; transform: scale(0.96) translateY(15px); } to { opacity: 1; transform: scale(1) translateY(0); } }
|
|
277
|
+
@keyframes scBackdropFade { from { opacity: 0; backdrop-filter: blur(0px); } to { opacity: 1; backdrop-filter: blur(8px); } }
|
|
278
|
+
|
|
279
|
+
/* Modal */
|
|
280
|
+
.sc-modal { position: fixed; inset: 0; background-color: rgba(0, 0, 0, 0.85); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); display: flex; align-items: center; justify-content: center; padding: 24px; animation: scBackdropFade 0.3s ease-out; font-family: var(--sc-font-sans); }
|
|
281
|
+
.sc-modal__inner { width: 100%; max-width: 680px; max-height: 80vh; background-color: var(--sc-color-bg-modal); border-radius: var(--sc-radius-lg); box-shadow: var(--sc-shadow-panel); display: flex; flex-direction: column; overflow: hidden; animation: scModalEnter 0.4s cubic-bezier(0.16, 1, 0.3, 1); }
|
|
282
|
+
.sc-modal__header { padding: 20px 24px; background: linear-gradient(135deg, rgba(233, 20, 41, 0.12), rgba(233, 20, 41, 0.02)); border-bottom: 1px solid var(--sc-border-error); display: flex; align-items: center; justify-content: space-between; flex-shrink: 0; }
|
|
283
|
+
.sc-modal__title { color: #ff6b6b; font-size: 18px; font-weight: 800; margin: 0; display: flex; align-items: center; gap: 10px; letter-spacing: -0.01em; }
|
|
284
|
+
.sc-modal__close-btn { background: var(--sc-color-bg-elevated); border: none; color: var(--sc-color-text-secondary); cursor: pointer; width: 32px; height: 32px; border-radius: var(--sc-radius-circle); display: flex; align-items: center; justify-content: center; transition: var(--sc-transition-smooth); }
|
|
285
|
+
.sc-modal__close-btn:hover { background: var(--sc-color-bg-hover); color: var(--sc-color-text-primary); }
|
|
286
|
+
.sc-modal__content { padding: 0; overflow-y: auto; flex: 1; scrollbar-width: thin; scrollbar-color: var(--sc-color-bg-hover) transparent; }
|
|
287
|
+
.sc-modal__content::-webkit-scrollbar { width: 6px; }
|
|
288
|
+
.sc-modal__content::-webkit-scrollbar-track { background: transparent; }
|
|
289
|
+
.sc-modal__content::-webkit-scrollbar-thumb { background: var(--sc-color-bg-hover); border-radius: 3px; }
|
|
290
|
+
|
|
291
|
+
/* Error Items */
|
|
292
|
+
.sc-err-item { padding: 20px 24px; border-bottom: 1px solid var(--sc-border-light); transition: background-color 0.2s; }
|
|
293
|
+
.sc-err-item:hover { background-color: rgba(255, 255, 255, 0.02); }
|
|
294
|
+
.sc-err-item:last-child { border-bottom: none; }
|
|
295
|
+
.sc-err-msg { color: var(--sc-color-text-primary); font-weight: 600; margin-bottom: 12px; font-size: 14px; line-height: 1.5; font-family: var(--sc-font-mono); }
|
|
296
|
+
.sc-err-loc { background-color: rgba(0, 0, 0, 0.3); padding: 14px; border-radius: var(--sc-radius-sm); border: 1px solid var(--sc-border-light); font-family: var(--sc-font-mono); font-size: 12px; overflow-x: auto; }
|
|
297
|
+
.sc-err-path { color: var(--sc-color-brand); margin-bottom: 8px; font-weight: 600; opacity: 0.9; }
|
|
298
|
+
.sc-err-code { color: var(--sc-color-text-muted); white-space: pre; line-height: 1.5; }
|
|
299
|
+
.sc-err-note { color: var(--sc-color-text-secondary); margin-top: 14px; padding-left: 14px; border-left: 2px solid var(--sc-color-error); font-size: 12px; font-weight: 500; }
|
|
300
|
+
|
|
301
|
+
/* Remove Section */
|
|
302
|
+
.sc-remove { padding: 16px 24px; background: linear-gradient(180deg, rgba(233, 20, 41, 0.06), rgba(233, 20, 41, 0.02)); border-top: 1px solid var(--sc-border-error); }
|
|
303
|
+
.sc-remove__title { color: #f15e6c; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 10px; display: flex; align-items: center; gap: 6px; }
|
|
304
|
+
.sc-remove__cmd { display: flex; align-items: stretch; background: rgba(0, 0, 0, 0.4); border-radius: var(--sc-radius-sm); border: 1px solid var(--sc-border-light); overflow: hidden; }
|
|
305
|
+
.sc-remove__cmd code { flex: 1; padding: 10px 14px; font-family: var(--sc-font-mono); font-size: 12px; color: var(--sc-color-text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
|
306
|
+
.sc-remove__copy { padding: 10px 14px; background: rgba(255, 255, 255, 0.03); border: none; border-left: 1px solid var(--sc-border-light); color: var(--sc-color-text-secondary); cursor: pointer; font-size: 11px; font-weight: 600; transition: var(--sc-transition-smooth); display: flex; align-items: center; gap: 6px; }
|
|
307
|
+
.sc-remove__copy:hover { background: var(--sc-color-bg-hover); color: var(--sc-color-text-primary); }
|
|
308
|
+
.sc-remove__copy.is-copied { color: var(--sc-color-brand); }`;
|
|
309
|
+
}
|
|
61
310
|
}
|
|
62
311
|
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
312
|
+
const start = () => {
|
|
313
|
+
const devTools = new SpicetifyDevTools();
|
|
314
|
+
devTools.init();
|
|
315
|
+
};
|
|
67
316
|
|
|
68
|
-
|
|
317
|
+
if (document.readyState === "loading") {
|
|
318
|
+
document.addEventListener("DOMContentLoaded", start);
|
|
319
|
+
} else {
|
|
320
|
+
start();
|
|
321
|
+
}
|
|
69
322
|
})();
|