From 9adff6e6be001f3f5ab4b76023370ed5fc042ada Mon Sep 17 00:00:00 2001 From: Danglewood <85772166+deeleeramone@users.noreply.github.com> Date: Fri, 17 Oct 2025 18:34:24 -0700 Subject: [PATCH] undo fix_dylib change and attempt to handle restart on update --- .github/workflows/build-desktop-osx64.yml | 62 --------------------- .github/workflows/build-desktop-osxARM.yml | 61 --------------------- desktop/src-tauri/scripts/fix_dylibs.sh | 63 +++++++++++----------- desktop/src-tauri/src/main.rs | 22 +++++++- 4 files changed, 51 insertions(+), 157 deletions(-) diff --git a/.github/workflows/build-desktop-osx64.yml b/.github/workflows/build-desktop-osx64.yml index 64173acfd29..dfb4a032a77 100644 --- a/.github/workflows/build-desktop-osx64.yml +++ b/.github/workflows/build-desktop-osx64.yml @@ -37,43 +37,6 @@ jobs: p12-file-base64: ${{ secrets.MACOS_CERTIFICATE }} p12-password: ${{ secrets.MACOS_CERTIFICATE_PWD }} - - name: Install OpenSSL - run: brew install openssl - - - name: Copy and Sign SSL dylibs - run: | - mkdir -p src-tauri/frameworks - OPENSSL_PREFIX=$(brew --prefix openssl@3) - - # Verify files exist before copying - if [ ! -f "${OPENSSL_PREFIX}/lib/libcrypto.3.dylib" ]; then - echo "Error: libcrypto.3.dylib not found at ${OPENSSL_PREFIX}/lib/" - exit 1 - fi - if [ ! -f "${OPENSSL_PREFIX}/lib/libssl.3.dylib" ]; then - echo "Error: libssl.3.dylib not found at ${OPENSSL_PREFIX}/lib/" - exit 1 - fi - - cp "${OPENSSL_PREFIX}/lib/libcrypto.3.dylib" src-tauri/frameworks/ - cp "${OPENSSL_PREFIX}/lib/libssl.3.dylib" src-tauri/frameworks/ - - codesign --force --sign "Developer ID Application" \ - --timestamp \ - --options runtime \ - src-tauri/frameworks/libcrypto.3.dylib - - codesign --force --sign "Developer ID Application" \ - --timestamp \ - --options runtime \ - src-tauri/frameworks/libssl.3.dylib - - # Verify signatures - codesign --verify --verbose=4 --deep --strict src-tauri/frameworks/libcrypto.3.dylib - codesign --verify --verbose=4 --deep --strict src-tauri/frameworks/libssl.3.dylib - - echo "Successfully copied and signed SSL dylibs" - - name: Setup Cargo Cache uses: actions/cache@v4 with: @@ -130,31 +93,6 @@ jobs: TAURI_SIGNING_PRIVATE_KEY_PASSWORD: ${{ secrets.TAURI_SIGNING_PRIVATE_KEY_PASSWORD }} run: npm run tauri build - - name: Re-sign bundled SSL dylibs after bundling - run: | - FRAMEWORKS_DIR="target/release/bundle/macos/Open Data Platform.app/Contents/Frameworks" - - if [ -f "$FRAMEWORKS_DIR/libcrypto.3.dylib" ]; then - codesign --force --sign "Developer ID Application" \ - --timestamp \ - --options runtime \ - "$FRAMEWORKS_DIR/libcrypto.3.dylib" - - codesign --verify --verbose=4 --deep --strict "$FRAMEWORKS_DIR/libcrypto.3.dylib" - echo "Re-signed libcrypto.3.dylib in bundle" - fi - - if [ -f "$FRAMEWORKS_DIR/libssl.3.dylib" ]; then - codesign --force --sign "Developer ID Application" \ - --timestamp \ - --options runtime \ - "$FRAMEWORKS_DIR/libssl.3.dylib" - - codesign --verify --verbose=4 --deep --strict "$FRAMEWORKS_DIR/libssl.3.dylib" - echo "Re-signed libssl.3.dylib in bundle" - fi - - - name: Rename artifacts run: | VERSION=$(jq -r .version src-tauri/tauri.conf.json) diff --git a/.github/workflows/build-desktop-osxARM.yml b/.github/workflows/build-desktop-osxARM.yml index 411b8c2caa4..1053a4f213c 100644 --- a/.github/workflows/build-desktop-osxARM.yml +++ b/.github/workflows/build-desktop-osxARM.yml @@ -37,43 +37,6 @@ jobs: p12-file-base64: ${{ secrets.MACOS_CERTIFICATE }} p12-password: ${{ secrets.MACOS_CERTIFICATE_PWD }} - - name: Install OpenSSL - run: brew install openssl - - - name: Copy and Sign SSL dylibs - run: | - mkdir -p src-tauri/frameworks - OPENSSL_PREFIX=$(brew --prefix openssl@3) - - # Verify files exist before copying - if [ ! -f "${OPENSSL_PREFIX}/lib/libcrypto.3.dylib" ]; then - echo "Error: libcrypto.3.dylib not found at ${OPENSSL_PREFIX}/lib/" - exit 1 - fi - if [ ! -f "${OPENSSL_PREFIX}/lib/libssl.3.dylib" ]; then - echo "Error: libssl.3.dylib not found at ${OPENSSL_PREFIX}/lib/" - exit 1 - fi - - cp "${OPENSSL_PREFIX}/lib/libcrypto.3.dylib" src-tauri/frameworks/ - cp "${OPENSSL_PREFIX}/lib/libssl.3.dylib" src-tauri/frameworks/ - - codesign --force --sign "Developer ID Application" \ - --timestamp \ - --options runtime \ - src-tauri/frameworks/libcrypto.3.dylib - - codesign --force --sign "Developer ID Application" \ - --timestamp \ - --options runtime \ - src-tauri/frameworks/libssl.3.dylib - - # Verify signatures - codesign --verify --verbose=4 --deep --strict src-tauri/frameworks/libcrypto.3.dylib - codesign --verify --verbose=4 --deep --strict src-tauri/frameworks/libssl.3.dylib - - echo "Successfully copied and signed SSL dylibs" - - name: Setup Cargo Cache uses: actions/cache@v4 with: @@ -131,30 +94,6 @@ jobs: TAURI_SIGNING_PRIVATE_KEY_PASSWORD: ${{ secrets.TAURI_SIGNING_PRIVATE_KEY_PASSWORD }} run: npm run tauri build - - name: Re-sign bundled SSL dylibs after bundling - run: | - FRAMEWORKS_DIR="target/release/bundle/macos/Open Data Platform.app/Contents/Frameworks" - - if [ -f "$FRAMEWORKS_DIR/libcrypto.3.dylib" ]; then - codesign --force --sign "Developer ID Application" \ - --timestamp \ - --options runtime \ - "$FRAMEWORKS_DIR/libcrypto.3.dylib" - - codesign --verify --verbose=4 --deep --strict "$FRAMEWORKS_DIR/libcrypto.3.dylib" - echo "Re-signed libcrypto.3.dylib in bundle" - fi - - if [ -f "$FRAMEWORKS_DIR/libssl.3.dylib" ]; then - codesign --force --sign "Developer ID Application" \ - --timestamp \ - --options runtime \ - "$FRAMEWORKS_DIR/libssl.3.dylib" - - codesign --verify --verbose=4 --deep --strict "$FRAMEWORKS_DIR/libssl.3.dylib" - echo "Re-signed libssl.3.dylib in bundle" - fi - - name: Rename artifacts run: | VERSION=$(jq -r .version src-tauri/tauri.conf.json) diff --git a/desktop/src-tauri/scripts/fix_dylibs.sh b/desktop/src-tauri/scripts/fix_dylibs.sh index e21da5866c6..333e22e557c 100644 --- a/desktop/src-tauri/scripts/fix_dylibs.sh +++ b/desktop/src-tauri/scripts/fix_dylibs.sh @@ -1,6 +1,8 @@ set -ex +# Determine the absolute path of the directory containing this script SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +# Determine the project root directory, which is two levels above src-tauri/scripts PROJECT_ROOT="$SCRIPT_DIR/../.." if [ "$TAURI_ENV_DEBUG" = "true" ]; then @@ -9,56 +11,51 @@ else PROFILE="release" fi -# Fix dylibs for the main binary +# --- Step 1: Fix dylibs for the main binary of the current profile --- BIN_PATH="$PROJECT_ROOT/target/$PROFILE/openbb-platform" if [ ! -f "$BIN_PATH" ]; then - echo "Binary not found at $BIN_PATH" + echo "Error: Main binary not found at $BIN_PATH" exit 1 fi LIBCRYPTO_PATH=$(otool -L "$BIN_PATH" | grep 'libcrypto.3.dylib' | awk '{print $1}') LIBSSL_PATH=$(otool -L "$BIN_PATH" | grep 'libssl.3.dylib' | awk '{print $1}') -# Fix main binary references install_name_tool -change \ - "$LIBCRYPTO_PATH" \ - "@executable_path/../Frameworks/libcrypto.3.dylib" \ - "$BIN_PATH" +"$LIBCRYPTO_PATH" \ +"@executable_path/../Frameworks/libcrypto.3.dylib" \ +"$BIN_PATH" install_name_tool -change \ - "$LIBSSL_PATH" \ - "@executable_path/../Frameworks/libssl.3.dylib" \ - "$BIN_PATH" +"$LIBSSL_PATH" \ +"@executable_path/../Frameworks/libssl.3.dylib" \ +"$BIN_PATH" -echo "Fixed dylibs for $PROFILE binary." +echo "Successfully fixed dylibs for $PROFILE binary." -# Fix the bundled dylibs themselves -FRAMEWORKS_DIR="$PROJECT_ROOT/target/$PROFILE/bundle/macos/Open Data Platform.app/Contents/Frameworks" +# --- Step 2: If it's a debug build, copy the release binary into the .app's Resources folder --- +if [ "$PROFILE" = "debug" ]; then + echo "DEBUG BUILD DETECTED: Copying release binary to app bundle." -if [ -d "$FRAMEWORKS_DIR" ]; then - echo "Fixing bundled dylib references..." + # This is the source: the release binary that has already been built + RELEASE_BIN_SOURCE_PATH="$PROJECT_ROOT/target/release/openbb-platform" - # Fix libssl.3.dylib's reference to libcrypto.3.dylib - if [ -f "$FRAMEWORKS_DIR/libssl.3.dylib" ]; then - LIBSSL_CRYPTO_PATH=$(otool -L "$FRAMEWORKS_DIR/libssl.3.dylib" | grep 'libcrypto.3.dylib' | awk '{print $1}') + # This is the destination, inside the .app bundle that Tauri creates before this script runs + APP_RESOURCES_DIR="$PROJECT_ROOT/target/debug/bundle/macos/OpenBB Platform.app/Contents/Resources" + DEST_PATH="$APP_RESOURCES_DIR/openbb-platform-release" - install_name_tool -change \ - "$LIBSSL_CRYPTO_PATH" \ - "@loader_path/libcrypto.3.dylib" \ - "$FRAMEWORKS_DIR/libssl.3.dylib" - - # Fix the install name of libssl itself - install_name_tool -id "@rpath/libssl.3.dylib" "$FRAMEWORKS_DIR/libssl.3.dylib" - - echo "Fixed libssl.3.dylib" + # Verify source and destination exist + if [ ! -f "$RELEASE_BIN_SOURCE_PATH" ]; then + echo "Error: Release binary not found at $RELEASE_BIN_SOURCE_PATH. A release build must exist." + exit 1 + fi + if [ ! -d "$APP_RESOURCES_DIR" ]; then + echo "Error: App bundle resources directory not found at $APP_RESOURCES_DIR" + exit 1 fi - # Fix the install name of libcrypto - if [ -f "$FRAMEWORKS_DIR/libcrypto.3.dylib" ]; then - install_name_tool -id "@rpath/libcrypto.3.dylib" "$FRAMEWORKS_DIR/libcrypto.3.dylib" - echo "Fixed libcrypto.3.dylib" - fi + echo "Copying $RELEASE_BIN_SOURCE_PATH to $DEST_PATH" + cp "$RELEASE_BIN_SOURCE_PATH" "$DEST_PATH" + echo "Successfully copied release binary." fi - -echo "Successfully fixed all dylib references." diff --git a/desktop/src-tauri/src/main.rs b/desktop/src-tauri/src/main.rs index 0b7e56431ff..3df3c2e1aad 100644 --- a/desktop/src-tauri/src/main.rs +++ b/desktop/src-tauri/src/main.rs @@ -6,10 +6,13 @@ pub mod uninstall; pub mod utils; use std::path::Path; +use std::sync::Arc; +use std::sync::atomic::{AtomicBool, Ordering}; + use tauri::State; use tauri::menu::{CheckMenuItemBuilder, Menu, MenuItemBuilder}; use tauri::tray::TrayIconBuilder; -use tauri::{AppHandle, Manager, Runtime}; +use tauri::{AppHandle, Manager, RESTART_EXIT_CODE, Runtime}; use tauri_plugin_dialog::DialogExt; #[cfg(target_os = "windows")] @@ -808,6 +811,8 @@ fn main() { std::process::exit(1); }) .run(|app_handle, event| { + let is_restart_requested = Arc::new(AtomicBool::new(false)); + let is_restart_requested_clone = is_restart_requested.clone(); if let tauri::RunEvent::ExitRequested { api, .. } = event { log::debug!("Caught applicationWillTerminate event, running cleanup..."); api.prevent_exit(); @@ -820,10 +825,25 @@ fn main() { } #[cfg(target_os = "macos")] + { if let tauri::RunEvent::Reopen { .. } = event && let Some(window) = app_handle.get_webview_window("main") { let _ = window.show(); let _ = window.set_focus(); } + } + if let tauri::RunEvent::ExitRequested { code, ..} = event { + if code.unwrap() == RESTART_EXIT_CODE { + is_restart_requested.store(true, Ordering::SeqCst); + } + } + + if let tauri::RunEvent::Exit { .. } = event { + if is_restart_requested_clone.load(Ordering::SeqCst) { + app_handle.cleanup_before_exit(); + let env = app_handle.env(); + tauri::process::restart(&env); + } + } }); }