Browse Source

feat(examples): showcase basics of multiwindows feature on api example (#1468)

Lucas Fernandes Nogueira 4 years ago
parent
commit
5b6c7bb6ee

+ 1 - 1
core/tauri/src/runtime/manager.rs

@@ -422,7 +422,7 @@ where
           },
         )
       }
-      WindowUrl::External(url) => (false, url.to_string()),
+      WindowUrl::External(url) => (url.as_str().starts_with("tauri://"), url.to_string()),
     };
 
     let attributes = pending.attributes.clone();

File diff suppressed because it is too large
+ 0 - 0
examples/api/public/build/bundle.js


File diff suppressed because it is too large
+ 0 - 0
examples/api/public/build/bundle.js.map


+ 11 - 2
examples/api/src/components/Window.svelte

@@ -1,5 +1,5 @@
 <script>
-  import { appWindow } from "@tauri-apps/api/window";
+  import { appWindow, WebviewWindow } from "@tauri-apps/api/window";
   import { open as openDialog } from "@tauri-apps/api/dialog";
   import { open } from "@tauri-apps/api/shell";
 
@@ -12,7 +12,6 @@
     unminimize,
     show,
     hide,
-    setTransparent,
     setDecorations,
     setAlwaysOnTop,
     setWidth,
@@ -27,6 +26,8 @@
     setIcon,
   } = appWindow;
 
+  export let onMessage;
+
   let urlValue = "https://tauri.studio";
   let resizable = true;
   let maximized = false;
@@ -69,6 +70,13 @@
     }).then(setIcon);
   }
 
+  function createWindow() {
+    const webview = new WebviewWindow(Math.random().toString());
+    webview.once('tauri://error', function () {
+      onMessage("Error creating new webview")
+    })
+  }
+
   $: setResizable(resizable);
   $: maximized ? maximize() : unmaximize();
   //$: setTransparent(transparent)
@@ -174,6 +182,7 @@
   <input id="url" bind:value={urlValue} />
   <button class="button" id="open-url"> Open URL </button>
 </form>
+<button class="button" on:click={createWindow}>New window</button>
 
 <style>
   .flex-row {

+ 1 - 1
tooling/api/src/window.ts

@@ -477,7 +477,7 @@ export class WindowManager {
 const appWindow = new WindowManager()
 
 export interface WindowOptions {
-  url?: 'app' | string
+  url?: string
   x?: number
   y?: number
   width?: number

Some files were not shown because too many files changed in this diff