diff --git a/Makefile b/Makefile index 1f287e8d..b8e9299d 100644 --- a/Makefile +++ b/Makefile @@ -66,9 +66,11 @@ install: @curl https://unpkg.com/3box@1.8.5/dist/3box.min.js -o $(VENDOR_DIR)/3box.min.js @curl https://unpkg.com/blockstack@19.2.1/dist/blockstack.js -o $(VENDOR_DIR)/blockstack.min.js @curl https://unpkg.com/lunr@2.3.6/lunr.js -o $(VENDOR_DIR)/lunr.js + @curl https://unpkg.com/inobounce@0.1.6/inobounce.min.js -o $(VENDOR_DIR)/inobounce.min.js @curl https://unpkg.com/remotestoragejs@1.2.2/release/remotestorage.js -o $(VENDOR_DIR)/remotestorage.min.js @curl https://unpkg.com/fast-text-encoding@1.0.0/text.min.js -o $(VENDOR_DIR)/text-encoding-polyfill.min.js @curl https://unpkg.com/tachyons@4.11.1/css/tachyons.min.css -o $(VENDOR_DIR)/tachyons.min.css + @curl https://unpkg.com/tocca@2.0.4/Tocca.min.js -o $(VENDOR_DIR)/tocca.min.js @# Non-NPM dependencies @curl https://raw.githubusercontent.com/icidasset/diffuse-musicmetadata/0ae8c854e18b6960b9f7e94b7eb47868416dc2ad/dist/musicmetadata.min.js -o $(VENDOR_DIR)/musicmetadata.min.js diff --git a/src/Applications/UI.elm b/src/Applications/UI.elm index 758f5f0f..715c8844 100644 --- a/src/Applications/UI.elm +++ b/src/Applications/UI.elm @@ -23,8 +23,9 @@ import File import File.Download import File.Select import Html.Events.Extra.Pointer as Pointer +import Html.Events.Extra.Touch as Touch import Html.Styled as Html exposing (Html, section, toUnstyled) -import Html.Styled.Attributes as Attributes exposing (css, id) +import Html.Styled.Attributes as Attributes exposing (css, id, style) import Html.Styled.Events exposing (onClick) import Html.Styled.Lazy as Lazy import Json.Decode @@ -116,6 +117,7 @@ init flags url key = , isDragging = False , isLoading = True , isOnline = flags.isOnline + , isTouchDevice = False , navKey = key , notifications = [] , page = page @@ -247,6 +249,9 @@ update msg model = , Cmd.none ) + IndicateTouchDevice -> + return { model | isTouchDevice = True } + StoppedDragging -> let notDragging = @@ -1224,6 +1229,9 @@ body model = , Attributes.fromUnstyled (Pointer.onUp <| always StoppedDragging) ] + else if not model.isTouchDevice then + [ Attributes.fromUnstyled (Touch.onStart <| always IndicateTouchDevice) ] + else [] ) @@ -1350,7 +1358,8 @@ defaultScreen model = content : List (Html msg) -> Html msg content = - chunk + brick + [ style "min-height" "calc(var(--vh, 1vh) * 100)" ] [ T.flex , T.flex_column , T.items_center @@ -1496,4 +1505,6 @@ vesselStyles = vesselInnerStyles : List Css.Style vesselInnerStyles = - [ Css.property "-webkit-mask-image" "-webkit-radial-gradient(white, black)" ] + [ Css.property "-webkit-mask-image" "-webkit-radial-gradient(white, black)" + , Css.property "-webkit-overflow-scrolling" "touch" + ] diff --git a/src/Applications/UI/Core.elm b/src/Applications/UI/Core.elm index 0a7fc361..4fe38a7f 100644 --- a/src/Applications/UI/Core.elm +++ b/src/Applications/UI/Core.elm @@ -51,6 +51,7 @@ type alias Model = , isDragging : Bool , isLoading : Bool , isOnline : Bool + , isTouchDevice : Bool , navKey : Nav.Key , notifications : List (Notification Msg) , page : Page @@ -96,6 +97,7 @@ type Msg | HideAlfred | HideContextMenu | HideOverlay + | IndicateTouchDevice | KeyboardMsg Keyboard.Msg | LoadEnclosedUserData Json.Value | LoadHypaethralUserData Json.Value diff --git a/src/Applications/UI/Equalizer.elm b/src/Applications/UI/Equalizer.elm index 807bade5..c4f2891a 100644 --- a/src/Applications/UI/Equalizer.elm +++ b/src/Applications/UI/Equalizer.elm @@ -6,6 +6,7 @@ import Color.Ext as Color import Common import Coordinates exposing (Coordinates) import Css +import Css.Ext as Css import Equalizer exposing (..) import Html.Events.Extra.Pointer as Pointer import Html.Styled exposing (Html, text) @@ -232,7 +233,8 @@ view model = ----------------------------------------- -- Content ----------------------------------------- - , chunk + , brick + [ css eqStyles ] [ T.relative ] [ chunk [ T.absolute, T.left_0, T.top_0 ] @@ -303,7 +305,12 @@ knob_ knobType value = -- , Html.Styled.Events.onDoubleClick (ResetKnob knobType) - , Html.Styled.Attributes.fromUnstyled <| Pointer.onDown (ActivateKnob knobType) + + -- + , knobType + |> ActivateKnob + |> Pointer.onDown + |> Html.Styled.Attributes.fromUnstyled ] [ T.br_100, T.center, T.pointer, T.relative ] [ Html.Styled.map never knob__ ] @@ -393,6 +400,11 @@ maxAngle = -- 🖼 +eqStyles : List Css.Style +eqStyles = + [ Css.disableUserSelection ] + + columnStyles : List Css.Style columnStyles = [ Css.borderRight3 (Css.px 1) Css.solid borderColor diff --git a/src/Applications/UI/Navigation.elm b/src/Applications/UI/Navigation.elm index cb5af1b7..ffbaedcc 100644 --- a/src/Applications/UI/Navigation.elm +++ b/src/Applications/UI/Navigation.elm @@ -128,12 +128,15 @@ localWithTabindex : Int -> List ( Icon msg, Label, Action msg ) -> Html msg localWithTabindex tabindex_ items = brick [ css localStyles ] - [ T.bb, T.flex ] - (items - |> List.reverse - |> List.map (localItem tabindex_) - |> List.reverse - ) + [ T.bb ] + [ chunk + [ T.flex ] + (items + |> List.reverse + |> List.map (localItem tabindex_) + |> List.reverse + ) + ] localItem : Int -> ( Icon msg, Label, Action msg ) -> Html msg @@ -169,7 +172,7 @@ localItem tabindex_ ( Icon icon, Label labelText labelType, action ) = , T.bg_transparent , T.bl_0 , T.fw6 - , T.inline_flex + , T.flex , T.items_center , T.justify_center , T.lh_solid diff --git a/src/Applications/UI/Tracks.elm b/src/Applications/UI/Tracks.elm index 24207c4d..de37a910 100644 --- a/src/Applications/UI/Tracks.elm +++ b/src/Applications/UI/Tracks.elm @@ -260,7 +260,7 @@ update msg model = ----------------------------------------- -- Menus ----------------------------------------- - ShowTrackMenu trackIndex mouseEvent -> + ShowTrackMenu trackIndex coordinates -> let selection = if List.isEmpty model.selectedTrackIndexes then @@ -281,7 +281,7 @@ update msg model = |> Maybe.withDefault acc ) [] - |> ShowTracksContextMenu (Coordinates.fromTuple mouseEvent.clientPos) + |> ShowTracksContextMenu coordinates |> returnReplyWithModel { model | selectedTrackIndexes = selection } ShowViewMenu grouping mouseEvent -> @@ -544,6 +544,7 @@ view core = List -> UI.Tracks.Scene.List.view { height = core.viewport.height + , isTouchDevice = core.isTouchDevice , isVisible = core.page == UI.Page.Index } core.tracks diff --git a/src/Applications/UI/Tracks/Core.elm b/src/Applications/UI/Tracks/Core.elm index 886708be..1edce93e 100644 --- a/src/Applications/UI/Tracks/Core.elm +++ b/src/Applications/UI/Tracks/Core.elm @@ -1,5 +1,6 @@ module UI.Tracks.Core exposing (Model, Msg(..), Scene(..)) +import Coordinates exposing (Coordinates) import Html.Events.Extra.Mouse as Mouse import InfiniteList import Json.Encode as Json @@ -69,7 +70,7 @@ type Msg ----------------------------------------- -- Menus ----------------------------------------- - | ShowTrackMenu Int Mouse.Event + | ShowTrackMenu Int Coordinates | ShowViewMenu (Maybe Grouping) Mouse.Event ----------------------------------------- -- Playlists diff --git a/src/Applications/UI/Tracks/Scene/List.elm b/src/Applications/UI/Tracks/Scene/List.elm index 43f7c051..794e8bed 100644 --- a/src/Applications/UI/Tracks/Scene/List.elm +++ b/src/Applications/UI/Tracks/Scene/List.elm @@ -7,17 +7,18 @@ import Color import Color.Ext as Color import Color.Manipulate as Color import Conditional exposing (ifThenElse) +import Coordinates import Css import Html exposing (Html, text) import Html.Attributes exposing (class, style) import Html.Events -import Html.Events.Extra.Mouse as Mouse exposing (onWithOptions) +import Html.Events.Extra.Mouse as Mouse import Html.Styled import Html.Styled.Attributes import Html.Styled.Events import Html.Styled.Lazy import InfiniteList -import Json.Decode +import Json.Decode as Decode import List.Ext as List import Material.Icons exposing (Coloring(..)) import Material.Icons.Av as Icons @@ -39,7 +40,10 @@ import UI.Tracks.Core exposing (..) type alias Necessities = - { height : Float, isVisible : Bool } + { height : Float + , isTouchDevice : Bool + , isVisible : Bool + } view : Necessities -> Model -> Html.Styled.Html Msg @@ -65,6 +69,7 @@ lazyView necessities harvest infiniteList favouritesOnly sortBy sortDirection ( [ Html.Styled.Attributes.fromUnstyled (InfiniteList.onScroll InfiniteListMsg) , Html.Styled.Attributes.id containerId , Html.Styled.Attributes.tabindex (ifThenElse necessities.isVisible 0 -1) + , Html.Styled.Attributes.style "-webkit-overflow-scrolling" "touch" ] [ C.disable_selection , T.flex_grow_1 @@ -91,10 +96,17 @@ lazyView necessities harvest infiniteList favouritesOnly sortBy sortDirection ( { itemView = case maybeDnD of Just dnd -> - playlistItemView favouritesOnly selectedTrackIndexes dnd + playlistItemView + necessities.isTouchDevice + favouritesOnly + selectedTrackIndexes + dnd _ -> - defaultItemView favouritesOnly selectedTrackIndexes + defaultItemView + necessities.isTouchDevice + favouritesOnly + selectedTrackIndexes -- , itemHeight = InfiniteList.withVariableHeight dynamicRowHeight @@ -288,8 +300,8 @@ dynamicRowHeight _ ( i, t ) = -- INFINITE LIST ITEM -defaultItemView : Bool -> List Int -> Int -> Int -> IdentifiedTrack -> Html Msg -defaultItemView favouritesOnly selectedTrackIndexes _ idx identifiedTrack = +defaultItemView : Bool -> Bool -> List Int -> Int -> Int -> IdentifiedTrack -> Html Msg +defaultItemView isTouchDevice favouritesOnly selectedTrackIndexes _ idx identifiedTrack = let ( identifiers, track ) = identifiedTrack @@ -316,10 +328,16 @@ defaultItemView favouritesOnly selectedTrackIndexes _ idx identifiedTrack = [ rowStyles idx isSelected identifiers -- - , [ contextMenuEvent identifiedTrack - , mousePlayEvent identifiedTrack - , mouseSelectEvent identifiedTrack - ] + , if isTouchDevice then + [ touchContextMenuEvent identifiedTrack + , touchPlayEvent identifiedTrack + ] + + else + [ mouseContextMenuEvent identifiedTrack + , mousePlayEvent identifiedTrack + , mouseSelectEvent identifiedTrack + ] -- , [ T.flex @@ -341,8 +359,8 @@ defaultItemView favouritesOnly selectedTrackIndexes _ idx identifiedTrack = ] -playlistItemView : Bool -> List Int -> DnD.Model Int -> Int -> Int -> IdentifiedTrack -> Html Msg -playlistItemView favouritesOnly selectedTrackIndexes dnd _ idx identifiedTrack = +playlistItemView : Bool -> Bool -> List Int -> DnD.Model Int -> Int -> Int -> IdentifiedTrack -> Html Msg +playlistItemView isTouchDevice favouritesOnly selectedTrackIndexes dnd _ idx identifiedTrack = let ( identifiers, track ) = identifiedTrack @@ -363,11 +381,18 @@ playlistItemView favouritesOnly selectedTrackIndexes dnd _ idx identifiedTrack = [ rowStyles idx isSelected identifiers -- - , [ contextMenuEvent identifiedTrack - , mousePlayEvent identifiedTrack - , mouseSelectEvent identifiedTrack - , DnD.listenToStart dragEnv listIdx - ] + , if isTouchDevice then + [ touchContextMenuEvent identifiedTrack + , touchPlayEvent identifiedTrack + , DnD.listenToStart dragEnv listIdx + ] + + else + [ mouseContextMenuEvent identifiedTrack + , mousePlayEvent identifiedTrack + , mouseSelectEvent identifiedTrack + , DnD.listenToStart dragEnv listIdx + ] -- , [ T.flex @@ -400,22 +425,26 @@ playlistItemView favouritesOnly selectedTrackIndexes dnd _ idx identifiedTrack = ] -contextMenuEvent : IdentifiedTrack -> Html.Attribute Msg -contextMenuEvent ( i, _ ) = - i.indexInList - |> ShowTrackMenu - |> onWithOptions - "contextmenu" - { stopPropagation = True - , preventDefault = True - } +mouseContextMenuEvent : IdentifiedTrack -> Html.Attribute Msg +mouseContextMenuEvent ( i, _ ) = + Html.Events.custom + "contextmenu" + (Decode.map + (\event -> + { message = ShowTrackMenu i.indexInList (Coordinates.fromTuple event.clientPos) + , stopPropagation = True + , preventDefault = True + } + ) + Mouse.eventDecoder + ) mousePlayEvent : IdentifiedTrack -> Html.Attribute Msg mousePlayEvent ( i, t ) = Html.Events.custom "dblclick" - (Json.Decode.succeed + (Decode.succeed { message = if i.isMissing then Bypass @@ -433,6 +462,39 @@ mouseSelectEvent ( i, _ ) = Mouse.onClick (MarkAsSelected i.indexInList) +touchContextMenuEvent : IdentifiedTrack -> Html.Attribute Msg +touchContextMenuEvent ( i, _ ) = + Html.Events.custom + "longtap" + (Decode.map2 + (\x y -> + { message = ShowTrackMenu i.indexInList { x = x, y = y } + , stopPropagation = True + , preventDefault = True + } + ) + (Decode.field "x" Decode.float) + (Decode.field "y" Decode.float) + ) + + +touchPlayEvent : IdentifiedTrack -> Html.Attribute Msg +touchPlayEvent ( i, t ) = + Html.Events.custom + "dbltap" + (Decode.succeed + { message = + if i.isMissing then + Bypass + + else + Reply [ UI.Reply.PlayTrack ( i, t ) ] + , stopPropagation = True + , preventDefault = True + } + ) + + -- ROWS diff --git a/src/Javascript/index.js b/src/Javascript/index.js index d827b515..2eaf35d5 100644 --- a/src/Javascript/index.js +++ b/src/Javascript/index.js @@ -214,3 +214,31 @@ document.addEventListener("MediaPrev", () => { document.addEventListener("MediaNext", () => { app.ports.requestNext.send(null) }) + + + +// Touch Events +// ------------ + +tocca({ + dbltapThreshold: 600 +}) + + + +// Vertical Height +// --------------- + +setVerticalHeightUnit() + + +window.addEventListener("resize", () => { + setTimeout(setVerticalHeightUnit, 0) + setTimeout(setVerticalHeightUnit, 32) +}) + + +function setVerticalHeightUnit() { + const vh = window.innerHeight * 0.01 + document.documentElement.style.setProperty("--vh", `${vh}px`) +} diff --git a/src/Javascript/rubber-band.js b/src/Javascript/rubber-band.js new file mode 100644 index 00000000..dc1b3209 --- /dev/null +++ b/src/Javascript/rubber-band.js @@ -0,0 +1,73 @@ +// +// Rubber Band +// \ (•◡•) / +// +// This prevents the iOS rubber-band scrolling on the body element. +// It's based on the https://github.com/lazd/iNoBounce library, +// with the difference that this'll scroll if the app is > 100vh. + + +let touchStartY = 0, + supportsPassiveOption = false + + +try { + window.addEventListener("test", null, Object.defineProperty( + {}, "passive", { get: _ => { supportsPassiveOption = true } } + )) +} catch (e) { + // +} + + +const documentTouchStart = event => { + touchStartY = event.touches ? event.touches[0].screenY : event.screenY +} + + +const documentTouchMove = event => { + let el = event.target + + while (el !== document.body && el !== document) { + const style = window.getComputedStyle(el) + if (!style) break + + // Ignore range input element + if (el.nodeName === "INPUT" && el.getAttribute("type") === "range") return + + // Determine if the element should scroll + const scrolling = style.getPropertyValue("-webkit-overflow-scrolling") + const overflowY = style.getPropertyValue("overflow-y") + const height = parseInt(style.getPropertyValue("height"), 10) + const isScrollable = scrolling === "touch" && (overflowY === "auto" || overflowY === "scroll") + const canScroll = el.scrollHeight > el.offsetHeight + + if (isScrollable && canScroll) { + const currentY = event.touches ? event.touches[0].screenY : event.screenY + const isAtTop = (touchStartY <= currentY && el.scrollTop === 0) + const isAtBottom = (touchStartY >= currentY && el.scrollHeight - el.scrollTop === height) + if (isAtTop || isAtBottom) event.preventDefault() + return + } + + el = el.parentNode + } + + if (document.body.scrollHeight <= window.innerHeight) { + event.preventDefault() + } +} + + +window.addEventListener( + "touchstart", + documentTouchStart, + supportsPassiveOption ? { passive : false } : false +) + + +window.addEventListener( + "touchmove", + documentTouchMove, + supportsPassiveOption ? { passive : false } : false +) diff --git a/src/Static/About/Layout.html b/src/Static/About/Layout.html index c8f320a8..2a73b5fd 100644 --- a/src/Static/About/Layout.html +++ b/src/Static/About/Layout.html @@ -13,9 +13,9 @@ - - - + + + diff --git a/src/Static/Favicons/site.webmanifest b/src/Static/Favicons/site.webmanifest deleted file mode 100644 index 65843ae9..00000000 --- a/src/Static/Favicons/site.webmanifest +++ /dev/null @@ -1,19 +0,0 @@ -{ - "name": "Diffuse", - "short_name": "Diffuse", - "icons": [ - { - "src": "/android-chrome-192x192.png", - "sizes": "192x192", - "type": "image/png" - }, - { - "src": "/android-chrome-512x512.png", - "sizes": "512x512", - "type": "image/png" - } - ], - "theme_color": "#995b6c", - "background_color": "#995b6c", - "display": "standalone" -} diff --git a/src/Static/Html/Application.html b/src/Static/Html/Application.html index 5286a965..8d76aa22 100644 --- a/src/Static/Html/Application.html +++ b/src/Static/Html/Application.html @@ -4,20 +4,21 @@ + Diffuse - + - - - + + + @@ -87,9 +88,11 @@ + + diff --git a/src/Static/manifest.json b/src/Static/Manifests/manifest.json similarity index 100% rename from src/Static/manifest.json rename to src/Static/Manifests/manifest.json diff --git a/src/Static/Manifests/site.webmanifest b/src/Static/Manifests/site.webmanifest new file mode 100644 index 00000000..70180cd9 --- /dev/null +++ b/src/Static/Manifests/site.webmanifest @@ -0,0 +1,19 @@ +{ + "name": "Diffuse", + "icons": [ + { + "src": "/images/icon.png", + "sizes": "192x192", + "type": "image/png" + }, + { + "src": "/images/icon.png", + "sizes": "512x512", + "type": "image/png" + } + ], + "theme_color": "#1E191A", + "background_color": "#1E191A", + "display": "standalone", + "start_url": "/" +} diff --git a/system/Build/Main.hs b/system/Build/Main.hs index fa63ce5c..01ae5d08 100644 --- a/system/Build/Main.hs +++ b/system/Build/Main.hs @@ -70,7 +70,7 @@ sequences = lsequence , ( Html, list "Static/Html/**/*.html" ) , ( Images, list "Static/Images/**/*.*" ) , ( Js, list "Javascript/**/*.js" ) - , ( Manifest, list "Static/manifest.json" ) + , ( Manifest, list "Static/Manifests/*.*" ) -- About Pages , ( AboutPages, list "Static/About/**/*.md" ) @@ -138,6 +138,7 @@ dependencies = do ] + -- INSERT @@ -184,6 +185,7 @@ insertVersion version dict = dict <> defs + -- COMMON