-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fix #2 and add runtime feature checks
- Loading branch information
Showing
17 changed files
with
220 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "protectus" | ||
version = "0.1.1" | ||
version = "0.1.2" | ||
edition = "2021" | ||
authors = ["Dan0xE <[email protected]>"] | ||
exclude = ["/webview-src", "/examples"] | ||
|
@@ -16,4 +16,9 @@ base64 = "0.22" | |
chrono = "0.4" | ||
|
||
[build-dependencies] | ||
tauri-plugin = { version = "2.0.0-beta", features = ["build"] } | ||
tauri-plugin = { version = "2.0.0-beta", features = ["build"] } | ||
|
||
[features] | ||
default = ["service"] | ||
service = [] | ||
licensing = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
permissions/autogenerated/commands/feature_check_command.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Automatically generated - DO NOT EDIT! | ||
|
||
"$schema" = "../../schemas/schema.json" | ||
|
||
[[permission]] | ||
identifier = "allow-feature-check-command" | ||
description = "Enables the feature_check_command command without any pre-configured scope." | ||
commands.allow = ["feature_check_command"] | ||
|
||
[[permission]] | ||
identifier = "deny-feature-check-command" | ||
description = "Denies the feature_check_command command without any pre-configured scope." | ||
commands.deny = ["feature_check_command"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,51 @@ | ||
pub mod helper; | ||
#[cfg(feature = "licensing")] | ||
pub mod licensing; | ||
#[cfg(feature = "service")] | ||
pub mod service; | ||
|
||
use serde::Serialize; | ||
use tauri::plugin::{Builder, TauriPlugin}; | ||
use tauri::Runtime; | ||
use tauri::{command, Runtime}; | ||
|
||
|
||
#[cfg(feature = "licensing")] | ||
use crate::licensing::*; | ||
#[cfg(feature = "service")] | ||
use crate::service::*; | ||
use helper::feature_check_command; | ||
|
||
|
||
|
||
|
||
|
||
pub fn init<R: Runtime>() -> TauriPlugin<R> { | ||
Builder::new("protectus") | ||
.invoke_handler(tauri::generate_handler![ | ||
let mut builder = Builder::new("protectus"); | ||
|
||
#[cfg(feature = "licensing")] | ||
{ | ||
use crate::licensing::*; | ||
builder = builder.invoke_handler(tauri::generate_handler![ | ||
feature_check_command, | ||
get_hwid_command, | ||
set_serial_number_command, | ||
get_serial_number_state_command, | ||
get_serial_number_data_command, | ||
activate_license_command, | ||
deactivate_license_command, | ||
is_protected_command, | ||
]); | ||
} | ||
|
||
#[cfg(feature = "service")] | ||
{ | ||
use crate::service::*; | ||
builder = builder.invoke_handler(tauri::generate_handler![ | ||
feature_check_command, | ||
is_virtual_machine_command, | ||
is_debugger_present_command | ||
]) | ||
.build() | ||
is_debugger_present_command, | ||
is_protected_command | ||
]); | ||
} | ||
|
||
builder.build() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import {invoke} from '@tauri-apps/api/core'; | ||
|
||
interface Features { | ||
licensing: boolean; | ||
service: boolean; | ||
} | ||
|
||
type GenericFunc<F> = () => Promise<F>; | ||
|
||
/** Checks if the required feature for the passed function is enabled on the rust backend | ||
* @param {keyof Features} featureEnabled Feature that has to be enabled for this function to be executed | ||
* @param {GenericFunc<F>[]} functionsToExecute Functions that should be executed if the required feature is enabled | ||
* @throws Throws if the required feature is not enabled in the rust backend | ||
*/ | ||
export async function featureGate<F>( | ||
featureEnabled: keyof Features, | ||
...functionsToExecute: GenericFunc<F>[] | ||
): Promise<F | undefined> { | ||
const features: Features = await invoke( | ||
'plugin:protectus|feature_check_command' | ||
); | ||
|
||
if (features[featureEnabled]) { | ||
let lastResult: F | undefined = undefined; | ||
for (const fn of functionsToExecute) { | ||
lastResult = await fn(); | ||
} | ||
return lastResult; | ||
} | ||
|
||
throw new Error( | ||
`${functionsToExecute} called but required feature ${featureEnabled} is not enabled!` | ||
); | ||
} |
Oops, something went wrong.