From 0a4eb8417c379a70ea09c574241d392ecaf2ca6c Mon Sep 17 00:00:00 2001 From: Steven Vandevelde Date: Mon, 22 Feb 2021 15:14:52 +0100 Subject: [PATCH] Don't process sources while offline unless it's ipfs or local webdav --- src/Applications/UI/Sources/State.elm | 15 ++++++++++++- src/Library/Sources.elm | 31 +++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/src/Applications/UI/Sources/State.elm b/src/Applications/UI/Sources/State.elm index c27e17ca..f0beffe6 100644 --- a/src/Applications/UI/Sources/State.elm +++ b/src/Applications/UI/Sources/State.elm @@ -201,7 +201,20 @@ process model = Return.singleton model toProcess -> - processSpecific toProcess model + if model.isOnline then + processSpecific toProcess model + + else + toProcess + |> List.filter Sources.worksOffline + |> (\s -> + case s of + [] -> + Return.singleton model + + _ -> + processSpecific s model + ) processSpecific : List Source -> Manager diff --git a/src/Library/Sources.elm b/src/Library/Sources.elm index 530df661..70517280 100644 --- a/src/Library/Sources.elm +++ b/src/Library/Sources.elm @@ -92,3 +92,34 @@ enabledSourceIds = setProperId : Int -> Time.Posix -> Source -> Source setProperId n time source = { source | id = String.fromInt (Time.posixToMillis time) ++ String.fromInt n } + + +worksOffline : Source -> Bool +worksOffline source = + case source.service of + AmazonS3 -> + False + + AzureBlob -> + False + + AzureFile -> + False + + Btfs -> + True + + Dropbox -> + False + + Google -> + False + + Ipfs -> + True + + WebDav -> + source.data + |> Dict.get "url" + |> Maybe.map (\u -> String.contains "localhost" u || String.contains "127.0.0.1" u) + |> Maybe.withDefault False -- 2.51.2