File size: 2,563 Bytes
2d8be8f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT

#[path = "src/scope.rs"]
#[allow(dead_code)]
mod scope;

const COMMANDS: &[&str] = &[
    "fetch",
    "fetch_cancel",
    "fetch_send",
    "fetch_read_body",
    "fetch_cancel_body",
];

/// HTTP scope entry.
#[derive(schemars::JsonSchema)]
#[serde(untagged)]
#[allow(unused)]
enum HttpScopeEntry {
    /// A URL that can be accessed by the webview when using the HTTP APIs.
    /// Wildcards can be used following the URL pattern standard.
    ///
    /// See [the URL Pattern spec](https://urlpattern.spec.whatwg.org/) for more information.
    ///
    /// Examples:
    ///
    /// - "https://*" : allows all HTTPS origin on port 443
    ///
    /// - "https://*:*" : allows all HTTPS origin on any port
    ///
    /// - "https://*.github.com/tauri-apps/tauri": allows any subdomain of "github.com" with the "tauri-apps/api" path
    ///
    /// - "https://myapi.service.com/users/*": allows access to any URLs that begins with "https://myapi.service.com/users/"
    Value(String),
    Object {
        /// A URL that can be accessed by the webview when using the HTTP APIs.
        /// Wildcards can be used following the URL pattern standard.
        ///
        /// See [the URL Pattern spec](https://urlpattern.spec.whatwg.org/) for more information.
        ///
        /// Examples:
        ///
        /// - "https://*" : allows all HTTPS origin on port 443
        ///
        /// - "https://*:*" : allows all HTTPS origin on any port
        ///
        /// - "https://*.github.com/tauri-apps/tauri": allows any subdomain of "github.com" with the "tauri-apps/api" path
        ///
        /// - "https://myapi.service.com/users/*": allows access to any URLs that begins with "https://myapi.service.com/users/"
        url: String,
    },
}

// Ensure `HttpScopeEntry` and `scope::EntryRaw` is kept in sync
fn _f() {
    match scope::EntryRaw::Value(String::new()) {
        scope::EntryRaw::Value(url) => HttpScopeEntry::Value(url),
        scope::EntryRaw::Object { url } => HttpScopeEntry::Object { url },
    };
    match HttpScopeEntry::Value(String::new()) {
        HttpScopeEntry::Value(url) => scope::EntryRaw::Value(url),
        HttpScopeEntry::Object { url } => scope::EntryRaw::Object { url },
    };
}

fn main() {
    tauri_plugin::Builder::new(COMMANDS)
        .global_api_script_path("./api-iife.js")
        .global_scope_schema(schemars::schema_for!(HttpScopeEntry))
        .build();
}