App.svelte 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. <script>
  2. import { onMount } from "svelte";
  3. import { writable } from "svelte/store";
  4. import hotkeys from "hotkeys-js";
  5. import { open } from "@tauri-apps/api/shell";
  6. import { invoke } from "@tauri-apps/api/tauri";
  7. import Welcome from "./components/Welcome.svelte";
  8. import Cli from "./components/Cli.svelte";
  9. import Communication from "./components/Communication.svelte";
  10. import Dialog from "./components/Dialog.svelte";
  11. import FileSystem from "./components/FileSystem.svelte";
  12. import Http from "./components/Http.svelte";
  13. import Notifications from "./components/Notifications.svelte";
  14. import Window from "./components/Window.svelte";
  15. import Shortcuts from "./components/Shortcuts.svelte";
  16. import Shell from "./components/Shell.svelte";
  17. import Updater from "./components/Updater.svelte";
  18. import Clipboard from "./components/Clipboard.svelte";
  19. import WebRTC from './components/WebRTC.svelte'
  20. import HttpForm from "./components/HttpForm.svelte";
  21. const MENU_TOGGLE_HOTKEY = 'ctrl+b';
  22. onMount(() => {
  23. hotkeys(MENU_TOGGLE_HOTKEY, () => {
  24. invoke('menu_toggle');
  25. });
  26. });
  27. const views = [
  28. {
  29. label: "Welcome",
  30. component: Welcome,
  31. },
  32. {
  33. label: "Messages",
  34. component: Communication,
  35. },
  36. {
  37. label: "CLI",
  38. component: Cli,
  39. },
  40. {
  41. label: "Dialog",
  42. component: Dialog,
  43. },
  44. {
  45. label: "File system",
  46. component: FileSystem,
  47. },
  48. {
  49. label: "HTTP",
  50. component: Http,
  51. },
  52. {
  53. label: "HTTP Form",
  54. component: HttpForm,
  55. },
  56. {
  57. label: "Notifications",
  58. component: Notifications,
  59. },
  60. {
  61. label: "Window",
  62. component: Window,
  63. },
  64. {
  65. label: "Shortcuts",
  66. component: Shortcuts,
  67. },
  68. {
  69. label: "Shell",
  70. component: Shell,
  71. },
  72. {
  73. label: "Updater",
  74. component: Updater,
  75. },
  76. {
  77. label: "Clipboard",
  78. component: Clipboard,
  79. },
  80. {
  81. label: "WebRTC",
  82. component: WebRTC,
  83. },
  84. ];
  85. let selected = views[0];
  86. let responses = writable([]);
  87. function select(view) {
  88. selected = view;
  89. }
  90. function onMessage(value) {
  91. responses.update(r => [{ text: `[${new Date().toLocaleTimeString()}]` + ': ' + (typeof value === "string" ? value : JSON.stringify(value)) }, ...r])
  92. }
  93. // this function is renders HTML without sanitizing it so it's insecure
  94. // we only use it with our own input data
  95. function insecureRenderHtml(html) {
  96. responses.update(r => [{ html }, ...r])
  97. }
  98. function clear() {
  99. responses.update(() => []);
  100. }
  101. function onLogoClick() {
  102. open("https://tauri.studio/");
  103. }
  104. </script>
  105. <main>
  106. <div class="flex row noselect just-around container" data-tauri-drag-region>
  107. <img class="logo" src="tauri logo.png" height="60" on:click={onLogoClick} alt="logo" />
  108. <div>
  109. <a class="dark-link" target="_blank" href="https://tauri.studio/en/docs/get-started/intro">
  110. Documentation
  111. </a>
  112. <a class="dark-link" target="_blank" href="https://github.com/tauri-apps/tauri">
  113. Github
  114. </a>
  115. <a class="dark-link" target="_blank" href="https://github.com/tauri-apps/tauri/tree/dev/tauri/examples/api">
  116. Source
  117. </a>
  118. </div>
  119. </div>
  120. <div class="flex row">
  121. <div class="view-container">
  122. {#each views as view}
  123. <p class="nv noselect {selected === view ? 'nv_selected' : ''}" on:click={()=> select(view)}
  124. >
  125. {view.label}
  126. </p>
  127. {/each}
  128. </div>
  129. <div class="content">
  130. <svelte:component this={selected.component} {onMessage} {insecureRenderHtml} />
  131. </div>
  132. </div>
  133. <div id="response">
  134. <p class="flex row just-around">
  135. <strong>Tauri Console</strong>
  136. <span class="nv" on:click={clear}>clear</span>
  137. </p>
  138. {#each $responses as r}
  139. {#if r.text}
  140. <p>{r.text}</p>
  141. {:else}
  142. {@html r.html}
  143. {/if}
  144. {/each}
  145. </div>
  146. </main>
  147. <style>
  148. .container {
  149. margin: 1em;
  150. }
  151. .view-container {
  152. width:15em;
  153. margin-left:0.5em;
  154. }
  155. #response {
  156. white-space: pre-line;
  157. }
  158. </style>