|
10 | 10 | */
|
11 | 11 | import path from 'path';
|
12 | 12 | import fs from 'fs';
|
13 |
| -import { app, BrowserWindow, dialog, shell, ipcMain } from 'electron'; |
| 13 | +import { app, BrowserWindow, dialog, shell, ipcMain, protocol } from 'electron'; |
14 | 14 | import { autoUpdater } from 'electron-updater';
|
15 | 15 | import log from 'electron-log';
|
16 | 16 | import MenuBuilder from './menu';
|
@@ -43,7 +43,8 @@ const HOME: string =
|
43 | 43 | const CONFIG_FILE: string = `${HOME}/.dub-editor-config.json`;
|
44 | 44 | const COLLECTIONS_FILE: string = `${HOME}/.dub-editor-collections.json`;
|
45 | 45 | const BATCH_CACHE_FILE: string = `${HOME}/.dub-editor-batch-cache.json`;
|
46 |
| -const BATCH_VIDEO_TEMP_FILE: string = `${HOME}/dub-editor-tmp.mp4`; |
| 46 | +const BATCH_VIDEO_TEMP_FILE: string = `${HOME}/dub-editor-batch-tmp.mp4`; |
| 47 | +const CLIP_VIDEO_TEMP_FILE: string = `${HOME}/dub-editor-clip-tmp.mp4`; |
47 | 48 |
|
48 | 49 | export default class AppUpdater {
|
49 | 50 | constructor() {
|
@@ -556,9 +557,48 @@ const createWindow = async () => {
|
556 | 557 | return { action: 'deny' };
|
557 | 558 | });
|
558 | 559 |
|
559 |
| - // Remove this if your app does not use auto updates |
560 |
| - // eslint-disable-next-line |
561 |
| - new AppUpdater(); |
| 560 | + protocol.interceptFileProtocol('app', (request, callback) => { |
| 561 | + let url = request.url.substring(6); |
| 562 | + let pattern = /^(rifftrax|whatthedub)\/(.+)\.(mp4|srt)$/; |
| 563 | + |
| 564 | + if (url === "batch.tmp.mp4") { |
| 565 | + return callback(BATCH_VIDEO_TEMP_FILE); |
| 566 | + } else if (url === "clip.tmp.mp4") { |
| 567 | + return callback(CLIP_VIDEO_TEMP_FILE); |
| 568 | + } |
| 569 | + |
| 570 | + let match : any = url.match(pattern); |
| 571 | + |
| 572 | + if (!match) { |
| 573 | + return null; |
| 574 | + } |
| 575 | + |
| 576 | + let game = match[1]; |
| 577 | + let id = match[2]; |
| 578 | + let ext = match[3]; |
| 579 | + |
| 580 | + let directory = null; |
| 581 | + if (game === 'rifftrax') { |
| 582 | + directory = config.rifftraxDirectory; |
| 583 | + } else if (game === 'whatthedub') { |
| 584 | + directory = config.whatTheDubDirectory; |
| 585 | + } |
| 586 | + |
| 587 | + let subdirectory; |
| 588 | + if (ext === 'mp4') { |
| 589 | + subdirectory = 'VideoClips'; |
| 590 | + } else if (ext = 'srt') { |
| 591 | + subdirectory = 'Subtitles'; |
| 592 | + } else { |
| 593 | + subdirectory = 'VideoClips'; |
| 594 | + } |
| 595 | + |
| 596 | + const assetDirectory: string = |
| 597 | + `${directory}/StreamingAssets/${subdirectory}`.replace('~', HOME); |
| 598 | + const filePath: string = `${assetDirectory}/${id}.${ext}`; |
| 599 | + |
| 600 | + callback(filePath); |
| 601 | + }); |
562 | 602 | };
|
563 | 603 |
|
564 | 604 | /**
|
@@ -630,24 +670,13 @@ ipcMain.handle('storeBatch', async (event, { clips, video, title }) => {
|
630 | 670 | title,
|
631 | 671 | clipNumber: 1,
|
632 | 672 | clips,
|
633 |
| - video, |
634 | 673 | };
|
635 | 674 |
|
636 | 675 | // Write cache file
|
637 | 676 | fs.writeFileSync(
|
638 | 677 | BATCH_CACHE_FILE,
|
639 | 678 | Buffer.from(JSON.stringify(batchCache, null, 5))
|
640 | 679 | );
|
641 |
| - |
642 |
| - // Write temporary video file |
643 |
| - let videoByteStream : any = batchCache.video; |
644 |
| - videoByteStream = videoByteStream.substring(videoByteStream.indexOf(',')); |
645 |
| - let buffer = Buffer.from(videoByteStream, "base64"); |
646 |
| - try { |
647 |
| - await fs.writeFileSync(BATCH_VIDEO_TEMP_FILE, buffer); |
648 |
| - } catch (err) { |
649 |
| - throw new Error("Unable to trim video: " + err); |
650 |
| - } |
651 | 680 | });
|
652 | 681 |
|
653 | 682 | ipcMain.handle('hasBatch', (event) => {
|
@@ -830,6 +859,31 @@ ipcMain.handle(
|
830 | 859 | }
|
831 | 860 | );
|
832 | 861 |
|
| 862 | +ipcMain.handle( |
| 863 | + 'storeTempVideo', |
| 864 | + (event, {videoArrayBuffer, type}) => { |
| 865 | + console.log( |
| 866 | + `STORING TEMP CLIP VIDEO` |
| 867 | + ); |
| 868 | + |
| 869 | + if (type === "clip") { |
| 870 | + fs.writeFileSync( |
| 871 | + CLIP_VIDEO_TEMP_FILE, |
| 872 | + Buffer.from(videoArrayBuffer) |
| 873 | + ); |
| 874 | + return `app://clip.tmp.mp4`; |
| 875 | + } else if (type === "batch") { |
| 876 | + fs.writeFileSync( |
| 877 | + BATCH_VIDEO_TEMP_FILE, |
| 878 | + Buffer.from(videoArrayBuffer) |
| 879 | + ); |
| 880 | + return `app://batch.tmp.mp4`; |
| 881 | + } |
| 882 | + |
| 883 | + return null; |
| 884 | + } |
| 885 | +); |
| 886 | + |
833 | 887 | ipcMain.handle('deleteVideo', (event, { id, game }) => {
|
834 | 888 | deleteClip(id, game);
|
835 | 889 | });
|
|
0 commit comments