linux_web_fix.patch 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. From fc3d6b0bf16133a67c2824cba1a38ffb77531040 Mon Sep 17 00:00:00 2001
  2. From: DHMike57 <14224881+DHMike57@users.noreply.github.com>
  3. Date: Thu, 26 Aug 2021 12:31:53 +0100
  4. Subject: [PATCH] fix for linux web interface
  5. ---
  6. Cargo.toml | 4 +-
  7. build.rs | 12 ++-
  8. web/index-linux.html | 55 +++++++++++++
  9. web/script-linux.js | 179 +++++++++++++++++++++++++++++++++++++++++++
  10. 4 files changed, 247 insertions(+), 3 deletions(-)
  11. create mode 100644 web/index-linux.html
  12. create mode 100644 web/script-linux.js
  13. diff --git a/Cargo.toml b/Cargo.toml
  14. index 1074e6d..c14b218 100644
  15. --- a/Cargo.toml
  16. +++ b/Cargo.toml
  17. @@ -19,7 +19,7 @@ quick-xml = "0.17"
  18. rand = "0.7"
  19. lazy_static = "1.4"
  20. crossbeam = "0.7.3"
  21. -web-view = "0.6"
  22. +web-view = "0.7"
  23. tinyfiledialogs = "3.3.9"
  24. getopts = "0.2"
  25. webbrowser = "0.5.2"
  26. @@ -45,4 +45,4 @@ panic = "abort"
  27. opt-level = 0
  28. [package.metadata.winres]
  29. -LegalCopyright = "© 2019-2020 prixt"
  30. \ No newline at end of file
  31. +LegalCopyright = "© 2019-2020 prixt"
  32. diff --git a/build.rs b/build.rs
  33. index 3a77902..7cf57b3 100644
  34. --- a/build.rs
  35. +++ b/build.rs
  36. @@ -15,12 +15,22 @@ fn main() -> Result<(), Box<dyn Error>> {
  37. #[cfg(all(target_os="windows", feature = "edge"))]
  38. let range_css = include_str!("web/range-windows-edge.css");
  39. + #[cfg(target_os="linux")]
  40. + let index_html = include_str!("web/index-linux.html")
  41. + .replace("{comment_start}" , "<!--")
  42. + .replace("{comment_end}" , "-->")
  43. + .replace("{range}" , range_css)
  44. + .replace("{w3}" , include_str!("web/w3.css"))
  45. + .replace("{js}" , include_str!("web/script-linux.js"));
  46. +
  47. + #[cfg(not(target_os="linux"))]
  48. let index_html = include_str!("web/index.html")
  49. .replace("{comment_start}" , "<!--")
  50. .replace("{comment_end}" , "-->")
  51. .replace("{range}" , range_css)
  52. .replace("{w3}" , include_str!("web/w3.css"))
  53. .replace("{js}" , include_str!("web/script.js"));
  54. +
  55. let index_html = html_minifier::minify(index_html)?;
  56. File::create(dest_dir)?
  57. @@ -32,4 +42,4 @@ fn main() -> Result<(), Box<dyn Error>> {
  58. .compile()?;
  59. Ok(())
  60. -}
  61. \ No newline at end of file
  62. +}
  63. diff --git a/web/index-linux.html b/web/index-linux.html
  64. new file mode 100644
  65. index 0000000..a219257
  66. --- /dev/null
  67. +++ b/web/index-linux.html
  68. @@ -0,0 +1,55 @@
  69. +<!doctype html>
  70. +<html>
  71. +<head>
  72. +<!--{comment_end}
  73. + <style type="text/css">{w3}</style>
  74. + <style type="text/css">{range}</style>
  75. + <script type="text/javascript">{js}</script>
  76. +{comment_start}-->
  77. +</head>
  78. +<body onload="main()">
  79. +<header class='w3-bar w3-light-grey w3-small'>
  80. + <div class='w3-dropdown-hover'>
  81. + <button class='w3-button'>Load</button>
  82. + <div class='w3-dropdown-content w3-bar-block w3-border'>
  83. + <button class='w3-bar-item w3-button'
  84. + onclick="window.webkit.messageHandlers.external.postMessage('load_gamelog')">Load gamelog.txt</button>
  85. + <button class='w3-bar-item w3-button'
  86. + onclick="window.webkit.messageHandlers.external.postMessage('load_soundpack')">Load soundpack</button>
  87. + <button class='w3-bar-item w3-button'
  88. + onclick="window.webkit.messageHandlers.external.postMessage('load_ignore_list')">Load ignore.txt</button>
  89. + </div>
  90. + </div>
  91. + <div class='w3-dropdown-hover'>
  92. + <button class='w3-button'>Settings</button>
  93. + <div class='w3-dropdown-content w3-bar-block w3-border'>
  94. + <button class='w3-bar-item w3-button'
  95. + onclick="window.webkit.messageHandlers.external.postMessage('set_default_paths')">Set current paths as default</button>
  96. + <button class='w3-bar-item w3-button'
  97. + onclick="window.webkit.messageHandlers.external.postMessage('remove_default_paths')">Delete default paths setting</button>
  98. + <button class='w3-bar-item w3-button'
  99. + onclick="window.webkit.messageHandlers.external.postMessage('set_default_volumes')">Set current volumes as default</button>
  100. + <button class='w3-bar-item w3-button'
  101. + onclick="window.webkit.messageHandlers.external.postMessage('remove_default_volumes')">Delete default volumes setting</button>
  102. + </div>
  103. + </div>
  104. + <div class='w3-dropdown-hover w3-right'>
  105. + <button class='w3-button'>Options</button>
  106. + <div class='w3-dropdown-content w3-bar-block w3-border' style='right:0'>
  107. + <button class='w3-bar-item w3-button'
  108. + onclick="window.webkit.messageHandlers.external.postMessage('link_original')">&#x1f517; - zwei's original SoundSense & soundpack</button>
  109. + <button class='w3-bar-item w3-button'
  110. + onclick="window.webkit.messageHandlers.external.postMessage('link_fork')">&#x1f517; - jecowa's soundpack fork</button>
  111. + <button class='w3-bar-item w3-button'
  112. + onclick="window.webkit.messageHandlers.external.postMessage('link_source')">&#x1f517; - SoundSense-RS Github repository</button>
  113. + <button class='w3-bar-item w3-button'
  114. + onclick="window.webkit.messageHandlers.external.postMessage('show_about')">&#x2139; - About</button>
  115. + </div>
  116. + </div>
  117. +</header>
  118. +<div class="w3-block" id="channels"></div>
  119. +<div class="w3-block" id="settings" style="display:none"></div>
  120. +<footer class='w3-bottom' id='alerts'></footer>
  121. +<footer class="w3-bottom" id='errors'></footer>
  122. +</body>
  123. +</html>
  124. diff --git a/web/script-linux.js b/web/script-linux.js
  125. new file mode 100644
  126. index 0000000..a60cc1c
  127. --- /dev/null
  128. +++ b/web/script-linux.js
  129. @@ -0,0 +1,179 @@
  130. +"use strict";
  131. +
  132. +let is_windows = null;
  133. +let channels = null;
  134. +
  135. +function addSlider(channel_name) {
  136. + channels.insertAdjacentElement(
  137. + 'beforeend',
  138. + createSlider(channel_name)
  139. + );
  140. + document.getElementById(channel_name+"_slider")
  141. + .addEventListener(is_windows?'change':'input',function(){
  142. + window.webkit.messageHandlers.external.postMessage("change_volume:"+channel_name+":"+this.value);
  143. + },
  144. + false
  145. + );
  146. + document.getElementById(channel_name+"_skip_button")
  147. + .addEventListener('click',function(){
  148. + window.webkit.messageHandlers.external.postMessage("skip_current_sound:"+channel_name);
  149. + },
  150. + false
  151. + );
  152. + document.getElementById(channel_name+"_play_pause_button")
  153. + .addEventListener('click',function(){
  154. + window.webkit.messageHandlers.external.postMessage("play_pause:"+channel_name);
  155. + },
  156. + false
  157. + );
  158. +}
  159. +function createSlider(channel_name) {
  160. + let slider = document.createElement("div");
  161. + slider.className="w3-cell-row w3-border-bottom";
  162. + slider.insertAdjacentHTML(
  163. + 'afterbegin',
  164. + "<div class='w3-cell w3-cell-middle w3-center w3-padding-small overlay-container' style='width:10%;min-width:90px'"+
  165. + "id='"+channel_name+"_head'>"+
  166. + "<div class='overlay-content w3-container w3-padding-small w3-animate-opacity w3-grey w3-center'>"+
  167. + "<span>Threshold</span><br>"+
  168. + "<select id='"+channel_name+"_selector' onchange='thresholdSelect(\""+channel_name+"\",this.value)'>"+
  169. + "<option value='4'>Everything</option>"+
  170. + "<option value='3'>Fluff</option>"+
  171. + "<option value='2'>Important</option>"+
  172. + "<option value='1'>Critical</option>"+
  173. + "<option value='0'>Nothing</option>"+
  174. + "</select>"+
  175. + "</div>"+
  176. + "<h4>"+channel_name+"</h4>"+
  177. + "</div>"+
  178. + "<div class='w3-cell w3-cell-middle w3-rest w3-container w3-padding-small'>"+
  179. + "<input type='range' id='"+channel_name+"_slider'"+
  180. + "min='0' max='100' value='100'>"+
  181. + "</div>"+
  182. + "<div class='w3-cell w3-cell-middle w3-center w3-small w3-padding-small' style='width:2%;min-width:10px;'>"+
  183. + "<div class='w3-button w3-block w3-round w3-small w3-padding-small'"+
  184. + "title='Skip "+channel_name+"'"+
  185. + "id='"+channel_name+"_skip_button'>"+
  186. + "&#x23ED;"+
  187. + "</div>"+
  188. + "<div class='w3-button w3-block w3-round w3-small w3-padding-small'"+
  189. + "title='Play/Pause "+channel_name+"'"+
  190. + "id='"+channel_name+"_play_pause_button'>"+
  191. + "&#x23EF;"+
  192. + "</div>"+
  193. + "</div>"
  194. + );
  195. + return slider;
  196. +}
  197. +function setSliderValue(channel_name, value) {
  198. + let slider = document.getElementById(channel_name+"_slider");
  199. + if (slider != null) slider.value = value;
  200. +}
  201. +function clearSliders() {
  202. + while (channels.firstChild)
  203. + channels.removeChild(channels.firstChild);
  204. +}
  205. +function setSliderHead(channel_name, is_paused) {
  206. + let slider_head = document.getElementById(channel_name+"_head");
  207. + let slider = document.getElementById(channel_name+"_slider");
  208. + if (is_paused) {
  209. + slider_head.classList.add("w3-opacity-max");
  210. + slider.classList.add("w3-opacity-max");
  211. + }
  212. + else {
  213. + slider_head.classList.remove("w3-opacity-max");
  214. + slider.classList.remove("w3-opacity-max");
  215. + }
  216. +}
  217. +
  218. +let alerts_footer = null;
  219. +let alerts = null;
  220. +function addAlert(name, color, text) {
  221. + removeAlert(name);
  222. + let new_alert = createAlert(name, color, text);
  223. + alerts[name] = new_alert;
  224. + alerts_footer.insertAdjacentElement('beforeend', new_alert);
  225. + if (alerts_footer.childElementCount > 10)
  226. + removeAlert(alerts_footer.firstChild.name);
  227. +}
  228. +function removeAlert(name) {
  229. + let alert = document.getElementById("alert_"+name);
  230. + if (alert != null) {
  231. + alerts_footer.removeChild(alert);
  232. + alerts.delete(name);
  233. + }
  234. +}
  235. +function createAlert(name, color, text) {
  236. + let alert=document.createElement("div");
  237. + alert.name = name;
  238. + alert.id="alert_"+name;
  239. + alert.className="w3-bar w3-animate-bottom w3-"+color;
  240. + alert.style.cssText="padding: 2px 15px 2px 15px;";
  241. + alert.innerHTML=text;
  242. + alert.timer = 4.0;
  243. +
  244. + let cross = document.createElement("span");
  245. + cross.className="w3-closebtn";
  246. + cross.setAttribute("onclick", "removeAlert('"+name+"')");
  247. + cross.innerHTML="&times;";
  248. +
  249. + alert.insertAdjacentElement('afterbegin',cross);
  250. +
  251. + return alert;
  252. +}
  253. +
  254. +let error_footer = null;
  255. +function addError(name, text) {
  256. + let new_error = createError(name, text);
  257. + error_footer.insertAdjacentElement('afterbegin', new_error);
  258. +}
  259. +function removeError(id) {
  260. + let error = document.getElementById(id);
  261. + if (error != null) {
  262. + error_footer.removeChild(error);
  263. + }
  264. +}
  265. +function createError(name, text) {
  266. + let error=document.createElement("div");
  267. + error.name=name;
  268. + error.id="error_"+name+toString(Math.floor(Math.random()*100000));
  269. + error.className="w3-bar w3-animate-bottom w3-red";
  270. + error.style.cssText="padding: 10px 15px 10px 15px;";
  271. + error.innerHTML="<h3>"+name+"</h3><p>"+text+"</p>";
  272. +
  273. + let cross = document.createElement("span");
  274. + cross.className="w3-closebtn";
  275. + cross.setAttribute("onclick", "removeError('"+error.id+"')");
  276. + cross.innerHTML="&times;";
  277. +
  278. + error.insertAdjacentElement('afterbegin',cross);
  279. +
  280. + return error;
  281. +}
  282. +
  283. +function thresholdSelect(channel_name, value) {
  284. + window.webkit.messageHandlers.external.postMessage("change_threshold:"+channel_name+":"+value);
  285. +
  286. +}
  287. +
  288. +function main() {
  289. + channels = document.getElementById('channels');
  290. + is_windows = /MSIE|Trident|Edge/.test(window.navigator.userAgent);
  291. + alerts_footer = document.getElementById('alerts');
  292. + error_footer = document.getElementById('errors');
  293. + alerts = new Map();
  294. +
  295. + let prev = null;
  296. + function step(now) {
  297. + let dt = (prev!=null) ? (now-prev)*0.001 : 0.0;
  298. + prev = now;
  299. + for (let key in alerts) {
  300. + let alert = alerts[key];
  301. + alert.timer -= dt;
  302. + if (alert.timer <= 1.0) alert.style.opacity = alert.timer;
  303. + if (alert.timer <= 0.0) removeAlert(alert.name);
  304. + }
  305. + window.requestAnimationFrame(step);
  306. + }
  307. + window.requestAnimationFrame(step);
  308. +}