-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpreload.js
More file actions
130 lines (110 loc) · 5.61 KB
/
preload.js
File metadata and controls
130 lines (110 loc) · 5.61 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
const { contextBridge, ipcRenderer } = require('electron');
// Helper: subscribe to a channel, removing any previous listener first
function onChannel(channel, handler) {
ipcRenderer.removeAllListeners(channel);
ipcRenderer.on(channel, handler);
}
contextBridge.exposeInMainWorld('electronAPI', {
// Streaming (legacy)
addMagnet: (magnet) => ipcRenderer.invoke('add-magnet', magnet),
stopCurrentStream: () => ipcRenderer.invoke('stop-current-stream'),
onTorrentProgress: (callback) => {
onChannel('torrent-progress', (_event, data) => callback(data));
},
// Search
search: (query, type) => ipcRenderer.invoke('search', query, type),
getMovieMagnet: (movieId) => ipcRenderer.invoke('get-movie-magnet', movieId),
resolveMovieMagnet: (meta) => ipcRenderer.invoke('resolve-movie-magnet', meta),
getShowTorrents: (imdbId, showName) => ipcRenderer.invoke('get-show-torrents', imdbId, showName),
// Subtitles
fetchSubtitles: (meta) => ipcRenderer.invoke('fetch-subtitles', meta),
downloadSubtitle: (fileId) => ipcRenderer.invoke('download-subtitle', fileId),
saveSubtitleTemp: (base64Content, fileName) => ipcRenderer.invoke('save-subtitle-temp', base64Content, fileName),
// Download Manager
startDownload: (magnet, meta) => ipcRenderer.invoke('start-download', magnet, meta),
pauseDownload: (infoHash) => ipcRenderer.invoke('pause-download', infoHash),
resumeDownload: (infoHash) => ipcRenderer.invoke('resume-download', infoHash),
deleteDownload: (infoHash, deleteFiles) => ipcRenderer.invoke('delete-download', infoHash, deleteFiles),
getDownloads: () => ipcRenderer.invoke('get-downloads'),
playCompleted: (infoHash) => ipcRenderer.invoke('play-completed', infoHash),
// Settings
setSeedRatio: (ratio) => ipcRenderer.invoke('set-seed-ratio', ratio),
getSettings: () => ipcRenderer.invoke('get-settings'),
// Onboarding
getOnboarding: () => ipcRenderer.invoke('get-onboarding'),
setOnboarding: (data) => ipcRenderer.invoke('set-onboarding', data),
// Settings - Providers and Region
getSelectedProviders: () => ipcRenderer.invoke('get-selected-providers'),
setSelectedProviders: (providers) => ipcRenderer.invoke('set-selected-providers', providers),
getRegion: () => ipcRenderer.invoke('get-region'),
setRegion: (region) => ipcRenderer.invoke('set-region', region),
// Browse/Discovery (TMDB)
getBrowseContent: (options) => ipcRenderer.invoke('get-browse-content', options),
getTrendingMovies: (options) => ipcRenderer.invoke('get-trending-movies', options),
getTrendingTV: (options) => ipcRenderer.invoke('get-trending-tv', options),
getPopularMovies: (options) => ipcRenderer.invoke('get-popular-movies', options),
getPopularTV: (options) => ipcRenderer.invoke('get-popular-tv', options),
invalidateTmdbCache: () => ipcRenderer.invoke('invalidate-tmdb-cache'),
// Download updates subscription
onDownloadsUpdate: (callback) => {
onChannel('downloads-update', (_event, data) => callback(data));
},
// mpv binary path (for external player support)
getMpvPath: () => ipcRenderer.invoke('get-mpv-path'),
// Display detection
getDisplayContext: () => ipcRenderer.invoke('get-display-context'),
// ─────────────────────────────────────────────────────────────────────────────
// mpv Player Control
// ─────────────────────────────────────────────────────────────────────────────
// Playback control
mpvStart: (streamUrl, options) => ipcRenderer.invoke('mpv-start', streamUrl, options),
mpvPlay: () => ipcRenderer.invoke('mpv-play'),
mpvPause: () => ipcRenderer.invoke('mpv-pause'),
mpvTogglePause: () => ipcRenderer.invoke('mpv-toggle-pause'),
mpvStop: () => ipcRenderer.invoke('mpv-stop'),
mpvQuit: () => ipcRenderer.invoke('mpv-quit'),
// Seeking
mpvSeek: (seconds) => ipcRenderer.invoke('mpv-seek', seconds),
mpvGoToPosition: (seconds) => ipcRenderer.invoke('mpv-go-to-position', seconds),
// Volume control
mpvVolume: (level) => ipcRenderer.invoke('mpv-volume', level),
mpvAdjustVolume: (delta) => ipcRenderer.invoke('mpv-adjust-volume', delta),
mpvMute: () => ipcRenderer.invoke('mpv-mute'),
mpvUnmute: () => ipcRenderer.invoke('mpv-unmute'),
mpvToggleMute: () => ipcRenderer.invoke('mpv-toggle-mute'),
// Fullscreen
mpvToggleFullscreen: () => ipcRenderer.invoke('mpv-toggle-fullscreen'),
// Subtitles
mpvAddSubtitles: (filePath) => ipcRenderer.invoke('mpv-add-subtitles', filePath),
// Status
mpvGetStatus: () => ipcRenderer.invoke('mpv-get-status'),
mpvIsPlaying: () => ipcRenderer.invoke('mpv-is-playing'),
// mpv Event subscriptions
onMpvTimePosition: (callback) => {
onChannel('mpv-timeposition', (_event, position) => callback(position));
},
onMpvStatus: (callback) => {
onChannel('mpv-status', (_event, status) => callback(status));
},
onMpvStarted: (callback) => {
onChannel('mpv-started', () => callback());
},
onMpvStopped: (callback) => {
onChannel('mpv-stopped', () => callback());
},
onMpvPaused: (callback) => {
onChannel('mpv-paused', () => callback());
},
onMpvResumed: (callback) => {
onChannel('mpv-resumed', () => callback());
},
onMpvSeek: (callback) => {
onChannel('mpv-seek', (_event, data) => callback(data));
},
onMpvQuit: (callback) => {
onChannel('mpv-quit', () => callback());
},
onMpvCrashed: (callback) => {
onChannel('mpv-crashed', () => callback());
},
});