@@ -860,3 +860,147 @@ pub fn get_plugin_sidebar_snapshot() -> Vec<BufferedSidebarEvent> {
860860pub fn get_plugin_context_menu_snapshot ( ) -> Vec < BufferedContextMenuEvent > {
861861 crate :: plugins:: api:: take_context_menu_snapshot ( )
862862}
863+
864+ #[ derive( Debug , Clone , serde:: Serialize , serde:: Deserialize ) ]
865+ pub struct PermissionInfo {
866+ pub id : String ,
867+ pub name : String ,
868+ pub description : String ,
869+ pub risk_level : String ,
870+ pub category : String ,
871+ }
872+
873+ #[ tauri:: command]
874+ pub fn get_permission_list ( ) -> Vec < PermissionInfo > {
875+ vec ! [
876+ PermissionInfo {
877+ id: "log" . to_string( ) ,
878+ name: "Logging" . to_string( ) ,
879+ description: "Allow plugin to write logs" . to_string( ) ,
880+ risk_level: "low" . to_string( ) ,
881+ category: "system" . to_string( ) ,
882+ } ,
883+ PermissionInfo {
884+ id: "fs" . to_string( ) ,
885+ name: "File System (Legacy)" . to_string( ) ,
886+ description: "Allow plugin to read/write files in plugin data directory (deprecated, use fs.data)" . to_string( ) ,
887+ risk_level: "low" . to_string( ) ,
888+ category: "filesystem" . to_string( ) ,
889+ } ,
890+ PermissionInfo {
891+ id: "fs.data" . to_string( ) ,
892+ name: "File System - Data" . to_string( ) ,
893+ description: "Allow plugin to read/write files in its private data directory" . to_string( ) ,
894+ risk_level: "low" . to_string( ) ,
895+ category: "filesystem" . to_string( ) ,
896+ } ,
897+ PermissionInfo {
898+ id: "fs.server" . to_string( ) ,
899+ name: "File System - Server" . to_string( ) ,
900+ description: "Allow plugin to read/write files in server configuration directory" . to_string( ) ,
901+ risk_level: "medium" . to_string( ) ,
902+ category: "filesystem" . to_string( ) ,
903+ } ,
904+ PermissionInfo {
905+ id: "fs.global" . to_string( ) ,
906+ name: "File System - Global" . to_string( ) ,
907+ description: "Allow plugin to read/write files in global application directory" . to_string( ) ,
908+ risk_level: "high" . to_string( ) ,
909+ category: "filesystem" . to_string( ) ,
910+ } ,
911+ PermissionInfo {
912+ id: "http" . to_string( ) ,
913+ name: "HTTP Requests" . to_string( ) ,
914+ description: "Allow plugin to make HTTP requests to external servers" . to_string( ) ,
915+ risk_level: "medium" . to_string( ) ,
916+ category: "network" . to_string( ) ,
917+ } ,
918+ PermissionInfo {
919+ id: "i18n" . to_string( ) ,
920+ name: "Internationalization" . to_string( ) ,
921+ description: "Allow plugin to access and modify locale settings" . to_string( ) ,
922+ risk_level: "low" . to_string( ) ,
923+ category: "system" . to_string( ) ,
924+ } ,
925+ PermissionInfo {
926+ id: "process" . to_string( ) ,
927+ name: "Process Control" . to_string( ) ,
928+ description: "Allow plugin to start and manage system processes" . to_string( ) ,
929+ risk_level: "high" . to_string( ) ,
930+ category: "system" . to_string( ) ,
931+ } ,
932+ PermissionInfo {
933+ id: "server" . to_string( ) ,
934+ name: "Server Control" . to_string( ) ,
935+ description: "Allow plugin to control Minecraft servers" . to_string( ) ,
936+ risk_level: "medium" . to_string( ) ,
937+ category: "server" . to_string( ) ,
938+ } ,
939+ PermissionInfo {
940+ id: "storage" . to_string( ) ,
941+ name: "Storage" . to_string( ) ,
942+ description: "Allow plugin to store persistent data" . to_string( ) ,
943+ risk_level: "low" . to_string( ) ,
944+ category: "storage" . to_string( ) ,
945+ } ,
946+ PermissionInfo {
947+ id: "ui" . to_string( ) ,
948+ name: "UI Components" . to_string( ) ,
949+ description: "Allow plugin to create and manage UI components" . to_string( ) ,
950+ risk_level: "low" . to_string( ) ,
951+ category: "ui" . to_string( ) ,
952+ } ,
953+ PermissionInfo {
954+ id: "system" . to_string( ) ,
955+ name: "System Information" . to_string( ) ,
956+ description: "Allow plugin to access system information" . to_string( ) ,
957+ risk_level: "medium" . to_string( ) ,
958+ category: "system" . to_string( ) ,
959+ } ,
960+ PermissionInfo {
961+ id: "console" . to_string( ) ,
962+ name: "Console Access" . to_string( ) ,
963+ description: "Allow plugin to access and control the console" . to_string( ) ,
964+ risk_level: "medium" . to_string( ) ,
965+ category: "system" . to_string( ) ,
966+ } ,
967+ PermissionInfo {
968+ id: "element" . to_string( ) ,
969+ name: "DOM Elements" . to_string( ) ,
970+ description: "Allow plugin to create and manipulate DOM elements" . to_string( ) ,
971+ risk_level: "low" . to_string( ) ,
972+ category: "ui" . to_string( ) ,
973+ } ,
974+ PermissionInfo {
975+ id: "api" . to_string( ) ,
976+ name: "Plugin API" . to_string( ) ,
977+ description: "Allow plugin to call other plugins' APIs" . to_string( ) ,
978+ risk_level: "medium" . to_string( ) ,
979+ category: "api" . to_string( ) ,
980+ } ,
981+ ]
982+ }
983+
984+ // 获取插件已申请的权限列表
985+ #[ tauri:: command]
986+ pub fn get_plugin_permissions (
987+ plugin_id : String ,
988+ manager : tauri:: State < ' _ , Arc < Mutex < PluginManager > > > ,
989+ ) -> Result < Vec < PermissionInfo > , String > {
990+ validate_plugin_id ( & plugin_id) ?;
991+ let mgr = manager. lock ( ) . unwrap_or_else ( |e| e. into_inner ( ) ) ;
992+ let plugin_list = mgr. get_plugin_list ( ) ;
993+
994+ let plugin = plugin_list
995+ . iter ( )
996+ . find ( |p| p. manifest . id == plugin_id)
997+ . ok_or_else ( || format ! ( "Plugin '{}' not found" , plugin_id) ) ?;
998+
999+ let all_permissions = get_permission_list ( ) ;
1000+ let plugin_permissions: Vec < PermissionInfo > = all_permissions
1001+ . into_iter ( )
1002+ . filter ( |p| plugin. manifest . permissions . contains ( & p. id ) )
1003+ . collect ( ) ;
1004+
1005+ Ok ( plugin_permissions)
1006+ }
0 commit comments