Skip to content

Commit d660cab

Browse files
committed
feat: enhance allowlist configuration [TRI-027] (#11)
1 parent 2a7bf6d commit d660cab

File tree

15 files changed

+922
-122
lines changed

15 files changed

+922
-122
lines changed

.changes/allowlist-clipboard.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"tauri-utils": patch
3+
---
4+
5+
The `allowlist` configuration now includes a `clipboard` object, controlling the exposure of the `writeText` and `readText` APIs.

.changes/allowlist-dialog.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"tauri-utils": patch
3+
"tauri": patch
4+
---
5+
6+
The dialog allowlist now includes flags for the `message`, `ask` and `confirm` APIs.

.changes/allowlist-process.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"tauri-utils": patch
3+
---
4+
5+
The `allowlist` configuration now includes a `process` object, controlling the exposure of the `relaunch` and `exit` APIs.

.changes/allowlist-window.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
tauri-utils: patch
3+
---
4+
5+
The `window` allowlist now includes options to enable all window modification APIs: `center`, `close`, `create`, `hide`, `maximize`, `minimize`, `print`, `requestUserAttention`, `setAlwaysOnTop`, `setDecorations`, `setFocus`, `setFullscreen`, `setIcon`, `setMaxSize`, `setMinSize`, `setPosition`, `setResizable`, `setSize`, `setSkipTaskbar`, `setTitle`, `show`, `startDragging`, `unmaximize` and `unminimize`.

core/tauri-utils/src/config.rs

Lines changed: 230 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -680,13 +680,105 @@ pub struct WindowAllowlistConfig {
680680
/// Allows dynamic window creation.
681681
#[serde(default)]
682682
pub create: bool,
683+
/// Allows centering the window.
684+
#[serde(default)]
685+
pub center: bool,
686+
/// Allows requesting user attention on the window.
687+
#[serde(default)]
688+
pub request_user_attention: bool,
689+
/// Allows setting the resizable flag of the window.
690+
#[serde(default)]
691+
pub set_resizable: bool,
692+
/// Allows changing the window title.
693+
#[serde(default)]
694+
pub set_title: bool,
695+
/// Allows maximizing the window.
696+
#[serde(default)]
697+
pub maximize: bool,
698+
/// Allows unmaximizing the window.
699+
#[serde(default)]
700+
pub unmaximize: bool,
701+
/// Allows minimizing the window.
702+
#[serde(default)]
703+
pub minimize: bool,
704+
/// Allows unminimizing the window.
705+
#[serde(default)]
706+
pub unminimize: bool,
707+
/// Allows showing the window.
708+
#[serde(default)]
709+
pub show: bool,
710+
/// Allows hiding the window.
711+
#[serde(default)]
712+
pub hide: bool,
713+
/// Allows closing the window.
714+
#[serde(default)]
715+
pub close: bool,
716+
/// Allows setting the decorations flag of the window.
717+
#[serde(default)]
718+
pub set_decorations: bool,
719+
/// Allows setting the always_on_top flag of the window.
720+
#[serde(default)]
721+
pub set_always_on_top: bool,
722+
/// Allows setting the window size.
723+
#[serde(default)]
724+
pub set_size: bool,
725+
/// Allows setting the window minimum size.
726+
#[serde(default)]
727+
pub set_min_size: bool,
728+
/// Allows setting the window maximum size.
729+
#[serde(default)]
730+
pub set_max_size: bool,
731+
/// Allows changing the position of the window.
732+
#[serde(default)]
733+
pub set_position: bool,
734+
/// Allows setting the fullscreen flag of the window.
735+
#[serde(default)]
736+
pub set_fullscreen: bool,
737+
/// Allows focusing the window.
738+
#[serde(default)]
739+
pub set_focus: bool,
740+
/// Allows changing the window icon.
741+
#[serde(default)]
742+
pub set_icon: bool,
743+
/// Allows setting the skip_taskbar flag of the window.
744+
#[serde(default)]
745+
pub set_skip_taskbar: bool,
746+
/// Allows start dragging on the window.
747+
#[serde(default)]
748+
pub start_dragging: bool,
749+
/// Allows opening the system dialog to print the window content.
750+
#[serde(default)]
751+
pub print: bool,
683752
}
684753

685754
impl Allowlist for WindowAllowlistConfig {
686755
fn all_features() -> Vec<&'static str> {
687756
let allowlist = Self {
688757
all: false,
689758
create: true,
759+
center: true,
760+
request_user_attention: true,
761+
set_resizable: true,
762+
set_title: true,
763+
maximize: true,
764+
unmaximize: true,
765+
minimize: true,
766+
unminimize: true,
767+
show: true,
768+
hide: true,
769+
close: true,
770+
set_decorations: true,
771+
set_always_on_top: true,
772+
set_size: true,
773+
set_min_size: true,
774+
set_max_size: true,
775+
set_position: true,
776+
set_fullscreen: true,
777+
set_focus: true,
778+
set_icon: true,
779+
set_skip_taskbar: true,
780+
start_dragging: true,
781+
print: true,
690782
};
691783
let mut features = allowlist.to_features();
692784
features.push("window-all");
@@ -699,6 +791,39 @@ impl Allowlist for WindowAllowlistConfig {
699791
} else {
700792
let mut features = Vec::new();
701793
check_feature!(self, features, create, "window-create");
794+
check_feature!(self, features, center, "window-center");
795+
check_feature!(
796+
self,
797+
features,
798+
request_user_attention,
799+
"window-request-user-attention"
800+
);
801+
check_feature!(self, features, set_resizable, "window-set-resizable");
802+
check_feature!(self, features, set_title, "window-set-title");
803+
check_feature!(self, features, maximize, "window-maximize");
804+
check_feature!(self, features, unmaximize, "window-unmaximize");
805+
check_feature!(self, features, minimize, "window-minimize");
806+
check_feature!(self, features, unminimize, "window-unminimize");
807+
check_feature!(self, features, show, "window-show");
808+
check_feature!(self, features, hide, "window-hide");
809+
check_feature!(self, features, close, "window-close");
810+
check_feature!(self, features, set_decorations, "window-set-decorations");
811+
check_feature!(
812+
self,
813+
features,
814+
set_always_on_top,
815+
"window-set-always-on-top"
816+
);
817+
check_feature!(self, features, set_size, "window-set-size");
818+
check_feature!(self, features, set_min_size, "window-set-min-size");
819+
check_feature!(self, features, set_max_size, "window-set-max-size");
820+
check_feature!(self, features, set_position, "window-set-position");
821+
check_feature!(self, features, set_fullscreen, "window-set-fullscreen");
822+
check_feature!(self, features, set_focus, "window-set-focus");
823+
check_feature!(self, features, set_icon, "window-set-icon");
824+
check_feature!(self, features, set_skip_taskbar, "window-set-skip-taskbar");
825+
check_feature!(self, features, start_dragging, "window-start-dragging");
826+
check_feature!(self, features, print, "window-print");
702827
features
703828
}
704829
}
@@ -752,12 +877,21 @@ pub struct DialogAllowlistConfig {
752877
/// Use this flag to enable all dialog API features.
753878
#[serde(default)]
754879
pub all: bool,
755-
/// Open dialog window to pick files.
880+
/// Allows the API to open a dialog window to pick files.
756881
#[serde(default)]
757882
pub open: bool,
758-
/// Open dialog window to pick where to save files.
883+
/// Allows the API to open a dialog window to pick where to save files.
759884
#[serde(default)]
760885
pub save: bool,
886+
/// Allows the API to show a message dialog window.
887+
#[serde(default)]
888+
pub message: bool,
889+
/// Allows the API to show a dialog window with Yes/No buttons.
890+
#[serde(default)]
891+
pub ask: bool,
892+
/// Allows the API to show a dialog window with Ok/Cancel buttons.
893+
#[serde(default)]
894+
pub confirm: bool,
761895
}
762896

763897
impl Allowlist for DialogAllowlistConfig {
@@ -766,6 +900,9 @@ impl Allowlist for DialogAllowlistConfig {
766900
all: false,
767901
open: true,
768902
save: true,
903+
message: true,
904+
ask: true,
905+
confirm: true,
769906
};
770907
let mut features = allowlist.to_features();
771908
features.push("dialog-all");
@@ -779,6 +916,9 @@ impl Allowlist for DialogAllowlistConfig {
779916
let mut features = Vec::new();
780917
check_feature!(self, features, open, "dialog-open");
781918
check_feature!(self, features, save, "dialog-save");
919+
check_feature!(self, features, message, "dialog-message");
920+
check_feature!(self, features, ask, "dialog-ask");
921+
check_feature!(self, features, confirm, "dialog-confirm");
782922
features
783923
}
784924
}
@@ -965,6 +1105,86 @@ impl Allowlist for ProtocolAllowlistConfig {
9651105
}
9661106
}
9671107

