From 122d64f7ec707d5a02e033e3a6ab82072e6a19bd Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Wed, 12 Jun 2019 02:39:47 +0200 Subject: [PATCH] Fixed #4 - Styles now load on WM AU --- SpotifyWPW/MainPage.xaml.cs | 6 +++++- SpotifyWPW/Package.appxmanifest | 2 +- SpotifyWPW/SpotifyWPW.csproj | 2 -- .../WebPlayer/Style/Components/Page.css.map | 10 ---------- .../WebPlayer/Style/Components/Page.min.css | 3 --- SpotifyWPW/WebPlayer/script.js | 20 +++++++++++++------ 6 files changed, 20 insertions(+), 23 deletions(-) delete mode 100644 SpotifyWPW/WebPlayer/Style/Components/Page.css.map delete mode 100644 SpotifyWPW/WebPlayer/Style/Components/Page.min.css diff --git a/SpotifyWPW/MainPage.xaml.cs b/SpotifyWPW/MainPage.xaml.cs index b9f9624..119d887 100644 --- a/SpotifyWPW/MainPage.xaml.cs +++ b/SpotifyWPW/MainPage.xaml.cs @@ -148,12 +148,16 @@ public async void NavigationCompleted(WebView sender, WebViewNavigationCompleted /// /// Receive control messages from the web player /// - public void ScriptNotify(object sender, NotifyEventArgs e) + public async void ScriptNotify(object sender, NotifyEventArgs e) { var data = e.Value.Split('\n'); switch (data[0]) { + // Custom styles are ready to be loaded + case "LoadCustomStyles": + await WebPlayer.InvokeScriptAsync("AppendCustomStyle", new[] { File.ReadAllText("WebPlayer/Style/Player.min.css")}); + break; // Song info change case "SystemMediaControlsSong": if (data.Length < 3) return; diff --git a/SpotifyWPW/Package.appxmanifest b/SpotifyWPW/Package.appxmanifest index 78ffdf0..a7cbe7b 100644 --- a/SpotifyWPW/Package.appxmanifest +++ b/SpotifyWPW/Package.appxmanifest @@ -1,6 +1,6 @@  - + Spotify WPW diff --git a/SpotifyWPW/SpotifyWPW.csproj b/SpotifyWPW/SpotifyWPW.csproj index 2b53306..02d374c 100644 --- a/SpotifyWPW/SpotifyWPW.csproj +++ b/SpotifyWPW/SpotifyWPW.csproj @@ -118,7 +118,6 @@ - @@ -162,7 +161,6 @@ - diff --git a/SpotifyWPW/WebPlayer/Style/Components/Page.css.map b/SpotifyWPW/WebPlayer/Style/Components/Page.css.map deleted file mode 100644 index b423963..0000000 --- a/SpotifyWPW/WebPlayer/Style/Components/Page.css.map +++ /dev/null @@ -1,10 +0,0 @@ -{ - "version": 3, - "file": "Page.css", - "sources": [ - "Page.scss", - "../_Generic.scss" - ], - "mappings": "ACUA,AAAA,IAAI,CAAE,AAAA,IAAI,AAAC,CACV,mBAAmB,CAAE,IAAK,CAC1B,AAGD,AAAsB,sBAAA,AAAA,wBAAwB,CAC9C,AAAA,6BAA6B,AAAC,CAC7B,OAAO,CAAE,IAAK,CACd,ADhBD,AAAA,gBAAgB,AAAC,CAChB,OAAO,CAAE,CAAE,CACX", - "names": [] -} \ No newline at end of file diff --git a/SpotifyWPW/WebPlayer/Style/Components/Page.min.css b/SpotifyWPW/WebPlayer/Style/Components/Page.min.css deleted file mode 100644 index 4d08977..0000000 --- a/SpotifyWPW/WebPlayer/Style/Components/Page.min.css +++ /dev/null @@ -1,3 +0,0 @@ -html,body{-ms-content-zooming:none}.ITVPJxOvtLt7upeE1TV9-._1x7i7dLhHZEm-xUAl44ncL,#js-message-bar-cookie-notice{display:none}.Root__main-view{padding:0} - -/*# sourceMappingURL=Page.css.map */ \ No newline at end of file diff --git a/SpotifyWPW/WebPlayer/script.js b/SpotifyWPW/WebPlayer/script.js index 01bcdca..e03bd62 100644 --- a/SpotifyWPW/WebPlayer/script.js +++ b/SpotifyWPW/WebPlayer/script.js @@ -28,9 +28,20 @@ const DARK_MODE = "amoledDarkMode"; } })(); +/** + * Append and apply CSS content + * + * @param {string} cssContent + * String of CSS rules to be applied + */ +function AppendCustomStyle(cssContent) { + const styleElement = document.createElement("style"); + styleElement.appendChild(document.createTextNode(cssContent)); + document.head.appendChild(styleElement); +} /** - * Apply custom styles and enable mobile mode + * Request custom styles load and enable mobile mode */ (function customStyles() { // Enable mobile mode @@ -39,11 +50,8 @@ const DARK_MODE = "amoledDarkMode"; metaViewport.content = "width=device-width;initial-scale=1"; document.head.appendChild(metaViewport); - // Load CSS - const customStyle = document.createElement("link"); - customStyle.rel = "stylesheet"; - customStyle.href = "ms-appx-web:///WebPlayer/Style/Player.min.css"; - document.head.appendChild(customStyle); + // Request CSS load + external.notify("LoadCustomStyles"); })();