-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
gui: Add partial sync configuration button (#2174)
We add a button in the `Preferences` tab of the main window to open the partial synchronization configuration for the Desktop's OAuth client within the remote Cozy Settings app. It will be opened in the user's own Web browser for 2 reasons: 1. it clearly shows the configuration can be done from the Settings Web app and thus any computer 2. the user is more likely to be logged into their Cozy in their own browser and thus not be required to log in again to configure the Desktop's partial synchronization The button will only be shown if the `settings.partial-desktop-sync.show-synced-folders-selection` flag is enabled (either in the local configuration or on the remote Cozy).
- Loading branch information
Showing
19 changed files
with
245 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
port module Data.SyncConfig exposing (SyncConfig, buildAppUrl, gotSyncConfig, init) | ||
|
||
import Url exposing (Url) | ||
|
||
|
||
type alias SyncConfig = | ||
{ address : Maybe Url | ||
, capabilities : | ||
{ flatSubdomains : Bool | ||
} | ||
, deviceId : String | ||
, deviceName : String | ||
, flags : | ||
{ partialSyncEnabled : Bool | ||
} | ||
} | ||
|
||
|
||
init : SyncConfig | ||
init = | ||
{ address = Nothing | ||
, capabilities = | ||
{ flatSubdomains = True | ||
} | ||
, deviceId = "" | ||
, deviceName = "" | ||
, flags = | ||
{ partialSyncEnabled = False | ||
} | ||
} | ||
|
||
|
||
type alias AppSlug = | ||
String | ||
|
||
|
||
buildAppUrl : SyncConfig -> AppSlug -> Maybe Url | ||
buildAppUrl { address, capabilities } slug = | ||
let | ||
cozyName = | ||
case address of | ||
Just url -> | ||
String.split "." url.host | ||
|> List.head | ||
|> Maybe.withDefault "" | ||
|
||
_ -> | ||
"" | ||
|
||
host = | ||
case ( address, capabilities.flatSubdomains ) of | ||
( Just url, True ) -> | ||
String.replace cozyName (cozyName ++ "-" ++ slug) url.host | ||
|
||
( Just url, False ) -> | ||
String.join "." [ slug, url.host ] | ||
|
||
( _, _ ) -> | ||
"" | ||
in | ||
Maybe.map | ||
(\url -> | ||
{ protocol = url.protocol | ||
, host = host | ||
, port_ = url.port_ | ||
, path = "" | ||
, query = Nothing | ||
, fragment = Nothing | ||
} | ||
) | ||
address | ||
|
||
|
||
|
||
-- Communicate through ports | ||
|
||
|
||
port syncConfig : (EncodedSyncConfig -> msg) -> Sub msg | ||
|
||
|
||
gotSyncConfig : (SyncConfig -> msg) -> Sub msg | ||
gotSyncConfig msg = | ||
syncConfig (msg << decode) | ||
|
||
|
||
type alias EncodedSyncConfig = | ||
{ address : String | ||
, capabilities : | ||
{ flatSubdomains : Bool | ||
} | ||
, deviceId : String | ||
, deviceName : String | ||
, flags : | ||
{ partialSyncEnabled : Bool | ||
} | ||
} | ||
|
||
|
||
decode : EncodedSyncConfig -> SyncConfig | ||
decode { address, capabilities, deviceId, deviceName, flags } = | ||
{ address = Url.fromString address | ||
, capabilities = capabilities | ||
, deviceId = deviceId | ||
, deviceName = deviceName | ||
, flags = flags | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module Util.Conditional exposing (viewIf) | ||
|
||
import Html exposing (Html, text) | ||
|
||
|
||
viewIf : Bool -> Html msg -> Html msg | ||
viewIf condition content = | ||
if condition then | ||
content | ||
|
||
else | ||
text "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.