From 604746c812762a4845fb156bff0463e2477ee32e Mon Sep 17 00:00:00 2001 From: Vincent de Saboulin Date: Wed, 10 Nov 2021 17:52:58 +0100 Subject: [PATCH] Fix permissions automatically #540 --- spotify-mini-player/src/action.php | 39 ++-------------------- spotify-mini-player/src/functions.php | 39 +++++++++++++++++++++- spotify-mini-player/src/refreshLibrary.php | 2 ++ 3 files changed, 42 insertions(+), 38 deletions(-) diff --git a/spotify-mini-player/src/action.php b/spotify-mini-player/src/action.php index 7ea1514b..7ff092e1 100644 --- a/spotify-mini-player/src/action.php +++ b/spotify-mini-player/src/action.php @@ -980,46 +980,11 @@ function main($query, $type, $add_to_option) return; } elseif ($other_action == 'fix_permissions') { - logMsg($w, "Info(fix_permissions) is called"); - // check for quarantine and remove it if required - exec('/usr/bin/xattr ./fzf', $response); - foreach ($response as $line) { - if (strpos($line, 'com.apple.quarantine') !== false) { - logMsg($w, "Info(fix_permissions) for fzf"); - exec('/usr/bin/xattr -d com.apple.quarantine ./fzf', $response); - break; - } - } - - // check for quarantine and remove it if required - exec('/usr/bin/xattr ./terminal-notifier.app', $response); - foreach ($response as $line) { - if (strpos($line, 'com.apple.quarantine') !== false) { - logMsg($w, "Info(fix_permissions) for terminal-notifier"); - exec('/usr/bin/xattr -d com.apple.quarantine ./terminal-notifier.app', $response); - break; - } - } - - exec('/usr/bin/xattr "' . './App/' . $theme_color . '/Spotify Mini Player.app' . '"', $response); - foreach ($response as $line) { - if (strpos($line, 'com.apple.quarantine') !== false) { - logMsg($w, "Info(fix_permissions) for Spotify Mini Player"); - exec('/usr/bin/xattr -d com.apple.quarantine "' . './App/' . $theme_color . '/Spotify Mini Player.app' . '"', $response); - break; - } - } + fixPermissions($w); displayNotificationWithArtwork($w, 'Done', './images/debug.png', 'Fix permissions'); return; } elseif ($other_action == 'enable_fuzzy_search') { - // check for quarantine and remove it if required - exec('/usr/bin/xattr ./fzf',$response); - foreach($response as $line) { - if (strpos($line, 'com.apple.quarantine') !== false) { - exec('/usr/bin/xattr -d com.apple.quarantine ./fzf',$response); - exit; - } - } + fixPermissions($w); $ret = updateSetting($w, 'fuzzy_search', 1); if ($ret == true) { displayNotificationWithArtwork($w, 'Fuzzy search is now enabled', './images/search.png', 'Settings'); diff --git a/spotify-mini-player/src/functions.php b/spotify-mini-player/src/functions.php index 048f4d06..68250d08 100644 --- a/spotify-mini-player/src/functions.php +++ b/spotify-mini-player/src/functions.php @@ -5,6 +5,43 @@ require_once './src/refreshLibrary.php'; require './vendor/autoload.php'; +/** + * fixPermissions function. + * + */ +function fixPermissions($w) +{ + $theme_color = getSetting($w, 'theme_color'); + + // check for quarantine and remove it if required + exec('/usr/bin/xattr ./fzf', $response); + foreach ($response as $line) { + if (strpos($line, 'com.apple.quarantine') !== false) { + logMsg($w, "Info(fix_permissions) for fzf"); + exec('/usr/bin/xattr -d com.apple.quarantine ./fzf', $response); + break; + } + } + + // check for quarantine and remove it if required + exec('/usr/bin/xattr ./terminal-notifier.app', $response); + foreach ($response as $line) { + if (strpos($line, 'com.apple.quarantine') !== false) { + logMsg($w, "Info(fix_permissions) for terminal-notifier"); + exec('/usr/bin/xattr -d com.apple.quarantine ./terminal-notifier.app', $response); + break; + } + } + + exec('/usr/bin/xattr "' . './App/' . $theme_color . '/Spotify Mini Player.app' . '"', $response); + foreach ($response as $line) { + if (strpos($line, 'com.apple.quarantine') !== false) { + logMsg($w, "Info(fix_permissions) for Spotify Mini Player"); + exec('/usr/bin/xattr -d com.apple.quarantine "' . './App/' . $theme_color . '/Spotify Mini Player.app' . '"', $response); + break; + } + } +} /** * getExternalSettings function. @@ -7878,7 +7915,7 @@ function checkForUpdate($w, $last_check_update_time, $download = false) // update workflow_version updateSetting($w, 'workflow_version', ''.$local_version); stathat_ez_count('AlfredSpotifyMiniPlayer', 'workflow_installations', 1); - + fixPermissions($w); // open SpotifyMiniPlayer.app for notifications exec('open "'.'./App/'.$theme_color.'/Spotify Mini Player.app'.'"',$response); } diff --git a/spotify-mini-player/src/refreshLibrary.php b/spotify-mini-player/src/refreshLibrary.php index ed794001..0bf36da6 100644 --- a/spotify-mini-player/src/refreshLibrary.php +++ b/spotify-mini-player/src/refreshLibrary.php @@ -15,6 +15,8 @@ function refreshLibrary($w, $silent = false) { return; } + fixPermissions($w); + $update_type = 'Refresh Library'; if (file_exists($w->data() . '/create_library')) { $update_type = 'Create Library';