Skip to content

Commit 9186f51

Browse files
committed
fix: iOS file saving
1 parent 08f7849 commit 9186f51

File tree

2 files changed

+35
-36
lines changed

2 files changed

+35
-36
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
},
2626
"packageManager": "pnpm@9.12.2",
2727
"scripts": {
28-
"dev": "vite",
28+
"dev": "vite --host",
2929
"build": "vite build",
3030
"preview": "vite preview"
3131
},

src/App.vue

Lines changed: 34 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -80,33 +80,32 @@ function initiate() {
8080
let recorder
8181
8282
const startVideo = () => {
83-
console.log('hello')
8483
videoRecording.value = Date.now()
8584
8685
recorder = new MediaRecorder(video.value.srcObject)
8786
8887
recorder.ondataavailable = (event) => {
8988
const blob = event.data;
9089
const url = URL.createObjectURL(blob);
91-
92-
// Create a new window to display the video
93-
const newWindow = window.open('', '_blank', `width=${width.value},height=${height.value + 1}`);
94-
newWindow.document.write(`
95-
<html style="overscroll-behavior: none;"><body style="margin:0; background: black; position: relative">
96-
<button onclick="saveVideo()" style="position: absolute; top: 1em; left: 1em; font-size: 3em;">Download video</button>
97-
<video controls autoplay >
98-
<source src="${url}" type="video/mp4">
99-
</video>
100-
</body></html>
101-
`);
102-
103-
newWindow.saveVideo = () => {
104-
const a = newWindow.document.createElement('a');
105-
a.href = url;
106-
a.download = 'recorded_video.mp4';
107-
a.click();
108-
URL.revokeObjectURL(url);
109-
};
90+
window.open(url, '_blank');
91+
92+
// const newWindow = window.open('', '_blank', `width=${width.value},height=${height.value + 1}`);
93+
// newWindow.document.write(`
94+
// <html style="overscroll-behavior: none;"><body style="margin:0; background: black; position: relative">
95+
// <button onclick="saveVideo()" style="position: absolute; top: 1em; left: 1em; font-size: 3em;">Download video</button>
96+
// <video controls autoplay >
97+
// <source src="${url}" type="video/mp4">
98+
// </video>
99+
// </body></html>
100+
// `);
101+
102+
// newWindow.saveVideo = () => {
103+
// const a = newWindow.document.createElement('a');
104+
// a.href = url;
105+
// a.download = 'recorded_video.mp4';
106+
// a.click();
107+
// URL.revokeObjectURL(url);
108+
// };
110109
};
111110
recorder.start()
112111
}
@@ -129,20 +128,20 @@ const stopRecording = () => {
129128
const filename = `spectrogram_${new Date().toISOString().slice(0, 19).replace(/T/, '_')}.png`;
130129
offscreenCanvas.toBlob((blob) => {
131130
const blobUrl = window.URL.createObjectURL(blob);
132-
// window.open(blobUrl, '_blank');
133-
const newWindow = window.open(undefined, '_blank');
134-
if (newWindow) {
135-
newWindow.document.write(`
136-
<html>
137-
<head>
138-
<title>${filename}</title>
139-
</head>
140-
<body style="margin: 0; display: flex; justify-content: center; align-items: center; min-height: 100vh; background: #222222;">
141-
<img src="${blobUrl}" alt="${filename}" style="cursor: pointer; max-width: 100%; max-height: 100vh; object-fit: contain;" onclick="const a = document.createElement('a'); a.href = '${blobUrl}'; a.download = '${filename}'; document.body.appendChild(a); a.click();">
142-
</body>
143-
</html>
144-
`);
145-
}
131+
window.open(blobUrl, '_blank');
132+
// const newWindow = window.open(undefined, '_blank');
133+
// if (newWindow) {
134+
// newWindow.document.write(`
135+
// <html>
136+
// <head>
137+
// <title>${filename}</title>
138+
// </head>
139+
// <body style="margin: 0; display: flex; justify-content: center; align-items: center; min-height: 100vh; background: #222222;">
140+
// <img src="${blobUrl}" alt="${filename}" style="cursor: pointer; max-width: 100%; max-height: 100vh; object-fit: contain;" onclick="const a = document.createElement('a'); a.href = '${blobUrl}'; a.download = '${filename}'; document.body.appendChild(a); a.click();">
141+
// </body>
142+
// </html>
143+
// `);
144+
// }
146145
}, 'image/png');
147146
};
148147
@@ -255,7 +254,7 @@ onKeyStroke('Enter', (e) => { e.preventDefault(); clear(); })
255254
@pointerdown="recording ? stopRecording() : startRecording()")
256255
.i-la-circle(v-if="!recording")
257256
.i-la-dot-circle(v-else)
258-
.p-0.text-sm.font-mono(v-if="recording && recordedWidth") {{ recordedWidth }}px ({{ ((time - recording) / 1000).toFixed(1) }}s)
257+
.p-0.text-sm.font-mono(v-if="recording && recordedWidth") {{ ((time - recording) / 1000).toFixed(0) }}s ({{ recordedWidth }}px)
259258
button.text-xl.select-none.cursor-pointer.flex.items-center.gap-1(
260259
:class="{ 'text-red': videoRecording }"
261260
@pointerdown="!videoRecording ? startVideo() : stopVideo()")

0 commit comments

Comments
 (0)