From f6d91327d91a8441651cf937de3b1cc9c1b29b11 Mon Sep 17 00:00:00 2001 From: tribhuwan-kumar Date: Fri, 27 Sep 2024 23:50:29 +0530 Subject: [PATCH 1/5] fix: pre_build.js for windows installation (minor changes) --- screenpipe-app-tauri/scripts/pre_build.js | 39 ++++++++++++++++------- 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/screenpipe-app-tauri/scripts/pre_build.js b/screenpipe-app-tauri/scripts/pre_build.js index 3c6ddcc5b..6a2fb2540 100644 --- a/screenpipe-app-tauri/scripts/pre_build.js +++ b/screenpipe-app-tauri/scripts/pre_build.js @@ -140,7 +140,18 @@ if (platform == 'linux') { /* ########## Windows ########## */ if (platform == 'windows') { - const wgetPath = await findWget(); + + async function isInstalled(command) { + try { + await $`powershell -Command "Get-Command ${command} -ErrorAction Stop"`; + return true; + } catch { + console.log(`${command} not found, Please install it`) + return false; + } + } + + const wgetPath = await findWget(); console.log('Copying screenpipe binary...'); @@ -171,10 +182,10 @@ if (platform == 'windows') { // process.exit(1); } - // Setup FFMPEG - if (!(await fs.exists(config.ffmpegRealname))) { - await $`${wgetPath} -nc --no-check-certificate --show-progress ${config.windows.ffmpegUrl} -O ${config.windows.ffmpegName}.7z` + const is7zipInstalled = await isInstalled("7z"); + if (!(await fs.exists(config.ffmpegRealname)) && is7zipInstalled) { + await $`${wgetPath} -O -nc --no-check-certificate --show-progress ${config.windows.ffmpegUrl} -O ${config.windows.ffmpegName}.7z` await $`'C:\\Program Files\\7-Zip\\7z.exe' x ${config.windows.ffmpegName}.7z` await $`mv ${config.windows.ffmpegName} ${config.ffmpegRealname}` await $`rm -rf ${config.windows.ffmpegName}.7z` @@ -188,7 +199,7 @@ if (platform == 'windows') { if (!(await fs.exists('tesseract'))) { console.log('Setting up Tesseract for Windows...') - await $`${wgetPath} -nc --no-check-certificate --show-progress ${tesseractUrl} -O ${tesseractInstaller}` + await $`${wgetPath} -O -nc --no-check-certificate --show-progress ${tesseractUrl} -O ${tesseractInstaller}` await $`"${process.cwd()}\\${tesseractInstaller}" /S /D=C:\\Program Files\\Tesseract-OCR` await $`rm ${tesseractInstaller}` // Replace the mv command with xcopy @@ -204,12 +215,13 @@ if (platform == 'windows') { process.env.PATH = `${process.cwd()}\\tesseract;${process.env.PATH}` // Setup ONNX Runtime + const isUnzipInstalled = await isInstalled("unzip"); const onnxRuntimeName = "onnxruntime-win-x64-gpu-1.19.2"; const onnxRuntimeLibs = `${onnxRuntimeName}.zip`; const onnxRuntimeUrl = `https://github.com/microsoft/onnxruntime/releases/download/v1.19.2/${onnxRuntimeLibs}` - if (!(await fs.exists(onnxRuntimeName))) { + if (!(await fs.exists(onnxRuntimeName)) && isUnzipInstalled) { console.log('Setting up ONNX Runtime libraries for Windows...') - await $`${wgetPath} -nc --no-check-certificate --show-progress ${onnxRuntimeUrl} -O ${onnxRuntimeLibs}` + await $`${wgetPath} -O -nc --no-check-certificate --show-progress ${onnxRuntimeUrl} -O ${onnxRuntimeLibs}` await $`unzip ${onnxRuntimeLibs} || tar -xf ${onnxRuntimeLibs} || echo "Done extracting"`; await $`rm -rf ${onnxRuntimeLibs} || rm ${onnxRuntimeLibs} -Recurse -Force || echo "Done cleaning up zip"`; console.log('ONNX Runtime libraries for Windows set up successfully.') @@ -219,7 +231,7 @@ if (platform == 'windows') { // Setup OpenBlas if (!(await fs.exists(config.openblasRealname)) && hasFeature('openblas')) { - await $`${wgetPath} -nc --show-progress ${config.windows.openBlasUrl} -O ${config.windows.openBlasName}.zip` + await $`${wgetPath} -O -nc --show-progress ${config.windows.openBlasUrl} -O ${config.windows.openBlasName}.zip` await $`"C:\\Program Files\\7-Zip\\7z.exe" x ${config.windows.openBlasName}.zip -o${config.openblasRealname}` await $`rm ${config.windows.openBlasName}.zip` fs.cp(path.join(config.openblasRealname, 'include'), path.join(config.openblasRealname, 'lib'), { recursive: true, force: true }) @@ -229,7 +241,7 @@ if (platform == 'windows') { // Setup CLBlast if (!(await fs.exists(config.clblastRealname)) && !hasFeature('cuda')) { - await $`${wgetPath} -nc --show-progress ${config.windows.clblastUrl} -O ${config.windows.clblastName}.zip` + await $`${wgetPath} -O -nc --show-progress ${config.windows.clblastUrl} -O ${config.windows.clblastName}.zip` await $`"C:\\Program Files\\7-Zip\\7z.exe" x ${config.windows.clblastName}.zip` // 7z file inside await $`"C:\\Program Files\\7-Zip\\7z.exe" x ${config.windows.clblastName}.7z` // Inner folder await $`mv ${config.windows.clblastName} ${config.clblastRealname}` @@ -237,8 +249,13 @@ if (platform == 'windows') { await $`rm ${config.windows.clblastName}.7z` } - // Setup vcpkg packages - await $`C:\\vcpkg\\vcpkg.exe install ${config.windows.vcpkgPackages}`.quiet() + // Setup vcpkg packages, requires VCPKG_ROOT env var + try { + await $`C:\\vcpkg\\vcpkg.exe install ${config.windows.vcpkgPackages}` + } catch (error) { + await $`vcpkg.exe install ${config.windows.vcpkgPackages}` + } + } async function getMostRecentBinaryPath(targetArch, paths) { From 36a22a11bac544717bc611ccb007ace702b41533 Mon Sep 17 00:00:00 2001 From: tribhuwan-kumar Date: Sat, 28 Sep 2024 00:23:15 +0530 Subject: [PATCH 2/5] fix: use H.264 video encoding in all platforms including windows --- screenpipe-server/src/video.rs | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/screenpipe-server/src/video.rs b/screenpipe-server/src/video.rs index 9ebd3f1cf..c0833f834 100644 --- a/screenpipe-server/src/video.rs +++ b/screenpipe-server/src/video.rs @@ -355,21 +355,8 @@ async fn start_ffmpeg_process(output_file: &str, fps: f64) -> Result Date: Sat, 28 Sep 2024 14:08:31 +0530 Subject: [PATCH 3/5] fix: pre_build.js for getting exe paths dynamically in windows & add --continue option in wget --- screenpipe-app-tauri/scripts/pre_build.js | 91 +++++++++++++---------- 1 file changed, 50 insertions(+), 41 deletions(-) diff --git a/screenpipe-app-tauri/scripts/pre_build.js b/screenpipe-app-tauri/scripts/pre_build.js index 6a2fb2540..d00200828 100644 --- a/screenpipe-app-tauri/scripts/pre_build.js +++ b/screenpipe-app-tauri/scripts/pre_build.js @@ -63,28 +63,28 @@ const config = { }, } -async function findWget() { - const possiblePaths = [ - 'C:\\ProgramData\\chocolatey\\bin\\wget.exe', - 'C:\\Program Files\\Git\\mingw64\\bin\\wget.exe', - 'C:\\msys64\\usr\\bin\\wget.exe', - 'C:\\Windows\\System32\\wget.exe', - 'wget' // This will work if wget is in PATH - ]; - - for (const wgetPath of possiblePaths) { - try { - await $`${wgetPath} --version`.quiet(); - console.log(`wget found at: ${wgetPath}`); - return wgetPath; - } catch (error) { - // wget not found at this path, continue searching - } - } - - console.error('wget not found. Please install wget and make sure it\'s in your PATH.'); - process.exit(1); -} +// async function findWget() { +// const possiblePaths = [ +// 'C:\\ProgramData\\chocolatey\\bin\\wget.exe', +// 'C:\\Program Files\\Git\\mingw64\\bin\\wget.exe', +// 'C:\\msys64\\usr\\bin\\wget.exe', +// 'C:\\Windows\\System32\\wget.exe', +// 'wget' // This will work if wget is in PATH +// ]; +// +// for (const wgetPath of possiblePaths) { +// try { +// await $`${wgetPath} --version`.quiet(); +// console.log(`wget found at: ${wgetPath}`); +// return wgetPath; +// } catch (error) { +// // wget not found at this path, continue searching +// } +// } +// +// console.error('wget not found. Please install wget and make sure it\'s in your PATH.'); +// process.exit(1); +// } // Export for Github actions const exports = { @@ -141,17 +141,25 @@ if (platform == 'linux') { /* ########## Windows ########## */ if (platform == 'windows') { - async function isInstalled(command) { + const childProcess = require('child_process'); + async function exePath(command) { try { - await $`powershell -Command "Get-Command ${command} -ErrorAction Stop"`; - return true; - } catch { + const result = childProcess.execSync(`where.exe ${command}`, { encoding: "utf-8" }); + let output = result.trim() + if (output.length > 0 && !output.startsWith('INFO: Could not find')) { + const lines = output.split('\n'); + const executablePath = lines[0].replace(/^\s+|\s+$/gm, '').trim(); + return executablePath; + } else { + throw new Error('Command not found'); + } + } catch (error) { console.log(`${command} not found, Please install it`) - return false; + return null; } } - const wgetPath = await findWget(); + const wgetPath = await exePath("wget"); console.log('Copying screenpipe binary...'); @@ -182,11 +190,12 @@ if (platform == 'windows') { // process.exit(1); } + const sevenZipPath = await exePath("7z"); + // Setup FFMPEG - const is7zipInstalled = await isInstalled("7z"); - if (!(await fs.exists(config.ffmpegRealname)) && is7zipInstalled) { - await $`${wgetPath} -O -nc --no-check-certificate --show-progress ${config.windows.ffmpegUrl} -O ${config.windows.ffmpegName}.7z` - await $`'C:\\Program Files\\7-Zip\\7z.exe' x ${config.windows.ffmpegName}.7z` + if (!(await fs.exists(config.ffmpegRealname)) && sevenZipPath) { + await $`'${wgetPath}' -O -nc --continue --no-check-certificate --show-progress ${config.windows.ffmpegUrl} -O ${config.windows.ffmpegName}.7z` + await $`'${sevenZipPath}' x ${config.windows.ffmpegName}.7z` await $`mv ${config.windows.ffmpegName} ${config.ffmpegRealname}` await $`rm -rf ${config.windows.ffmpegName}.7z` await $`mv ${config.ffmpegRealname}/lib/x64/* ${config.ffmpegRealname}/lib/` @@ -199,7 +208,7 @@ if (platform == 'windows') { if (!(await fs.exists('tesseract'))) { console.log('Setting up Tesseract for Windows...') - await $`${wgetPath} -O -nc --no-check-certificate --show-progress ${tesseractUrl} -O ${tesseractInstaller}` + await $`'${wgetPath}' -O -nc --continue --no-check-certificate --show-progress ${tesseractUrl} -O ${tesseractInstaller}` await $`"${process.cwd()}\\${tesseractInstaller}" /S /D=C:\\Program Files\\Tesseract-OCR` await $`rm ${tesseractInstaller}` // Replace the mv command with xcopy @@ -215,13 +224,13 @@ if (platform == 'windows') { process.env.PATH = `${process.cwd()}\\tesseract;${process.env.PATH}` // Setup ONNX Runtime - const isUnzipInstalled = await isInstalled("unzip"); + const unzipPath = await exePath("unzip"); const onnxRuntimeName = "onnxruntime-win-x64-gpu-1.19.2"; const onnxRuntimeLibs = `${onnxRuntimeName}.zip`; const onnxRuntimeUrl = `https://github.com/microsoft/onnxruntime/releases/download/v1.19.2/${onnxRuntimeLibs}` - if (!(await fs.exists(onnxRuntimeName)) && isUnzipInstalled) { + if (!(await fs.exists(onnxRuntimeName)) && unzipPath) { console.log('Setting up ONNX Runtime libraries for Windows...') - await $`${wgetPath} -O -nc --no-check-certificate --show-progress ${onnxRuntimeUrl} -O ${onnxRuntimeLibs}` + await $`'${wgetPath}' -O -nc --continue --no-check-certificate --show-progress ${onnxRuntimeUrl} -O ${onnxRuntimeLibs}` await $`unzip ${onnxRuntimeLibs} || tar -xf ${onnxRuntimeLibs} || echo "Done extracting"`; await $`rm -rf ${onnxRuntimeLibs} || rm ${onnxRuntimeLibs} -Recurse -Force || echo "Done cleaning up zip"`; console.log('ONNX Runtime libraries for Windows set up successfully.') @@ -231,8 +240,8 @@ if (platform == 'windows') { // Setup OpenBlas if (!(await fs.exists(config.openblasRealname)) && hasFeature('openblas')) { - await $`${wgetPath} -O -nc --show-progress ${config.windows.openBlasUrl} -O ${config.windows.openBlasName}.zip` - await $`"C:\\Program Files\\7-Zip\\7z.exe" x ${config.windows.openBlasName}.zip -o${config.openblasRealname}` + await $`'${wgetPath}' -O -nc --continue --show-progress ${config.windows.openBlasUrl} -O ${config.windows.openBlasName}.zip` + await $`${sevenZipPath} x ${config.windows.openBlasName}.zip -o${config.openblasRealname}` await $`rm ${config.windows.openBlasName}.zip` fs.cp(path.join(config.openblasRealname, 'include'), path.join(config.openblasRealname, 'lib'), { recursive: true, force: true }) // It tries to link only openblas.lib but our is libopenblas.lib` @@ -241,9 +250,9 @@ if (platform == 'windows') { // Setup CLBlast if (!(await fs.exists(config.clblastRealname)) && !hasFeature('cuda')) { - await $`${wgetPath} -O -nc --show-progress ${config.windows.clblastUrl} -O ${config.windows.clblastName}.zip` - await $`"C:\\Program Files\\7-Zip\\7z.exe" x ${config.windows.clblastName}.zip` // 7z file inside - await $`"C:\\Program Files\\7-Zip\\7z.exe" x ${config.windows.clblastName}.7z` // Inner folder + await $`'${wgetPath}' -O -nc --continue --show-progress ${config.windows.clblastUrl} -O ${config.windows.clblastName}.zip` + await $`'${sevenZipPath}' x ${config.windows.clblastName}.zip` // 7z file inside + await $`'${sevenZipPath}' x ${config.windows.clblastName}.7z` // Inner folder await $`mv ${config.windows.clblastName} ${config.clblastRealname}` await $`rm ${config.windows.clblastName}.zip` await $`rm ${config.windows.clblastName}.7z` From e8f21b4c6e8bbd1abe32eba5fd6294f688a7aac1 Mon Sep 17 00:00:00 2001 From: tribhuwan-kumar Date: Sat, 28 Sep 2024 14:12:40 +0530 Subject: [PATCH 4/5] fix: use h264_mf format for windows, its available in avbuild ffmpeg --- screenpipe-server/src/video.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/screenpipe-server/src/video.rs b/screenpipe-server/src/video.rs index c0833f834..0e040ca0c 100644 --- a/screenpipe-server/src/video.rs +++ b/screenpipe-server/src/video.rs @@ -355,8 +355,21 @@ async fn start_ffmpeg_process(output_file: &str, fps: f64) -> Result Date: Sat, 28 Sep 2024 14:55:25 +0530 Subject: [PATCH 5/5] fix: remove findWget() func. from pre_build.js --- screenpipe-app-tauri/scripts/pre_build.js | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/screenpipe-app-tauri/scripts/pre_build.js b/screenpipe-app-tauri/scripts/pre_build.js index d00200828..89a5c1a3a 100644 --- a/screenpipe-app-tauri/scripts/pre_build.js +++ b/screenpipe-app-tauri/scripts/pre_build.js @@ -63,29 +63,6 @@ const config = { }, } -// async function findWget() { -// const possiblePaths = [ -// 'C:\\ProgramData\\chocolatey\\bin\\wget.exe', -// 'C:\\Program Files\\Git\\mingw64\\bin\\wget.exe', -// 'C:\\msys64\\usr\\bin\\wget.exe', -// 'C:\\Windows\\System32\\wget.exe', -// 'wget' // This will work if wget is in PATH -// ]; -// -// for (const wgetPath of possiblePaths) { -// try { -// await $`${wgetPath} --version`.quiet(); -// console.log(`wget found at: ${wgetPath}`); -// return wgetPath; -// } catch (error) { -// // wget not found at this path, continue searching -// } -// } -// -// console.error('wget not found. Please install wget and make sure it\'s in your PATH.'); -// process.exit(1); -// } - // Export for Github actions const exports = { ffmpeg: path.join(cwd, config.ffmpegRealname),