From 2f836aa201accf73e1db42eb23a3bdeb21827954 Mon Sep 17 00:00:00 2001 From: Steven Vandevelde Date: Mon, 28 May 2018 17:07:38 +0200 Subject: [PATCH] Closes #100 --- src/App/Ports.elm | 3 +++ src/App/Sources/Services/AmazonS3.elm | 4 +-- src/App/Sources/Services/AzureBlob.elm | 4 +-- src/App/Sources/Services/AzureFile.elm | 4 +-- src/App/Sources/Services/Local.elm | 1 - src/App/State.elm | 6 +++++ src/App/Tracks/ContextMenu.elm | 26 +++++++++++++++--- src/App/Types.elm | 1 + src/Js/elm-loader.js | 37 ++++++++++++++++++++++++++ 9 files changed, 76 insertions(+), 10 deletions(-) diff --git a/src/App/Ports.elm b/src/App/Ports.elm index b30f7717..1a10eda7 100644 --- a/src/App/Ports.elm +++ b/src/App/Ports.elm @@ -14,6 +14,9 @@ import Types exposing (AlienEvent) -- 💡 +port copyToClipboard : String -> Cmd msg + + port fadeInNotifications : () -> Cmd msg diff --git a/src/App/Sources/Services/AmazonS3.elm b/src/App/Sources/Services/AmazonS3.elm index b3e69521..970a1c46 100644 --- a/src/App/Sources/Services/AmazonS3.elm +++ b/src/App/Sources/Services/AmazonS3.elm @@ -157,9 +157,9 @@ postProcessTree = {-| Create a public url for a file. We need this to play the track. -(!) Creates a presigned url that's valid for 24 hours +(!) Creates a presigned url that's valid for 48 hours -} makeTrackUrl : Date -> SourceData -> HttpMethod -> String -> String makeTrackUrl currentDate srcData method pathToFile = - presignedUrl method (Time.second * 86400) [] currentDate srcData pathToFile + presignedUrl method (Time.second * 172800) [] currentDate srcData pathToFile diff --git a/src/App/Sources/Services/AzureBlob.elm b/src/App/Sources/Services/AzureBlob.elm index d4e65f1d..7d1c0eff 100644 --- a/src/App/Sources/Services/AzureBlob.elm +++ b/src/App/Sources/Services/AzureBlob.elm @@ -139,9 +139,9 @@ postProcessTree = {-| Create a public url for a file. We need this to play the track. -(!) Creates a presigned url that's valid for 24 hours +(!) Creates a presigned url that's valid for 48 hours -} makeTrackUrl : Date -> SourceData -> HttpMethod -> String -> String makeTrackUrl currentDate srcData method pathToFile = - presignedUrl Blob Read Get 24 currentDate srcData pathToFile [] + presignedUrl Blob Read Get 48 currentDate srcData pathToFile [] diff --git a/src/App/Sources/Services/AzureFile.elm b/src/App/Sources/Services/AzureFile.elm index 19e53e64..dbcca0d1 100644 --- a/src/App/Sources/Services/AzureFile.elm +++ b/src/App/Sources/Services/AzureFile.elm @@ -143,9 +143,9 @@ postProcessTree = {-| Create a public url for a file. We need this to play the track. -(!) Creates a presigned url that's valid for 24 hours +(!) Creates a presigned url that's valid for 48 hours -} makeTrackUrl : Date -> SourceData -> HttpMethod -> String -> String makeTrackUrl currentDate srcData method pathToFile = - presignedUrl File Read Get 24 currentDate srcData pathToFile [] + presignedUrl File Read Get 48 currentDate srcData pathToFile [] diff --git a/src/App/Sources/Services/Local.elm b/src/App/Sources/Services/Local.elm index de5c27a6..36f3bdd7 100644 --- a/src/App/Sources/Services/Local.elm +++ b/src/App/Sources/Services/Local.elm @@ -132,7 +132,6 @@ postProcessTree = {-| Create a public url for a file. We need this to play the track. -(!) Creates a presigned url that's valid for 24 hours -} makeTrackUrl : Date -> SourceData -> HttpMethod -> String -> String diff --git a/src/App/State.elm b/src/App/State.elm index 1a51d186..ef7666b4 100644 --- a/src/App/State.elm +++ b/src/App/State.elm @@ -148,6 +148,10 @@ update msg model = in (!) { model | alfred = alfred, contextMenu = contextMenu } [] + -- Copy some text to the clipboard + CopyToClipboard text -> + (!) model [ Ports.copyToClipboard text ] + -- Sometimes you just wanna chill. NoOp -> (!) model [] @@ -752,6 +756,8 @@ update msg model = model.tracks model.playlists.lastModifiedPlaylist tracks + model.sources.collection + model.timestamp mousePos contextMenu = diff --git a/src/App/Tracks/ContextMenu.elm b/src/App/Tracks/ContextMenu.elm index d33b683f..5f2d1549 100644 --- a/src/App/Tracks/ContextMenu.elm +++ b/src/App/Tracks/ContextMenu.elm @@ -1,27 +1,31 @@ module Tracks.ContextMenu exposing (..) import ContextMenu.Types exposing (..) +import Date exposing (Date) import Material.Icons.Action as Icons +import Material.Icons.Content as Icons import Material.Icons.Editor as Icons import Mouse import Playlists.Types exposing (Msg(..)) import Playlists.Utils import Queue.Types +import Queue.Utils +import Sources.Types exposing (Source) import Tracks.Types exposing (..) import Tracks.Utils import Types as TopLevel exposing (..) import Variables exposing (colorDerivatives) -trackMenu : Tracks.Types.Model -> Maybe String -> List IdentifiedTrack -> Mouse.Position -> ContextMenu TopLevel.Msg -trackMenu model lastModifiedPlaylist identifiedTracks = +trackMenu : Tracks.Types.Model -> Maybe String -> List IdentifiedTrack -> List Source -> Date -> Mouse.Position -> ContextMenu TopLevel.Msg +trackMenu model lastModifiedPlaylist identifiedTracks sources timestamp = let tracks = List.map Tracks.Utils.unindentify identifiedTracks in [ queueActions identifiedTracks - -- + -- Playlist actions -- , case model.selectedPlaylist of Just selectedPlaylist -> @@ -46,6 +50,22 @@ trackMenu model lastModifiedPlaylist identifiedTracks = Nothing -> -- Playlist actions, default. defaultPlaylistActions tracks lastModifiedPlaylist + + -- Track URL + -- + , if List.length identifiedTracks == 1 then + [ ( Icons.link colorDerivatives.text 14 + , "Copy short-lived url" + , identifiedTracks + |> List.head + |> Maybe.map (Queue.Utils.makeEngineItem timestamp sources) + |> Maybe.map .url + |> Maybe.withDefault "" + |> CopyToClipboard + ) + ] + else + [] ] |> List.concat |> ContextMenu diff --git a/src/App/Types.elm b/src/App/Types.elm index 3fce68aa..6907e3c0 100644 --- a/src/App/Types.elm +++ b/src/App/Types.elm @@ -35,6 +35,7 @@ import Tracks.Types as Tracks type Msg = ClickAway + | CopyToClipboard String | NoOp | Reset | SetIsTouchDevice Bool diff --git a/src/Js/elm-loader.js b/src/Js/elm-loader.js index bc444a71..86351434 100644 --- a/src/Js/elm-loader.js +++ b/src/Js/elm-loader.js @@ -158,6 +158,43 @@ app.ports.storeLocalUserData.subscribe(data => { +// +// > Clipboard + +app.ports.copyToClipboard.subscribe(text => { + + // Insert a textarea element + const el = document.createElement("textarea"); + + el.value = text; + el.setAttribute("readonly", ""); + el.style.position = "absolute"; + el.style.left = "-9999px"; + + document.body.appendChild(el); + + // Store original selection + const selected = document.getSelection().rangeCount > 0 + ? document.getSelection().getRangeAt(0) + : false; + + // Select & copy the text + el.select(); + document.execCommand("copy"); + + // Remove textarea element + document.body.removeChild(el); + + // Restore original selection + if (selected) { + document.getSelection().removeAllRanges(); + document.getSelection().addRange(selected); + } + +}); + + + // // > Equalizer -- knotmirror 0.0.1