presave before repo split
This commit is contained in:
Vendored
+3
-1
@@ -7,5 +7,7 @@
|
|||||||
"rust-analyzer.check.targets": [
|
"rust-analyzer.check.targets": [
|
||||||
"aarch64-linux-android",
|
"aarch64-linux-android",
|
||||||
"x86_64-unknown-linux-gnu"
|
"x86_64-unknown-linux-gnu"
|
||||||
]
|
],
|
||||||
|
"makefile.configureOnOpen": false,
|
||||||
|
"kotlin.java.home": "/usr/lib/jvm/java-17-openjdk-amd64"
|
||||||
}
|
}
|
||||||
|
|||||||
Generated
+28
@@ -2461,6 +2461,7 @@ dependencies = [
|
|||||||
"serde",
|
"serde",
|
||||||
"tauri",
|
"tauri",
|
||||||
"tauri-build",
|
"tauri-build",
|
||||||
|
"tauri-plugin-vpn",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -4153,6 +4154,33 @@ dependencies = [
|
|||||||
"tauri-utils",
|
"tauri-utils",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tauri-plugin"
|
||||||
|
version = "2.5.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ddde7d51c907b940fb573006cdda9a642d6a7c8153657e88f8a5c3c9290cd4aa"
|
||||||
|
dependencies = [
|
||||||
|
"anyhow",
|
||||||
|
"glob",
|
||||||
|
"plist",
|
||||||
|
"schemars 0.8.22",
|
||||||
|
"serde",
|
||||||
|
"serde_json",
|
||||||
|
"tauri-utils",
|
||||||
|
"toml 0.9.12+spec-1.1.0",
|
||||||
|
"walkdir",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tauri-plugin-vpn"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"serde",
|
||||||
|
"tauri",
|
||||||
|
"tauri-plugin",
|
||||||
|
"thiserror 2.0.18",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tauri-runtime"
|
name = "tauri-runtime"
|
||||||
version = "2.10.1"
|
version = "2.10.1"
|
||||||
|
|||||||
@@ -19,3 +19,4 @@ serde = { version = "1.0", features = ["derive"] }
|
|||||||
ndk-context = "0.1"
|
ndk-context = "0.1"
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
android_logger = "0.14"
|
android_logger = "0.14"
|
||||||
|
tauri-plugin-vpn = { path = "./src/plugins/vpn-plugin" }
|
||||||
|
|||||||
@@ -1,15 +1,3 @@
|
|||||||
fn main() {
|
fn main() {
|
||||||
let manifest_dir = std::env::var("CARGO_MANIFEST_DIR").unwrap();
|
|
||||||
println!("cargo:warning=MANIFEST_DIR is: {}", manifest_dir);
|
|
||||||
|
|
||||||
let path = std::path::Path::new(&manifest_dir).join("../../gen/arm64-v8a");
|
|
||||||
println!(
|
|
||||||
"cargo:warning=LINKER_SEARCH_PATH is: {:?}",
|
|
||||||
path.canonicalize()
|
|
||||||
);
|
|
||||||
|
|
||||||
println!("cargo:rustc-link-search=native={}", path.display());
|
|
||||||
println!("cargo:rustc-link-lib=dylib=netrunner_client");
|
|
||||||
|
|
||||||
tauri_build::build();
|
tauri_build::build();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
pub mod start_vpn_android;
|
|
||||||
|
|||||||
@@ -1,56 +0,0 @@
|
|||||||
use jni::errors::Error as JniError;
|
|
||||||
use jni::objects::{JObject, JString, JValue};
|
|
||||||
use tauri::command;
|
|
||||||
|
|
||||||
#[command]
|
|
||||||
pub fn start_vpn_android(remote_address: String) -> Result<i32, String> {
|
|
||||||
#[cfg(target_os = "android")]
|
|
||||||
{
|
|
||||||
let ctx = ndk_context::android_context();
|
|
||||||
let vm_ptr = ctx.vm() as *mut jni::sys::JavaVM;
|
|
||||||
|
|
||||||
let vm = unsafe { jni::JavaVM::from_raw(vm_ptr) }.map_err(|e: JniError| e.to_string())?;
|
|
||||||
|
|
||||||
let mut env = vm
|
|
||||||
.attach_current_thread()
|
|
||||||
.map_err(|e: JniError| e.to_string())?;
|
|
||||||
|
|
||||||
let class_name = "com/netrunner/vpn/NetrunnerVpnService";
|
|
||||||
let class = env
|
|
||||||
.find_class(class_name)
|
|
||||||
.map_err(|e: JniError| e.to_string())?;
|
|
||||||
|
|
||||||
let companion = env
|
|
||||||
.get_static_field(
|
|
||||||
class,
|
|
||||||
"Companion",
|
|
||||||
"Lcom/netrunner/vpn/NetrunnerVpnService$Companion;",
|
|
||||||
)
|
|
||||||
.map_err(|e: JniError| e.to_string())?
|
|
||||||
.l()
|
|
||||||
.map_err(|e: JniError| e.to_string())?;
|
|
||||||
|
|
||||||
let j_remote_addr = env
|
|
||||||
.new_string(remote_address)
|
|
||||||
.map_err(|e: JniError| e.to_string())?;
|
|
||||||
|
|
||||||
// Явное приведение контекста к JObject
|
|
||||||
let context_obj = unsafe { JObject::from_raw(ctx.context() as *mut _) };
|
|
||||||
|
|
||||||
let result = env
|
|
||||||
.call_method(
|
|
||||||
companion,
|
|
||||||
"startVpn",
|
|
||||||
"(Landroid/app/Activity;Ljava/lang/String;)I",
|
|
||||||
&[JValue::Object(&context_obj), JValue::Object(&j_remote_addr)],
|
|
||||||
)
|
|
||||||
.map_err(|e: JniError| e.to_string())?;
|
|
||||||
|
|
||||||
result.i().map_err(|e: JniError| e.to_string())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(not(target_os = "android"))]
|
|
||||||
{
|
|
||||||
Err("VPN доступен только на Android".into())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
mod core;
|
mod core;
|
||||||
use core::start_vpn_android::start_vpn_android;
|
|
||||||
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
||||||
pub fn run() {
|
pub fn run() {
|
||||||
#[cfg(target_os = "android")]
|
#[cfg(target_os = "android")]
|
||||||
@@ -9,7 +8,6 @@ pub fn run() {
|
|||||||
.with_tag("NetrunnerRust"),
|
.with_tag("NetrunnerRust"),
|
||||||
);
|
);
|
||||||
tauri::Builder::default()
|
tauri::Builder::default()
|
||||||
.invoke_handler(tauri::generate_handler![start_vpn_android])
|
|
||||||
.run(tauri::generate_context!())
|
.run(tauri::generate_context!())
|
||||||
.expect("error while running tauri application");
|
.expect("error while running tauri application");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,64 +0,0 @@
|
|||||||
package com.netrunner.vpn
|
|
||||||
|
|
||||||
import android.app.Activity
|
|
||||||
import android.content.Intent
|
|
||||||
import android.net.VpnService
|
|
||||||
import android.os.ParcelFileDescriptor
|
|
||||||
import uniffi.netrunner_client.SessionManager
|
|
||||||
|
|
||||||
class NetrunnerVpnService : VpnService() {
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
|
|
||||||
private var vpnInterface: ParcelFileDescriptor? = null
|
|
||||||
|
|
||||||
fun start(activity: Activity): Int {
|
|
||||||
val intent = VpnService.prepare(activity)
|
|
||||||
|
|
||||||
if (intent != null) {
|
|
||||||
activity.startActivityForResult(intent, 1001)
|
|
||||||
return -1
|
|
||||||
}
|
|
||||||
|
|
||||||
return startVpn(activity)
|
|
||||||
}
|
|
||||||
@JvmStatic
|
|
||||||
fun startVpn(activity: Activity, remoteAddress: String): Int {
|
|
||||||
val builder = Builder()
|
|
||||||
|
|
||||||
builder.setSession("NetrunnerVPN")
|
|
||||||
.addAddress("10.0.0.1", 32)
|
|
||||||
.addRoute("0.0.0.0", 0)
|
|
||||||
.setMtu(1500)
|
|
||||||
|
|
||||||
vpnInterface = builder.establish()
|
|
||||||
val fd = vpnInterface?.fd ?: -1
|
|
||||||
|
|
||||||
if (fd != -1) {
|
|
||||||
try {
|
|
||||||
// 1. Создаем менеджер сессий
|
|
||||||
val sessionManager = uniffi.netrunner_client.SessionManager()
|
|
||||||
|
|
||||||
// 2. Вызываем метод start, прокидывая адрес и дескриптор
|
|
||||||
// Обратите внимание: метод .start() возвращает объект Session
|
|
||||||
sessionManager.start(
|
|
||||||
remoteAddress = remoteAddress, // Ваша пустая строка или адрес
|
|
||||||
tunFd = fd
|
|
||||||
)
|
|
||||||
|
|
||||||
Log.d("NetrunnerVPN", "Сессия успешно запущена с FD: $fd")
|
|
||||||
} catch (e: Exception) {
|
|
||||||
Log.e("NetrunnerVPN", "Ошибка при запуске Rust-сессии: ${e.message}")
|
|
||||||
stop() // Закрываем интерфейс, если нативная часть не стартанула
|
|
||||||
return -1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return fd
|
|
||||||
}
|
|
||||||
fun stop() {
|
|
||||||
vpnInterface?.close()
|
|
||||||
vpnInterface = null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
/.vs
|
||||||
|
.DS_Store
|
||||||
|
.Thumbs.db
|
||||||
|
*.sublime*
|
||||||
|
.idea/
|
||||||
|
debug.log
|
||||||
|
package-lock.json
|
||||||
|
.vscode/settings.json
|
||||||
|
yarn.lock
|
||||||
|
|
||||||
|
/.tauri
|
||||||
|
/target
|
||||||
|
Cargo.lock
|
||||||
|
node_modules/
|
||||||
|
|
||||||
|
dist-js
|
||||||
|
dist
|
||||||
|
|
||||||
|
|
||||||
|
/android/.tauri
|
||||||
|
/android/.gradle
|
||||||
|
/android/build
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
[package]
|
||||||
|
name = "tauri-plugin-vpn"
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = [ "You" ]
|
||||||
|
description = ""
|
||||||
|
edition = "2021"
|
||||||
|
rust-version = "1.77.2"
|
||||||
|
exclude = ["/examples", "/dist-js", "/guest-js", "/node_modules"]
|
||||||
|
links = "tauri-plugin-vpn"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
tauri = { version = "2.10.3" }
|
||||||
|
serde = "1.0"
|
||||||
|
thiserror = "2"
|
||||||
|
|
||||||
|
[build-dependencies]
|
||||||
|
tauri-plugin = { version = "2.5.4", features = ["build"] }
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
# Tauri Plugin vpn
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
plugins {
|
||||||
|
id("com.android.library")
|
||||||
|
id("org.jetbrains.kotlin.android")
|
||||||
|
}
|
||||||
|
|
||||||
|
android {
|
||||||
|
namespace = "app.netrunner.vpn"
|
||||||
|
compileSdk = 36
|
||||||
|
|
||||||
|
defaultConfig {
|
||||||
|
minSdk = 21
|
||||||
|
}
|
||||||
|
compileOptions {
|
||||||
|
sourceCompatibility = JavaVersion.VERSION_17
|
||||||
|
targetCompatibility = JavaVersion.VERSION_17
|
||||||
|
}
|
||||||
|
|
||||||
|
kotlinOptions {
|
||||||
|
jvmTarget = "17"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
implementation("androidx.core:core-ktx:1.9.0")
|
||||||
|
implementation("androidx.appcompat:appcompat:1.6.0")
|
||||||
|
implementation(project(":tauri-android"))
|
||||||
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
include ':tauri-android'
|
||||||
|
project(':tauri-android').projectDir = new File('./.tauri/tauri-api')
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
package="app.netrunner.vpn">
|
||||||
|
|
||||||
|
<application>
|
||||||
|
<service
|
||||||
|
android:name=".ExampleVpnService"
|
||||||
|
android:permission="android.permission.BIND_VPN_SERVICE"
|
||||||
|
android:exported="true">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.net.VpnService"/>
|
||||||
|
</intent-filter>
|
||||||
|
</service>
|
||||||
|
</application>
|
||||||
|
</manifest>
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
package app.netrunner.vpn;
|
||||||
|
import android.net.VpnService;
|
||||||
|
|
||||||
|
class VpnEngine : VpnService() {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
const COMMANDS: &[&str] = &["ping"];
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
tauri_plugin::Builder::new(COMMANDS)
|
||||||
|
.android_path("android")
|
||||||
|
.ios_path("ios")
|
||||||
|
.build();
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
import { invoke } from '@tauri-apps/api/core'
|
||||||
|
|
||||||
|
export async function ping(value: string): Promise<string | null> {
|
||||||
|
return await invoke<{value?: string}>('plugin:vpn|ping', {
|
||||||
|
payload: {
|
||||||
|
value,
|
||||||
|
},
|
||||||
|
}).then((r) => (r.value ? r.value : null));
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
{
|
||||||
|
"name": "tauri-plugin-vpn-api",
|
||||||
|
"version": "0.1.0",
|
||||||
|
"author": "You",
|
||||||
|
"description": "",
|
||||||
|
"type": "module",
|
||||||
|
"types": "./dist-js/index.d.ts",
|
||||||
|
"main": "./dist-js/index.cjs",
|
||||||
|
"module": "./dist-js/index.js",
|
||||||
|
"exports": {
|
||||||
|
"types": "./dist-js/index.d.ts",
|
||||||
|
"import": "./dist-js/index.js",
|
||||||
|
"require": "./dist-js/index.cjs"
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"dist-js",
|
||||||
|
"README.md"
|
||||||
|
],
|
||||||
|
"scripts": {
|
||||||
|
"build": "rollup -c",
|
||||||
|
"prepublishOnly": "pnpm build",
|
||||||
|
"pretest": "pnpm build"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@tauri-apps/api": "^2.0.0"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@rollup/plugin-typescript": "^12.0.0",
|
||||||
|
"rollup": "^4.9.6",
|
||||||
|
"typescript": "^5.3.3",
|
||||||
|
"tslib": "^2.6.2"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
# Automatically generated - DO NOT EDIT!
|
||||||
|
|
||||||
|
"$schema" = "../../schemas/schema.json"
|
||||||
|
|
||||||
|
[[permission]]
|
||||||
|
identifier = "allow-ping"
|
||||||
|
description = "Enables the ping command without any pre-configured scope."
|
||||||
|
commands.allow = ["ping"]
|
||||||
|
|
||||||
|
[[permission]]
|
||||||
|
identifier = "deny-ping"
|
||||||
|
description = "Denies the ping command without any pre-configured scope."
|
||||||
|
commands.deny = ["ping"]
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
## Permission Table
|
||||||
|
|
||||||
|
<table>
|
||||||
|
<tr>
|
||||||
|
<th>Identifier</th>
|
||||||
|
<th>Description</th>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
|
||||||
|
`vpn:allow-ping`
|
||||||
|
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
|
||||||
|
Enables the ping command without any pre-configured scope.
|
||||||
|
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
|
||||||
|
`vpn:deny-ping`
|
||||||
|
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
|
||||||
|
Denies the ping command without any pre-configured scope.
|
||||||
|
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
|
||||||
|
`vpn:vpn-control`
|
||||||
|
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
|
||||||
|
Allows access to VPN Service
|
||||||
|
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
[[permission]]
|
||||||
|
identifier = "vpn-control"
|
||||||
|
description = "Allows access to VPN Service"
|
||||||
|
name = "allow-vpn-control"
|
||||||
|
commands = { allow = ["ping", "prepare_vpn", "start_vpn", "stop_vpn"] }
|
||||||
@@ -0,0 +1,318 @@
|
|||||||
|
{
|
||||||
|
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||||
|
"title": "PermissionFile",
|
||||||
|
"description": "Permission file that can define a default permission, a set of permissions or a list of inlined permissions.",
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"default": {
|
||||||
|
"description": "The default permission set for the plugin",
|
||||||
|
"anyOf": [
|
||||||
|
{
|
||||||
|
"$ref": "#/definitions/DefaultPermission"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "null"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"set": {
|
||||||
|
"description": "A list of permissions sets defined",
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"$ref": "#/definitions/PermissionSet"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"permission": {
|
||||||
|
"description": "A list of inlined permissions",
|
||||||
|
"default": [],
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"$ref": "#/definitions/Permission"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"definitions": {
|
||||||
|
"DefaultPermission": {
|
||||||
|
"description": "The default permission set of the plugin.\n\nWorks similarly to a permission with the \"default\" identifier.",
|
||||||
|
"type": "object",
|
||||||
|
"required": [
|
||||||
|
"permissions"
|
||||||
|
],
|
||||||
|
"properties": {
|
||||||
|
"version": {
|
||||||
|
"description": "The version of the permission.",
|
||||||
|
"type": [
|
||||||
|
"integer",
|
||||||
|
"null"
|
||||||
|
],
|
||||||
|
"format": "uint64",
|
||||||
|
"minimum": 1.0
|
||||||
|
},
|
||||||
|
"description": {
|
||||||
|
"description": "Human-readable description of what the permission does. Tauri convention is to use `<h4>` headings in markdown content for Tauri documentation generation purposes.",
|
||||||
|
"type": [
|
||||||
|
"string",
|
||||||
|
"null"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"permissions": {
|
||||||
|
"description": "All permissions this set contains.",
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"PermissionSet": {
|
||||||
|
"description": "A set of direct permissions grouped together under a new name.",
|
||||||
|
"type": "object",
|
||||||
|
"required": [
|
||||||
|
"description",
|
||||||
|
"identifier",
|
||||||
|
"permissions"
|
||||||
|
],
|
||||||
|
"properties": {
|
||||||
|
"identifier": {
|
||||||
|
"description": "A unique identifier for the permission.",
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"description": {
|
||||||
|
"description": "Human-readable description of what the permission does.",
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"permissions": {
|
||||||
|
"description": "All permissions this set contains.",
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"$ref": "#/definitions/PermissionKind"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"Permission": {
|
||||||
|
"description": "Descriptions of explicit privileges of commands.\n\nIt can enable commands to be accessible in the frontend of the application.\n\nIf the scope is defined it can be used to fine grain control the access of individual or multiple commands.",
|
||||||
|
"type": "object",
|
||||||
|
"required": [
|
||||||
|
"identifier"
|
||||||
|
],
|
||||||
|
"properties": {
|
||||||
|
"version": {
|
||||||
|
"description": "The version of the permission.",
|
||||||
|
"type": [
|
||||||
|
"integer",
|
||||||
|
"null"
|
||||||
|
],
|
||||||
|
"format": "uint64",
|
||||||
|
"minimum": 1.0
|
||||||
|
},
|
||||||
|
"identifier": {
|
||||||
|
"description": "A unique identifier for the permission.",
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"description": {
|
||||||
|
"description": "Human-readable description of what the permission does. Tauri internal convention is to use `<h4>` headings in markdown content for Tauri documentation generation purposes.",
|
||||||
|
"type": [
|
||||||
|
"string",
|
||||||
|
"null"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"commands": {
|
||||||
|
"description": "Allowed or denied commands when using this permission.",
|
||||||
|
"default": {
|
||||||
|
"allow": [],
|
||||||
|
"deny": []
|
||||||
|
},
|
||||||
|
"allOf": [
|
||||||
|
{
|
||||||
|
"$ref": "#/definitions/Commands"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"scope": {
|
||||||
|
"description": "Allowed or denied scoped when using this permission.",
|
||||||
|
"allOf": [
|
||||||
|
{
|
||||||
|
"$ref": "#/definitions/Scopes"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"platforms": {
|
||||||
|
"description": "Target platforms this permission applies. By default all platforms are affected by this permission.",
|
||||||
|
"type": [
|
||||||
|
"array",
|
||||||
|
"null"
|
||||||
|
],
|
||||||
|
"items": {
|
||||||
|
"$ref": "#/definitions/Target"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"Commands": {
|
||||||
|
"description": "Allowed and denied commands inside a permission.\n\nIf two commands clash inside of `allow` and `deny`, it should be denied by default.",
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"allow": {
|
||||||
|
"description": "Allowed command.",
|
||||||
|
"default": [],
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"deny": {
|
||||||
|
"description": "Denied command, which takes priority.",
|
||||||
|
"default": [],
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"Scopes": {
|
||||||
|
"description": "An argument for fine grained behavior control of Tauri commands.\n\nIt can be of any serde serializable type and is used to allow or prevent certain actions inside a Tauri command. The configured scope is passed to the command and will be enforced by the command implementation.\n\n## Example\n\n```json { \"allow\": [{ \"path\": \"$HOME/**\" }], \"deny\": [{ \"path\": \"$HOME/secret.txt\" }] } ```",
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"allow": {
|
||||||
|
"description": "Data that defines what is allowed by the scope.",
|
||||||
|
"type": [
|
||||||
|
"array",
|
||||||
|
"null"
|
||||||
|
],
|
||||||
|
"items": {
|
||||||
|
"$ref": "#/definitions/Value"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"deny": {
|
||||||
|
"description": "Data that defines what is denied by the scope. This should be prioritized by validation logic.",
|
||||||
|
"type": [
|
||||||
|
"array",
|
||||||
|
"null"
|
||||||
|
],
|
||||||
|
"items": {
|
||||||
|
"$ref": "#/definitions/Value"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"Value": {
|
||||||
|
"description": "All supported ACL values.",
|
||||||
|
"anyOf": [
|
||||||
|
{
|
||||||
|
"description": "Represents a null JSON value.",
|
||||||
|
"type": "null"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"description": "Represents a [`bool`].",
|
||||||
|
"type": "boolean"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"description": "Represents a valid ACL [`Number`].",
|
||||||
|
"allOf": [
|
||||||
|
{
|
||||||
|
"$ref": "#/definitions/Number"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"description": "Represents a [`String`].",
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"description": "Represents a list of other [`Value`]s.",
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"$ref": "#/definitions/Value"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"description": "Represents a map of [`String`] keys to [`Value`]s.",
|
||||||
|
"type": "object",
|
||||||
|
"additionalProperties": {
|
||||||
|
"$ref": "#/definitions/Value"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"Number": {
|
||||||
|
"description": "A valid ACL number.",
|
||||||
|
"anyOf": [
|
||||||
|
{
|
||||||
|
"description": "Represents an [`i64`].",
|
||||||
|
"type": "integer",
|
||||||
|
"format": "int64"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"description": "Represents a [`f64`].",
|
||||||
|
"type": "number",
|
||||||
|
"format": "double"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"Target": {
|
||||||
|
"description": "Platform target.",
|
||||||
|
"oneOf": [
|
||||||
|
{
|
||||||
|
"description": "MacOS.",
|
||||||
|
"type": "string",
|
||||||
|
"enum": [
|
||||||
|
"macOS"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"description": "Windows.",
|
||||||
|
"type": "string",
|
||||||
|
"enum": [
|
||||||
|
"windows"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"description": "Linux.",
|
||||||
|
"type": "string",
|
||||||
|
"enum": [
|
||||||
|
"linux"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"description": "Android.",
|
||||||
|
"type": "string",
|
||||||
|
"enum": [
|
||||||
|
"android"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"description": "iOS.",
|
||||||
|
"type": "string",
|
||||||
|
"enum": [
|
||||||
|
"iOS"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"PermissionKind": {
|
||||||
|
"type": "string",
|
||||||
|
"oneOf": [
|
||||||
|
{
|
||||||
|
"description": "Enables the ping command without any pre-configured scope.",
|
||||||
|
"type": "string",
|
||||||
|
"const": "allow-ping",
|
||||||
|
"markdownDescription": "Enables the ping command without any pre-configured scope."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"description": "Denies the ping command without any pre-configured scope.",
|
||||||
|
"type": "string",
|
||||||
|
"const": "deny-ping",
|
||||||
|
"markdownDescription": "Denies the ping command without any pre-configured scope."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"description": "Allows access to VPN Service",
|
||||||
|
"type": "string",
|
||||||
|
"const": "vpn-control",
|
||||||
|
"markdownDescription": "Allows access to VPN Service"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
import { readFileSync } from 'node:fs'
|
||||||
|
import { dirname, join } from 'node:path'
|
||||||
|
import { cwd } from 'node:process'
|
||||||
|
import typescript from '@rollup/plugin-typescript'
|
||||||
|
|
||||||
|
const pkg = JSON.parse(readFileSync(join(cwd(), 'package.json'), 'utf8'))
|
||||||
|
|
||||||
|
export default {
|
||||||
|
input: 'guest-js/index.ts',
|
||||||
|
output: [
|
||||||
|
{
|
||||||
|
file: pkg.exports.import,
|
||||||
|
format: 'esm'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
file: pkg.exports.require,
|
||||||
|
format: 'cjs'
|
||||||
|
}
|
||||||
|
],
|
||||||
|
plugins: [
|
||||||
|
typescript({
|
||||||
|
declaration: true,
|
||||||
|
declarationDir: dirname(pkg.exports.import)
|
||||||
|
})
|
||||||
|
],
|
||||||
|
external: [
|
||||||
|
/^@tauri-apps\/api/,
|
||||||
|
...Object.keys(pkg.dependencies || {}),
|
||||||
|
...Object.keys(pkg.peerDependencies || {})
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
use tauri::{AppHandle, command, Runtime};
|
||||||
|
|
||||||
|
use crate::models::*;
|
||||||
|
use crate::Result;
|
||||||
|
use crate::VpnExt;
|
||||||
|
|
||||||
|
#[command]
|
||||||
|
pub(crate) async fn ping<R: Runtime>(
|
||||||
|
app: AppHandle<R>,
|
||||||
|
payload: PingRequest,
|
||||||
|
) -> Result<PingResponse> {
|
||||||
|
app.vpn().ping(payload)
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
use serde::de::DeserializeOwned;
|
||||||
|
use tauri::{plugin::PluginApi, AppHandle, Runtime};
|
||||||
|
|
||||||
|
use crate::models::*;
|
||||||
|
|
||||||
|
pub fn init<R: Runtime, C: DeserializeOwned>(
|
||||||
|
app: &AppHandle<R>,
|
||||||
|
_api: PluginApi<R, C>,
|
||||||
|
) -> crate::Result<Vpn<R>> {
|
||||||
|
Ok(Vpn(app.clone()))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Access to the vpn APIs.
|
||||||
|
pub struct Vpn<R: Runtime>(AppHandle<R>);
|
||||||
|
|
||||||
|
impl<R: Runtime> Vpn<R> {
|
||||||
|
pub fn ping(&self, payload: PingRequest) -> crate::Result<PingResponse> {
|
||||||
|
Ok(PingResponse {
|
||||||
|
value: payload.value,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
use serde::{ser::Serializer, Serialize};
|
||||||
|
|
||||||
|
pub type Result<T> = std::result::Result<T, Error>;
|
||||||
|
|
||||||
|
#[derive(Debug, thiserror::Error)]
|
||||||
|
pub enum Error {
|
||||||
|
#[error(transparent)]
|
||||||
|
Io(#[from] std::io::Error),
|
||||||
|
#[cfg(mobile)]
|
||||||
|
#[error(transparent)]
|
||||||
|
PluginInvoke(#[from] tauri::plugin::mobile::PluginInvokeError),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Serialize for Error {
|
||||||
|
fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
|
||||||
|
where
|
||||||
|
S: Serializer,
|
||||||
|
{
|
||||||
|
serializer.serialize_str(self.to_string().as_ref())
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
use tauri::{
|
||||||
|
plugin::{Builder, TauriPlugin},
|
||||||
|
Manager, Runtime,
|
||||||
|
};
|
||||||
|
|
||||||
|
pub use models::*;
|
||||||
|
|
||||||
|
#[cfg(desktop)]
|
||||||
|
mod desktop;
|
||||||
|
#[cfg(mobile)]
|
||||||
|
mod mobile;
|
||||||
|
|
||||||
|
mod commands;
|
||||||
|
mod error;
|
||||||
|
mod models;
|
||||||
|
|
||||||
|
pub use error::{Error, Result};
|
||||||
|
|
||||||
|
#[cfg(desktop)]
|
||||||
|
use desktop::Vpn;
|
||||||
|
#[cfg(mobile)]
|
||||||
|
use mobile::Vpn;
|
||||||
|
|
||||||
|
/// Extensions to [`tauri::App`], [`tauri::AppHandle`] and [`tauri::Window`] to access the vpn APIs.
|
||||||
|
pub trait VpnExt<R: Runtime> {
|
||||||
|
fn vpn(&self) -> &Vpn<R>;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<R: Runtime, T: Manager<R>> crate::VpnExt<R> for T {
|
||||||
|
fn vpn(&self) -> &Vpn<R> {
|
||||||
|
self.state::<Vpn<R>>().inner()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Initializes the plugin.
|
||||||
|
pub fn init<R: Runtime>() -> TauriPlugin<R> {
|
||||||
|
Builder::new("vpn")
|
||||||
|
.invoke_handler(tauri::generate_handler![commands::ping])
|
||||||
|
.setup(|app, api| {
|
||||||
|
#[cfg(mobile)]
|
||||||
|
let vpn = mobile::init(app, api)?;
|
||||||
|
#[cfg(desktop)]
|
||||||
|
let vpn = desktop::init(app, api)?;
|
||||||
|
app.manage(vpn);
|
||||||
|
Ok(())
|
||||||
|
})
|
||||||
|
.build()
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
use serde::de::DeserializeOwned;
|
||||||
|
use tauri::{
|
||||||
|
plugin::{PluginApi, PluginHandle},
|
||||||
|
AppHandle, Runtime,
|
||||||
|
};
|
||||||
|
|
||||||
|
use crate::models::*;
|
||||||
|
|
||||||
|
#[cfg(target_os = "ios")]
|
||||||
|
tauri::ios_plugin_binding!(init_plugin_vpn);
|
||||||
|
|
||||||
|
// initializes the Kotlin or Swift plugin classes
|
||||||
|
pub fn init<R: Runtime, C: DeserializeOwned>(
|
||||||
|
_app: &AppHandle<R>,
|
||||||
|
api: PluginApi<R, C>,
|
||||||
|
) -> crate::Result<Vpn<R>> {
|
||||||
|
#[cfg(target_os = "android")]
|
||||||
|
let handle = api.register_android_plugin("", "ExamplePlugin")?;
|
||||||
|
#[cfg(target_os = "ios")]
|
||||||
|
let handle = api.register_ios_plugin(init_plugin_vpn)?;
|
||||||
|
Ok(Vpn(handle))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Access to the vpn APIs.
|
||||||
|
pub struct Vpn<R: Runtime>(PluginHandle<R>);
|
||||||
|
|
||||||
|
impl<R: Runtime> Vpn<R> {
|
||||||
|
pub fn ping(&self, payload: PingRequest) -> crate::Result<PingResponse> {
|
||||||
|
self
|
||||||
|
.0
|
||||||
|
.run_mobile_plugin("ping", payload)
|
||||||
|
.map_err(Into::into)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
#[derive(Debug, Deserialize, Serialize)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
pub struct PingRequest {
|
||||||
|
pub value: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Default, Deserialize, Serialize)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
pub struct PingResponse {
|
||||||
|
pub value: Option<String>,
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"target": "es2021",
|
||||||
|
"module": "esnext",
|
||||||
|
"moduleResolution": "bundler",
|
||||||
|
"skipLibCheck": true,
|
||||||
|
"strict": true,
|
||||||
|
"noUnusedLocals": true,
|
||||||
|
"noImplicitAny": true,
|
||||||
|
"noEmit": true
|
||||||
|
},
|
||||||
|
"include": ["guest-js/*.ts"],
|
||||||
|
"exclude": ["dist-js", "node_modules"]
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user