Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="Content-Security-Policy"
content="default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data:">
content="default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; media-src 'self' blob: whisperdesk-media:">
<title>WhisperDesk</title>
</head>

Expand All @@ -14,4 +14,4 @@
<script type="module" src="/src/renderer/main.tsx"></script>
</body>

</html>
</html>
3 changes: 3 additions & 0 deletions src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import { registerIpcHandlers } from './ipc';
import { initAnalytics, trackEvent, AnalyticsEvents } from './services/analytics';
import { initAutoUpdater, checkForUpdates } from './services/auto-updater';
import { safeSend } from './utils/safe-send';
import { registerMediaProtocolHandler, registerMediaProtocolScheme } from './utils/media-protocol';
import packageJson from '../../package.json';

initAnalytics();
registerMediaProtocolScheme();

const APP_DISPLAY_NAME = 'WhisperDesk';
const APP_USER_MODEL_ID = 'com.whisperdesk.app';
Expand Down Expand Up @@ -251,6 +253,7 @@ const createWindow = () => {
};

app.on('ready', () => {
registerMediaProtocolHandler();
createWindow();

if (!isDev) {
Expand Down
33 changes: 31 additions & 2 deletions src/main/ipc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,18 @@ import {
generateMarkdownDocument,
} from '../utils/export-helper';
import { generateFileFingerprint } from '../utils/media-info';
import { createMediaProtocolUrl } from '../utils/media-protocol';
import {
approveMediaFilePaths,
resolveApprovedMediaFilePath,
} from '../utils/media-source-authorization';
import { safeSend } from '../utils/safe-send';
import { trackEvent, AnalyticsEvents } from '../services/analytics';
import { SUPPORTED_EXTENSIONS } from '../../shared/types';
import { SUPPORTED_EXTENSIONS, VIDEO_EXTENSIONS } from '../../shared/types';
import type { TranscriptionOptions, SaveFileOptions } from '../../shared/types';

const OPEN_DIALOG_MEDIA_EXTENSIONS = [...SUPPORTED_EXTENSIONS];
const VIDEO_EXTENSION_SET = new Set<string>(VIDEO_EXTENSIONS);

export function registerIpcHandlers(getMainWindow: () => BrowserWindow | null) {
ipcMain.handle('dialog:openFile', async () => {
Expand All @@ -41,6 +47,7 @@ export function registerIpcHandlers(getMainWindow: () => BrowserWindow | null) {
if (canceled) {
return null;
}
await approveMediaFilePaths(filePaths);
return filePaths[0];
});

Expand All @@ -57,7 +64,12 @@ export function registerIpcHandlers(getMainWindow: () => BrowserWindow | null) {
},
],
});
return canceled ? null : filePaths;
if (canceled) {
return null;
}

await approveMediaFilePaths(filePaths);
return filePaths;
});

ipcMain.handle('dialog:saveFile', async (_event, options: SaveFileOptions) => {
Expand Down Expand Up @@ -115,6 +127,23 @@ export function registerIpcHandlers(getMainWindow: () => BrowserWindow | null) {
}
});

ipcMain.handle('file:getMediaSource', async (_event, filePath: string) => {
try {
const validation = await resolveApprovedMediaFilePath(filePath);
if (!validation.success) {
return { success: false, error: validation.error };
}

return {
success: true,
url: createMediaProtocolUrl(validation.filePath),
mediaType: VIDEO_EXTENSION_SET.has(validation.extension) ? 'video' : 'audio',
};
Comment thread
pedrovsiqueira marked this conversation as resolved.
} catch (error) {
return { success: false, error: error instanceof Error ? error.message : String(error) };
}
});

ipcMain.handle('models:list', async () => {
const models = listModels();
return { models };
Expand Down
5 changes: 5 additions & 0 deletions src/main/services/whisper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ const MODEL_ALIASES: Record<string, string> = {
turbo: 'large-v3-turbo',
};

const SUBTITLE_MAX_SEGMENT_CHARS = 80;

const isDev = process.env.NODE_ENV === 'development' || !app.isPackaged;

export function getWhisperBinaryPath(): string {
Expand Down Expand Up @@ -508,6 +510,9 @@ export function transcribe(
'--output-txt', // Output plain text
'--output-vtt', // Output VTT subtitles
'--no-timestamps', // Don't print timestamps in main output (we use VTT)
'--max-len',
String(SUBTITLE_MAX_SEGMENT_CHARS),
'--split-on-word',
'-pp', // Print progress
'-of',
outputBase,
Expand Down
Loading
Loading