-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwidget-minimal.html
More file actions
143 lines (129 loc) · 4.64 KB
/
widget-minimal.html
File metadata and controls
143 lines (129 loc) · 4.64 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Music Controls</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
background: linear-gradient(135deg, #1a1a1a 0%, #2d2d2d 100%);
font-family: system-ui, -apple-system, sans-serif;
display: flex;
align-items: center;
justify-content: center;
min-height: 100px;
padding: 12px;
}
.widget-minimal {
display: flex;
gap: 8px;
align-items: center;
justify-content: center;
}
.control-btn {
background: rgba(220, 53, 69, 0.9);
border: none;
color: white;
width: 56px;
height: 56px;
border-radius: 50%;
font-size: 24px;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
transition: all 0.2s ease;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}
.control-btn:active {
background: rgba(220, 53, 69, 1);
transform: scale(0.95);
}
.control-btn.play {
width: 64px;
height: 64px;
font-size: 28px;
background: linear-gradient(135deg, #dc3545 0%, #c82333 100%);
}
.control-btn:disabled {
opacity: 0.3;
cursor: not-allowed;
}
.status-text {
position: absolute;
bottom: 4px;
left: 0;
right: 0;
text-align: center;
font-size: 10px;
color: #666;
}
</style>
</head>
<body>
<div class="widget-minimal">
<button class="control-btn" id="prev-btn" onclick="sendCommand('PREVIOUS')">⏮️</button>
<button class="control-btn play" id="play-btn" onclick="sendCommand('PLAY_PAUSE')">▶️</button>
<button class="control-btn" id="next-btn" onclick="sendCommand('NEXT')">⏭️</button>
</div>
<div class="status-text" id="status">Ready</div>
<script>
let isPlaying = false;
// Send command to main app via Service Worker
function sendCommand(action) {
if ('serviceWorker' in navigator && navigator.serviceWorker.controller) {
navigator.serviceWorker.controller.postMessage({
type: 'WIDGET_COMMAND',
action: action
});
// Visual feedback
if (action === 'PLAY_PAUSE') {
isPlaying = !isPlaying;
updatePlayButton();
}
} else {
// Fallback: try to open app
window.open('/index.html', '_blank');
}
}
function updatePlayButton() {
const btn = document.getElementById('play-btn');
btn.textContent = isPlaying ? '⏸️' : '▶️';
}
// Listen for state updates from Service Worker
if ('serviceWorker' in navigator) {
navigator.serviceWorker.addEventListener('message', (event) => {
if (event.data.type === 'WIDGET_STATE_UPDATE') {
const state = event.data.state;
isPlaying = state.isPlaying;
updatePlayButton();
const status = document.getElementById('status');
if (state.currentTrack && state.currentTrack.title !== 'No track loaded') {
status.textContent = state.isPlaying ? '▶ Playing' : '⏸ Paused';
} else {
status.textContent = 'No track';
}
}
});
// Register Service Worker if not already registered
navigator.serviceWorker.register('/service-worker.js').then(() => {
// Request initial state
setTimeout(() => {
if (navigator.serviceWorker.controller) {
navigator.serviceWorker.controller.postMessage({
type: 'WIDGET_REQUEST_STATE'
});
}
}, 100);
}).catch(err => {
console.error('Service Worker registration failed:', err);
});
}
</script>
</body>
</html>