fix webapp opening in termux
Open real url not html shim since android and file:// urls is a nasty kettle of fish. This commit was sponsored by John Pellman on Patreon.
This commit is contained in:
parent
b0df331b4a
commit
9807e5bead
5 changed files with 40 additions and 27 deletions
|
@ -38,6 +38,7 @@ import Config
|
|||
import Utility.Gpg
|
||||
import qualified Remote.GCrypt as GCrypt
|
||||
import qualified Types.Remote
|
||||
import Utility.Android
|
||||
|
||||
import qualified Data.Text as T
|
||||
import qualified Data.Map as M
|
||||
|
@ -144,10 +145,6 @@ defaultRepositoryPath firstrun = do
|
|||
legit d = not <$> doesFileExist (d </> "git-annex")
|
||||
#endif
|
||||
|
||||
-- Detect when the Linux build is running on Android, eg in termux.
|
||||
osAndroid :: IO Bool
|
||||
osAndroid = ("Android" == ) <$> readProcess "uname" ["-o"]
|
||||
|
||||
newRepositoryForm :: FilePath -> Hamlet.Html -> MkMForm RepositoryPath
|
||||
newRepositoryForm defpath msg = do
|
||||
(pathRes, pathView) <- mreq (repositoryPathField True) (bfs "")
|
||||
|
|
|
@ -31,6 +31,7 @@ import qualified Annex
|
|||
import Config.Files
|
||||
import Upgrade
|
||||
import Annex.Version
|
||||
import Utility.Android
|
||||
|
||||
import Control.Concurrent
|
||||
import Control.Concurrent.STM
|
||||
|
@ -207,43 +208,42 @@ openBrowser mcmd htmlshim realurl outh errh = do
|
|||
|
||||
openBrowser' :: Maybe FilePath -> FilePath -> String -> Maybe Handle -> Maybe Handle -> IO ()
|
||||
#ifndef __ANDROID__
|
||||
openBrowser' mcmd htmlshim _realurl outh errh = runbrowser
|
||||
openBrowser' mcmd htmlshim realurl outh errh =
|
||||
ifM osAndroid
|
||||
{- Android does not support file:// urls well, but neither
|
||||
- is the security of the url in the process table important
|
||||
- there, so just use the real url. -}
|
||||
( runbrowser realurl
|
||||
, runbrowser (fileUrl htmlshim)
|
||||
)
|
||||
#else
|
||||
openBrowser' mcmd htmlshim realurl outh errh = do
|
||||
recordUrl url
|
||||
recordUrl realurl
|
||||
{- Android's `am` command does not work reliably across the
|
||||
- wide range of Android devices. Intead, FIFO should be set to
|
||||
- the filename of a fifo that we can write the URL to. -}
|
||||
v <- getEnv "FIFO"
|
||||
case v of
|
||||
Nothing -> runbrowser
|
||||
Nothing -> runbrowser realurl
|
||||
Just f -> void $ forkIO $ do
|
||||
fd <- openFd f WriteOnly Nothing defaultFileFlags
|
||||
void $ fdWrite fd url
|
||||
void $ fdWrite fd realurl
|
||||
closeFd fd
|
||||
#endif
|
||||
where
|
||||
p = case mcmd of
|
||||
Just c -> proc c [htmlshim]
|
||||
Nothing ->
|
||||
runbrowser url = do
|
||||
let p = case mcmd of
|
||||
Just c -> proc c [url]
|
||||
Nothing ->
|
||||
#ifndef mingw32_HOST_OS
|
||||
browserProc url
|
||||
browserProc url
|
||||
#else
|
||||
{- Windows hack to avoid using the full path,
|
||||
- which might contain spaces that cause problems
|
||||
- for browserProc. -}
|
||||
(browserProc (takeFileName htmlshim))
|
||||
{ cwd = Just (takeDirectory htmlshim) }
|
||||
{- Windows hack to avoid using the full path,
|
||||
- which might contain spaces that cause problems
|
||||
- for browserProc. -}
|
||||
(browserProc (takeFileName htmlshim))
|
||||
{ cwd = Just (takeDirectory htmlshim) }
|
||||
#endif
|
||||
#ifdef __ANDROID__
|
||||
{- Android does not support file:// urls, but neither is
|
||||
- the security of the url in the process table important
|
||||
- there, so just use the real url. -}
|
||||
url = realurl
|
||||
#else
|
||||
url = fileUrl htmlshim
|
||||
#endif
|
||||
runbrowser = do
|
||||
hPutStrLn (fromMaybe stdout outh) $ "Launching web browser on " ++ url
|
||||
hFlush stdout
|
||||
environ <- cleanEnvironment
|
||||
|
|
14
Utility/Android.hs
Normal file
14
Utility/Android.hs
Normal file
|
@ -0,0 +1,14 @@
|
|||
{- Android stuff
|
||||
-
|
||||
- Copyright 2018 Joey Hess <id@joeyh.name>
|
||||
-
|
||||
- License: BSD-2-clause
|
||||
-}
|
||||
|
||||
module Utility.Android where
|
||||
|
||||
import Common
|
||||
|
||||
-- Detect when the Linux build is running on Android, eg in termux.
|
||||
osAndroid :: IO Bool
|
||||
osAndroid = ("Android" == ) <$> readProcess "uname" ["-o"]
|
|
@ -21,11 +21,12 @@ The webapp is able to open an url (after I upgraded termux) via xdg-open
|
|||
chrome was not able to access, apparently a permissions problem. The
|
||||
webapp.html does not add any security on android, since it's not a
|
||||
multiuser unix system, and so it should open the url to the webapp
|
||||
directly.
|
||||
directly. (Done)
|
||||
|
||||
Accessing the sdcard may need termux-setup-storage to be run once,
|
||||
depending on the version of android. That sets up $HOME/storage.
|
||||
The webapp ought to default to making a repository somewhere in there.
|
||||
(Done)
|
||||
|
||||
webbapp won't start on boot, but could be made to using https://wiki.termux.com/wiki/Termux:Boot
|
||||
|
||||
|
|
|
@ -1000,6 +1000,7 @@ Executable git-annex
|
|||
Upgrade.V4
|
||||
Upgrade.V5
|
||||
Utility.Aeson
|
||||
Utility.Android
|
||||
Utility.Applicative
|
||||
Utility.AuthToken
|
||||
Utility.Base64
|
||||
|
|
Loading…
Reference in a new issue