forked from tauri-apps/plugins-workspace
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.rs
136 lines (126 loc) · 4.54 KB
/
build.rs
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
use std::path::PathBuf;
#[path = "src/scope_entry.rs"]
#[allow(dead_code)]
mod scope;
/// Opener scope application.
#[derive(schemars::JsonSchema)]
#[serde(untagged)]
#[allow(unused)]
enum Application {
/// Open in default application.
Default,
/// If true, allow open with any application.
Enable(bool),
/// Allow specific application to open with.
App(String),
}
impl Default for Application {
fn default() -> Self {
Self::Default
}
}
/// Opener scope entry.
#[derive(schemars::JsonSchema)]
#[serde(untagged)]
#[allow(unused)]
enum OpenerScopeEntry {
Url {
/// A URL that can be opened by the webview when using the Opener APIs.
///
/// Wildcards can be used following the UNIX glob pattern.
///
/// Examples:
///
/// - "https://*" : allows all HTTPS origin
///
/// - "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,
/// An application to open this url with, for example: firefox.
#[serde(default)]
app: Application,
},
Path {
/// A path that can be opened by the webview when using the Opener APIs.
///
/// The pattern can start with a variable that resolves to a system base directory.
/// The variables are: `$AUDIO`, `$CACHE`, `$CONFIG`, `$DATA`, `$LOCALDATA`, `$DESKTOP`,
/// `$DOCUMENT`, `$DOWNLOAD`, `$EXE`, `$FONT`, `$HOME`, `$PICTURE`, `$PUBLIC`, `$RUNTIME`,
/// `$TEMPLATE`, `$VIDEO`, `$RESOURCE`, `$APP`, `$LOG`, `$TEMP`, `$APPCONFIG`, `$APPDATA`,
/// `$APPLOCALDATA`, `$APPCACHE`, `$APPLOG`.
path: PathBuf,
/// An application to open this path with, for example: xdg-open.
#[serde(default)]
app: Application,
},
}
// Ensure `OpenerScopeEntry` and `scope::EntryRaw` is kept in sync
fn _f() {
match (scope::EntryRaw::Url {
url: String::new(),
app: scope::Application::Enable(true),
}) {
scope::EntryRaw::Url { url, app } => OpenerScopeEntry::Url {
url,
app: match app {
scope::Application::Enable(p) => Application::Enable(p),
scope::Application::App(p) => Application::App(p),
scope::Application::Default => Application::Default,
},
},
scope::EntryRaw::Path { path, app } => OpenerScopeEntry::Path {
path,
app: match app {
scope::Application::Enable(p) => Application::Enable(p),
scope::Application::App(p) => Application::App(p),
scope::Application::Default => Application::Default,
},
},
};
match (OpenerScopeEntry::Url {
url: String::new(),
app: Application::Enable(true),
}) {
OpenerScopeEntry::Url { url, app } => scope::EntryRaw::Url {
url,
app: match app {
Application::Enable(p) => scope::Application::Enable(p),
Application::App(p) => scope::Application::App(p),
Application::Default => scope::Application::Default,
},
},
OpenerScopeEntry::Path { path, app } => scope::EntryRaw::Path {
path,
app: match app {
Application::Enable(p) => scope::Application::Enable(p),
Application::App(p) => scope::Application::App(p),
Application::Default => scope::Application::Default,
},
},
};
}
const COMMANDS: &[&str] = &["open_url", "open_path", "reveal_item_in_dir"];
fn main() {
tauri_plugin::Builder::new(COMMANDS)
.global_api_script_path("./api-iife.js")
.android_path("android")
.ios_path("ios")
.global_scope_schema(schemars::schema_for!(OpenerScopeEntry))
.build();
let target_os = std::env::var("CARGO_CFG_TARGET_OS").unwrap();
let mobile = target_os == "ios" || target_os == "android";
alias("desktop", !mobile);
alias("mobile", mobile);
}
// creates a cfg alias if `has_feature` is true.
// `alias` must be a snake case string.
fn alias(alias: &str, has_feature: bool) {
println!("cargo:rustc-check-cfg=cfg({alias})");
if has_feature {
println!("cargo:rustc-cfg={alias}");
}
}