Skip to content
This repository has been archived by the owner on Aug 1, 2023. It is now read-only.

Commit

Permalink
Use osascript to display message on mac
Browse files Browse the repository at this point in the history
  • Loading branch information
Hiroto Shioi committed Oct 31, 2019
1 parent 27c929f commit 2beb6f3
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 5 deletions.
31 changes: 28 additions & 3 deletions cardano-launcher/app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ import qualified Prelude
import Data.IORef (newIORef, readIORef, writeIORef)
import Data.Text.Lazy.Builder (fromString, fromText)

import Distribution.System (OS (Windows), buildOS)
import Distribution.System (OS (Windows, OSX), buildOS)
import System.Environment (setEnv)
import System.Exit (exitWith)
import System.IO.Silently (hSilence)
import System.Process (waitForProcess, withCreateProcess, proc)

import Formatting (bprint, build, formatToString)
import Formatting.Buildable (Buildable (..))
Expand All @@ -40,7 +41,7 @@ import Cardano.Shell.Launcher (LoggingDependencies (..), TLSError,
walletRunnerProcess)
import Cardano.Shell.Update.Lib (UpdaterData (..),
runDefaultUpdateProcess)
import Control.Exception.Safe (throwM)
import Control.Exception.Safe (throwM, tryAny)


--------------------------------------------------------------------------------
Expand All @@ -49,7 +50,7 @@ import Control.Exception.Safe (throwM)

-- | Main function.
main :: IO ()
main = silence $ do
main = showErrorDarwin $ silence $ do

defaultConfigPath <- getDefaultConfigPath

Expand Down Expand Up @@ -277,3 +278,27 @@ silence :: IO a -> IO a
silence runAction = case buildOS of
Windows -> hSilence [stdout, stderr] runAction
_ -> runAction

showErrorDarwin :: IO a -> IO a
showErrorDarwin action = case buildOS of
OSX -> do
eVal <- tryAny action
case eVal of
Left err -> do
displayErrorDarwin (show err)
throwM err
Right val -> return val
_ -> action
where
displayErrorDarwin :: Text -> IO ()
displayErrorDarwin errorMessage = do
let displayProcess = proc "osascript" ["-e", toS (mkErrorMessage errorMessage)]
void $ withCreateProcess displayProcess (\ _ _ _ ph -> waitForProcess ph)
mkErrorMessage :: Text -> Text
mkErrorMessage errorMessage = mconcat
[ "display dialog "
, show (errorMessage :: Text)
, " buttons {\"Ok\"} "
, "default button 1 with title "
, show ("Cardano Launcher Error" :: Text)
]
Binary file added cardano-launcher/cardano-launcher
Binary file not shown.
1 change: 1 addition & 0 deletions cardano-launcher/cardano-launcher.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ executable cardano-launcher
, text
, silently
, Cabal
, process
-- cli
, optparse-applicative

Expand Down
7 changes: 5 additions & 2 deletions cardano-launcher/src/Cardano/Shell/Environment.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Cardano.Prelude
import Cardano.Shell.Template (substituteA)
import Data.Yaml (Value (..))
import System.Environment (lookupEnv)

import Prelude (Show(..))
-- | Substitute envrionment variable with value of its name.
--
-- @
Expand All @@ -33,7 +33,10 @@ expandVariable var = do
data SubstitutionError
= FailedToLookupEnv Text
-- ^ Failed to lookup environment variable
deriving (Eq, Show)
deriving (Eq)

instance Show SubstitutionError where
show (FailedToLookupEnv env) = "Failed to lookup environment variable: " <> toS env

-- | Given an Aeson 'Value', parse and substitute environment variables in all
-- 'String' objects.
Expand Down
1 change: 1 addition & 0 deletions nix/.stack.nix/cardano-launcher.nix

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2beb6f3

Please sign in to comment.