1108+
/// Allowlist for the process APIs.
1109+
#[derive(Debug, Default, PartialEq, Clone, Deserialize, Serialize)]
1110+
#[cfg_attr(feature = "schema", derive(JsonSchema))]
1111+
#[serde(rename_all = "camelCase", deny_unknown_fields)]
1112+
pub struct ProcessAllowlistConfig {
1113+
/// Use this flag to enable all process APIs.
1114+
#[serde(default)]
1115+
pub all: bool,
1116+
/// Enables the relaunch API.
1117+
#[serde(default)]
1118+
pub relaunch: bool,
1119+
/// Enables the exit API.
1120+
#[serde(default)]
1121+
pub exit: bool,
1122+
}
1123+
1124+
impl Allowlist for ProcessAllowlistConfig {
1125+
fn all_features() -> Vec<&'static str> {
1126+
let allowlist = Self {
1127+
all: false,
1128+
relaunch: true,
1129+
exit: true,
1130+
};
1131+
let mut features = allowlist.to_features();
1132+
features.push("process-all");
1133+
features
1134+
}
1135+
1136+
fn to_features(&self) -> Vec<&'static str> {
1137+
if self.all {
1138+
vec!["process-all"]
1139+
} else {
1140+
let mut features = Vec::new();
1141+
check_feature!(self, features, relaunch, "process-relaunch");
1142+
check_feature!(self, features, exit, "process-exit");
1143+
features
1144+
}
1145+
}
1146+
}
1147+
1148+
/// Allowlist for the clipboard APIs.
1149+
#[derive(Debug, Default, PartialEq, Clone, Deserialize, Serialize)]
1150+
#[cfg_attr(feature = "schema", derive(JsonSchema))]
1151+
#[serde(rename_all = "camelCase", deny_unknown_fields)]
1152+
pub struct ClipboardAllowlistConfig {
1153+
/// Use this flag to enable all clipboard APIs.
1154+
#[serde(default)]
1155+
pub all: bool,
1156+
/// Enables the clipboard's `writeText` API.
1157+
#[serde(default)]
1158+
pub write_text: bool,
1159+
/// Enables the clipboard's `readText` API.
1160+
#[serde(default)]
1161+
pub read_text: bool,
1162+
}
1163+
1164+
impl Allowlist for ClipboardAllowlistConfig {
1165+
fn all_features() -> Vec<&'static str> {
1166+
let allowlist = Self {
1167+
all: false,
1168+
write_text: true,
1169+
read_text: true,
1170+
};
1171+
let mut features = allowlist.to_features();
1172+
features.push("clipboard-all");
1173+
features
1174+
}
1175+
1176+
fn to_features(&self) -> Vec<&'static str> {
1177+
if self.all {
1178+
vec!["clipboard-all"]
1179+
} else {
1180+
let mut features = Vec::new();
1181+
check_feature!(self, features, write_text, "clipboard-write-text");
1182+
check_feature!(self, features, read_text, "clipboard-read-text");
1183+
features
1184+
}
1185+
}
1186+
}
1187+
9681188
/// Allowlist configuration.
9691189
#[derive(Debug, Default, PartialEq, Clone, Deserialize, Serialize)]
9701190
#[cfg_attr(feature = "schema", derive(JsonSchema))]
@@ -1003,6 +1223,12 @@ pub struct AllowlistConfig {
10031223
/// Custom protocol allowlist.
10041224
#[serde(default)]
10051225
pub protocol: ProtocolAllowlistConfig,
1226+
/// Process API allowlist.
1227+
#[serde(default)]
1228+
pub process: ProcessAllowlistConfig,
1229+
/// Clipboard APIs allowlist.
1230+
#[serde(default)]
1231+
pub clipboard: ClipboardAllowlistConfig,
10061232
}
10071233

10081234
impl Allowlist for AllowlistConfig {
@@ -1018,6 +1244,8 @@ impl Allowlist for AllowlistConfig {
10181244
features.extend(OsAllowlistConfig::all_features());
10191245
features.extend(PathAllowlistConfig::all_features());
10201246
features.extend(ProtocolAllowlistConfig::all_features());
1247+
features.extend(ProcessAllowlistConfig::all_features());
1248+
features.extend(ClipboardAllowlistConfig::all_features());
10211249
features
10221250
}
10231251

0 commit comments

Comments
 (0)