mirror of
https://github.com/Cyrix126/gupaxx.git
synced 2024-12-22 06:39:21 +00:00
cargo fmt
This commit is contained in:
parent
1810e135a2
commit
abaaf72e4d
19 changed files with 10362 additions and 7852 deletions
6
build.rs
6
build.rs
|
@ -14,7 +14,8 @@ fn main() -> std::io::Result<()> {
|
|||
// This sets the [Run as Administrator] metadata flag for Windows.
|
||||
// Why do I do this?: [https://github.com/hinto-janai/gupax/tree/main/src#why-does-gupax-need-to-be-admin-on-windows]
|
||||
// TL;DR: Because Windows.
|
||||
res.set_manifest(r#"
|
||||
res.set_manifest(
|
||||
r#"
|
||||
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
|
||||
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
|
||||
<security>
|
||||
|
@ -24,7 +25,8 @@ fn main() -> std::io::Result<()> {
|
|||
</security>
|
||||
</trustInfo>
|
||||
</assembly>
|
||||
"#);
|
||||
"#,
|
||||
);
|
||||
res.compile()
|
||||
}
|
||||
|
||||
|
|
164
src/constants.rs
164
src/constants.rs
|
@ -45,8 +45,7 @@ pub const APP_DEFAULT_SCALE: f32 = 1.0;
|
|||
|
||||
// Constants specific for Linux distro packaging of Gupax
|
||||
#[cfg(feature = "distro")]
|
||||
pub const DISTRO_NO_UPDATE: &str =
|
||||
r#"This [Gupax] was compiled for use as a Linux distro package. Built-in updates are disabled. The below settings [Update-via-Tor] & [Auto-Update] will not do anything. Please use your package manager to update [Gupax/P2Pool/XMRig]."#;
|
||||
pub const DISTRO_NO_UPDATE: &str = r#"This [Gupax] was compiled for use as a Linux distro package. Built-in updates are disabled. The below settings [Update-via-Tor] & [Auto-Update] will not do anything. Please use your package manager to update [Gupax/P2Pool/XMRig]."#;
|
||||
|
||||
// Use macOS shaped icon for macOS
|
||||
#[cfg(target_os = "macos")]
|
||||
|
@ -58,8 +57,7 @@ pub const HORIZONTAL: &str = "--------------------------------------------";
|
|||
pub const HORI_CONSOLE: &str = "---------------------------------------------------------------------------------------------------------------------------";
|
||||
|
||||
// Keyboard shortcuts
|
||||
pub const KEYBOARD_SHORTCUTS: &str =
|
||||
r#"*---------------------------------------*
|
||||
pub const KEYBOARD_SHORTCUTS: &str = r#"*---------------------------------------*
|
||||
| Key shortcuts |
|
||||
|---------------------------------------|
|
||||
| F11 | Fullscreen |
|
||||
|
@ -93,7 +91,8 @@ pub const P2POOL_ALIVE: &str = "P2Pool is online and fully synchronized";
|
|||
pub const P2POOL_DEAD: &str = "P2Pool is offline";
|
||||
pub const P2POOL_FAILED: &str = "P2Pool is offline and failed when exiting";
|
||||
pub const P2POOL_MIDDLE: &str = "P2Pool is in the middle of (re)starting/stopping";
|
||||
pub const P2POOL_SYNCING: &str = "P2Pool is still syncing. This indicator will turn GREEN when P2Pool is ready";
|
||||
pub const P2POOL_SYNCING: &str =
|
||||
"P2Pool is still syncing. This indicator will turn GREEN when P2Pool is ready";
|
||||
|
||||
pub const XMRIG_ALIVE: &str = "XMRig is online and mining";
|
||||
pub const XMRIG_DEAD: &str = "XMRig is offline";
|
||||
|
@ -125,15 +124,13 @@ pub const DARK_GRAY: egui::Color32 = egui::Color32::from_gray(13);
|
|||
pub const SECOND: std::time::Duration = std::time::Duration::from_secs(1);
|
||||
|
||||
// The explanation given to the user on why XMRig needs sudo.
|
||||
pub const XMRIG_ADMIN_REASON: &str =
|
||||
r#"The large hashrate difference between XMRig and other miners like Monero and P2Pool's built-in miners is mostly due to XMRig configuring CPU MSRs and setting up hugepages. Other miners like Monero or P2Pool's built-in miner do not do this. It can be done manually but it isn't recommended since XMRig does this for you automatically, but only if it has the proper admin privileges."#;
|
||||
pub const XMRIG_ADMIN_REASON: &str = r#"The large hashrate difference between XMRig and other miners like Monero and P2Pool's built-in miners is mostly due to XMRig configuring CPU MSRs and setting up hugepages. Other miners like Monero or P2Pool's built-in miner do not do this. It can be done manually but it isn't recommended since XMRig does this for you automatically, but only if it has the proper admin privileges."#;
|
||||
// Password buttons
|
||||
pub const PASSWORD_TEXT: &str = "Enter sudo/admin password...";
|
||||
pub const PASSWORD_LEAVE: &str = "Return to the previous screen";
|
||||
pub const PASSWORD_ENTER: &str = "Attempt with the current password";
|
||||
pub const PASSWORD_HIDE: &str = "Toggle hiding/showing the password";
|
||||
|
||||
|
||||
// OS specific
|
||||
#[cfg(target_os = "windows")]
|
||||
pub const OS: &str = " Windows";
|
||||
|
@ -155,18 +152,22 @@ pub const OS_NAME: &str = "Linux";
|
|||
// Tooltips
|
||||
// Status
|
||||
pub const STATUS_GUPAX_UPTIME: &str = "How long Gupax has been online";
|
||||
pub const STATUS_GUPAX_CPU_USAGE: &str = "How much CPU Gupax is currently using. This accounts for all your threads (it is out of 100%)";
|
||||
pub const STATUS_GUPAX_CPU_USAGE: &str =
|
||||
"How much CPU Gupax is currently using. This accounts for all your threads (it is out of 100%)";
|
||||
pub const STATUS_GUPAX_MEMORY_USAGE: &str = "How much memory Gupax is currently using in Megabytes";
|
||||
pub const STATUS_GUPAX_SYSTEM_CPU_USAGE: &str = "How much CPU your entire system is currently using. This accounts for all your threads (it is out of 100%)";
|
||||
pub const STATUS_GUPAX_SYSTEM_MEMORY: &str = "How much memory your entire system has (including swap) and is currently using in Gigabytes";
|
||||
pub const STATUS_GUPAX_SYSTEM_CPU_MODEL: &str = "The detected model of your system's CPU and its current frequency";
|
||||
pub const STATUS_GUPAX_SYSTEM_MEMORY: &str =
|
||||
"How much memory your entire system has (including swap) and is currently using in Gigabytes";
|
||||
pub const STATUS_GUPAX_SYSTEM_CPU_MODEL: &str =
|
||||
"The detected model of your system's CPU and its current frequency";
|
||||
//--
|
||||
pub const STATUS_P2POOL_UPTIME: &str = "How long P2Pool has been online";
|
||||
pub const STATUS_P2POOL_PAYOUTS: &str = "The total amount of payouts received in this instance of P2Pool and an extrapolated estimate of how many you will receive. Warning: these stats will be quite inaccurate if your P2Pool hasn't been running for a long time!";
|
||||
pub const STATUS_P2POOL_XMR: &str = "The total amount of XMR mined in this instance of P2Pool and an extrapolated estimate of how many you will mine in the future. Warning: these stats will be quite inaccurate if your P2Pool hasn't been running for a long time!";
|
||||
pub const STATUS_P2POOL_HASHRATE: &str = "The total amount of hashrate your P2Pool has pointed at it in 15 minute, 1 hour, and 24 hour averages";
|
||||
pub const STATUS_P2POOL_SHARES: &str = "The total amount of shares found on P2Pool";
|
||||
pub const STATUS_P2POOL_EFFORT: &str = "The average amount of effort needed to find a share, and the current effort";
|
||||
pub const STATUS_P2POOL_EFFORT: &str =
|
||||
"The average amount of effort needed to find a share, and the current effort";
|
||||
pub const STATUS_P2POOL_CONNECTIONS: &str = "The total amount of miner connections on this P2Pool";
|
||||
pub const STATUS_P2POOL_MONERO_NODE: &str = "The Monero node being used by P2Pool";
|
||||
pub const STATUS_P2POOL_POOL: &str = "The P2Pool sidechain you're currently connected to";
|
||||
|
@ -180,7 +181,8 @@ pub const STATUS_XMRIG_SHARES: &str = "The amount of accepted and rejected
|
|||
pub const STATUS_XMRIG_POOL: &str = "The pool XMRig is currently mining to";
|
||||
pub const STATUS_XMRIG_THREADS: &str = "The amount of threads XMRig is currently using";
|
||||
// Status Submenus
|
||||
pub const STATUS_SUBMENU_PROCESSES: &str = "View the status of process related data for [Gupax|P2Pool|XMRig]";
|
||||
pub const STATUS_SUBMENU_PROCESSES: &str =
|
||||
"View the status of process related data for [Gupax|P2Pool|XMRig]";
|
||||
pub const STATUS_SUBMENU_P2POOL: &str = "View P2Pool specific data";
|
||||
pub const STATUS_SUBMENU_HASHRATE: &str = "Compare your CPU hashrate with others";
|
||||
//-- P2Pool
|
||||
|
@ -190,32 +192,44 @@ pub const STATUS_SUBMENU_LATEST: &str = "Sort the payouts from latest to olde
|
|||
pub const STATUS_SUBMENU_OLDEST: &str = "Sort the payouts from oldest to latest";
|
||||
pub const STATUS_SUBMENU_BIGGEST: &str = "Sort the payouts from biggest to smallest";
|
||||
pub const STATUS_SUBMENU_SMALLEST: &str = "Sort the payouts from smallest to biggest";
|
||||
pub const STATUS_SUBMENU_AUTOMATIC: &str = "Automatically calculate share/block time with your current P2Pool 1 hour average hashrate";
|
||||
pub const STATUS_SUBMENU_AUTOMATIC: &str =
|
||||
"Automatically calculate share/block time with your current P2Pool 1 hour average hashrate";
|
||||
pub const STATUS_SUBMENU_MANUAL: &str = "Manually input a hashrate to calculate share/block time with current P2Pool/Monero network stats";
|
||||
pub const STATUS_SUBMENU_HASH: &str = "Use [Hash] as the hashrate metric";
|
||||
pub const STATUS_SUBMENU_KILO: &str = "Use [Kilo] as the hashrate metric (1,000x hash)";
|
||||
pub const STATUS_SUBMENU_MEGA: &str = "Use [Mega] as the hashrate metric (1,000,000x hash)";
|
||||
pub const STATUS_SUBMENU_GIGA: &str = "Use [Giga] as the hashrate metric (1,000,000,000x hash)";
|
||||
pub const STATUS_SUBMENU_P2POOL_BLOCK_MEAN: &str = "The average time it takes for P2Pool to find a block";
|
||||
pub const STATUS_SUBMENU_P2POOL_BLOCK_MEAN: &str =
|
||||
"The average time it takes for P2Pool to find a block";
|
||||
pub const STATUS_SUBMENU_YOUR_P2POOL_HASHRATE: &str = "Your 1 hour average hashrate on P2Pool";
|
||||
pub const STATUS_SUBMENU_P2POOL_SHARE_MEAN: &str = "The average time it takes for your hashrate to find a share on P2Pool";
|
||||
pub const STATUS_SUBMENU_SOLO_BLOCK_MEAN: &str = "The average time it would take for your hashrate to find a block solo mining Monero";
|
||||
pub const STATUS_SUBMENU_P2POOL_SHARE_MEAN: &str =
|
||||
"The average time it takes for your hashrate to find a share on P2Pool";
|
||||
pub const STATUS_SUBMENU_SOLO_BLOCK_MEAN: &str =
|
||||
"The average time it would take for your hashrate to find a block solo mining Monero";
|
||||
pub const STATUS_SUBMENU_MONERO_DIFFICULTY: &str = "The current Monero network's difficulty (how many hashes it will take on average to find a block)";
|
||||
pub const STATUS_SUBMENU_MONERO_HASHRATE: &str = "The current Monero network's hashrate";
|
||||
pub const STATUS_SUBMENU_P2POOL_DIFFICULTY: &str = "The current P2Pool network's difficulty (how many hashes it will take on average to find a share)";
|
||||
pub const STATUS_SUBMENU_P2POOL_HASHRATE: &str = "The current P2Pool network's hashrate";
|
||||
pub const STATUS_SUBMENU_P2POOL_MINERS: &str = "The current amount of miners on P2Pool";
|
||||
pub const STATUS_SUBMENU_P2POOL_DOMINANCE: &str = "The percent of hashrate P2Pool accounts for in the entire Monero network";
|
||||
pub const STATUS_SUBMENU_YOUR_P2POOL_DOMINANCE: &str = "The percent of hashrate you account for in P2Pool";
|
||||
pub const STATUS_SUBMENU_YOUR_MONERO_DOMINANCE: &str = "The percent of hashrate you account for in the entire Monero network";
|
||||
pub const STATUS_SUBMENU_P2POOL_DOMINANCE: &str =
|
||||
"The percent of hashrate P2Pool accounts for in the entire Monero network";
|
||||
pub const STATUS_SUBMENU_YOUR_P2POOL_DOMINANCE: &str =
|
||||
"The percent of hashrate you account for in P2Pool";
|
||||
pub const STATUS_SUBMENU_YOUR_MONERO_DOMINANCE: &str =
|
||||
"The percent of hashrate you account for in the entire Monero network";
|
||||
pub const STATUS_SUBMENU_PROGRESS_BAR: &str = "The next time Gupax will update P2Pool stats. Each [*] is 900ms (updates roughly every 54 seconds)";
|
||||
//-- Benchmarks
|
||||
pub const STATUS_SUBMENU_YOUR_CPU: &str = "The CPU detected by Gupax";
|
||||
pub const STATUS_SUBMENU_YOUR_BENCHMARKS: &str = "How many benchmarks your CPU has had uploaded to [https://xmrig.com/benchmark] ";
|
||||
pub const STATUS_SUBMENU_YOUR_RANK: &str = "Your CPU's rank out of all CPUs listed on [https://xmrig.com/benchmark] (higher is better)";
|
||||
pub const STATUS_SUBMENU_YOUR_HIGH: &str = "The highest hashrate recorded for your CPU on [https://xmrig.com/benchmark]";
|
||||
pub const STATUS_SUBMENU_YOUR_AVERAGE: &str = "The average hashrate of your CPU based off the data at [https://xmrig.com/benchmark]";
|
||||
pub const STATUS_SUBMENU_YOUR_LOW: &str = "The lowest hashrate recorded for your CPU on [https://xmrig.com/benchmark]";
|
||||
pub const STATUS_SUBMENU_YOUR_BENCHMARKS: &str =
|
||||
"How many benchmarks your CPU has had uploaded to [https://xmrig.com/benchmark] ";
|
||||
pub const STATUS_SUBMENU_YOUR_RANK: &str =
|
||||
"Your CPU's rank out of all CPUs listed on [https://xmrig.com/benchmark] (higher is better)";
|
||||
pub const STATUS_SUBMENU_YOUR_HIGH: &str =
|
||||
"The highest hashrate recorded for your CPU on [https://xmrig.com/benchmark]";
|
||||
pub const STATUS_SUBMENU_YOUR_AVERAGE: &str =
|
||||
"The average hashrate of your CPU based off the data at [https://xmrig.com/benchmark]";
|
||||
pub const STATUS_SUBMENU_YOUR_LOW: &str =
|
||||
"The lowest hashrate recorded for your CPU on [https://xmrig.com/benchmark]";
|
||||
pub const STATUS_SUBMENU_OTHER_CPUS: &str = "A list of ALL the recorded CPU benchmarks. The CPUs most similar to yours are listed first. All this data is taken from [https://xmrig.com/benchmark].";
|
||||
pub const STATUS_SUBMENU_OTHER_CPU: &str = "The CPU name";
|
||||
pub const STATUS_SUBMENU_OTHER_RELATIVE: &str = "The relative hashrate power compared to the fastest recorded CPU, which is current: [AMD EPYC 7T83 64-Core Processor]";
|
||||
|
@ -223,12 +237,15 @@ pub const STATUS_SUBMENU_OTHER_HIGH: &str = "Highest hashrate record";
|
|||
pub const STATUS_SUBMENU_OTHER_AVERAGE: &str = "Average hashrate";
|
||||
pub const STATUS_SUBMENU_OTHER_LOW: &str = "Lowest hashrate record";
|
||||
pub const STATUS_SUBMENU_OTHER_RANK: &str = "The rank of this CPU out of [1567] (lower is better)";
|
||||
pub const STATUS_SUBMENU_OTHER_BENCHMARKS: &str = "How many benchmarks this CPU has had posted to [https://xmrig.com/benchmark]";
|
||||
pub const STATUS_SUBMENU_OTHER_BENCHMARKS: &str =
|
||||
"How many benchmarks this CPU has had posted to [https://xmrig.com/benchmark]";
|
||||
|
||||
// Gupax
|
||||
pub const GUPAX_UPDATE: &str = "Check for updates on Gupax, P2Pool, and XMRig via GitHub's API and upgrade automatically";
|
||||
pub const GUPAX_UPDATE: &str =
|
||||
"Check for updates on Gupax, P2Pool, and XMRig via GitHub's API and upgrade automatically";
|
||||
pub const GUPAX_AUTO_UPDATE: &str = "Automatically check for updates at startup";
|
||||
pub const GUPAX_SHOULD_RESTART: &str = "Gupax was updated. A restart is recommended but not required";
|
||||
pub const GUPAX_SHOULD_RESTART: &str =
|
||||
"Gupax was updated. A restart is recommended but not required";
|
||||
pub const GUPAX_UP_TO_DATE: &str = "Gupax is up-to-date";
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
pub const GUPAX_UPDATE_VIA_TOR: &str = "Update through the Tor network. Tor is embedded within Gupax; a Tor system proxy is not required";
|
||||
|
@ -241,9 +258,12 @@ pub const GUPAX_AUTO_XMRIG: &str = "Automatically start XMRig on Gupax sta
|
|||
pub const GUPAX_ADJUST: &str = "Adjust and set the width/height of the Gupax window";
|
||||
pub const GUPAX_WIDTH: &str = "Set the width of the Gupax window";
|
||||
pub const GUPAX_HEIGHT: &str = "Set the height of the Gupax window";
|
||||
pub const GUPAX_SCALE: &str = "Set the resolution scaling of the Gupax window (resize window to re-apply scaling)";
|
||||
pub const GUPAX_LOCK_WIDTH: &str = "Automatically match the HEIGHT against the WIDTH in a 4:3 ratio";
|
||||
pub const GUPAX_LOCK_HEIGHT: &str = "Automatically match the WIDTH against the HEIGHT in a 4:3 ratio";
|
||||
pub const GUPAX_SCALE: &str =
|
||||
"Set the resolution scaling of the Gupax window (resize window to re-apply scaling)";
|
||||
pub const GUPAX_LOCK_WIDTH: &str =
|
||||
"Automatically match the HEIGHT against the WIDTH in a 4:3 ratio";
|
||||
pub const GUPAX_LOCK_HEIGHT: &str =
|
||||
"Automatically match the WIDTH against the HEIGHT in a 4:3 ratio";
|
||||
pub const GUPAX_NO_LOCK: &str = "Allow individual selection of width and height";
|
||||
pub const GUPAX_SET: &str = "Set the width/height of the Gupax window to the current values";
|
||||
pub const GUPAX_TAB: &str = "Set the default tab Gupax starts on";
|
||||
|
@ -253,12 +273,10 @@ pub const GUPAX_TAB_GUPAX: &str = "Set the tab Gupax starts on to: Gupax"
|
|||
pub const GUPAX_TAB_P2POOL: &str = "Set the tab Gupax starts on to: P2Pool";
|
||||
pub const GUPAX_TAB_XMRIG: &str = "Set the tab Gupax starts on to: XMRig";
|
||||
|
||||
pub const GUPAX_SIMPLE: &str =
|
||||
r#"Use simple Gupax settings:
|
||||
pub const GUPAX_SIMPLE: &str = r#"Use simple Gupax settings:
|
||||
- Update button
|
||||
- Basic toggles"#;
|
||||
pub const GUPAX_ADVANCED: &str =
|
||||
r#"Use advanced Gupax settings:
|
||||
pub const GUPAX_ADVANCED: &str = r#"Use advanced Gupax settings:
|
||||
- Update button
|
||||
- Basic toggles
|
||||
- P2Pool/XMRig binary path selector
|
||||
|
@ -276,20 +294,20 @@ pub const P2POOL_OUT: &str = "How many out-bound peers to con
|
|||
pub const P2POOL_IN: &str = "How many in-bound peers to allow? (others connecting to you)";
|
||||
pub const P2POOL_LOG: &str = "Verbosity of the console log";
|
||||
pub const P2POOL_AUTO_NODE: &str = "Automatically ping the remote Monero nodes at Gupax startup";
|
||||
pub const P2POOL_AUTO_SELECT: &str = "Automatically select the fastest remote Monero node after pinging";
|
||||
pub const P2POOL_BACKUP_HOST_SIMPLE: &str =
|
||||
r#"Automatically switch to the other nodes listed if the current one is down.
|
||||
pub const P2POOL_AUTO_SELECT: &str =
|
||||
"Automatically select the fastest remote Monero node after pinging";
|
||||
pub const P2POOL_BACKUP_HOST_SIMPLE: &str = r#"Automatically switch to the other nodes listed if the current one is down.
|
||||
|
||||
Note: you must ping the remote nodes or this feature will default to only using the currently selected node."#;
|
||||
pub const P2POOL_BACKUP_HOST_ADVANCED: &str = "Automatically switch to the other nodes in your list if the current one is down.";
|
||||
pub const P2POOL_BACKUP_HOST_ADVANCED: &str =
|
||||
"Automatically switch to the other nodes in your list if the current one is down.";
|
||||
pub const P2POOL_SELECT_FASTEST: &str = "Select the fastest remote Monero node";
|
||||
pub const P2POOL_SELECT_RANDOM: &str = "Select a random remote Monero node";
|
||||
pub const P2POOL_SELECT_LAST: &str = "Select the previous remote Monero node";
|
||||
pub const P2POOL_SELECT_NEXT: &str = "Select the next remote Monero node";
|
||||
pub const P2POOL_PING: &str = "Ping the built-in remote Monero nodes";
|
||||
pub const P2POOL_ADDRESS: &str = "You must use a primary Monero address to mine on P2Pool (starts with a 4). It is highly recommended to create a new wallet since addresses are public on P2Pool!";
|
||||
pub const P2POOL_COMMUNITY_NODE_WARNING: &str =
|
||||
r#"TL;DR: Run & use your own Monero Node.
|
||||
pub const P2POOL_COMMUNITY_NODE_WARNING: &str = r#"TL;DR: Run & use your own Monero Node.
|
||||
|
||||
Using a Remote Monero Node is convenient but comes at the cost of privacy and reliability.
|
||||
|
||||
|
@ -300,17 +318,14 @@ Running and using your own local Monero node improves privacy and ensures your c
|
|||
For a simple guide, see the [Running a Local Monero Node] section on Gupax's GitHub by clicking this message."#;
|
||||
|
||||
pub const P2POOL_INPUT: &str = "Send a command to P2Pool";
|
||||
pub const P2POOL_ARGUMENTS: &str =
|
||||
r#"WARNING: Use [--no-color] and make sure to set [--data-api <PATH>] & [--local-api] so that the [Status] tab can work!
|
||||
pub const P2POOL_ARGUMENTS: &str = r#"WARNING: Use [--no-color] and make sure to set [--data-api <PATH>] & [--local-api] so that the [Status] tab can work!
|
||||
|
||||
Start P2Pool with these arguments and override all below settings"#;
|
||||
pub const P2POOL_SIMPLE: &str =
|
||||
r#"Use simple P2Pool settings:
|
||||
pub const P2POOL_SIMPLE: &str = r#"Use simple P2Pool settings:
|
||||
- Remote remote Monero node
|
||||
- Default P2Pool settings + Mini
|
||||
- Backup host setting"#;
|
||||
pub const P2POOL_ADVANCED: &str =
|
||||
r#"Use advanced P2Pool settings:
|
||||
pub const P2POOL_ADVANCED: &str = r#"Use advanced P2Pool settings:
|
||||
- Terminal input
|
||||
- Overriding command arguments
|
||||
- Manual node list
|
||||
|
@ -334,13 +349,11 @@ pub const LIST_DELETE: &str = "Delete the currently selected entry";
|
|||
pub const LIST_CLEAR: &str = "Clear all current values";
|
||||
|
||||
// XMRig
|
||||
pub const XMRIG_SIMPLE: &str =
|
||||
r#"Use simple XMRig settings:
|
||||
pub const XMRIG_SIMPLE: &str = r#"Use simple XMRig settings:
|
||||
- Mine to local P2Pool (localhost:3333)
|
||||
- CPU thread slider
|
||||
- HTTP API @ localhost:18088"#;
|
||||
pub const XMRIG_ADVANCED: &str =
|
||||
r#"Use advanced XMRig settings:
|
||||
pub const XMRIG_ADVANCED: &str = r#"Use advanced XMRig settings:
|
||||
- Terminal input
|
||||
- Overriding command arguments
|
||||
- Custom payout address
|
||||
|
@ -350,8 +363,7 @@ r#"Use advanced XMRig settings:
|
|||
- TLS setting
|
||||
- Keepalive setting"#;
|
||||
pub const XMRIG_INPUT: &str = "Send a command to XMRig";
|
||||
pub const XMRIG_ARGUMENTS: &str =
|
||||
r#"WARNING: Use [--no-color] and make sure to set [--http-host <IP>] & [--http-port <PORT>] so that the [Status] tab can work!
|
||||
pub const XMRIG_ARGUMENTS: &str = r#"WARNING: Use [--no-color] and make sure to set [--http-host <IP>] & [--http-port <PORT>] so that the [Status] tab can work!
|
||||
|
||||
Start XMRig with these arguments and override all below settings"#;
|
||||
pub const XMRIG_ADDRESS: &str = "Specify which Monero address to payout to. This does nothing if mining to P2Pool since the address being paid out to will be the one P2Pool started with. This doubles as a rig identifier for P2Pool and some pools.";
|
||||
|
@ -360,9 +372,12 @@ pub const XMRIG_IP: &str = "Specify the pool IP to connect to with X
|
|||
pub const XMRIG_PORT: &str = "Specify the port of the pool; [1-65535]";
|
||||
pub const XMRIG_RIG: &str = "Add an optional rig ID. This will be the name shown on the pool; Only [A-Za-z0-9-_] and spaces allowed; Max length = 30 characters";
|
||||
#[cfg(not(target_os = "linux"))]
|
||||
pub const XMRIG_PAUSE: &str = "THIS SETTING IS DISABLED IF SET TO [0]. Pause mining if user is active, resume after";
|
||||
pub const XMRIG_API_IP: &str = "Specify which IP to bind to for XMRig's HTTP API; If empty: [localhost/127.0.0.1]";
|
||||
pub const XMRIG_API_PORT: &str = "Specify which port to bind to for XMRig's HTTP API; If empty: [18088]";
|
||||
pub const XMRIG_PAUSE: &str =
|
||||
"THIS SETTING IS DISABLED IF SET TO [0]. Pause mining if user is active, resume after";
|
||||
pub const XMRIG_API_IP: &str =
|
||||
"Specify which IP to bind to for XMRig's HTTP API; If empty: [localhost/127.0.0.1]";
|
||||
pub const XMRIG_API_PORT: &str =
|
||||
"Specify which port to bind to for XMRig's HTTP API; If empty: [18088]";
|
||||
pub const XMRIG_TLS: &str = "Enable SSL/TLS connections (needs pool support)";
|
||||
pub const XMRIG_KEEPALIVE: &str = "Send keepalive packets to prevent timeout (needs pool support)";
|
||||
pub const XMRIG_THREADS: &str = "Number of CPU threads to use for mining";
|
||||
|
@ -372,8 +387,7 @@ pub const XMRIG_PATH_OK: &str = "XMRig was found at the given PATH";
|
|||
pub const XMRIG_PATH_EMPTY: &str = "XMRig PATH is empty! To fix: goto the [Gupax Advanced] tab, select [Open] and specify where XMRig is located.";
|
||||
|
||||
// CLI argument messages
|
||||
pub const ARG_HELP: &str =
|
||||
r#"USAGE: ./gupax [--flag]
|
||||
pub const ARG_HELP: &str = r#"USAGE: ./gupax [--flag]
|
||||
|
||||
--help Print this help message
|
||||
--version Print version and build info
|
||||
|
@ -390,29 +404,16 @@ r#"USAGE: ./gupax [--flag]
|
|||
To view more detailed console debug information, start Gupax with
|
||||
the environment variable [RUST_LOG] set to a log level like so:
|
||||
RUST_LOG=(trace|debug|info|warn|error) ./gupax"#;
|
||||
pub const ARG_COPYRIGHT: &str =
|
||||
r#"Gupax is licensed under GPLv3.
|
||||
pub const ARG_COPYRIGHT: &str = r#"Gupax is licensed under GPLv3.
|
||||
For more information, see link below:
|
||||
<https://github.com/hinto-janai/gupax>"#;
|
||||
|
||||
//---------------------------------------------------------------------------------------------------- Visuals
|
||||
use egui::epaint::{
|
||||
Rounding,
|
||||
Shadow,
|
||||
Stroke
|
||||
};
|
||||
use egui::epaint::{Rounding, Shadow, Stroke};
|
||||
|
||||
use egui::{
|
||||
Color32,
|
||||
Visuals,
|
||||
style::Spacing,
|
||||
};
|
||||
use egui::{style::Spacing, Color32, Visuals};
|
||||
|
||||
use egui::style::{
|
||||
Selection,
|
||||
Widgets,
|
||||
WidgetVisuals,
|
||||
};
|
||||
use egui::style::{Selection, WidgetVisuals, Widgets};
|
||||
use once_cell::sync::Lazy;
|
||||
|
||||
pub const ACCENT_COLOR: Color32 = Color32::from_rgb(200, 100, 100);
|
||||
|
@ -497,8 +498,17 @@ mod test {
|
|||
|
||||
#[test]
|
||||
fn default_app_ratio_is_4_by_3() {
|
||||
assert_eq!(format!("{:.3}", crate::APP_MIN_WIDTH/crate::APP_MIN_HEIGHT), "1.333");
|
||||
assert_eq!(format!("{:.3}", crate::APP_DEFAULT_WIDTH/crate::APP_DEFAULT_HEIGHT), "1.333");
|
||||
assert_eq!(
|
||||
format!("{:.3}", crate::APP_MIN_WIDTH / crate::APP_MIN_HEIGHT),
|
||||
"1.333"
|
||||
);
|
||||
assert_eq!(
|
||||
format!(
|
||||
"{:.3}",
|
||||
crate::APP_DEFAULT_WIDTH / crate::APP_DEFAULT_HEIGHT
|
||||
),
|
||||
"1.333"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
395
src/disk.rs
395
src/disk.rs
|
@ -30,28 +30,21 @@
|
|||
// ├─ Version/
|
||||
// ├─ ...
|
||||
|
||||
use crate::{constants::*, gupax::Ratio, human::*, macros::*, xmr::*, Tab};
|
||||
use figment::providers::{Format, Toml};
|
||||
use figment::Figment;
|
||||
use log::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
#[cfg(target_family = "unix")]
|
||||
use std::os::unix::fs::PermissionsExt;
|
||||
use std::{
|
||||
fs,
|
||||
fmt::Display,
|
||||
fmt::Write,
|
||||
fs,
|
||||
path::PathBuf,
|
||||
result::Result,
|
||||
sync::{Arc, Mutex},
|
||||
fmt::Write,
|
||||
};
|
||||
use serde::{Serialize,Deserialize};
|
||||
use figment::Figment;
|
||||
use figment::providers::{Format,Toml};
|
||||
use crate::{
|
||||
human::*,
|
||||
constants::*,
|
||||
gupax::Ratio,
|
||||
Tab,
|
||||
xmr::*,
|
||||
macros::*,
|
||||
};
|
||||
use log::*;
|
||||
#[cfg(target_family = "unix")]
|
||||
use std::os::unix::fs::PermissionsExt;
|
||||
|
||||
//---------------------------------------------------------------------------------------------------- Const
|
||||
// State file
|
||||
|
@ -132,8 +125,11 @@ pub fn get_gupax_data_path() -> Result<PathBuf, TomlError> {
|
|||
gupax_p2pool_dir.push(GUPAX_P2POOL_API_DIRECTORY);
|
||||
create_gupax_p2pool_dir(&gupax_p2pool_dir)?;
|
||||
Ok(path)
|
||||
},
|
||||
None => { error!("OS | Data path ... FAIL"); Err(TomlError::Path(PATH_ERROR.to_string())) },
|
||||
}
|
||||
None => {
|
||||
error!("OS | Data path ... FAIL");
|
||||
Err(TomlError::Path(PATH_ERROR.to_string()))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -142,8 +138,21 @@ pub fn set_unix_750_perms(path: &PathBuf) -> Result<(), TomlError> {
|
|||
return Ok(());
|
||||
#[cfg(target_family = "unix")]
|
||||
match fs::set_permissions(path, fs::Permissions::from_mode(0o750)) {
|
||||
Ok(_) => { info!("OS | Unix 750 permissions on path [{}] ... OK", path.display()); Ok(()) },
|
||||
Err(e) => { error!("OS | Unix 750 permissions on path [{}] ... FAIL ... {}", path.display(), e); Err(TomlError::Io(e)) },
|
||||
Ok(_) => {
|
||||
info!(
|
||||
"OS | Unix 750 permissions on path [{}] ... OK",
|
||||
path.display()
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
Err(e) => {
|
||||
error!(
|
||||
"OS | Unix 750 permissions on path [{}] ... FAIL ... {}",
|
||||
path.display(),
|
||||
e
|
||||
);
|
||||
Err(TomlError::Io(e))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -152,8 +161,21 @@ pub fn set_unix_660_perms(path: &PathBuf) -> Result<(), TomlError> {
|
|||
return Ok(());
|
||||
#[cfg(target_family = "unix")]
|
||||
match fs::set_permissions(path, fs::Permissions::from_mode(0o660)) {
|
||||
Ok(_) => { info!("OS | Unix 660 permissions on path [{}] ... OK", path.display()); Ok(()) },
|
||||
Err(e) => { error!("OS | Unix 660 permissions on path [{}] ... FAIL ... {}", path.display(), e); Err(TomlError::Io(e)) },
|
||||
Ok(_) => {
|
||||
info!(
|
||||
"OS | Unix 660 permissions on path [{}] ... OK",
|
||||
path.display()
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
Err(e) => {
|
||||
error!(
|
||||
"OS | Unix 660 permissions on path [{}] ... FAIL ... {}",
|
||||
path.display(),
|
||||
e
|
||||
);
|
||||
Err(TomlError::Io(e))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -167,7 +189,10 @@ pub fn create_gupax_dir(path: &PathBuf) -> Result<(), TomlError> {
|
|||
// Create Gupax directory
|
||||
match fs::create_dir_all(path) {
|
||||
Ok(_) => info!("OS | Create data path ... OK"),
|
||||
Err(e) => { error!("OS | Create data path ... FAIL ... {}", e); return Err(TomlError::Io(e)) },
|
||||
Err(e) => {
|
||||
error!("OS | Create data path ... FAIL ... {}", e);
|
||||
return Err(TomlError::Io(e));
|
||||
}
|
||||
}
|
||||
set_unix_750_perms(path)
|
||||
}
|
||||
|
@ -175,8 +200,21 @@ pub fn create_gupax_dir(path: &PathBuf) -> Result<(), TomlError> {
|
|||
pub fn create_gupax_p2pool_dir(path: &PathBuf) -> Result<(), TomlError> {
|
||||
// Create Gupax directory
|
||||
match fs::create_dir_all(path) {
|
||||
Ok(_) => { info!("OS | Create Gupax-P2Pool API path [{}] ... OK", path.display()); Ok(()) },
|
||||
Err(e) => { error!("OS | Create Gupax-P2Pool API path [{}] ... FAIL ... {}", path.display(), e); Err(TomlError::Io(e)) },
|
||||
Ok(_) => {
|
||||
info!(
|
||||
"OS | Create Gupax-P2Pool API path [{}] ... OK",
|
||||
path.display()
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
Err(e) => {
|
||||
error!(
|
||||
"OS | Create Gupax-P2Pool API path [{}] ... FAIL ... {}",
|
||||
path.display(),
|
||||
e
|
||||
);
|
||||
Err(TomlError::Io(e))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -186,18 +224,20 @@ pub fn read_to_string(file: File, path: &PathBuf) -> Result<String, TomlError> {
|
|||
Ok(string) => {
|
||||
info!("{:?} | Read ... OK", file);
|
||||
Ok(string)
|
||||
},
|
||||
}
|
||||
Err(err) => {
|
||||
warn!("{:?} | Read ... FAIL", file);
|
||||
Err(TomlError::Io(err))
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Write str to console with [info!] surrounded by "---"
|
||||
pub fn print_dash(toml: &str) {
|
||||
info!("{}", HORIZONTAL);
|
||||
for i in toml.lines() { info!("{}", i); }
|
||||
for i in toml.lines() {
|
||||
info!("{}", i);
|
||||
}
|
||||
info!("{}", HORIZONTAL);
|
||||
}
|
||||
|
||||
|
@ -251,7 +291,7 @@ impl State {
|
|||
Err(err) => {
|
||||
warn!("State | String -> State ... FAIL ... {}", err);
|
||||
Err(TomlError::Deserialize(err))
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -259,7 +299,10 @@ impl State {
|
|||
pub fn to_string(&self) -> Result<String, TomlError> {
|
||||
match toml::ser::to_string(self) {
|
||||
Ok(s) => Ok(s),
|
||||
Err(e) => { error!("State | Couldn't serialize default file: {}", e); Err(TomlError::Serialize(e)) },
|
||||
Err(e) => {
|
||||
error!("State | Couldn't serialize default file: {}", e);
|
||||
Err(TomlError::Serialize(e))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -280,7 +323,7 @@ impl State {
|
|||
Ok(s) => s,
|
||||
Err(e) => return Err(e),
|
||||
}
|
||||
},
|
||||
}
|
||||
};
|
||||
// Deserialize, attempt merge if failed
|
||||
match Self::from_str(&string) {
|
||||
|
@ -288,10 +331,13 @@ impl State {
|
|||
Err(_) => {
|
||||
warn!("State | Attempting merge...");
|
||||
match Self::merge(&string) {
|
||||
Ok(mut new) => { Self::save(&mut new, path)?; Ok(new) },
|
||||
Ok(mut new) => {
|
||||
Self::save(&mut new, path)?;
|
||||
Ok(new)
|
||||
}
|
||||
Err(e) => Err(e),
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -317,12 +363,21 @@ impl State {
|
|||
info!("State | Parse ... OK");
|
||||
print_dash(&string);
|
||||
string
|
||||
},
|
||||
Err(err) => { error!("State | Couldn't parse TOML into string ... FAIL"); return Err(TomlError::Serialize(err)) },
|
||||
}
|
||||
Err(err) => {
|
||||
error!("State | Couldn't parse TOML into string ... FAIL");
|
||||
return Err(TomlError::Serialize(err));
|
||||
}
|
||||
};
|
||||
match fs::write(path, string) {
|
||||
Ok(_) => { info!("State | Save ... OK"); Ok(()) },
|
||||
Err(err) => { error!("State | Couldn't overwrite TOML file ... FAIL"); Err(TomlError::Io(err)) },
|
||||
Ok(_) => {
|
||||
info!("State | Save ... OK");
|
||||
Ok(())
|
||||
}
|
||||
Err(err) => {
|
||||
error!("State | Couldn't overwrite TOML file ... FAIL");
|
||||
Err(TomlError::Io(err))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -330,9 +385,18 @@ impl State {
|
|||
// leaving behind old keys+values and updating [default] with old valid ones.
|
||||
pub fn merge(old: &str) -> Result<Self, TomlError> {
|
||||
let default = toml::ser::to_string(&Self::new()).unwrap();
|
||||
let new: Self = match Figment::from(Toml::string(&default)).merge(Toml::string(old)).extract() {
|
||||
Ok(new) => { info!("State | TOML merge ... OK"); new },
|
||||
Err(err) => { error!("State | Couldn't merge default + old TOML"); return Err(TomlError::Merge(err)) },
|
||||
let new: Self = match Figment::from(Toml::string(&default))
|
||||
.merge(Toml::string(old))
|
||||
.extract()
|
||||
{
|
||||
Ok(new) => {
|
||||
info!("State | TOML merge ... OK");
|
||||
new
|
||||
}
|
||||
Err(err) => {
|
||||
error!("State | Couldn't merge default + old TOML");
|
||||
return Err(TomlError::Merge(err));
|
||||
}
|
||||
};
|
||||
Ok(new)
|
||||
}
|
||||
|
@ -365,8 +429,8 @@ impl Node {
|
|||
}
|
||||
Err(err) => {
|
||||
error!("Node | String parse ... FAIL ... {}", err);
|
||||
return Err(TomlError::Deserialize(err))
|
||||
},
|
||||
return Err(TomlError::Deserialize(err));
|
||||
}
|
||||
};
|
||||
let size = nodes.keys().len();
|
||||
let mut vec = Vec::with_capacity(size);
|
||||
|
@ -374,29 +438,43 @@ impl Node {
|
|||
let ip = match values.get("ip") {
|
||||
Some(ip) => match ip.as_str() {
|
||||
Some(ip) => ip.to_string(),
|
||||
None => { error!("Node | [None] at [ip] parse"); return Err(TomlError::Parse("[None] at [ip] parse")) },
|
||||
None => {
|
||||
error!("Node | [None] at [ip] parse");
|
||||
return Err(TomlError::Parse("[None] at [ip] parse"));
|
||||
}
|
||||
},
|
||||
None => { error!("Node | [None] at [ip] parse"); return Err(TomlError::Parse("[None] at [ip] parse")) },
|
||||
None => {
|
||||
error!("Node | [None] at [ip] parse");
|
||||
return Err(TomlError::Parse("[None] at [ip] parse"));
|
||||
}
|
||||
};
|
||||
let rpc = match values.get("rpc") {
|
||||
Some(rpc) => match rpc.as_str() {
|
||||
Some(rpc) => rpc.to_string(),
|
||||
None => { error!("Node | [None] at [rpc] parse"); return Err(TomlError::Parse("[None] at [rpc] parse")) },
|
||||
None => {
|
||||
error!("Node | [None] at [rpc] parse");
|
||||
return Err(TomlError::Parse("[None] at [rpc] parse"));
|
||||
}
|
||||
},
|
||||
None => { error!("Node | [None] at [rpc] parse"); return Err(TomlError::Parse("[None] at [rpc] parse")) },
|
||||
None => {
|
||||
error!("Node | [None] at [rpc] parse");
|
||||
return Err(TomlError::Parse("[None] at [rpc] parse"));
|
||||
}
|
||||
};
|
||||
let zmq = match values.get("zmq") {
|
||||
Some(zmq) => match zmq.as_str() {
|
||||
Some(zmq) => zmq.to_string(),
|
||||
None => { error!("Node | [None] at [zmq] parse"); return Err(TomlError::Parse("[None] at [zmq] parse")) },
|
||||
None => {
|
||||
error!("Node | [None] at [zmq] parse");
|
||||
return Err(TomlError::Parse("[None] at [zmq] parse"));
|
||||
}
|
||||
},
|
||||
None => { error!("Node | [None] at [zmq] parse"); return Err(TomlError::Parse("[None] at [zmq] parse")) },
|
||||
};
|
||||
let node = Node {
|
||||
ip,
|
||||
rpc,
|
||||
zmq,
|
||||
None => {
|
||||
error!("Node | [None] at [zmq] parse");
|
||||
return Err(TomlError::Parse("[None] at [zmq] parse"));
|
||||
}
|
||||
};
|
||||
let node = Node { ip, rpc, zmq };
|
||||
vec.push((key.clone(), node));
|
||||
}
|
||||
Ok(vec)
|
||||
|
@ -410,10 +488,7 @@ impl Node {
|
|||
write!(
|
||||
toml,
|
||||
"[\'{}\']\nip = {:#?}\nrpc = {:#?}\nzmq = {:#?}\n\n",
|
||||
key,
|
||||
value.ip,
|
||||
value.rpc,
|
||||
value.zmq,
|
||||
key, value.ip, value.rpc, value.zmq,
|
||||
)?;
|
||||
}
|
||||
Ok(toml)
|
||||
|
@ -433,7 +508,7 @@ impl Node {
|
|||
_ => {
|
||||
Self::create_new(path)?;
|
||||
read_to_string(file, path)?
|
||||
},
|
||||
}
|
||||
};
|
||||
// Deserialize, attempt merge if failed
|
||||
Self::from_str_to_vec(&string)
|
||||
|
@ -455,8 +530,14 @@ impl Node {
|
|||
info!("Node | Saving to disk ... [{}]", path.display());
|
||||
let string = Self::to_string(vec)?;
|
||||
match fs::write(path, string) {
|
||||
Ok(_) => { info!("Node | Save ... OK"); Ok(()) },
|
||||
Err(err) => { error!("Node | Couldn't overwrite file"); Err(TomlError::Io(err)) },
|
||||
Ok(_) => {
|
||||
info!("Node | Save ... OK");
|
||||
Ok(())
|
||||
}
|
||||
Err(err) => {
|
||||
error!("Node | Couldn't overwrite file");
|
||||
Err(TomlError::Io(err))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -502,8 +583,8 @@ impl Pool {
|
|||
}
|
||||
Err(err) => {
|
||||
error!("Pool | String parse ... FAIL ... {}", err);
|
||||
return Err(TomlError::Deserialize(err))
|
||||
},
|
||||
return Err(TomlError::Deserialize(err));
|
||||
}
|
||||
};
|
||||
let size = pools.keys().len();
|
||||
let mut vec = Vec::with_capacity(size);
|
||||
|
@ -512,29 +593,43 @@ impl Pool {
|
|||
let rig = match values.get("rig") {
|
||||
Some(rig) => match rig.as_str() {
|
||||
Some(rig) => rig.to_string(),
|
||||
None => { error!("Pool | [None] at [rig] parse"); return Err(TomlError::Parse("[None] at [rig] parse")) },
|
||||
None => {
|
||||
error!("Pool | [None] at [rig] parse");
|
||||
return Err(TomlError::Parse("[None] at [rig] parse"));
|
||||
}
|
||||
},
|
||||
None => { error!("Pool | [None] at [rig] parse"); return Err(TomlError::Parse("[None] at [rig] parse")) },
|
||||
None => {
|
||||
error!("Pool | [None] at [rig] parse");
|
||||
return Err(TomlError::Parse("[None] at [rig] parse"));
|
||||
}
|
||||
};
|
||||
let ip = match values.get("ip") {
|
||||
Some(ip) => match ip.as_str() {
|
||||
Some(ip) => ip.to_string(),
|
||||
None => { error!("Pool | [None] at [ip] parse"); return Err(TomlError::Parse("[None] at [ip] parse")) },
|
||||
None => {
|
||||
error!("Pool | [None] at [ip] parse");
|
||||
return Err(TomlError::Parse("[None] at [ip] parse"));
|
||||
}
|
||||
},
|
||||
None => { error!("Pool | [None] at [ip] parse"); return Err(TomlError::Parse("[None] at [ip] parse")) },
|
||||
None => {
|
||||
error!("Pool | [None] at [ip] parse");
|
||||
return Err(TomlError::Parse("[None] at [ip] parse"));
|
||||
}
|
||||
};
|
||||
let port = match values.get("port") {
|
||||
Some(port) => match port.as_str() {
|
||||
Some(port) => port.to_string(),
|
||||
None => { error!("Pool | [None] at [port] parse"); return Err(TomlError::Parse("[None] at [port] parse")) },
|
||||
None => {
|
||||
error!("Pool | [None] at [port] parse");
|
||||
return Err(TomlError::Parse("[None] at [port] parse"));
|
||||
}
|
||||
},
|
||||
None => { error!("Pool | [None] at [port] parse"); return Err(TomlError::Parse("[None] at [port] parse")) },
|
||||
};
|
||||
let pool = Pool {
|
||||
rig,
|
||||
ip,
|
||||
port,
|
||||
None => {
|
||||
error!("Pool | [None] at [port] parse");
|
||||
return Err(TomlError::Parse("[None] at [port] parse"));
|
||||
}
|
||||
};
|
||||
let pool = Pool { rig, ip, port };
|
||||
vec.push((key.clone(), pool));
|
||||
}
|
||||
Ok(vec)
|
||||
|
@ -546,10 +641,7 @@ impl Pool {
|
|||
write!(
|
||||
toml,
|
||||
"[\'{}\']\nrig = {:#?}\nip = {:#?}\nport = {:#?}\n\n",
|
||||
key,
|
||||
value.rig,
|
||||
value.ip,
|
||||
value.port,
|
||||
key, value.rig, value.ip, value.port,
|
||||
)?;
|
||||
}
|
||||
Ok(toml)
|
||||
|
@ -564,7 +656,7 @@ impl Pool {
|
|||
_ => {
|
||||
Self::create_new(path)?;
|
||||
read_to_string(file, path)?
|
||||
},
|
||||
}
|
||||
};
|
||||
// Deserialize
|
||||
Self::from_str_to_vec(&string)
|
||||
|
@ -583,8 +675,14 @@ impl Pool {
|
|||
info!("Pool | Saving to disk ... [{}]", path.display());
|
||||
let string = Self::to_string(vec)?;
|
||||
match fs::write(path, string) {
|
||||
Ok(_) => { info!("Pool | Save ... OK"); Ok(()) },
|
||||
Err(err) => { error!("Pool | Couldn't overwrite file"); Err(TomlError::Io(err)) },
|
||||
Ok(_) => {
|
||||
info!("Pool | Save ... OK");
|
||||
Ok(())
|
||||
}
|
||||
Err(err) => {
|
||||
error!("Pool | Couldn't overwrite file");
|
||||
Err(TomlError::Io(err))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -605,7 +703,11 @@ pub struct GupaxP2poolApi {
|
|||
pub path_xmr: PathBuf, // Path to [xmr]
|
||||
}
|
||||
|
||||
impl Default for GupaxP2poolApi { fn default() -> Self { Self::new() } }
|
||||
impl Default for GupaxP2poolApi {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl GupaxP2poolApi {
|
||||
//---------------------------------------------------------------------------------------------------- Init, these pretty much only get called once
|
||||
|
@ -646,8 +748,11 @@ impl GupaxP2poolApi {
|
|||
let mut path = gupax_p2pool_dir.clone();
|
||||
path.push(file);
|
||||
if path.exists() {
|
||||
info!("GupaxP2poolApi | [{}] already exists, skipping...", path.display());
|
||||
continue
|
||||
info!(
|
||||
"GupaxP2poolApi | [{}] already exists, skipping...",
|
||||
path.display()
|
||||
);
|
||||
continue;
|
||||
}
|
||||
match std::fs::File::create(&path) {
|
||||
Ok(mut f) => {
|
||||
|
@ -656,21 +761,40 @@ impl GupaxP2poolApi {
|
|||
_ => (),
|
||||
}
|
||||
info!("GupaxP2poolApi | [{}] create ... OK", path.display());
|
||||
},
|
||||
Err(e) => { warn!("GupaxP2poolApi | [{}] create ... FAIL: {}", path.display(), e); return Err(TomlError::Io(e)) },
|
||||
}
|
||||
Err(e) => {
|
||||
warn!(
|
||||
"GupaxP2poolApi | [{}] create ... FAIL: {}",
|
||||
path.display(),
|
||||
e
|
||||
);
|
||||
return Err(TomlError::Io(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn read_all_files_and_update(&mut self) -> Result<(), TomlError> {
|
||||
let payout_u64 = match read_to_string(File::Payout, &self.path_payout)?.trim().parse::<u64>() {
|
||||
let payout_u64 = match read_to_string(File::Payout, &self.path_payout)?
|
||||
.trim()
|
||||
.parse::<u64>()
|
||||
{
|
||||
Ok(o) => o,
|
||||
Err(e) => { warn!("GupaxP2poolApi | [payout] parse error: {}", e); return Err(TomlError::Parse("payout")) }
|
||||
Err(e) => {
|
||||
warn!("GupaxP2poolApi | [payout] parse error: {}", e);
|
||||
return Err(TomlError::Parse("payout"));
|
||||
}
|
||||
};
|
||||
let xmr = match read_to_string(File::Xmr, &self.path_xmr)?.trim().parse::<u64>() {
|
||||
let xmr = match read_to_string(File::Xmr, &self.path_xmr)?
|
||||
.trim()
|
||||
.parse::<u64>()
|
||||
{
|
||||
Ok(o) => AtomicUnit::from_u64(o),
|
||||
Err(e) => { warn!("GupaxP2poolApi | [xmr] parse error: {}", e); return Err(TomlError::Parse("xmr")) }
|
||||
Err(e) => {
|
||||
warn!("GupaxP2poolApi | [xmr] parse error: {}", e);
|
||||
return Err(TomlError::Parse("xmr"));
|
||||
}
|
||||
};
|
||||
let payout = HumanNumber::from_u64(payout_u64);
|
||||
let log = read_to_string(File::Log, &self.path_log)?;
|
||||
|
@ -689,9 +813,15 @@ impl GupaxP2poolApi {
|
|||
|
||||
// Completely delete the [p2pool] folder and create defaults.
|
||||
pub fn create_new(path: &PathBuf) -> Result<(), TomlError> {
|
||||
info!("GupaxP2poolApi | Deleting old folder at [{}]...", path.display());
|
||||
info!(
|
||||
"GupaxP2poolApi | Deleting old folder at [{}]...",
|
||||
path.display()
|
||||
);
|
||||
std::fs::remove_dir_all(&path)?;
|
||||
info!("GupaxP2poolApi | Creating new default folder at [{}]...", path.display());
|
||||
info!(
|
||||
"GupaxP2poolApi | Creating new default folder at [{}]...",
|
||||
path.display()
|
||||
);
|
||||
create_gupax_p2pool_dir(&path)?;
|
||||
Self::create_all_files(&path)?;
|
||||
Ok(())
|
||||
|
@ -736,7 +866,13 @@ impl GupaxP2poolApi {
|
|||
}
|
||||
|
||||
// Takes the (date, atomic_unit, block) and updates [self] and the [PayoutOrd]
|
||||
pub fn add_payout(&mut self, formatted_log_line: &str, date: String, atomic_unit: AtomicUnit, block: HumanNumber) {
|
||||
pub fn add_payout(
|
||||
&mut self,
|
||||
formatted_log_line: &str,
|
||||
date: String,
|
||||
atomic_unit: AtomicUnit,
|
||||
block: HumanNumber,
|
||||
) {
|
||||
self.append_log(formatted_log_line);
|
||||
self.append_head_log_rev(formatted_log_line);
|
||||
self.payout_u64 += 1;
|
||||
|
@ -757,23 +893,62 @@ impl GupaxP2poolApi {
|
|||
use std::io::Write;
|
||||
let mut file = match fs::OpenOptions::new().append(true).create(true).open(path) {
|
||||
Ok(f) => f,
|
||||
Err(e) => { error!("GupaxP2poolApi | Append [{}] ... FAIL: {}", path.display(), e); return Err(TomlError::Io(e)) },
|
||||
Err(e) => {
|
||||
error!(
|
||||
"GupaxP2poolApi | Append [{}] ... FAIL: {}",
|
||||
path.display(),
|
||||
e
|
||||
);
|
||||
return Err(TomlError::Io(e));
|
||||
}
|
||||
};
|
||||
match writeln!(file, "{}", formatted_log_line) {
|
||||
Ok(_) => { debug!("GupaxP2poolApi | Append [{}] ... OK", path.display()); Ok(()) },
|
||||
Err(e) => { error!("GupaxP2poolApi | Append [{}] ... FAIL: {}", path.display(), e); Err(TomlError::Io(e)) },
|
||||
Ok(_) => {
|
||||
debug!("GupaxP2poolApi | Append [{}] ... OK", path.display());
|
||||
Ok(())
|
||||
}
|
||||
Err(e) => {
|
||||
error!(
|
||||
"GupaxP2poolApi | Append [{}] ... FAIL: {}",
|
||||
path.display(),
|
||||
e
|
||||
);
|
||||
Err(TomlError::Io(e))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn disk_overwrite(string: &str, path: &PathBuf) -> Result<(), TomlError> {
|
||||
use std::io::Write;
|
||||
let mut file = match fs::OpenOptions::new().write(true).truncate(true).create(true).open(path) {
|
||||
let mut file = match fs::OpenOptions::new()
|
||||
.write(true)
|
||||
.truncate(true)
|
||||
.create(true)
|
||||
.open(path)
|
||||
{
|
||||
Ok(f) => f,
|
||||
Err(e) => { error!("GupaxP2poolApi | Overwrite [{}] ... FAIL: {}", path.display(), e); return Err(TomlError::Io(e)) },
|
||||
Err(e) => {
|
||||
error!(
|
||||
"GupaxP2poolApi | Overwrite [{}] ... FAIL: {}",
|
||||
path.display(),
|
||||
e
|
||||
);
|
||||
return Err(TomlError::Io(e));
|
||||
}
|
||||
};
|
||||
match writeln!(file, "{}", string) {
|
||||
Ok(_) => { debug!("GupaxP2poolApi | Overwrite [{}] ... OK", path.display()); Ok(()) },
|
||||
Err(e) => { error!("GupaxP2poolApi | Overwrite [{}] ... FAIL: {}", path.display(), e); Err(TomlError::Io(e)) },
|
||||
Ok(_) => {
|
||||
debug!("GupaxP2poolApi | Overwrite [{}] ... OK", path.display());
|
||||
Ok(())
|
||||
}
|
||||
Err(e) => {
|
||||
error!(
|
||||
"GupaxP2poolApi | Overwrite [{}] ... FAIL: {}",
|
||||
path.display(),
|
||||
e
|
||||
);
|
||||
Err(TomlError::Io(e))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -910,37 +1085,29 @@ impl Hash {
|
|||
|
||||
pub fn convert(f: f64, og: Self, new: Self) -> f64 {
|
||||
match og {
|
||||
Self::Hash => {
|
||||
match new {
|
||||
Self::Hash => match new {
|
||||
Self::Hash => f,
|
||||
Self::Kilo => f / 1_000.0,
|
||||
Self::Mega => f / 1_000_000.0,
|
||||
Self::Giga => f / 1_000_000_000.0,
|
||||
}
|
||||
},
|
||||
Self::Kilo => {
|
||||
match new {
|
||||
Self::Kilo => match new {
|
||||
Self::Hash => f * 1_000.0,
|
||||
Self::Kilo => f,
|
||||
Self::Mega => f / 1_000.0,
|
||||
Self::Giga => f / 1_000_000.0,
|
||||
}
|
||||
},
|
||||
Self::Mega => {
|
||||
match new {
|
||||
Self::Mega => match new {
|
||||
Self::Hash => f * 1_000_000.0,
|
||||
Self::Kilo => f * 1_000.0,
|
||||
Self::Mega => f,
|
||||
Self::Giga => f / 1_000.0,
|
||||
}
|
||||
},
|
||||
Self::Giga => {
|
||||
match new {
|
||||
Self::Giga => match new {
|
||||
Self::Hash => f * 1_000_000_000.0,
|
||||
Self::Kilo => f * 1_000_000.0,
|
||||
Self::Mega => f * 1_000.0,
|
||||
Self::Giga => f,
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -1412,8 +1579,8 @@ mod test {
|
|||
#[test]
|
||||
fn create_and_serde_gupax_p2pool_api() {
|
||||
use crate::disk::GupaxP2poolApi;
|
||||
use crate::xmr::PayoutOrd;
|
||||
use crate::xmr::AtomicUnit;
|
||||
use crate::xmr::PayoutOrd;
|
||||
|
||||
// Get API dir, fill paths.
|
||||
let mut api = GupaxP2poolApi::new();
|
||||
|
@ -1440,7 +1607,9 @@ mod test {
|
|||
assert_eq!(api.payout_u64, 1);
|
||||
assert_eq!(api.xmr.to_u64(), 2);
|
||||
assert!(!api.payout_ord.is_empty());
|
||||
assert!(api.log.contains("2022-01-27 01:30:23.1377 | 0.000000000001 XMR | Block 2,642,816"));
|
||||
assert!(api
|
||||
.log
|
||||
.contains("2022-01-27 01:30:23.1377 | 0.000000000001 XMR | Block 2,642,816"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
File diff suppressed because one or more lines are too long
376
src/gupax.rs
376
src/gupax.rs
|
@ -16,30 +16,18 @@
|
|||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::State;
|
||||
use crate::{constants::*, macros::*, update::*, ErrorState, Restart, Tab};
|
||||
use egui::{
|
||||
TextEdit,
|
||||
TextStyle,
|
||||
TextStyle::Monospace,
|
||||
Checkbox,ProgressBar,Spinner,Button,Label,Slider,
|
||||
SelectableLabel,
|
||||
RichText,
|
||||
Vec2,
|
||||
};
|
||||
use crate::{
|
||||
constants::*,
|
||||
update::*,
|
||||
ErrorState,
|
||||
Restart,
|
||||
Tab,
|
||||
macros::*,
|
||||
};
|
||||
use std::{
|
||||
thread,
|
||||
sync::{Arc,Mutex},
|
||||
path::Path,
|
||||
Button, Checkbox, Label, ProgressBar, RichText, SelectableLabel, Slider, Spinner, TextEdit,
|
||||
TextStyle, TextStyle::Monospace, Vec2,
|
||||
};
|
||||
use log::*;
|
||||
use serde::{Serialize,Deserialize};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::{
|
||||
path::Path,
|
||||
sync::{Arc, Mutex},
|
||||
thread,
|
||||
};
|
||||
|
||||
//---------------------------------------------------------------------------------------------------- FileWindow
|
||||
// Struct for writing/reading the path state.
|
||||
|
@ -95,13 +83,21 @@ impl crate::disk::Gupax {
|
|||
height: f32,
|
||||
frame: &mut eframe::Frame,
|
||||
_ctx: &egui::Context,
|
||||
ui: &mut egui::Ui
|
||||
ui: &mut egui::Ui,
|
||||
) {
|
||||
// Update button + Progress bar
|
||||
debug!("Gupax Tab | Rendering [Update] button + progress bar");
|
||||
ui.group(|ui| {
|
||||
let button = if self.simple { height/5.0 } else { height/15.0 };
|
||||
let height = if self.simple { height/5.0 } else { height/10.0 };
|
||||
let button = if self.simple {
|
||||
height / 5.0
|
||||
} else {
|
||||
height / 15.0
|
||||
};
|
||||
let height = if self.simple {
|
||||
height / 5.0
|
||||
} else {
|
||||
height / 10.0
|
||||
};
|
||||
let width = width - SPACE;
|
||||
let updating = *lock2!(update, updating);
|
||||
ui.vertical(|ui| {
|
||||
|
@ -110,11 +106,16 @@ impl crate::disk::Gupax {
|
|||
#[cfg(feature = "distro")]
|
||||
ui.set_enabled(false);
|
||||
#[cfg(feature = "distro")]
|
||||
ui.add_sized([width, button], Button::new("Updates are disabled")).on_disabled_hover_text(DISTRO_NO_UPDATE);
|
||||
ui.add_sized([width, button], Button::new("Updates are disabled"))
|
||||
.on_disabled_hover_text(DISTRO_NO_UPDATE);
|
||||
#[cfg(not(feature = "distro"))]
|
||||
ui.set_enabled(!updating);
|
||||
#[cfg(not(feature = "distro"))]
|
||||
if ui.add_sized([width, button], Button::new("Check for updates")).on_hover_text(GUPAX_UPDATE).clicked() {
|
||||
if ui
|
||||
.add_sized([width, button], Button::new("Check for updates"))
|
||||
.on_hover_text(GUPAX_UPDATE)
|
||||
.clicked()
|
||||
{
|
||||
Update::spawn_thread(og, self, state_path, update, error_state, restart);
|
||||
}
|
||||
});
|
||||
|
@ -129,7 +130,10 @@ impl crate::disk::Gupax {
|
|||
} else {
|
||||
ui.add_sized([width, height], Label::new("..."));
|
||||
}
|
||||
ui.add_sized([width, height], ProgressBar::new(lock2!(update,prog).round() / 100.0));
|
||||
ui.add_sized(
|
||||
[width, height],
|
||||
ProgressBar::new(lock2!(update, prog).round() / 100.0),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -137,69 +141,153 @@ impl crate::disk::Gupax {
|
|||
ui.horizontal(|ui| {
|
||||
ui.group(|ui| {
|
||||
let width = (width - SPACE * 12.0) / 6.0;
|
||||
let height = if self.simple { height/10.0 } else { height/15.0 };
|
||||
let height = if self.simple {
|
||||
height / 10.0
|
||||
} else {
|
||||
height / 15.0
|
||||
};
|
||||
ui.style_mut().override_text_style = Some(egui::TextStyle::Small);
|
||||
ui.add_sized([width, height], Checkbox::new(&mut self.update_via_tor, "Update via Tor")).on_hover_text(GUPAX_UPDATE_VIA_TOR);
|
||||
ui.add_sized(
|
||||
[width, height],
|
||||
Checkbox::new(&mut self.update_via_tor, "Update via Tor"),
|
||||
)
|
||||
.on_hover_text(GUPAX_UPDATE_VIA_TOR);
|
||||
ui.separator();
|
||||
ui.add_sized([width, height], Checkbox::new(&mut self.auto_update, "Auto-Update")).on_hover_text(GUPAX_AUTO_UPDATE);
|
||||
ui.add_sized(
|
||||
[width, height],
|
||||
Checkbox::new(&mut self.auto_update, "Auto-Update"),
|
||||
)
|
||||
.on_hover_text(GUPAX_AUTO_UPDATE);
|
||||
ui.separator();
|
||||
ui.add_sized([width, height], Checkbox::new(&mut self.auto_p2pool, "Auto-P2Pool")).on_hover_text(GUPAX_AUTO_P2POOL);
|
||||
ui.add_sized(
|
||||
[width, height],
|
||||
Checkbox::new(&mut self.auto_p2pool, "Auto-P2Pool"),
|
||||
)
|
||||
.on_hover_text(GUPAX_AUTO_P2POOL);
|
||||
ui.separator();
|
||||
ui.add_sized([width, height], Checkbox::new(&mut self.auto_xmrig, "Auto-XMRig")).on_hover_text(GUPAX_AUTO_XMRIG);
|
||||
ui.add_sized(
|
||||
[width, height],
|
||||
Checkbox::new(&mut self.auto_xmrig, "Auto-XMRig"),
|
||||
)
|
||||
.on_hover_text(GUPAX_AUTO_XMRIG);
|
||||
ui.separator();
|
||||
ui.add_sized([width, height], Checkbox::new(&mut self.ask_before_quit, "Ask before quit")).on_hover_text(GUPAX_ASK_BEFORE_QUIT);
|
||||
ui.add_sized(
|
||||
[width, height],
|
||||
Checkbox::new(&mut self.ask_before_quit, "Ask before quit"),
|
||||
)
|
||||
.on_hover_text(GUPAX_ASK_BEFORE_QUIT);
|
||||
ui.separator();
|
||||
ui.add_sized([width, height], Checkbox::new(&mut self.save_before_quit, "Save before quit")).on_hover_text(GUPAX_SAVE_BEFORE_QUIT);
|
||||
ui.add_sized(
|
||||
[width, height],
|
||||
Checkbox::new(&mut self.save_before_quit, "Save before quit"),
|
||||
)
|
||||
.on_hover_text(GUPAX_SAVE_BEFORE_QUIT);
|
||||
});
|
||||
});
|
||||
|
||||
if self.simple { return }
|
||||
if self.simple {
|
||||
return;
|
||||
}
|
||||
|
||||
debug!("Gupax Tab | Rendering P2Pool/XMRig path selection");
|
||||
// P2Pool/XMRig binary path selection
|
||||
let height = height / 28.0;
|
||||
let text_edit = (ui.available_width() / 10.0) - SPACE;
|
||||
ui.group(|ui| {
|
||||
ui.add_sized([ui.available_width(), height/2.0], Label::new(RichText::new("P2Pool/XMRig PATHs").underline().color(LIGHT_GRAY))).on_hover_text("Gupax is online");
|
||||
ui.add_sized(
|
||||
[ui.available_width(), height / 2.0],
|
||||
Label::new(
|
||||
RichText::new("P2Pool/XMRig PATHs")
|
||||
.underline()
|
||||
.color(LIGHT_GRAY),
|
||||
),
|
||||
)
|
||||
.on_hover_text("Gupax is online");
|
||||
ui.separator();
|
||||
ui.horizontal(|ui| {
|
||||
if self.p2pool_path.is_empty() {
|
||||
ui.add_sized([text_edit, height], Label::new(RichText::new("P2Pool Binary Path ➖").color(LIGHT_GRAY))).on_hover_text(P2POOL_PATH_EMPTY);
|
||||
ui.add_sized(
|
||||
[text_edit, height],
|
||||
Label::new(RichText::new("P2Pool Binary Path ➖").color(LIGHT_GRAY)),
|
||||
)
|
||||
.on_hover_text(P2POOL_PATH_EMPTY);
|
||||
} else if !Self::path_is_file(&self.p2pool_path) {
|
||||
ui.add_sized([text_edit, height], Label::new(RichText::new("P2Pool Binary Path ❌").color(RED))).on_hover_text(P2POOL_PATH_NOT_FILE);
|
||||
ui.add_sized(
|
||||
[text_edit, height],
|
||||
Label::new(RichText::new("P2Pool Binary Path ❌").color(RED)),
|
||||
)
|
||||
.on_hover_text(P2POOL_PATH_NOT_FILE);
|
||||
} else if !crate::update::check_p2pool_path(&self.p2pool_path) {
|
||||
ui.add_sized([text_edit, height], Label::new(RichText::new("P2Pool Binary Path ❌").color(RED))).on_hover_text(P2POOL_PATH_NOT_VALID);
|
||||
ui.add_sized(
|
||||
[text_edit, height],
|
||||
Label::new(RichText::new("P2Pool Binary Path ❌").color(RED)),
|
||||
)
|
||||
.on_hover_text(P2POOL_PATH_NOT_VALID);
|
||||
} else {
|
||||
ui.add_sized([text_edit, height], Label::new(RichText::new("P2Pool Binary Path ✔").color(GREEN))).on_hover_text(P2POOL_PATH_OK);
|
||||
ui.add_sized(
|
||||
[text_edit, height],
|
||||
Label::new(RichText::new("P2Pool Binary Path ✔").color(GREEN)),
|
||||
)
|
||||
.on_hover_text(P2POOL_PATH_OK);
|
||||
}
|
||||
ui.spacing_mut().text_edit_width = ui.available_width() - SPACE;
|
||||
ui.set_enabled(!lock!(file_window).thread);
|
||||
if ui.button("Open").on_hover_text(GUPAX_SELECT).clicked() {
|
||||
Self::spawn_file_window_thread(file_window, FileType::P2pool);
|
||||
}
|
||||
ui.add_sized([ui.available_width(), height], TextEdit::singleline(&mut self.p2pool_path)).on_hover_text(GUPAX_PATH_P2POOL);
|
||||
ui.add_sized(
|
||||
[ui.available_width(), height],
|
||||
TextEdit::singleline(&mut self.p2pool_path),
|
||||
)
|
||||
.on_hover_text(GUPAX_PATH_P2POOL);
|
||||
});
|
||||
ui.horizontal(|ui| {
|
||||
if self.xmrig_path.is_empty() {
|
||||
ui.add_sized([text_edit, height], Label::new(RichText::new(" XMRig Binary Path ➖").color(LIGHT_GRAY))).on_hover_text(XMRIG_PATH_EMPTY);
|
||||
ui.add_sized(
|
||||
[text_edit, height],
|
||||
Label::new(RichText::new(" XMRig Binary Path ➖").color(LIGHT_GRAY)),
|
||||
)
|
||||
.on_hover_text(XMRIG_PATH_EMPTY);
|
||||
} else if !Self::path_is_file(&self.xmrig_path) {
|
||||
ui.add_sized([text_edit, height], Label::new(RichText::new(" XMRig Binary Path ❌").color(RED))).on_hover_text(XMRIG_PATH_NOT_FILE);
|
||||
ui.add_sized(
|
||||
[text_edit, height],
|
||||
Label::new(RichText::new(" XMRig Binary Path ❌").color(RED)),
|
||||
)
|
||||
.on_hover_text(XMRIG_PATH_NOT_FILE);
|
||||
} else if !crate::update::check_xmrig_path(&self.xmrig_path) {
|
||||
ui.add_sized([text_edit, height], Label::new(RichText::new(" XMRig Binary Path ❌").color(RED))).on_hover_text(XMRIG_PATH_NOT_VALID);
|
||||
ui.add_sized(
|
||||
[text_edit, height],
|
||||
Label::new(RichText::new(" XMRig Binary Path ❌").color(RED)),
|
||||
)
|
||||
.on_hover_text(XMRIG_PATH_NOT_VALID);
|
||||
} else {
|
||||
ui.add_sized([text_edit, height], Label::new(RichText::new(" XMRig Binary Path ✔").color(GREEN))).on_hover_text(XMRIG_PATH_OK);
|
||||
ui.add_sized(
|
||||
[text_edit, height],
|
||||
Label::new(RichText::new(" XMRig Binary Path ✔").color(GREEN)),
|
||||
)
|
||||
.on_hover_text(XMRIG_PATH_OK);
|
||||
}
|
||||
ui.spacing_mut().text_edit_width = ui.available_width() - SPACE;
|
||||
ui.set_enabled(!lock!(file_window).thread);
|
||||
if ui.button("Open").on_hover_text(GUPAX_SELECT).clicked() {
|
||||
Self::spawn_file_window_thread(file_window, FileType::Xmrig);
|
||||
}
|
||||
ui.add_sized([ui.available_width(), height], TextEdit::singleline(&mut self.xmrig_path)).on_hover_text(GUPAX_PATH_XMRIG);
|
||||
ui.add_sized(
|
||||
[ui.available_width(), height],
|
||||
TextEdit::singleline(&mut self.xmrig_path),
|
||||
)
|
||||
.on_hover_text(GUPAX_PATH_XMRIG);
|
||||
});
|
||||
});
|
||||
let mut guard = lock!(file_window);
|
||||
if guard.picked_p2pool { self.p2pool_path = guard.p2pool_path.clone(); guard.picked_p2pool = false; }
|
||||
if guard.picked_xmrig { self.xmrig_path = guard.xmrig_path.clone(); guard.picked_xmrig = false; }
|
||||
if guard.picked_p2pool {
|
||||
self.p2pool_path = guard.p2pool_path.clone();
|
||||
guard.picked_p2pool = false;
|
||||
}
|
||||
if guard.picked_xmrig {
|
||||
self.xmrig_path = guard.xmrig_path.clone();
|
||||
guard.picked_xmrig = false;
|
||||
}
|
||||
drop(guard);
|
||||
|
||||
let height = ui.available_height() / 6.0;
|
||||
|
@ -208,24 +296,82 @@ impl crate::disk::Gupax {
|
|||
debug!("Gupax Tab | Rendering [Tab] selector");
|
||||
ui.group(|ui| {
|
||||
let width = (width / 5.0) - (SPACE * 1.93);
|
||||
ui.add_sized([ui.available_width(), height/2.0], Label::new(RichText::new("Default Tab").underline().color(LIGHT_GRAY))).on_hover_text(GUPAX_TAB);
|
||||
ui.add_sized(
|
||||
[ui.available_width(), height / 2.0],
|
||||
Label::new(RichText::new("Default Tab").underline().color(LIGHT_GRAY)),
|
||||
)
|
||||
.on_hover_text(GUPAX_TAB);
|
||||
ui.separator();
|
||||
ui.horizontal(|ui| {
|
||||
if ui.add_sized([width, height], SelectableLabel::new(self.tab == Tab::About, "About")).on_hover_text(GUPAX_TAB_ABOUT).clicked() { self.tab = Tab::About; }
|
||||
if ui
|
||||
.add_sized(
|
||||
[width, height],
|
||||
SelectableLabel::new(self.tab == Tab::About, "About"),
|
||||
)
|
||||
.on_hover_text(GUPAX_TAB_ABOUT)
|
||||
.clicked()
|
||||
{
|
||||
self.tab = Tab::About;
|
||||
}
|
||||
ui.separator();
|
||||
if ui.add_sized([width, height], SelectableLabel::new(self.tab == Tab::Status, "Status")).on_hover_text(GUPAX_TAB_STATUS).clicked() { self.tab = Tab::Status; }
|
||||
if ui
|
||||
.add_sized(
|
||||
[width, height],
|
||||
SelectableLabel::new(self.tab == Tab::Status, "Status"),
|
||||
)
|
||||
.on_hover_text(GUPAX_TAB_STATUS)
|
||||
.clicked()
|
||||
{
|
||||
self.tab = Tab::Status;
|
||||
}
|
||||
ui.separator();
|
||||
if ui.add_sized([width, height], SelectableLabel::new(self.tab == Tab::Gupax, "Gupax")).on_hover_text(GUPAX_TAB_GUPAX).clicked() { self.tab = Tab::Gupax; }
|
||||
if ui
|
||||
.add_sized(
|
||||
[width, height],
|
||||
SelectableLabel::new(self.tab == Tab::Gupax, "Gupax"),
|
||||
)
|
||||
.on_hover_text(GUPAX_TAB_GUPAX)
|
||||
.clicked()
|
||||
{
|
||||
self.tab = Tab::Gupax;
|
||||
}
|
||||
ui.separator();
|
||||
if ui.add_sized([width, height], SelectableLabel::new(self.tab == Tab::P2pool, "P2Pool")).on_hover_text(GUPAX_TAB_P2POOL).clicked() { self.tab = Tab::P2pool; }
|
||||
if ui
|
||||
.add_sized(
|
||||
[width, height],
|
||||
SelectableLabel::new(self.tab == Tab::P2pool, "P2Pool"),
|
||||
)
|
||||
.on_hover_text(GUPAX_TAB_P2POOL)
|
||||
.clicked()
|
||||
{
|
||||
self.tab = Tab::P2pool;
|
||||
}
|
||||
ui.separator();
|
||||
if ui.add_sized([width, height], SelectableLabel::new(self.tab == Tab::Xmrig, "XMRig")).on_hover_text(GUPAX_TAB_XMRIG).clicked() { self.tab = Tab::Xmrig; }
|
||||
})});
|
||||
if ui
|
||||
.add_sized(
|
||||
[width, height],
|
||||
SelectableLabel::new(self.tab == Tab::Xmrig, "XMRig"),
|
||||
)
|
||||
.on_hover_text(GUPAX_TAB_XMRIG)
|
||||
.clicked()
|
||||
{
|
||||
self.tab = Tab::Xmrig;
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
// Gupax App resolution sliders
|
||||
debug!("Gupax Tab | Rendering resolution sliders");
|
||||
ui.group(|ui| {
|
||||
ui.add_sized([ui.available_width(), height/2.0], Label::new(RichText::new("Width/Height Adjust").underline().color(LIGHT_GRAY))).on_hover_text(GUPAX_ADJUST);
|
||||
ui.add_sized(
|
||||
[ui.available_width(), height / 2.0],
|
||||
Label::new(
|
||||
RichText::new("Width/Height Adjust")
|
||||
.underline()
|
||||
.color(LIGHT_GRAY),
|
||||
),
|
||||
)
|
||||
.on_hover_text(GUPAX_ADJUST);
|
||||
ui.separator();
|
||||
ui.vertical(|ui| {
|
||||
let width = width / 10.0;
|
||||
|
@ -237,27 +383,61 @@ impl crate::disk::Gupax {
|
|||
let width = self.selected_width as f64;
|
||||
let height = (width / 1.333).round();
|
||||
self.selected_height = height as u16;
|
||||
},
|
||||
}
|
||||
Ratio::Height => {
|
||||
let height = self.selected_height as f64;
|
||||
let width = (height * 1.333).round();
|
||||
self.selected_width = width as u16;
|
||||
},
|
||||
}
|
||||
}
|
||||
let height = height / 3.5;
|
||||
ui.horizontal(|ui| {
|
||||
ui.set_enabled(self.ratio != Ratio::Height);
|
||||
ui.add_sized([width, height], Label::new(format!(" Width [{}-{}]:", APP_MIN_WIDTH as u16, APP_MAX_WIDTH as u16)));
|
||||
ui.add_sized([width, height], Slider::new(&mut self.selected_width, APP_MIN_WIDTH as u16..=APP_MAX_WIDTH as u16)).on_hover_text(GUPAX_WIDTH);
|
||||
ui.add_sized(
|
||||
[width, height],
|
||||
Label::new(format!(
|
||||
" Width [{}-{}]:",
|
||||
APP_MIN_WIDTH as u16, APP_MAX_WIDTH as u16
|
||||
)),
|
||||
);
|
||||
ui.add_sized(
|
||||
[width, height],
|
||||
Slider::new(
|
||||
&mut self.selected_width,
|
||||
APP_MIN_WIDTH as u16..=APP_MAX_WIDTH as u16,
|
||||
),
|
||||
)
|
||||
.on_hover_text(GUPAX_WIDTH);
|
||||
});
|
||||
ui.horizontal(|ui| {
|
||||
ui.set_enabled(self.ratio != Ratio::Width);
|
||||
ui.add_sized([width, height], Label::new(format!("Height [{}-{}]:", APP_MIN_HEIGHT as u16, APP_MAX_HEIGHT as u16)));
|
||||
ui.add_sized([width, height], Slider::new(&mut self.selected_height, APP_MIN_HEIGHT as u16..=APP_MAX_HEIGHT as u16)).on_hover_text(GUPAX_HEIGHT);
|
||||
ui.add_sized(
|
||||
[width, height],
|
||||
Label::new(format!(
|
||||
"Height [{}-{}]:",
|
||||
APP_MIN_HEIGHT as u16, APP_MAX_HEIGHT as u16
|
||||
)),
|
||||
);
|
||||
ui.add_sized(
|
||||
[width, height],
|
||||
Slider::new(
|
||||
&mut self.selected_height,
|
||||
APP_MIN_HEIGHT as u16..=APP_MAX_HEIGHT as u16,
|
||||
),
|
||||
)
|
||||
.on_hover_text(GUPAX_HEIGHT);
|
||||
});
|
||||
ui.horizontal(|ui| {
|
||||
ui.add_sized([width, height], Label::new(format!("Scaling [{APP_MIN_SCALE}..{APP_MAX_SCALE}]:")));
|
||||
ui.add_sized([width, height], Slider::new(&mut self.selected_scale, APP_MIN_SCALE..=APP_MAX_SCALE).step_by(0.1)).on_hover_text(GUPAX_SCALE);
|
||||
ui.add_sized(
|
||||
[width, height],
|
||||
Label::new(format!("Scaling [{APP_MIN_SCALE}..{APP_MAX_SCALE}]:")),
|
||||
);
|
||||
ui.add_sized(
|
||||
[width, height],
|
||||
Slider::new(&mut self.selected_scale, APP_MIN_SCALE..=APP_MAX_SCALE)
|
||||
.step_by(0.1),
|
||||
)
|
||||
.on_hover_text(GUPAX_SCALE);
|
||||
});
|
||||
});
|
||||
ui.style_mut().override_text_style = Some(egui::TextStyle::Button);
|
||||
|
@ -266,16 +446,49 @@ impl crate::disk::Gupax {
|
|||
ui.horizontal(|ui| {
|
||||
use Ratio::*;
|
||||
let width = (width / 4.0) - (SPACE * 1.5);
|
||||
if ui.add_sized([width, height], SelectableLabel::new(self.ratio == Width, "Lock to width")).on_hover_text(GUPAX_LOCK_WIDTH).clicked() { self.ratio = Width; }
|
||||
ui.separator();
|
||||
if ui.add_sized([width, height], SelectableLabel::new(self.ratio == Height, "Lock to height")).on_hover_text(GUPAX_LOCK_HEIGHT).clicked() { self.ratio = Height; }
|
||||
ui.separator();
|
||||
if ui.add_sized([width, height], SelectableLabel::new(self.ratio == None, "No lock")).on_hover_text(GUPAX_NO_LOCK).clicked() { self.ratio = None; }
|
||||
if ui.add_sized([width, height], Button::new("Set")).on_hover_text(GUPAX_SET).clicked() {
|
||||
let size = Vec2::new(self.selected_width as f32, self.selected_height as f32);
|
||||
ui.ctx().send_viewport_cmd(egui::viewport::ViewportCommand::InnerSize(size));
|
||||
if ui
|
||||
.add_sized(
|
||||
[width, height],
|
||||
SelectableLabel::new(self.ratio == Width, "Lock to width"),
|
||||
)
|
||||
.on_hover_text(GUPAX_LOCK_WIDTH)
|
||||
.clicked()
|
||||
{
|
||||
self.ratio = Width;
|
||||
}
|
||||
})});
|
||||
ui.separator();
|
||||
if ui
|
||||
.add_sized(
|
||||
[width, height],
|
||||
SelectableLabel::new(self.ratio == Height, "Lock to height"),
|
||||
)
|
||||
.on_hover_text(GUPAX_LOCK_HEIGHT)
|
||||
.clicked()
|
||||
{
|
||||
self.ratio = Height;
|
||||
}
|
||||
ui.separator();
|
||||
if ui
|
||||
.add_sized(
|
||||
[width, height],
|
||||
SelectableLabel::new(self.ratio == None, "No lock"),
|
||||
)
|
||||
.on_hover_text(GUPAX_NO_LOCK)
|
||||
.clicked()
|
||||
{
|
||||
self.ratio = None;
|
||||
}
|
||||
if ui
|
||||
.add_sized([width, height], Button::new("Set"))
|
||||
.on_hover_text(GUPAX_SET)
|
||||
.clicked()
|
||||
{
|
||||
let size = Vec2::new(self.selected_width as f32, self.selected_height as f32);
|
||||
ui.ctx()
|
||||
.send_viewport_cmd(egui::viewport::ViewportCommand::InnerSize(size));
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
// Checks if a path is a valid path to a file.
|
||||
|
@ -298,14 +511,23 @@ impl crate::disk::Gupax {
|
|||
let file_window = file_window.clone();
|
||||
lock!(file_window).thread = true;
|
||||
thread::spawn(move || {
|
||||
match rfd::FileDialog::new().set_title(&format!("Select {} Binary for Gupax", name)).pick_file() {
|
||||
match rfd::FileDialog::new()
|
||||
.set_title(&format!("Select {} Binary for Gupax", name))
|
||||
.pick_file()
|
||||
{
|
||||
Some(path) => {
|
||||
info!("Gupax | Path selected for {} ... {}", name, path.display());
|
||||
match file_type {
|
||||
P2pool => { lock!(file_window).p2pool_path = path.display().to_string(); lock!(file_window).picked_p2pool = true; },
|
||||
Xmrig => { lock!(file_window).xmrig_path = path.display().to_string(); lock!(file_window).picked_xmrig = true; },
|
||||
P2pool => {
|
||||
lock!(file_window).p2pool_path = path.display().to_string();
|
||||
lock!(file_window).picked_p2pool = true;
|
||||
}
|
||||
Xmrig => {
|
||||
lock!(file_window).xmrig_path = path.display().to_string();
|
||||
lock!(file_window).picked_xmrig = true;
|
||||
}
|
||||
};
|
||||
},
|
||||
}
|
||||
None => info!("Gupax | No path selected for {}", name),
|
||||
};
|
||||
lock!(file_window).thread = false;
|
||||
|
|
952
src/helper.rs
952
src/helper.rs
File diff suppressed because it is too large
Load diff
112
src/human.rs
112
src/human.rs
|
@ -51,7 +51,12 @@ impl HumanTime {
|
|||
HumanTime(Duration::from_secs(u))
|
||||
}
|
||||
|
||||
fn plural(f: &mut std::fmt::Formatter, started: &mut bool, name: &str, value: u64) -> std::fmt::Result {
|
||||
fn plural(
|
||||
f: &mut std::fmt::Formatter,
|
||||
started: &mut bool,
|
||||
name: &str,
|
||||
value: u64,
|
||||
) -> std::fmt::Result {
|
||||
if value > 0 {
|
||||
if *started {
|
||||
f.write_str(", ")?;
|
||||
|
@ -206,7 +211,7 @@ impl HumanNumber {
|
|||
buf.write_formatted(&f, &LOCALE);
|
||||
string.push_str(buf.as_str());
|
||||
string.push_str(" H/s");
|
||||
},
|
||||
}
|
||||
None => string.push_str("??? H/s"),
|
||||
}
|
||||
if n != 2 {
|
||||
|
@ -214,7 +219,7 @@ impl HumanNumber {
|
|||
n += 1;
|
||||
} else {
|
||||
string.push(']');
|
||||
break
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -234,7 +239,7 @@ impl HumanNumber {
|
|||
n += 1;
|
||||
} else {
|
||||
string.push(']');
|
||||
break
|
||||
break;
|
||||
}
|
||||
}
|
||||
Self(string)
|
||||
|
@ -278,10 +283,22 @@ mod test {
|
|||
assert!(HumanNumber::to_percent(0.001).to_string() == "0%");
|
||||
assert!(HumanNumber::to_percent(12.123123123123).to_string() == "12.12%");
|
||||
assert!(HumanNumber::to_percent_3_point(0.001).to_string() == "0.001%");
|
||||
assert!(HumanNumber::from_hashrate([Some(123.1), Some(11111.1), None]).to_string() == "[123 H/s, 11,111 H/s, ??? H/s]");
|
||||
assert!(HumanNumber::from_hashrate([None, Some(1.123), Some(123123.312)]).to_string() == "[??? H/s, 1 H/s, 123,123 H/s]");
|
||||
assert!(HumanNumber::from_load([Some(123.1234), Some(321.321), None]).to_string() == "[123.12, 321.32, ???]");
|
||||
assert!(HumanNumber::from_load([None, Some(4321.43), Some(1234.1)]).to_string() == "[???, 4321.43, 1234.10]");
|
||||
assert!(
|
||||
HumanNumber::from_hashrate([Some(123.1), Some(11111.1), None]).to_string()
|
||||
== "[123 H/s, 11,111 H/s, ??? H/s]"
|
||||
);
|
||||
assert!(
|
||||
HumanNumber::from_hashrate([None, Some(1.123), Some(123123.312)]).to_string()
|
||||
== "[??? H/s, 1 H/s, 123,123 H/s]"
|
||||
);
|
||||
assert!(
|
||||
HumanNumber::from_load([Some(123.1234), Some(321.321), None]).to_string()
|
||||
== "[123.12, 321.32, ???]"
|
||||
);
|
||||
assert!(
|
||||
HumanNumber::from_load([None, Some(4321.43), Some(1234.1)]).to_string()
|
||||
== "[???, 4321.43, 1234.10]"
|
||||
);
|
||||
assert!(HumanNumber::from_f32(123_123.123123123).to_string() == "123,123");
|
||||
assert!(HumanNumber::from_f64(123_123_123.123123123123123).to_string() == "123,123,123");
|
||||
assert!(HumanNumber::from_u16(1_000).to_string() == "1,000");
|
||||
|
@ -299,16 +316,31 @@ mod test {
|
|||
assert!(HumanNumber::from_u64(1_000_000_000_000).to_string() == "1,000,000,000,000");
|
||||
assert!(HumanNumber::from_u64(10_000_000_000_000).to_string() == "10,000,000,000,000");
|
||||
assert!(HumanNumber::from_u64(100_000_000_000_000).to_string() == "100,000,000,000,000");
|
||||
assert!(HumanNumber::from_u64(1_000_000_000_000_000).to_string() == "1,000,000,000,000,000");
|
||||
assert!(HumanNumber::from_u64(10_000_000_000_000_000).to_string() == "10,000,000,000,000,000");
|
||||
assert!(HumanNumber::from_u64(18_446_744_073_709_551_615).to_string() == "18,446,744,073,709,551,615");
|
||||
assert!(HumanNumber::from_u128(18_446_744_073_709_551_616).to_string() == "18,446,744,073,709,551,616");
|
||||
assert!(HumanNumber::from_u128(100_000_000_000_000_000_000).to_string() == "100,000,000,000,000,000,000");
|
||||
assert!(
|
||||
HumanNumber::from_u64(1_000_000_000_000_000).to_string() == "1,000,000,000,000,000"
|
||||
);
|
||||
assert!(
|
||||
HumanNumber::from_u64(10_000_000_000_000_000).to_string() == "10,000,000,000,000,000"
|
||||
);
|
||||
assert!(
|
||||
HumanNumber::from_u64(18_446_744_073_709_551_615).to_string()
|
||||
== "18,446,744,073,709,551,615"
|
||||
);
|
||||
assert!(
|
||||
HumanNumber::from_u128(18_446_744_073_709_551_616).to_string()
|
||||
== "18,446,744,073,709,551,616"
|
||||
);
|
||||
assert!(
|
||||
HumanNumber::from_u128(100_000_000_000_000_000_000).to_string()
|
||||
== "100,000,000,000,000,000,000"
|
||||
);
|
||||
assert_eq!(
|
||||
HumanNumber::from_u128(340_282_366_920_938_463_463_374_607_431_768_211_455).to_string(),
|
||||
"340,282,366,920,938,463,463,374,607,431,768,211,455",
|
||||
);
|
||||
assert!(HumanNumber::from_u64_to_gigahash_3_point(1_000_000_000).to_string() == "1.000 GH/s");
|
||||
assert!(
|
||||
HumanNumber::from_u64_to_gigahash_3_point(1_000_000_000).to_string() == "1.000 GH/s"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -321,29 +353,57 @@ mod test {
|
|||
assert!(HumanTime::into_human(Duration::from_secs(59)).to_string() == "59 seconds");
|
||||
assert!(HumanTime::into_human(Duration::from_secs(60)).to_string() == "1 minute");
|
||||
assert!(HumanTime::into_human(Duration::from_secs(61)).to_string() == "1 minute, 1 second");
|
||||
assert!(HumanTime::into_human(Duration::from_secs(62)).to_string() == "1 minute, 2 seconds");
|
||||
assert!(
|
||||
HumanTime::into_human(Duration::from_secs(62)).to_string() == "1 minute, 2 seconds"
|
||||
);
|
||||
assert!(HumanTime::into_human(Duration::from_secs(120)).to_string() == "2 minutes");
|
||||
assert!(HumanTime::into_human(Duration::from_secs(121)).to_string() == "2 minutes, 1 second");
|
||||
assert!(HumanTime::into_human(Duration::from_secs(122)).to_string() == "2 minutes, 2 seconds");
|
||||
assert!(HumanTime::into_human(Duration::from_secs(179)).to_string() == "2 minutes, 59 seconds");
|
||||
assert!(HumanTime::into_human(Duration::from_secs(3599)).to_string() == "59 minutes, 59 seconds");
|
||||
assert!(
|
||||
HumanTime::into_human(Duration::from_secs(121)).to_string() == "2 minutes, 1 second"
|
||||
);
|
||||
assert!(
|
||||
HumanTime::into_human(Duration::from_secs(122)).to_string() == "2 minutes, 2 seconds"
|
||||
);
|
||||
assert!(
|
||||
HumanTime::into_human(Duration::from_secs(179)).to_string() == "2 minutes, 59 seconds"
|
||||
);
|
||||
assert!(
|
||||
HumanTime::into_human(Duration::from_secs(3599)).to_string()
|
||||
== "59 minutes, 59 seconds"
|
||||
);
|
||||
assert!(HumanTime::into_human(Duration::from_secs(3600)).to_string() == "1 hour");
|
||||
assert!(HumanTime::into_human(Duration::from_secs(3601)).to_string() == "1 hour, 1 second");
|
||||
assert!(HumanTime::into_human(Duration::from_secs(3602)).to_string() == "1 hour, 2 seconds");
|
||||
assert!(
|
||||
HumanTime::into_human(Duration::from_secs(3602)).to_string() == "1 hour, 2 seconds"
|
||||
);
|
||||
assert!(HumanTime::into_human(Duration::from_secs(3660)).to_string() == "1 hour, 1 minute");
|
||||
assert!(HumanTime::into_human(Duration::from_secs(3720)).to_string() == "1 hour, 2 minutes");
|
||||
assert!(HumanTime::into_human(Duration::from_secs(86399)).to_string() == "23 hours, 59 minutes, 59 seconds");
|
||||
assert!(
|
||||
HumanTime::into_human(Duration::from_secs(3720)).to_string() == "1 hour, 2 minutes"
|
||||
);
|
||||
assert!(
|
||||
HumanTime::into_human(Duration::from_secs(86399)).to_string()
|
||||
== "23 hours, 59 minutes, 59 seconds"
|
||||
);
|
||||
assert!(HumanTime::into_human(Duration::from_secs(86400)).to_string() == "1 day");
|
||||
assert!(HumanTime::into_human(Duration::from_secs(86401)).to_string() == "1 day, 1 second");
|
||||
assert!(HumanTime::into_human(Duration::from_secs(86402)).to_string() == "1 day, 2 seconds");
|
||||
assert!(
|
||||
HumanTime::into_human(Duration::from_secs(86402)).to_string() == "1 day, 2 seconds"
|
||||
);
|
||||
assert!(HumanTime::into_human(Duration::from_secs(86460)).to_string() == "1 day, 1 minute");
|
||||
assert!(HumanTime::into_human(Duration::from_secs(86520)).to_string() == "1 day, 2 minutes");
|
||||
assert!(
|
||||
HumanTime::into_human(Duration::from_secs(86520)).to_string() == "1 day, 2 minutes"
|
||||
);
|
||||
assert!(HumanTime::into_human(Duration::from_secs(90000)).to_string() == "1 day, 1 hour");
|
||||
assert!(HumanTime::into_human(Duration::from_secs(93600)).to_string() == "1 day, 2 hours");
|
||||
assert!(HumanTime::into_human(Duration::from_secs(604799)).to_string() == "6 days, 23 hours, 59 minutes, 59 seconds");
|
||||
assert!(
|
||||
HumanTime::into_human(Duration::from_secs(604799)).to_string()
|
||||
== "6 days, 23 hours, 59 minutes, 59 seconds"
|
||||
);
|
||||
assert!(HumanTime::into_human(Duration::from_secs(604800)).to_string() == "7 days");
|
||||
assert!(HumanTime::into_human(Duration::from_secs(2630016)).to_string() == "1 month");
|
||||
assert!(HumanTime::into_human(Duration::from_secs(3234815)).to_string() == "1 month, 6 days, 23 hours, 59 minutes, 59 seconds");
|
||||
assert!(
|
||||
HumanTime::into_human(Duration::from_secs(3234815)).to_string()
|
||||
== "1 month, 6 days, 23 hours, 59 minutes, 59 seconds"
|
||||
);
|
||||
assert!(HumanTime::into_human(Duration::from_secs(5260032)).to_string() == "2 months");
|
||||
assert!(HumanTime::into_human(Duration::from_secs(31557600)).to_string() == "1 year");
|
||||
assert!(HumanTime::into_human(Duration::from_secs(63115200)).to_string() == "2 years");
|
||||
|
|
|
@ -97,11 +97,9 @@ mod test {
|
|||
a: Arc<Mutex<bool>>,
|
||||
}
|
||||
use std::sync::{Arc, Mutex};
|
||||
let arc_mutex = Arc::new(Mutex::new(
|
||||
Ab {
|
||||
let arc_mutex = Arc::new(Mutex::new(Ab {
|
||||
a: Arc::new(Mutex::new(false)),
|
||||
}
|
||||
));
|
||||
}));
|
||||
*lock2!(arc_mutex, a) = true;
|
||||
assert!(*lock2!(arc_mutex, a) == true);
|
||||
}
|
||||
|
|
1055
src/main.rs
1055
src/main.rs
File diff suppressed because it is too large
Load diff
130
src/node.rs
130
src/node.rs
|
@ -15,20 +15,14 @@
|
|||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::{
|
||||
constants::*,
|
||||
macros::*,
|
||||
};
|
||||
use serde::{Serialize,Deserialize};
|
||||
use rand::{thread_rng, Rng};
|
||||
use std::time::{Instant,Duration};
|
||||
use std::sync::{Arc,Mutex};
|
||||
use crate::{constants::*, macros::*};
|
||||
use egui::Color32;
|
||||
use hyper::{client::HttpConnector, Body, Client, Request};
|
||||
use log::*;
|
||||
use hyper::{
|
||||
client::HttpConnector,
|
||||
Client,Body,Request,
|
||||
};
|
||||
use rand::{thread_rng, Rng};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
//---------------------------------------------------------------------------------------------------- Node list
|
||||
// Remote Monero Nodes with ZMQ enabled.
|
||||
|
@ -96,11 +90,14 @@ impl RemoteNode {
|
|||
for (ip, _, _, _) in REMOTE_NODES {
|
||||
if og_ip == ip {
|
||||
info!("Found remote node in array: {}", ip);
|
||||
return ip.to_string()
|
||||
return ip.to_string();
|
||||
}
|
||||
}
|
||||
let ip = REMOTE_NODES[0].0.to_string();
|
||||
warn!("[{}] remote node does not exist, returning default: {}", og_ip, ip);
|
||||
warn!(
|
||||
"[{}] remote node does not exist, returning default: {}",
|
||||
og_ip, ip
|
||||
);
|
||||
ip
|
||||
}
|
||||
|
||||
|
@ -108,7 +105,12 @@ impl RemoteNode {
|
|||
pub fn from_ip(from_ip: &str) -> Self {
|
||||
for (ip, location, rpc, zmq) in REMOTE_NODES {
|
||||
if from_ip == ip {
|
||||
return Self { ip, location, rpc, zmq }
|
||||
return Self {
|
||||
ip,
|
||||
location,
|
||||
rpc,
|
||||
zmq,
|
||||
};
|
||||
}
|
||||
}
|
||||
Self::new()
|
||||
|
@ -120,18 +122,30 @@ impl RemoteNode {
|
|||
Self::new()
|
||||
} else {
|
||||
let (ip, location, rpc, zmq) = REMOTE_NODES[index];
|
||||
Self { ip, location, rpc, zmq }
|
||||
Self {
|
||||
ip,
|
||||
location,
|
||||
rpc,
|
||||
zmq,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn from_tuple(t: (&'static str, &'static str, &'static str, &'static str)) -> Self {
|
||||
let (ip, location, rpc, zmq) = (t.0, t.1, t.2, t.3);
|
||||
Self { ip, location, rpc, zmq }
|
||||
Self {
|
||||
ip,
|
||||
location,
|
||||
rpc,
|
||||
zmq,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_ip_rpc_zmq(og_ip: &str) -> (&str, &str, &str) {
|
||||
for (ip, _, rpc, zmq) in REMOTE_NODES {
|
||||
if og_ip == ip { return (ip, rpc, zmq) }
|
||||
if og_ip == ip {
|
||||
return (ip, rpc, zmq);
|
||||
}
|
||||
}
|
||||
let (ip, _, rpc, zmq) = REMOTE_NODES[0];
|
||||
(ip, rpc, zmq)
|
||||
|
@ -159,8 +173,14 @@ impl RemoteNode {
|
|||
let mut found = false;
|
||||
let mut last = current_ip;
|
||||
for (ip, _, _, _) in REMOTE_NODES {
|
||||
if found { return ip.to_string() }
|
||||
if current_ip == ip { found = true; } else { last = ip; }
|
||||
if found {
|
||||
return ip.to_string();
|
||||
}
|
||||
if current_ip == ip {
|
||||
found = true;
|
||||
} else {
|
||||
last = ip;
|
||||
}
|
||||
}
|
||||
last.to_string()
|
||||
}
|
||||
|
@ -169,8 +189,12 @@ impl RemoteNode {
|
|||
pub fn get_next(current_ip: &str) -> String {
|
||||
let mut found = false;
|
||||
for (ip, _, _, _) in REMOTE_NODES {
|
||||
if found { return ip.to_string() }
|
||||
if current_ip == ip { found = true; }
|
||||
if found {
|
||||
return ip.to_string();
|
||||
}
|
||||
if current_ip == ip {
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
current_ip.to_string()
|
||||
}
|
||||
|
@ -180,8 +204,14 @@ impl RemoteNode {
|
|||
let mut found = false;
|
||||
let mut last = current_ip;
|
||||
for data in nodes {
|
||||
if found { return last.to_string() }
|
||||
if current_ip == data.ip { found = true; } else { last = data.ip; }
|
||||
if found {
|
||||
return last.to_string();
|
||||
}
|
||||
if current_ip == data.ip {
|
||||
found = true;
|
||||
} else {
|
||||
last = data.ip;
|
||||
}
|
||||
}
|
||||
last.to_string()
|
||||
}
|
||||
|
@ -189,8 +219,12 @@ impl RemoteNode {
|
|||
pub fn get_next_from_ping(current_ip: &str, nodes: &Vec<NodeData>) -> String {
|
||||
let mut found = false;
|
||||
for data in nodes {
|
||||
if found { return data.ip.to_string() }
|
||||
if current_ip == data.ip { found = true; }
|
||||
if found {
|
||||
return data.ip.to_string();
|
||||
}
|
||||
if current_ip == data.ip {
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
current_ip.to_string()
|
||||
}
|
||||
|
@ -218,7 +252,11 @@ pub fn format_ms(ms: u128) -> String {
|
|||
pub fn format_ip_location(og_ip: &str, extra_space: bool) -> String {
|
||||
for (ip, location, _, _) in REMOTE_NODES {
|
||||
if og_ip == ip {
|
||||
let ip = if extra_space { format_ip(ip) } else { ip.to_string() };
|
||||
let ip = if extra_space {
|
||||
format_ip(ip)
|
||||
} else {
|
||||
ip.to_string()
|
||||
};
|
||||
return format!("{ip} | {location}");
|
||||
}
|
||||
}
|
||||
|
@ -226,7 +264,9 @@ pub fn format_ip_location(og_ip: &str, extra_space: bool) -> String {
|
|||
}
|
||||
|
||||
pub fn format_ip(ip: &str) -> String {
|
||||
const _: () = if 23 != REMOTE_NODE_MAX_CHARS { panic!(); };
|
||||
const _: () = if 23 != REMOTE_NODE_MAX_CHARS {
|
||||
panic!();
|
||||
};
|
||||
format!("{ip: >23}")
|
||||
}
|
||||
|
||||
|
@ -323,12 +363,12 @@ impl Ping {
|
|||
lock!(ping).pinged = true;
|
||||
lock!(ping).auto_selected = false;
|
||||
lock!(ping).prog = 100.0;
|
||||
},
|
||||
}
|
||||
Err(err) => {
|
||||
error!("Ping ... FAIL ... {}", err);
|
||||
lock!(ping).pinged = false;
|
||||
lock!(ping).msg = err.to_string();
|
||||
},
|
||||
}
|
||||
}
|
||||
info!("Ping ... Took [{}] seconds...", now.elapsed().as_secs_f32());
|
||||
lock!(ping).pinging = false;
|
||||
|
@ -365,8 +405,7 @@ impl Ping {
|
|||
// Create HTTP client
|
||||
let info = "Creating HTTP Client".to_string();
|
||||
lock!(ping).msg = info;
|
||||
let client: Client<HttpConnector> = Client::builder()
|
||||
.build(HttpConnector::new());
|
||||
let client: Client<HttpConnector> = Client::builder().build(HttpConnector::new());
|
||||
|
||||
// Random User Agent
|
||||
let rand_user_agent = crate::Pkg::get_user_agent();
|
||||
|
@ -382,9 +421,13 @@ impl Ping {
|
|||
.method("POST")
|
||||
.uri("http://".to_string() + ip + ":" + rpc + "/json_rpc")
|
||||
.header("User-Agent", rand_user_agent)
|
||||
.body(hyper::Body::from(r#"{"jsonrpc":"2.0","id":"0","method":"get_info"}"#))
|
||||
.body(hyper::Body::from(
|
||||
r#"{"jsonrpc":"2.0","id":"0","method":"get_info"}"#,
|
||||
))
|
||||
.unwrap();
|
||||
let handle = tokio::task::spawn(async move { Self::response(client, request, ip, ping, percent, node_vec).await; });
|
||||
let handle = tokio::task::spawn(async move {
|
||||
Self::response(client, request, ip, ping, percent, node_vec).await;
|
||||
});
|
||||
handles.push(handle);
|
||||
}
|
||||
|
||||
|
@ -414,7 +457,7 @@ impl Ping {
|
|||
ip: &'static str,
|
||||
ping: Arc<Mutex<Self>>,
|
||||
percent: f32,
|
||||
node_vec: Arc<Mutex<Vec<NodeData>>>
|
||||
node_vec: Arc<Mutex<Vec<NodeData>>>,
|
||||
) {
|
||||
let ms;
|
||||
let now = Instant::now();
|
||||
|
@ -423,8 +466,7 @@ impl Ping {
|
|||
Ok(Ok(json_rpc)) => {
|
||||
// Attempt to convert to JSON-RPC.
|
||||
match hyper::body::to_bytes(json_rpc.into_body()).await {
|
||||
Ok(b) => {
|
||||
match serde_json::from_slice::<GetInfo<'_>>(&b) {
|
||||
Ok(b) => match serde_json::from_slice::<GetInfo<'_>>(&b) {
|
||||
Ok(rpc) => {
|
||||
if rpc.result.mainnet && rpc.result.synchronized {
|
||||
ms = now.elapsed().as_millis();
|
||||
|
@ -437,11 +479,10 @@ impl Ping {
|
|||
ms = TIMEOUT_NODE_PING;
|
||||
warn!("Ping | {ip} responded but with invalid get_info, remove this node!");
|
||||
}
|
||||
}
|
||||
},
|
||||
_ => ms = TIMEOUT_NODE_PING,
|
||||
};
|
||||
},
|
||||
}
|
||||
_ => ms = TIMEOUT_NODE_PING,
|
||||
};
|
||||
|
||||
|
@ -493,12 +534,9 @@ mod test {
|
|||
#[tokio::test]
|
||||
#[ignore]
|
||||
async fn full_ping() {
|
||||
use hyper::{
|
||||
client::HttpConnector,
|
||||
Client,Body,Request,
|
||||
};
|
||||
use crate::{REMOTE_NODES, REMOTE_NODE_LENGTH};
|
||||
use serde::{Serialize,Deserialize};
|
||||
use hyper::{client::HttpConnector, Body, Client, Request};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Deserialize, Serialize)]
|
||||
struct GetInfo {
|
||||
|
@ -529,7 +567,9 @@ mod test {
|
|||
.method("POST")
|
||||
.uri("http://".to_string() + ip + ":" + rpc + "/json_rpc")
|
||||
.header("User-Agent", rand_user_agent)
|
||||
.body(hyper::Body::from(r#"{"jsonrpc":"2.0","id":"0","method":"get_info"}"#))
|
||||
.body(hyper::Body::from(
|
||||
r#"{"jsonrpc":"2.0","id":"0","method":"get_info"}"#,
|
||||
))
|
||||
.unwrap();
|
||||
match client.request(request).await {
|
||||
Ok(response) => break response,
|
||||
|
|
217
src/p2pool.rs
217
src/p2pool.rs
|
@ -15,32 +15,21 @@
|
|||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::{
|
||||
Regexes,
|
||||
constants::*,
|
||||
disk::*,
|
||||
node::*,
|
||||
helper::*,
|
||||
macros::*,
|
||||
};
|
||||
use crate::regex::REGEXES;
|
||||
use crate::{constants::*, disk::*, helper::*, macros::*, node::*, Regexes};
|
||||
use egui::{
|
||||
TextEdit,SelectableLabel,ComboBox,Label,Button,
|
||||
Color32,RichText,Slider,Checkbox,ProgressBar,Spinner,
|
||||
TextStyle::*,Hyperlink
|
||||
Button, Checkbox, Color32, ComboBox, Hyperlink, Label, ProgressBar, RichText, SelectableLabel,
|
||||
Slider, Spinner, TextEdit, TextStyle::*,
|
||||
};
|
||||
use std::sync::{Arc,Mutex};
|
||||
use regex::Regex;
|
||||
use log::*;
|
||||
use crate::regex::{
|
||||
REGEXES,
|
||||
};
|
||||
use regex::Regex;
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
impl crate::disk::P2pool {
|
||||
#[inline(always)] // called once
|
||||
pub fn show(
|
||||
&mut self,
|
||||
node_vec: &mut Vec<(String,
|
||||
Node)>,
|
||||
node_vec: &mut Vec<(String, Node)>,
|
||||
_og: &Arc<Mutex<State>>,
|
||||
ping: &Arc<Mutex<Ping>>,
|
||||
process: &Arc<Mutex<Process>>,
|
||||
|
@ -49,7 +38,7 @@ pub fn show(
|
|||
width: f32,
|
||||
height: f32,
|
||||
_ctx: &egui::Context,
|
||||
ui: &mut egui::Ui
|
||||
ui: &mut egui::Ui,
|
||||
) {
|
||||
let text_edit = height / 25.0;
|
||||
//---------------------------------------------------------------------------------------------------- [Simple] Console
|
||||
|
@ -60,8 +49,16 @@ pub fn show(
|
|||
let width = width - SPACE;
|
||||
egui::Frame::none().fill(DARK_GRAY).show(ui, |ui| {
|
||||
ui.style_mut().override_text_style = Some(Name("MonospaceSmall".into()));
|
||||
egui::ScrollArea::vertical().stick_to_bottom(true).max_width(width).max_height(height).auto_shrink([false; 2]).show_viewport(ui, |ui, _| {
|
||||
ui.add_sized([width, height], TextEdit::multiline(&mut lock!(api).output.as_str()));
|
||||
egui::ScrollArea::vertical()
|
||||
.stick_to_bottom(true)
|
||||
.max_width(width)
|
||||
.max_height(height)
|
||||
.auto_shrink([false; 2])
|
||||
.show_viewport(ui, |ui, _| {
|
||||
ui.add_sized(
|
||||
[width, height],
|
||||
TextEdit::multiline(&mut lock!(api).output.as_str()),
|
||||
);
|
||||
});
|
||||
});
|
||||
//---------------------------------------------------------------------------------------------------- [Advanced] Console
|
||||
|
@ -70,18 +67,36 @@ pub fn show(
|
|||
let width = width - SPACE;
|
||||
egui::Frame::none().fill(DARK_GRAY).show(ui, |ui| {
|
||||
ui.style_mut().override_text_style = Some(Name("MonospaceSmall".into()));
|
||||
egui::ScrollArea::vertical().stick_to_bottom(true).max_width(width).max_height(height).auto_shrink([false; 2]).show_viewport(ui, |ui, _| {
|
||||
ui.add_sized([width, height], TextEdit::multiline(&mut lock!(api).output.as_str()));
|
||||
egui::ScrollArea::vertical()
|
||||
.stick_to_bottom(true)
|
||||
.max_width(width)
|
||||
.max_height(height)
|
||||
.auto_shrink([false; 2])
|
||||
.show_viewport(ui, |ui, _| {
|
||||
ui.add_sized(
|
||||
[width, height],
|
||||
TextEdit::multiline(&mut lock!(api).output.as_str()),
|
||||
);
|
||||
});
|
||||
});
|
||||
ui.separator();
|
||||
let response = ui.add_sized([width, text_edit], TextEdit::hint_text(TextEdit::singleline(buffer), r#"Type a command (e.g "help" or "status") and press Enter"#)).on_hover_text(P2POOL_INPUT);
|
||||
let response = ui
|
||||
.add_sized(
|
||||
[width, text_edit],
|
||||
TextEdit::hint_text(
|
||||
TextEdit::singleline(buffer),
|
||||
r#"Type a command (e.g "help" or "status") and press Enter"#,
|
||||
),
|
||||
)
|
||||
.on_hover_text(P2POOL_INPUT);
|
||||
// If the user pressed enter, dump buffer contents into the process STDIN
|
||||
if response.lost_focus() && ui.input(|i| i.key_pressed(egui::Key::Enter)) {
|
||||
response.request_focus(); // Get focus back
|
||||
let buffer = std::mem::take(buffer); // Take buffer
|
||||
let mut process = lock!(process); // Lock
|
||||
if process.is_alive() { process.input.push(buffer); } // Push only if alive
|
||||
if process.is_alive() {
|
||||
process.input.push(buffer);
|
||||
} // Push only if alive
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -89,12 +104,21 @@ pub fn show(
|
|||
//---------------------------------------------------------------------------------------------------- Args
|
||||
if !self.simple {
|
||||
debug!("P2Pool Tab | Rendering [Arguments]");
|
||||
ui.group(|ui| { ui.horizontal(|ui| {
|
||||
ui.group(|ui| {
|
||||
ui.horizontal(|ui| {
|
||||
let width = (width / 10.0) - SPACE;
|
||||
ui.add_sized([width, text_edit], Label::new("Command arguments:"));
|
||||
ui.add_sized([ui.available_width(), text_edit], TextEdit::hint_text(TextEdit::singleline(&mut self.arguments), r#"--wallet <...> --host <...>"#)).on_hover_text(P2POOL_ARGUMENTS);
|
||||
ui.add_sized(
|
||||
[ui.available_width(), text_edit],
|
||||
TextEdit::hint_text(
|
||||
TextEdit::singleline(&mut self.arguments),
|
||||
r#"--wallet <...> --host <...>"#,
|
||||
),
|
||||
)
|
||||
.on_hover_text(P2POOL_ARGUMENTS);
|
||||
self.arguments.truncate(1024);
|
||||
})});
|
||||
})
|
||||
});
|
||||
ui.set_enabled(self.arguments.is_empty());
|
||||
}
|
||||
|
||||
|
@ -116,8 +140,15 @@ pub fn show(
|
|||
text = format!("Monero Address [{}/95] ❌", len);
|
||||
color = Color32::from_rgb(230, 50, 50);
|
||||
}
|
||||
ui.add_sized([width, text_edit], Label::new(RichText::new(text).color(color)));
|
||||
ui.add_sized([width, text_edit], TextEdit::hint_text(TextEdit::singleline(&mut self.address), "4...")).on_hover_text(P2POOL_ADDRESS);
|
||||
ui.add_sized(
|
||||
[width, text_edit],
|
||||
Label::new(RichText::new(text).color(color)),
|
||||
);
|
||||
ui.add_sized(
|
||||
[width, text_edit],
|
||||
TextEdit::hint_text(TextEdit::singleline(&mut self.address), "4..."),
|
||||
)
|
||||
.on_hover_text(P2POOL_ADDRESS);
|
||||
self.address.truncate(95);
|
||||
});
|
||||
|
||||
|
@ -147,7 +178,6 @@ pub fn show(
|
|||
|
||||
ui.vertical(|ui| {
|
||||
ui.horizontal(|ui| {
|
||||
|
||||
debug!("P2Pool Tab | Rendering [Ping List]");
|
||||
// [Ping List]
|
||||
let mut ms = 0;
|
||||
|
@ -157,18 +187,22 @@ pub fn show(
|
|||
if data.ip == self.node {
|
||||
ms = data.ms;
|
||||
color = data.color;
|
||||
break
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
debug!("P2Pool Tab | Rendering [ComboBox] of Remote Nodes");
|
||||
let ip_location = crate::node::format_ip_location(&self.node, false);
|
||||
let text = RichText::new(format!(" ⏺ {}ms | {}", ms, ip_location)).color(color);
|
||||
ComboBox::from_id_source("remote_nodes").selected_text(text).width(width).show_ui(ui, |ui| {
|
||||
ComboBox::from_id_source("remote_nodes")
|
||||
.selected_text(text)
|
||||
.width(width)
|
||||
.show_ui(ui, |ui| {
|
||||
for data in lock!(ping).nodes.iter() {
|
||||
let ms = crate::node::format_ms(data.ms);
|
||||
let ip_location = crate::node::format_ip_location(data.ip, true);
|
||||
let text = RichText::new(format!(" ⏺ {} | {}", ms, ip_location)).color(data.color);
|
||||
let text = RichText::new(format!(" ⏺ {} | {}", ms, ip_location))
|
||||
.color(data.color);
|
||||
ui.selectable_value(&mut self.node, data.ip.to_string(), text);
|
||||
}
|
||||
});
|
||||
|
@ -180,33 +214,58 @@ pub fn show(
|
|||
ui.horizontal(|ui| {
|
||||
let width = (width / 5.0) - 6.0;
|
||||
// [Select random node]
|
||||
if ui.add_sized([width, height], Button::new("Select random node")).on_hover_text(P2POOL_SELECT_RANDOM).clicked() {
|
||||
if ui
|
||||
.add_sized([width, height], Button::new("Select random node"))
|
||||
.on_hover_text(P2POOL_SELECT_RANDOM)
|
||||
.clicked()
|
||||
{
|
||||
self.node = RemoteNode::get_random(&self.node);
|
||||
}
|
||||
// [Select fastest node]
|
||||
if ui.add_sized([width, height], Button::new("Select fastest node")).on_hover_text(P2POOL_SELECT_FASTEST).clicked() && lock!(ping).pinged {
|
||||
if ui
|
||||
.add_sized([width, height], Button::new("Select fastest node"))
|
||||
.on_hover_text(P2POOL_SELECT_FASTEST)
|
||||
.clicked()
|
||||
&& lock!(ping).pinged
|
||||
{
|
||||
self.node = lock!(ping).fastest.to_string();
|
||||
}
|
||||
// [Ping Button]
|
||||
ui.add_enabled_ui(!lock!(ping).pinging, |ui| {
|
||||
if ui.add_sized([width, height], Button::new("Ping remote nodes")).on_hover_text(P2POOL_PING).clicked() {
|
||||
if ui
|
||||
.add_sized([width, height], Button::new("Ping remote nodes"))
|
||||
.on_hover_text(P2POOL_PING)
|
||||
.clicked()
|
||||
{
|
||||
Ping::spawn_thread(ping);
|
||||
}
|
||||
});
|
||||
// [Last <-]
|
||||
if ui.add_sized([width, height], Button::new("⬅ Last")).on_hover_text(P2POOL_SELECT_LAST).clicked() {
|
||||
if ui
|
||||
.add_sized([width, height], Button::new("⬅ Last"))
|
||||
.on_hover_text(P2POOL_SELECT_LAST)
|
||||
.clicked()
|
||||
{
|
||||
let ping = lock!(ping);
|
||||
match ping.pinged {
|
||||
true => self.node = RemoteNode::get_last_from_ping(&self.node, &ping.nodes),
|
||||
true => {
|
||||
self.node = RemoteNode::get_last_from_ping(&self.node, &ping.nodes)
|
||||
}
|
||||
false => self.node = RemoteNode::get_last(&self.node),
|
||||
}
|
||||
drop(ping);
|
||||
}
|
||||
// [Next ->]
|
||||
if ui.add_sized([width, height], Button::new("Next ➡")).on_hover_text(P2POOL_SELECT_NEXT).clicked() {
|
||||
if ui
|
||||
.add_sized([width, height], Button::new("Next ➡"))
|
||||
.on_hover_text(P2POOL_SELECT_NEXT)
|
||||
.clicked()
|
||||
{
|
||||
let ping = lock!(ping);
|
||||
match ping.pinged {
|
||||
true => self.node = RemoteNode::get_next_from_ping(&self.node, &ping.nodes),
|
||||
true => {
|
||||
self.node = RemoteNode::get_next_from_ping(&self.node, &ping.nodes)
|
||||
}
|
||||
false => self.node = RemoteNode::get_next(&self.node),
|
||||
}
|
||||
drop(ping);
|
||||
|
@ -238,14 +297,27 @@ pub fn show(
|
|||
ui.horizontal(|ui| {
|
||||
let width = (width / 3.0) - (SPACE * 1.75);
|
||||
// [Auto-node]
|
||||
ui.add_sized([width, height], Checkbox::new(&mut self.auto_select, "Auto-select")).on_hover_text(P2POOL_AUTO_SELECT);
|
||||
ui.add_sized(
|
||||
[width, height],
|
||||
Checkbox::new(&mut self.auto_select, "Auto-select"),
|
||||
)
|
||||
.on_hover_text(P2POOL_AUTO_SELECT);
|
||||
ui.separator();
|
||||
// [Auto-node]
|
||||
ui.add_sized([width, height], Checkbox::new(&mut self.auto_ping, "Auto-ping")).on_hover_text(P2POOL_AUTO_NODE);
|
||||
ui.add_sized(
|
||||
[width, height],
|
||||
Checkbox::new(&mut self.auto_ping, "Auto-ping"),
|
||||
)
|
||||
.on_hover_text(P2POOL_AUTO_NODE);
|
||||
ui.separator();
|
||||
// [Backup host]
|
||||
ui.add_sized([width, height], Checkbox::new(&mut self.backup_host, "Backup host")).on_hover_text(P2POOL_BACKUP_HOST_SIMPLE);
|
||||
})});
|
||||
ui.add_sized(
|
||||
[width, height],
|
||||
Checkbox::new(&mut self.backup_host, "Backup host"),
|
||||
)
|
||||
.on_hover_text(P2POOL_BACKUP_HOST_SIMPLE);
|
||||
})
|
||||
});
|
||||
|
||||
debug!("P2Pool Tab | Rendering warning text");
|
||||
ui.add_sized([width, height/2.0], Hyperlink::from_label_and_url("WARNING: It is recommended to run/use your own Monero Node (hover for details)", "https://github.com/hinto-janai/gupax#running-a-local-monero-node")).on_hover_text(P2POOL_COMMUNITY_NODE_WARNING);
|
||||
|
@ -472,14 +544,35 @@ pub fn show(
|
|||
// [Main/Mini]
|
||||
ui.horizontal(|ui| {
|
||||
let height = height / 4.0;
|
||||
ui.group(|ui| { ui.horizontal(|ui| {
|
||||
ui.group(|ui| {
|
||||
ui.horizontal(|ui| {
|
||||
let width = (width / 4.0) - SPACE;
|
||||
let height = height + 6.0;
|
||||
if ui.add_sized([width, height], SelectableLabel::new(!self.mini, "P2Pool Main")).on_hover_text(P2POOL_MAIN).clicked() { self.mini = false; }
|
||||
if ui.add_sized([width, height], SelectableLabel::new(self.mini, "P2Pool Mini")).on_hover_text(P2POOL_MINI).clicked() { self.mini = true; }
|
||||
})});
|
||||
if ui
|
||||
.add_sized(
|
||||
[width, height],
|
||||
SelectableLabel::new(!self.mini, "P2Pool Main"),
|
||||
)
|
||||
.on_hover_text(P2POOL_MAIN)
|
||||
.clicked()
|
||||
{
|
||||
self.mini = false;
|
||||
}
|
||||
if ui
|
||||
.add_sized(
|
||||
[width, height],
|
||||
SelectableLabel::new(self.mini, "P2Pool Mini"),
|
||||
)
|
||||
.on_hover_text(P2POOL_MINI)
|
||||
.clicked()
|
||||
{
|
||||
self.mini = true;
|
||||
}
|
||||
})
|
||||
});
|
||||
// [Out/In Peers] + [Log Level]
|
||||
ui.group(|ui| { ui.vertical(|ui| {
|
||||
ui.group(|ui| {
|
||||
ui.vertical(|ui| {
|
||||
let text = (ui.available_width() / 10.0) - SPACE;
|
||||
let width = (text * 8.0) - SPACE;
|
||||
let height = height / 3.0;
|
||||
|
@ -488,18 +581,28 @@ pub fn show(
|
|||
ui.style_mut().override_text_style = Some(Name("MonospaceSmall".into()));
|
||||
ui.horizontal(|ui| {
|
||||
ui.add_sized([text, height], Label::new("Out peers [10-450]:"));
|
||||
ui.add_sized([width, height], Slider::new(&mut self.out_peers, 10..=450)).on_hover_text(P2POOL_OUT);
|
||||
ui.add_sized(
|
||||
[width, height],
|
||||
Slider::new(&mut self.out_peers, 10..=450),
|
||||
)
|
||||
.on_hover_text(P2POOL_OUT);
|
||||
ui.add_space(ui.available_width() - 4.0);
|
||||
});
|
||||
ui.horizontal(|ui| {
|
||||
ui.add_sized([text, height], Label::new(" In peers [10-450]:"));
|
||||
ui.add_sized([width, height], Slider::new(&mut self.in_peers, 10..=450)).on_hover_text(P2POOL_IN);
|
||||
ui.add_sized(
|
||||
[width, height],
|
||||
Slider::new(&mut self.in_peers, 10..=450),
|
||||
)
|
||||
.on_hover_text(P2POOL_IN);
|
||||
});
|
||||
ui.horizontal(|ui| {
|
||||
ui.add_sized([text, height], Label::new(" Log level [0-6]:"));
|
||||
ui.add_sized([width, height], Slider::new(&mut self.log_level, 0..=6)).on_hover_text(P2POOL_LOG);
|
||||
ui.add_sized([width, height], Slider::new(&mut self.log_level, 0..=6))
|
||||
.on_hover_text(P2POOL_LOG);
|
||||
});
|
||||
})
|
||||
});
|
||||
})});
|
||||
});
|
||||
|
||||
debug!("P2Pool Tab | Rendering Backup host button");
|
||||
|
@ -507,7 +610,11 @@ pub fn show(
|
|||
let width = width - SPACE;
|
||||
let height = ui.available_height() / 3.0;
|
||||
// [Backup host]
|
||||
ui.add_sized([width, height], Checkbox::new(&mut self.backup_host, "Backup host")).on_hover_text(P2POOL_BACKUP_HOST_ADVANCED);
|
||||
ui.add_sized(
|
||||
[width, height],
|
||||
Checkbox::new(&mut self.backup_host, "Backup host"),
|
||||
)
|
||||
.on_hover_text(P2POOL_BACKUP_HOST_ADVANCED);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
14
src/panic.rs
14
src/panic.rs
|
@ -1,11 +1,5 @@
|
|||
//---------------------------------------------------------------------------------------------------- Use
|
||||
use crate::constants::{
|
||||
GUPAX_VERSION,
|
||||
P2POOL_VERSION,
|
||||
XMRIG_VERSION,
|
||||
OS_NAME,
|
||||
COMMIT,
|
||||
};
|
||||
use crate::constants::{COMMIT, GUPAX_VERSION, OS_NAME, P2POOL_VERSION, XMRIG_VERSION};
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
#[cold]
|
||||
|
@ -39,10 +33,12 @@ stack backtrace:\n{stack_trace}",
|
|||
Ok(mut path) => {
|
||||
path.push("crash.txt");
|
||||
match std::fs::write(&path, &panic_info) {
|
||||
Ok(_) => eprintln!("\nmass_panic!() - Saved panic log to: {}\n", path.display()),
|
||||
Ok(_) => {
|
||||
eprintln!("\nmass_panic!() - Saved panic log to: {}\n", path.display())
|
||||
}
|
||||
Err(e) => eprintln!("\nmass_panic!() - Could not save panic log: {e}\n"),
|
||||
}
|
||||
},
|
||||
}
|
||||
Err(e) => eprintln!("panic_hook PATH error: {e}"),
|
||||
}
|
||||
|
||||
|
|
31
src/regex.rs
31
src/regex.rs
|
@ -17,8 +17,8 @@
|
|||
|
||||
// Some regexes used throughout Gupax.
|
||||
|
||||
use regex::Regex;
|
||||
use once_cell::sync::Lazy;
|
||||
use regex::Regex;
|
||||
|
||||
//---------------------------------------------------------------------------------------------------- Lazy
|
||||
pub static REGEXES: Lazy<Regexes> = Lazy::new(|| Regexes::new());
|
||||
|
@ -54,11 +54,14 @@ impl Regexes {
|
|||
// This actually only checks for length & Base58, and doesn't do any checksum validation
|
||||
// (the last few bytes of a Monero address are a Keccak hash checksum) so some invalid addresses can trick this function.
|
||||
pub fn addr_ok(address: &str) -> bool {
|
||||
address.len() == 95 && REGEXES.address.is_match(address) && !address.contains('0') && !address.contains('O') && !address.contains('l')
|
||||
address.len() == 95
|
||||
&& REGEXES.address.is_match(address)
|
||||
&& !address.contains('0')
|
||||
&& !address.contains('O')
|
||||
&& !address.contains('l')
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------------------------------- [P2poolRegex]
|
||||
// Meant for parsing the output of P2Pool and finding payouts and total XMR found.
|
||||
// Why Regex instead of the standard library?
|
||||
|
@ -124,8 +127,8 @@ impl XmrigRegex {
|
|||
//---------------------------------------------------------------------------------------------------- TESTS
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use regex::Regex;
|
||||
use super::*;
|
||||
use regex::Regex;
|
||||
|
||||
#[test]
|
||||
fn build_regexes() {
|
||||
|
@ -157,9 +160,18 @@ mod test {
|
|||
let text = "NOTICE 2022-11-11 11:11:11.1111 P2Pool You received a payout of 0.111111111111 XMR in block 1111111";
|
||||
let text2 = "2022-11-11 11:11:11.1111 | 0.111111111111 XMR | Block 1,111,111";
|
||||
let text3 = "NOTICE 2020-12-11 12:35:41.3150 SideChain SYNCHRONIZED";
|
||||
assert_eq!(r.payout.find(text).unwrap().as_str(), "payout of 0.111111111111 XMR");
|
||||
assert_eq!(r.payout_float.find(text).unwrap().as_str(), "0.111111111111");
|
||||
assert_eq!(r.date.find(text).unwrap().as_str(), "2022-11-11 11:11:11.1111");
|
||||
assert_eq!(
|
||||
r.payout.find(text).unwrap().as_str(),
|
||||
"payout of 0.111111111111 XMR"
|
||||
);
|
||||
assert_eq!(
|
||||
r.payout_float.find(text).unwrap().as_str(),
|
||||
"0.111111111111"
|
||||
);
|
||||
assert_eq!(
|
||||
r.date.find(text).unwrap().as_str(),
|
||||
"2022-11-11 11:11:11.1111"
|
||||
);
|
||||
assert_eq!(r.block.find(text).unwrap().as_str(), "block 1111111");
|
||||
assert_eq!(r.block_int.find(text).unwrap().as_str(), "1111111");
|
||||
assert_eq!(r.block_comma.find(text2).unwrap().as_str(), "1,111,111");
|
||||
|
@ -171,7 +183,10 @@ mod test {
|
|||
let r = XmrigRegex::new();
|
||||
let text = "[2022-02-12 12:49:30.311] net no active pools, stop mining";
|
||||
let text2 = "[2022-02-12 12:49:30.311] net new job from 192.168.2.1:3333 diff 402K algo rx/0 height 2241142 (11 tx)";
|
||||
assert_eq!(r.not_mining.find(text).unwrap().as_str(), "no active pools, stop mining");
|
||||
assert_eq!(
|
||||
r.not_mining.find(text).unwrap().as_str(),
|
||||
"no active pools, stop mining"
|
||||
);
|
||||
assert_eq!(r.new_job.find(text2).unwrap().as_str(), "new job");
|
||||
}
|
||||
}
|
||||
|
|
876
src/status.rs
876
src/status.rs
File diff suppressed because it is too large
Load diff
61
src/sudo.rs
61
src/sudo.rs
|
@ -19,22 +19,16 @@
|
|||
// [zeroize] is used to wipe the memory after use.
|
||||
// Only gets imported in [main.rs] for Unix.
|
||||
|
||||
use zeroize::Zeroize;
|
||||
use crate::{constants::*, disk::Xmrig, macros::*, Helper, ProcessSignal};
|
||||
use log::*;
|
||||
use std::{
|
||||
thread,
|
||||
sync::{Arc,Mutex},
|
||||
process::*,
|
||||
io::Write,
|
||||
path::PathBuf,
|
||||
process::*,
|
||||
sync::{Arc, Mutex},
|
||||
thread,
|
||||
};
|
||||
use crate::{
|
||||
Helper,
|
||||
disk::Xmrig,
|
||||
ProcessSignal,
|
||||
constants::*,
|
||||
macros::*,
|
||||
};
|
||||
use log::*;
|
||||
use zeroize::Zeroize;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct SudoState {
|
||||
|
@ -113,7 +107,12 @@ impl SudoState {
|
|||
// Spawns a thread and tests sudo with the provided password.
|
||||
// Sudo takes the password through STDIN via [--stdin].
|
||||
// Sets the appropriate state fields on success/failure.
|
||||
pub fn test_sudo(state: Arc<Mutex<Self>>, helper: &Arc<Mutex<Helper>>, xmrig: &Xmrig, path: &PathBuf) {
|
||||
pub fn test_sudo(
|
||||
state: Arc<Mutex<Self>>,
|
||||
helper: &Arc<Mutex<Helper>>,
|
||||
xmrig: &Xmrig,
|
||||
path: &PathBuf,
|
||||
) {
|
||||
let helper = Arc::clone(helper);
|
||||
let xmrig = xmrig.clone();
|
||||
let path = path.clone();
|
||||
|
@ -135,8 +134,8 @@ impl SudoState {
|
|||
Self::wipe(&state);
|
||||
lock!(state).msg = format!("Sudo error: {}", e);
|
||||
lock!(state).testing = false;
|
||||
return
|
||||
},
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Spawn testing sudo
|
||||
|
@ -158,30 +157,44 @@ impl SudoState {
|
|||
// results for 5 seconds in a loop.
|
||||
for i in 1..=5 {
|
||||
match sudo.try_wait() {
|
||||
Ok(Some(code)) => if code.success() {
|
||||
Ok(Some(code)) => {
|
||||
if code.success() {
|
||||
info!("Sudo | Password ... OK!");
|
||||
lock!(state).success = true;
|
||||
break
|
||||
},
|
||||
break;
|
||||
}
|
||||
}
|
||||
Ok(None) => {
|
||||
info!("Sudo | Waiting [{}/5]...", i);
|
||||
std::thread::sleep(SECOND);
|
||||
},
|
||||
}
|
||||
Err(e) => {
|
||||
error!("Sudo | Couldn't reset timestamp: {}", e);
|
||||
Self::wipe(&state);
|
||||
lock!(state).msg = format!("Sudo error: {}", e);
|
||||
lock!(state).testing = false;
|
||||
return
|
||||
},
|
||||
return;
|
||||
}
|
||||
}
|
||||
if let Err(e) = sudo.kill() { warn!("Sudo | Kill error (it probably already exited): {}", e); }
|
||||
}
|
||||
if let Err(e) = sudo.kill() {
|
||||
warn!("Sudo | Kill error (it probably already exited): {}", e);
|
||||
}
|
||||
if lock!(state).success {
|
||||
match lock!(state).signal {
|
||||
ProcessSignal::Restart => crate::helper::Helper::restart_xmrig(&helper, &xmrig, &path, Arc::clone(&state)),
|
||||
ProcessSignal::Restart => crate::helper::Helper::restart_xmrig(
|
||||
&helper,
|
||||
&xmrig,
|
||||
&path,
|
||||
Arc::clone(&state),
|
||||
),
|
||||
ProcessSignal::Stop => crate::helper::Helper::stop_xmrig(&helper),
|
||||
_ => crate::helper::Helper::start_xmrig(&helper, &xmrig, &path, Arc::clone(&state)),
|
||||
_ => crate::helper::Helper::start_xmrig(
|
||||
&helper,
|
||||
&xmrig,
|
||||
&path,
|
||||
Arc::clone(&state),
|
||||
),
|
||||
}
|
||||
} else {
|
||||
lock!(state).msg = "Incorrect password! (or sudo timeout)".to_string();
|
||||
|
|
346
src/update.rs
346
src/update.rs
|
@ -24,25 +24,21 @@
|
|||
// b. auto-update at startup
|
||||
|
||||
//---------------------------------------------------------------------------------------------------- Imports
|
||||
use crate::{
|
||||
constants::GUPAX_VERSION, disk::*, macros::*, update::Name::*, ErrorButtons, ErrorFerris,
|
||||
ErrorState, Restart,
|
||||
};
|
||||
use anyhow::{anyhow, Error};
|
||||
use arti_client::TorClient;
|
||||
use arti_hyper::*;
|
||||
use crate::{
|
||||
constants::GUPAX_VERSION,
|
||||
disk::*,
|
||||
update::Name::*,
|
||||
ErrorState,ErrorFerris,ErrorButtons,
|
||||
Restart,
|
||||
macros::*,
|
||||
};
|
||||
use hyper::{
|
||||
Client,Body,Request,
|
||||
header::{HeaderValue, LOCATION},
|
||||
Body, Client, Request,
|
||||
};
|
||||
use log::*;
|
||||
use rand::distributions::Alphanumeric;
|
||||
use rand::{thread_rng, Rng};
|
||||
use serde::{Serialize,Deserialize};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::sync::{Arc, Mutex};
|
||||
use tokio::task::JoinHandle;
|
||||
|
@ -52,15 +48,12 @@ use walkdir::WalkDir;
|
|||
// tls implementation so this makes it fall back to the openssl variant.
|
||||
//
|
||||
// https://gitlab.torproject.org/tpo/core/arti/-/issues/715
|
||||
#[cfg(target_os = "macos")]
|
||||
use tls_api_openssl::TlsConnector;
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
use tls_api_native_tls::TlsConnector;
|
||||
#[cfg(target_os = "macos")]
|
||||
use tls_api_openssl::TlsConnector;
|
||||
|
||||
use tls_api::{
|
||||
TlsConnector as TlsConnectorTrait,
|
||||
TlsConnectorBuilder,
|
||||
};
|
||||
use tls_api::{TlsConnector as TlsConnectorTrait, TlsConnectorBuilder};
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
use zip::ZipArchive;
|
||||
|
@ -169,14 +162,41 @@ use impl_platform::*;
|
|||
|
||||
const VALID_GUPAX: [&str; 3] = [VALID_GUPAX_1, VALID_GUPAX_2, VALID_GUPAX_3];
|
||||
const VALID_XMRIG: [&str; 4] = [VALID_XMRIG_1, VALID_XMRIG_2, VALID_XMRIG_3, VALID_XMRIG_4];
|
||||
const VALID_P2POOL: [&str; 4] = [VALID_P2POOL_1, VALID_P2POOL_2, VALID_P2POOL_3, VALID_P2POOL_4];
|
||||
const VALID_P2POOL: [&str; 4] = [
|
||||
VALID_P2POOL_1,
|
||||
VALID_P2POOL_2,
|
||||
VALID_P2POOL_3,
|
||||
VALID_P2POOL_4,
|
||||
];
|
||||
|
||||
// Some fake Curl/Wget user-agents because GitHub API requires one and a Tor browser
|
||||
// user-agent might be fingerprintable without all the associated headers.
|
||||
const FAKE_USER_AGENT: [&str; 25] = [
|
||||
"Wget/1.16.3","Wget/1.17","Wget/1.17.1","Wget/1.18","Wget/1.18","Wget/1.19","Wget/1.19.1","Wget/1.19.2","Wget/1.19.3","Wget/1.19.4",
|
||||
"Wget/1.19.5","Wget/1.20","Wget/1.20.1","Wget/1.20.2","Wget/1.20.3","Wget/1.21","Wget/1.21.1","Wget/1.21.2","Wget/1.21.3","Wget/1.21.4",
|
||||
"curl/7.65.3","curl/7.66.0","curl/7.67.0","curl/7.68.0","curl/8.4.0",
|
||||
"Wget/1.16.3",
|
||||
"Wget/1.17",
|
||||
"Wget/1.17.1",
|
||||
"Wget/1.18",
|
||||
"Wget/1.18",
|
||||
"Wget/1.19",
|
||||
"Wget/1.19.1",
|
||||
"Wget/1.19.2",
|
||||
"Wget/1.19.3",
|
||||
"Wget/1.19.4",
|
||||
"Wget/1.19.5",
|
||||
"Wget/1.20",
|
||||
"Wget/1.20.1",
|
||||
"Wget/1.20.2",
|
||||
"Wget/1.20.3",
|
||||
"Wget/1.21",
|
||||
"Wget/1.21.1",
|
||||
"Wget/1.21.2",
|
||||
"Wget/1.21.3",
|
||||
"Wget/1.21.4",
|
||||
"curl/7.65.3",
|
||||
"curl/7.66.0",
|
||||
"curl/7.67.0",
|
||||
"curl/7.68.0",
|
||||
"curl/8.4.0",
|
||||
];
|
||||
|
||||
const MSG_NONE: &str = "No update in progress";
|
||||
|
@ -194,7 +214,8 @@ const MSG_EXTRACT: &str = "Extracting packages";
|
|||
const MSG_UPGRADE: &str = "Upgrading packages";
|
||||
pub const MSG_SUCCESS: &str = "Update successful";
|
||||
pub const MSG_FAILED: &str = "Update failed";
|
||||
pub const MSG_FAILED_HELP: &str = "Consider manually replacing your executable from: https://gupax.io/downloads";
|
||||
pub const MSG_FAILED_HELP: &str =
|
||||
"Consider manually replacing your executable from: https://gupax.io/downloads";
|
||||
|
||||
const INIT: &str = "------------------- Init -------------------";
|
||||
const METADATA: &str = "----------------- Metadata -----------------";
|
||||
|
@ -211,9 +232,15 @@ pub fn check_p2pool_path(path: &str) -> bool {
|
|||
};
|
||||
let path = match path.file_name() {
|
||||
Some(p) => p,
|
||||
None => { error!("Couldn't get P2Pool file name"); return false; },
|
||||
None => {
|
||||
error!("Couldn't get P2Pool file name");
|
||||
return false;
|
||||
}
|
||||
};
|
||||
path == VALID_P2POOL[0] || path == VALID_P2POOL[1] || path == VALID_P2POOL[2] || path == VALID_P2POOL[3]
|
||||
path == VALID_P2POOL[0]
|
||||
|| path == VALID_P2POOL[1]
|
||||
|| path == VALID_P2POOL[2]
|
||||
|| path == VALID_P2POOL[3]
|
||||
}
|
||||
|
||||
pub fn check_xmrig_path(path: &str) -> bool {
|
||||
|
@ -223,9 +250,15 @@ pub fn check_xmrig_path(path: &str) -> bool {
|
|||
};
|
||||
let path = match path.file_name() {
|
||||
Some(p) => p,
|
||||
None => { error!("Couldn't get XMRig file name"); return false; },
|
||||
None => {
|
||||
error!("Couldn't get XMRig file name");
|
||||
return false;
|
||||
}
|
||||
};
|
||||
path == VALID_XMRIG[0] || path == VALID_XMRIG[1] || path == VALID_XMRIG[2] || path == VALID_XMRIG[3]
|
||||
path == VALID_XMRIG[0]
|
||||
|| path == VALID_XMRIG[1]
|
||||
|| path == VALID_XMRIG[2]
|
||||
|| path == VALID_XMRIG[3]
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------- Update struct/impl
|
||||
|
@ -306,7 +339,9 @@ impl Update {
|
|||
// Below is async, bootstraps immediately but has issues when recreating the circuit
|
||||
// let tor = TorClient::create_bootstrapped(TorClientConfig::default()).await?;
|
||||
// This one below is non-async, and doesn't bootstrap immediately.
|
||||
let tor = TorClient::builder().bootstrap_behavior(arti_client::BootstrapBehavior::OnDemand).create_unbootstrapped()?;
|
||||
let tor = TorClient::builder()
|
||||
.bootstrap_behavior(arti_client::BootstrapBehavior::OnDemand)
|
||||
.create_unbootstrapped()?;
|
||||
// This makes sure the Tor circuit is different each time
|
||||
let tor = TorClient::isolated_client(&tor);
|
||||
let tls = TlsConnector::builder()?.build()?;
|
||||
|
@ -328,7 +363,14 @@ impl Update {
|
|||
// actually contains the code. This is so that everytime
|
||||
// an update needs to happen (Gupax tab, auto-update), the
|
||||
// code only needs to be edited once, here.
|
||||
pub fn spawn_thread(og: &Arc<Mutex<State>>, gupax: &crate::disk::Gupax, state_path: &Path, update: &Arc<Mutex<Update>>, error_state: &mut ErrorState, restart: &Arc<Mutex<Restart>>) {
|
||||
pub fn spawn_thread(
|
||||
og: &Arc<Mutex<State>>,
|
||||
gupax: &crate::disk::Gupax,
|
||||
state_path: &Path,
|
||||
update: &Arc<Mutex<Update>>,
|
||||
error_state: &mut ErrorState,
|
||||
restart: &Arc<Mutex<Restart>>,
|
||||
) {
|
||||
// We really shouldn't be in the function for
|
||||
// the Linux distro Gupax (UI gets disabled)
|
||||
// but if somehow get in here, just return.
|
||||
|
@ -341,7 +383,17 @@ impl Update {
|
|||
// Attempt relative to absolute path
|
||||
let p2pool_path = match into_absolute_path(gupax.p2pool_path.clone()) {
|
||||
Ok(p) => p,
|
||||
Err(e) => { error_state.set(format!("Provided P2Pool path could not be turned into an absolute path: {}", e), ErrorFerris::Error, ErrorButtons::Okay); return; },
|
||||
Err(e) => {
|
||||
error_state.set(
|
||||
format!(
|
||||
"Provided P2Pool path could not be turned into an absolute path: {}",
|
||||
e
|
||||
),
|
||||
ErrorFerris::Error,
|
||||
ErrorButtons::Okay,
|
||||
);
|
||||
return;
|
||||
}
|
||||
};
|
||||
// Attempt to get basename
|
||||
let file = match p2pool_path.file_name() {
|
||||
|
@ -349,10 +401,20 @@ impl Update {
|
|||
// Attempt to turn into str
|
||||
match p.to_str() {
|
||||
Some(p) => p,
|
||||
None => { error_state.set("Provided P2Pool path could not be turned into a UTF-8 string (are you using non-English characters?)", ErrorFerris::Error, ErrorButtons::Okay); return; },
|
||||
None => {
|
||||
error_state.set("Provided P2Pool path could not be turned into a UTF-8 string (are you using non-English characters?)", ErrorFerris::Error, ErrorButtons::Okay);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
None => {
|
||||
error_state.set(
|
||||
"Provided P2Pool path could not be found",
|
||||
ErrorFerris::Error,
|
||||
ErrorButtons::Okay,
|
||||
);
|
||||
return;
|
||||
}
|
||||
},
|
||||
None => { error_state.set("Provided P2Pool path could not be found", ErrorFerris::Error, ErrorButtons::Okay); return; },
|
||||
};
|
||||
// If it doesn't look like [P2Pool], its probably a bad move
|
||||
// to overwrite it with an update, so set an error.
|
||||
|
@ -361,7 +423,10 @@ impl Update {
|
|||
if check_p2pool_path(file) {
|
||||
info!("Update | Using P2Pool path: [{}]", p2pool_path.display());
|
||||
} else {
|
||||
warn!("Update | Aborting update, incorrect P2Pool path: [{}]", file);
|
||||
warn!(
|
||||
"Update | Aborting update, incorrect P2Pool path: [{}]",
|
||||
file
|
||||
);
|
||||
let text = format!("Provided P2Pool path seems incorrect. Not starting update for safety.\nTry one of these: {:?}", VALID_P2POOL);
|
||||
error_state.set(text, ErrorFerris::Error, ErrorButtons::Okay);
|
||||
return;
|
||||
|
@ -370,17 +435,37 @@ impl Update {
|
|||
// Check XMRig path for safety
|
||||
let xmrig_path = match into_absolute_path(gupax.xmrig_path.clone()) {
|
||||
Ok(p) => p,
|
||||
Err(e) => { error_state.set(format!("Provided XMRig path could not be turned into an absolute path: {}", e), ErrorFerris::Error, ErrorButtons::Okay); return; },
|
||||
Err(e) => {
|
||||
error_state.set(
|
||||
format!(
|
||||
"Provided XMRig path could not be turned into an absolute path: {}",
|
||||
e
|
||||
),
|
||||
ErrorFerris::Error,
|
||||
ErrorButtons::Okay,
|
||||
);
|
||||
return;
|
||||
}
|
||||
};
|
||||
let file = match xmrig_path.file_name() {
|
||||
Some(p) => {
|
||||
// Attempt to turn into str
|
||||
match p.to_str() {
|
||||
Some(p) => p,
|
||||
None => { error_state.set("Provided XMRig path could not be turned into a UTF-8 string (are you using non-English characters?)", ErrorFerris::Error, ErrorButtons::Okay); return; },
|
||||
None => {
|
||||
error_state.set("Provided XMRig path could not be turned into a UTF-8 string (are you using non-English characters?)", ErrorFerris::Error, ErrorButtons::Okay);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
None => {
|
||||
error_state.set(
|
||||
"Provided XMRig path could not be found",
|
||||
ErrorFerris::Error,
|
||||
ErrorButtons::Okay,
|
||||
);
|
||||
return;
|
||||
}
|
||||
},
|
||||
None => { error_state.set("Provided XMRig path could not be found", ErrorFerris::Error, ErrorButtons::Okay); return; },
|
||||
};
|
||||
if check_xmrig_path(file) {
|
||||
info!("Update | Using XMRig path: [{}]", xmrig_path.display());
|
||||
|
@ -413,14 +498,15 @@ impl Update {
|
|||
Err(e) => {
|
||||
warn!("Update | Saving state ... FAIL: {}", e);
|
||||
lock!(og).version = original_version;
|
||||
*lock2!(update,msg) = "Saving new versions into state failed".to_string();
|
||||
},
|
||||
*lock2!(update, msg) =
|
||||
"Saving new versions into state failed".to_string();
|
||||
}
|
||||
};
|
||||
}
|
||||
Err(e) => {
|
||||
info!("Update ... FAIL: {}", e);
|
||||
*lock2!(update, msg) = format!("{} | {}\n{}", MSG_FAILED, e, MSG_FAILED_HELP);
|
||||
},
|
||||
}
|
||||
};
|
||||
*lock2!(update, updating) = false;
|
||||
});
|
||||
|
@ -436,11 +522,18 @@ impl Update {
|
|||
// 4. loop over vec, download links
|
||||
// 5. extract, upgrade
|
||||
#[tokio::main]
|
||||
pub async fn start(update: Arc<Mutex<Self>>, _og: Arc<Mutex<State>>, state_ver: Arc<Mutex<Version>>, restart: Arc<Mutex<Restart>>) -> Result<(), anyhow::Error> {
|
||||
pub async fn start(
|
||||
update: Arc<Mutex<Self>>,
|
||||
_og: Arc<Mutex<State>>,
|
||||
state_ver: Arc<Mutex<Version>>,
|
||||
restart: Arc<Mutex<Restart>>,
|
||||
) -> Result<(), anyhow::Error> {
|
||||
#[cfg(feature = "distro")]
|
||||
error!("Update | This is the [Linux distro] version of Gupax, updates are disabled");
|
||||
#[cfg(feature = "distro")]
|
||||
return Err(anyhow!("This is the [Linux distro] version of Gupax, updates are disabled"));
|
||||
return Err(anyhow!(
|
||||
"This is the [Linux distro] version of Gupax, updates are disabled"
|
||||
));
|
||||
|
||||
//---------------------------------------------------------------------------------------------------- Init
|
||||
*lock2!(update, updating) = true;
|
||||
|
@ -460,11 +553,7 @@ impl Update {
|
|||
std::fs::create_dir(&tmp_dir)?;
|
||||
|
||||
// Make Pkg vector
|
||||
let mut vec = vec![
|
||||
Pkg::new(Gupax),
|
||||
Pkg::new(P2pool),
|
||||
Pkg::new(Xmrig),
|
||||
];
|
||||
let mut vec = vec![Pkg::new(Gupax), Pkg::new(P2pool), Pkg::new(Xmrig)];
|
||||
|
||||
// Generate fake user-agent
|
||||
let user_agent = Pkg::get_user_agent();
|
||||
|
@ -503,7 +592,9 @@ impl Update {
|
|||
// function itself but for some reason, it was getting skipped over,
|
||||
// so the [new_ver] check is now here, in the outer scope.
|
||||
for i in 1..=3 {
|
||||
if i > 1 { *lock2!(update,msg) = format!("{} [{}/3]", MSG_METADATA_RETRY, i); }
|
||||
if i > 1 {
|
||||
*lock2!(update, msg) = format!("{} [{}/3]", MSG_METADATA_RETRY, i);
|
||||
}
|
||||
let mut handles: Vec<JoinHandle<Result<(), anyhow::Error>>> = vec![];
|
||||
for pkg in vec.iter() {
|
||||
// Clone data before sending to async
|
||||
|
@ -514,7 +605,9 @@ impl Update {
|
|||
let handle: JoinHandle<Result<(), anyhow::Error>> = tokio::spawn(async move {
|
||||
match client {
|
||||
ClientEnum::Tor(t) => Pkg::get_metadata(new_ver, t, link, user_agent).await,
|
||||
ClientEnum::Https(h) => Pkg::get_metadata(new_ver, h, link, user_agent).await,
|
||||
ClientEnum::Https(h) => {
|
||||
Pkg::get_metadata(new_ver, h, link, user_agent).await
|
||||
}
|
||||
}
|
||||
});
|
||||
handles.push(handle);
|
||||
|
@ -524,7 +617,9 @@ impl Update {
|
|||
// Two [??] will send the error.
|
||||
// We don't actually want to return the error here since we
|
||||
// prefer looping and retrying over immediately erroring out.
|
||||
if let Err(e) = handle.await? { warn!("Update | {}", e) }
|
||||
if let Err(e) = handle.await? {
|
||||
warn!("Update | {}", e)
|
||||
}
|
||||
}
|
||||
// Check for empty version
|
||||
let mut indexes = vec![];
|
||||
|
@ -545,7 +640,9 @@ impl Update {
|
|||
for index in indexes {
|
||||
vec.remove(index);
|
||||
}
|
||||
if vec.is_empty() { break }
|
||||
if vec.is_empty() {
|
||||
break;
|
||||
}
|
||||
// Some Tor exit nodes seem to be blocked by GitHub's API,
|
||||
// so recreate the circuit every loop.
|
||||
if tor {
|
||||
|
@ -557,7 +654,7 @@ impl Update {
|
|||
info!("Update | Metadata ... OK ... {}%", lock2!(update, prog));
|
||||
} else {
|
||||
error!("Update | Metadata ... FAIL");
|
||||
return Err(anyhow!("Metadata fetch failed"))
|
||||
return Err(anyhow!("Metadata fetch failed"));
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------- Compare
|
||||
|
@ -592,11 +689,17 @@ impl Update {
|
|||
}
|
||||
}
|
||||
if diff {
|
||||
info!("Update | {} {} != {} ... ADDING", pkg.name, old_ver, new_ver);
|
||||
info!(
|
||||
"Update | {} {} != {} ... ADDING",
|
||||
pkg.name, old_ver, new_ver
|
||||
);
|
||||
new_pkgs.push(format!("\n{} {} -> {}", name, old_ver, new_ver));
|
||||
vec3.push(pkg);
|
||||
} else {
|
||||
info!("Update | {} {} == {} ... SKIPPING", pkg.name, old_ver, new_ver);
|
||||
info!(
|
||||
"Update | {} {} == {} ... SKIPPING",
|
||||
pkg.name, old_ver, new_ver
|
||||
);
|
||||
}
|
||||
}
|
||||
*lock2!(update, prog) += 5.0;
|
||||
|
@ -609,7 +712,7 @@ impl Update {
|
|||
info!("Update | All packages up-to-date ... RETURNING");
|
||||
*lock2!(update, prog) = 100.0;
|
||||
*lock2!(update, msg) = MSG_UP_TO_DATE.to_string();
|
||||
return Ok(())
|
||||
return Ok(());
|
||||
}
|
||||
let new_pkgs: String = new_pkgs.concat();
|
||||
|
||||
|
@ -618,7 +721,9 @@ impl Update {
|
|||
info!("Update | {}", DOWNLOAD);
|
||||
let mut vec4 = vec![];
|
||||
for i in 1..=3 {
|
||||
if i > 1 { *lock2!(update,msg) = format!("{} [{}/3]{}", MSG_DOWNLOAD_RETRY, i, new_pkgs); }
|
||||
if i > 1 {
|
||||
*lock2!(update, msg) = format!("{} [{}/3]{}", MSG_DOWNLOAD_RETRY, i, new_pkgs);
|
||||
}
|
||||
let mut handles: Vec<JoinHandle<Result<(), anyhow::Error>>> = vec![];
|
||||
for pkg in vec3.iter() {
|
||||
// Clone data before async
|
||||
|
@ -629,8 +734,20 @@ impl Update {
|
|||
// Example: https://github.com/hinto-janai/gupax/releases/download/v0.0.1/gupax-v0.0.1-linux-x64-standalone
|
||||
// XMRig doesn't have a [v], so slice it out
|
||||
let link = match pkg.name {
|
||||
Name::Xmrig => pkg.link_prefix.to_string() + &version + pkg.link_suffix + &version[1..] + pkg.link_extension,
|
||||
_ => pkg.link_prefix.to_string() + &version + pkg.link_suffix + &version + pkg.link_extension,
|
||||
Name::Xmrig => {
|
||||
pkg.link_prefix.to_string()
|
||||
+ &version
|
||||
+ pkg.link_suffix
|
||||
+ &version[1..]
|
||||
+ pkg.link_extension
|
||||
}
|
||||
_ => {
|
||||
pkg.link_prefix.to_string()
|
||||
+ &version
|
||||
+ pkg.link_suffix
|
||||
+ &version
|
||||
+ pkg.link_extension
|
||||
}
|
||||
};
|
||||
info!("Update | {} ... {}", pkg.name, link);
|
||||
let handle: JoinHandle<Result<(), anyhow::Error>> = tokio::spawn(async move {
|
||||
|
@ -643,7 +760,9 @@ impl Update {
|
|||
}
|
||||
// Handle await
|
||||
for handle in handles {
|
||||
if let Err(e) = handle.await? { warn!("Update | {}", e) }
|
||||
if let Err(e) = handle.await? {
|
||||
warn!("Update | {}", e)
|
||||
}
|
||||
}
|
||||
// Check for empty bytes
|
||||
let mut indexes = vec![];
|
||||
|
@ -664,13 +783,15 @@ impl Update {
|
|||
for index in indexes {
|
||||
vec3.remove(index);
|
||||
}
|
||||
if vec3.is_empty() { break }
|
||||
if vec3.is_empty() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if vec3.is_empty() {
|
||||
info!("Update | Download ... OK ... {}%", *lock2!(update, prog));
|
||||
} else {
|
||||
error!("Update | Download ... FAIL");
|
||||
return Err(anyhow!("Download failed"))
|
||||
return Err(anyhow!("Download failed"));
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------- Extract
|
||||
|
@ -682,9 +803,13 @@ impl Update {
|
|||
_ => tmp_dir.to_owned() + &pkg.name.to_string(),
|
||||
};
|
||||
#[cfg(target_os = "windows")]
|
||||
ZipArchive::extract(&mut ZipArchive::new(std::io::Cursor::new(lock!(pkg.bytes).as_ref()))?, tmp)?;
|
||||
ZipArchive::extract(
|
||||
&mut ZipArchive::new(std::io::Cursor::new(lock!(pkg.bytes).as_ref()))?,
|
||||
tmp,
|
||||
)?;
|
||||
#[cfg(target_family = "unix")]
|
||||
tar::Archive::new(flate2::read::GzDecoder::new(lock!(pkg.bytes).as_ref())).unpack(tmp)?;
|
||||
tar::Archive::new(flate2::read::GzDecoder::new(lock!(pkg.bytes).as_ref()))
|
||||
.unpack(tmp)?;
|
||||
*lock2!(update, prog) += (5.0 / pkg_amount).round();
|
||||
info!("Update | {} ... OK", pkg.name);
|
||||
}
|
||||
|
@ -703,12 +828,17 @@ impl Update {
|
|||
for entry in WalkDir::new(tmp_dir.clone()) {
|
||||
let entry = entry?.clone();
|
||||
// If not a file, continue
|
||||
if ! entry.file_type().is_file() { continue }
|
||||
let basename = entry.file_name().to_str().ok_or_else(|| anyhow!("WalkDir basename failed"))?;
|
||||
if !entry.file_type().is_file() {
|
||||
continue;
|
||||
}
|
||||
let basename = entry
|
||||
.file_name()
|
||||
.to_str()
|
||||
.ok_or_else(|| anyhow!("WalkDir basename failed"))?;
|
||||
match basename {
|
||||
VALID_GUPAX_1|VALID_GUPAX_2|VALID_GUPAX_3|
|
||||
VALID_P2POOL_1|VALID_P2POOL_2|VALID_P2POOL_3|VALID_P2POOL_4|
|
||||
VALID_XMRIG_1|VALID_XMRIG_2|VALID_XMRIG_3|VALID_XMRIG_4 => {
|
||||
VALID_GUPAX_1 | VALID_GUPAX_2 | VALID_GUPAX_3 | VALID_P2POOL_1 | VALID_P2POOL_2
|
||||
| VALID_P2POOL_3 | VALID_P2POOL_4 | VALID_XMRIG_1 | VALID_XMRIG_2
|
||||
| VALID_XMRIG_3 | VALID_XMRIG_4 => {
|
||||
found = true;
|
||||
let name = match basename {
|
||||
VALID_GUPAX_1 | VALID_GUPAX_2 | VALID_GUPAX_3 => Gupax,
|
||||
|
@ -733,13 +863,24 @@ impl Update {
|
|||
P2pool => tmp_dir.clone() + "p2pool_old.exe",
|
||||
Xmrig => tmp_dir.clone() + "xmrig_old.exe",
|
||||
};
|
||||
info!("Update | WINDOWS ONLY ... Moving old [{}] -> [{}]", path.display(), tmp_windows);
|
||||
info!(
|
||||
"Update | WINDOWS ONLY ... Moving old [{}] -> [{}]",
|
||||
path.display(),
|
||||
tmp_windows
|
||||
);
|
||||
std::fs::rename(&path, tmp_windows)?;
|
||||
}
|
||||
info!("Update | Moving new [{}] -> [{}]", entry.path().display(), path.display());
|
||||
info!(
|
||||
"Update | Moving new [{}] -> [{}]",
|
||||
entry.path().display(),
|
||||
path.display()
|
||||
);
|
||||
// Create folder for [P2Pool/XMRig]
|
||||
if name == P2pool || name == Xmrig {
|
||||
std::fs::create_dir_all(path.parent().ok_or_else(|| anyhow!(format!("{} path failed", name)))?)?;
|
||||
std::fs::create_dir_all(
|
||||
path.parent()
|
||||
.ok_or_else(|| anyhow!(format!("{} path failed", name)))?,
|
||||
)?;
|
||||
}
|
||||
// Move downloaded path into old path
|
||||
std::fs::rename(entry.path(), path)?;
|
||||
|
@ -749,16 +890,20 @@ impl Update {
|
|||
lock!(state_ver).gupax = Pkg::get_new_pkg_version(Gupax, &vec4)?;
|
||||
// If we're updating Gupax, set the [Restart] state so that the user knows to restart
|
||||
*lock!(restart) = Restart::Yes;
|
||||
},
|
||||
P2pool => lock!(state_ver).p2pool = Pkg::get_new_pkg_version(P2pool, &vec4)?,
|
||||
}
|
||||
P2pool => {
|
||||
lock!(state_ver).p2pool = Pkg::get_new_pkg_version(P2pool, &vec4)?
|
||||
}
|
||||
Xmrig => lock!(state_ver).xmrig = Pkg::get_new_pkg_version(Xmrig, &vec4)?,
|
||||
};
|
||||
*lock2!(update, prog) += (5.0 / pkg_amount).round();
|
||||
},
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
if !found { return Err(anyhow!("Fatal error: Package binary could not be found")) }
|
||||
if !found {
|
||||
return Err(anyhow!("Fatal error: Package binary could not be found"));
|
||||
}
|
||||
|
||||
// Remove tmp dir (on Unix)
|
||||
#[cfg(target_family = "unix")]
|
||||
|
@ -769,9 +914,17 @@ impl Update {
|
|||
let seconds = now.elapsed().as_secs();
|
||||
info!("Update | Seconds elapsed ... [{}s]", seconds);
|
||||
match seconds {
|
||||
0 => *lock2!(update,msg) = format!("{}! Took 0 seconds... What...?!{}", MSG_SUCCESS, new_pkgs),
|
||||
1 => *lock2!(update,msg) = format!("{}! Took 1 second... Wow!{}", MSG_SUCCESS, new_pkgs),
|
||||
_ => *lock2!(update,msg) = format!("{}! Took {} seconds.{}", MSG_SUCCESS, seconds, new_pkgs),
|
||||
0 => {
|
||||
*lock2!(update, msg) =
|
||||
format!("{}! Took 0 seconds... What...?!{}", MSG_SUCCESS, new_pkgs)
|
||||
}
|
||||
1 => {
|
||||
*lock2!(update, msg) = format!("{}! Took 1 second... Wow!{}", MSG_SUCCESS, new_pkgs)
|
||||
}
|
||||
_ => {
|
||||
*lock2!(update, msg) =
|
||||
format!("{}! Took {} seconds.{}", MSG_SUCCESS, seconds, new_pkgs)
|
||||
}
|
||||
}
|
||||
*lock2!(update, prog) = 100.0;
|
||||
Ok(())
|
||||
|
@ -851,7 +1004,10 @@ impl Pkg {
|
|||
let request = Request::builder()
|
||||
.method("GET")
|
||||
.uri(link)
|
||||
.header(hyper::header::USER_AGENT, HeaderValue::from_static(user_agent))
|
||||
.header(
|
||||
hyper::header::USER_AGENT,
|
||||
HeaderValue::from_static(user_agent),
|
||||
)
|
||||
.body(Body::empty())?;
|
||||
Ok(request)
|
||||
}
|
||||
|
@ -860,8 +1016,15 @@ impl Pkg {
|
|||
#[inline(never)]
|
||||
// Get metadata using [Generic hyper::client<C>] & [Request]
|
||||
// and change [version, prog] under an Arc<Mutex>
|
||||
async fn get_metadata<C>(new_ver: Arc<Mutex<String>>, client: Client<C>, link: String, user_agent: &'static str) -> Result<(), Error>
|
||||
where C: hyper::client::connect::Connect + Clone + Send + Sync + 'static, {
|
||||
async fn get_metadata<C>(
|
||||
new_ver: Arc<Mutex<String>>,
|
||||
client: Client<C>,
|
||||
link: String,
|
||||
user_agent: &'static str,
|
||||
) -> Result<(), Error>
|
||||
where
|
||||
C: hyper::client::connect::Connect + Clone + Send + Sync + 'static,
|
||||
{
|
||||
let request = Pkg::get_request(link, user_agent)?;
|
||||
let mut response = client.request(request).await?;
|
||||
let body = hyper::body::to_bytes(response.body_mut()).await?;
|
||||
|
@ -874,15 +1037,30 @@ impl Pkg {
|
|||
#[inline(never)]
|
||||
// Takes a [Request], fills the appropriate [Pkg]
|
||||
// [bytes] field with the [Archive/Standalone]
|
||||
async fn get_bytes<C>(bytes: Arc<Mutex<bytes::Bytes>>, client: Client<C>, link: String, user_agent: &'static str) -> Result<(), anyhow::Error>
|
||||
where C: hyper::client::connect::Connect + Clone + Send + Sync + 'static, {
|
||||
async fn get_bytes<C>(
|
||||
bytes: Arc<Mutex<bytes::Bytes>>,
|
||||
client: Client<C>,
|
||||
link: String,
|
||||
user_agent: &'static str,
|
||||
) -> Result<(), anyhow::Error>
|
||||
where
|
||||
C: hyper::client::connect::Connect + Clone + Send + Sync + 'static,
|
||||
{
|
||||
let request = Self::get_request(link, user_agent)?;
|
||||
let mut response = client.request(request).await?;
|
||||
// GitHub sends a 302 redirect, so we must follow
|
||||
// the [Location] header... only if Reqwest had custom
|
||||
// connectors so I didn't have to manually do this...
|
||||
if response.headers().contains_key(LOCATION) {
|
||||
let request = Self::get_request(response.headers().get(LOCATION).ok_or_else(|| anyhow!("HTTP Location header GET failed"))?.to_str()?.to_string(), user_agent)?;
|
||||
let request = Self::get_request(
|
||||
response
|
||||
.headers()
|
||||
.get(LOCATION)
|
||||
.ok_or_else(|| anyhow!("HTTP Location header GET failed"))?
|
||||
.to_str()?
|
||||
.to_string(),
|
||||
user_agent,
|
||||
)?;
|
||||
response = client.request(request).await?;
|
||||
}
|
||||
let body = hyper::body::to_bytes(response.into_body()).await?;
|
||||
|
@ -897,7 +1075,7 @@ impl Pkg {
|
|||
fn get_new_pkg_version(name: Name, vec: &[&Pkg]) -> Result<String, Error> {
|
||||
for pkg in vec.iter() {
|
||||
if pkg.name == name {
|
||||
return Ok(lock!(pkg.new_ver).to_string())
|
||||
return Ok(lock!(pkg.new_ver).to_string());
|
||||
}
|
||||
}
|
||||
Err(anyhow!("Couldn't find new_pkg_version"))
|
||||
|
|
180
src/xmr.rs
180
src/xmr.rs
|
@ -22,12 +22,8 @@
|
|||
// These represent:
|
||||
// "(DATE, ATOMIC_UNIT, MONERO_BLOCK)"
|
||||
|
||||
use crate::{
|
||||
human::*,
|
||||
};
|
||||
use crate::regex::{
|
||||
P2POOL_REGEX,
|
||||
};
|
||||
use crate::human::*;
|
||||
use crate::regex::P2POOL_REGEX;
|
||||
|
||||
use log::*;
|
||||
|
||||
|
@ -122,7 +118,11 @@ pub struct PayoutOrd(Vec<(String, AtomicUnit, HumanNumber)>);
|
|||
|
||||
impl PayoutOrd {
|
||||
pub fn new() -> Self {
|
||||
Self(vec![(String::from("????-??-?? ??:??:??.????"), AtomicUnit::new(), HumanNumber::unknown())])
|
||||
Self(vec![(
|
||||
String::from("????-??-?? ??:??:??.????"),
|
||||
AtomicUnit::new(),
|
||||
HumanNumber::unknown(),
|
||||
)])
|
||||
}
|
||||
|
||||
pub const fn from_vec(vec: Vec<(String, AtomicUnit, HumanNumber)>) -> Self {
|
||||
|
@ -130,13 +130,23 @@ impl PayoutOrd {
|
|||
}
|
||||
|
||||
pub fn is_same(a: &Self, b: &Self) -> bool {
|
||||
if a.0.is_empty() && b.0.is_empty() { return true }
|
||||
if a.0.len() != b.0.len() { return false }
|
||||
if a.0.is_empty() && b.0.is_empty() {
|
||||
return true;
|
||||
}
|
||||
if a.0.len() != b.0.len() {
|
||||
return false;
|
||||
}
|
||||
let mut n = 0;
|
||||
for (date, atomic_unit, block) in &a.0 {
|
||||
if *date != b.0[n].0 { return false }
|
||||
if *atomic_unit != b.0[n].1 { return false }
|
||||
if *block != b.0[n].2 { return false }
|
||||
if *date != b.0[n].0 {
|
||||
return false;
|
||||
}
|
||||
if *atomic_unit != b.0[n].1 {
|
||||
return false;
|
||||
}
|
||||
if *block != b.0[n].2 {
|
||||
return false;
|
||||
}
|
||||
n += 1;
|
||||
}
|
||||
true
|
||||
|
@ -151,14 +161,20 @@ impl PayoutOrd {
|
|||
// Date
|
||||
let date = match P2POOL_REGEX.date.find(line) {
|
||||
Some(date) => date.as_str().to_string(),
|
||||
None => { error!("P2Pool | Date parse error: [{}]", line); "????-??-?? ??:??:??.????".to_string() },
|
||||
None => {
|
||||
error!("P2Pool | Date parse error: [{}]", line);
|
||||
"????-??-?? ??:??:??.????".to_string()
|
||||
}
|
||||
};
|
||||
// AtomicUnit
|
||||
let atomic_unit = if let Some(word) = P2POOL_REGEX.payout.find(line) {
|
||||
if let Some(word) = P2POOL_REGEX.payout_float.find(word.as_str()) {
|
||||
match word.as_str().parse::<f64>() {
|
||||
Ok(au) => AtomicUnit::from_f64(au),
|
||||
Err(e) => { error!("P2Pool | AtomicUnit parse error: [{}] on [{}]", e, line); AtomicUnit::new() },
|
||||
Err(e) => {
|
||||
error!("P2Pool | AtomicUnit parse error: [{}] on [{}]", e, line);
|
||||
AtomicUnit::new()
|
||||
}
|
||||
}
|
||||
} else {
|
||||
error!("P2Pool | AtomicUnit parse error: [{}]", line);
|
||||
|
@ -173,7 +189,10 @@ impl PayoutOrd {
|
|||
if let Some(word) = P2POOL_REGEX.block_int.find(word.as_str()) {
|
||||
match word.as_str().parse::<u64>() {
|
||||
Ok(b) => HumanNumber::from_u64(b),
|
||||
Err(e) => { error!("P2Pool | Block parse error: [{}] on [{}]", e, line); HumanNumber::unknown() },
|
||||
Err(e) => {
|
||||
error!("P2Pool | Block parse error: [{}] on [{}]", e, line);
|
||||
HumanNumber::unknown()
|
||||
}
|
||||
}
|
||||
} else {
|
||||
error!("P2Pool | Block parse error: [{}]", line);
|
||||
|
@ -191,13 +210,19 @@ impl PayoutOrd {
|
|||
// Date
|
||||
let date = match P2POOL_REGEX.date.find(line) {
|
||||
Some(date) => date.as_str().to_string(),
|
||||
None => { error!("P2Pool | Date parse error: [{}]", line); "????-??-?? ??:??:??.????".to_string() },
|
||||
None => {
|
||||
error!("P2Pool | Date parse error: [{}]", line);
|
||||
"????-??-?? ??:??:??.????".to_string()
|
||||
}
|
||||
};
|
||||
// AtomicUnit
|
||||
let atomic_unit = if let Some(word) = P2POOL_REGEX.payout_float.find(line) {
|
||||
match word.as_str().parse::<f64>() {
|
||||
Ok(au) => AtomicUnit::from_f64(au),
|
||||
Err(e) => { error!("P2Pool | AtomicUnit parse error: [{}] on [{}]", e, line); AtomicUnit::new() },
|
||||
Err(e) => {
|
||||
error!("P2Pool | AtomicUnit parse error: [{}] on [{}]", e, line);
|
||||
AtomicUnit::new()
|
||||
}
|
||||
}
|
||||
} else {
|
||||
error!("P2Pool | AtomicUnit parse error: [{}]", line);
|
||||
|
@ -206,7 +231,10 @@ impl PayoutOrd {
|
|||
// Block
|
||||
let block = match P2POOL_REGEX.block_comma.find(line) {
|
||||
Some(b) => HumanNumber::from_str(b.as_str()),
|
||||
None => { error!("P2Pool | Block parse error: [{}]", line); HumanNumber::unknown() },
|
||||
None => {
|
||||
error!("P2Pool | Block parse error: [{}]", line);
|
||||
HumanNumber::unknown()
|
||||
}
|
||||
};
|
||||
(date, atomic_unit, block)
|
||||
}
|
||||
|
@ -222,7 +250,8 @@ impl PayoutOrd {
|
|||
// Add 7 more bytes for wrapper type overhead and it's an even [70] bytes per line.
|
||||
pub fn update_from_payout_log(&mut self, log: &str) {
|
||||
let amount_of_lines = log.lines().count();
|
||||
let mut vec: Vec<(String, AtomicUnit, HumanNumber)> = Vec::with_capacity(70 * amount_of_lines);
|
||||
let mut vec: Vec<(String, AtomicUnit, HumanNumber)> =
|
||||
Vec::with_capacity(70 * amount_of_lines);
|
||||
for line in log.lines() {
|
||||
debug!("PayoutOrd | Parsing line: [{}]", line);
|
||||
vec.push(Self::parse_formatted_payout_line(line));
|
||||
|
@ -267,7 +296,9 @@ impl PayoutOrd {
|
|||
|
||||
// Returns a reversed [Iter] of the [PayoutOrd]
|
||||
// This is obviously faster than actually reordering the Vec.
|
||||
pub fn rev_iter(&self) -> std::iter::Rev<std::slice::Iter<'_, (String, AtomicUnit, HumanNumber)>> {
|
||||
pub fn rev_iter(
|
||||
&self,
|
||||
) -> std::iter::Rev<std::slice::Iter<'_, (String, AtomicUnit, HumanNumber)>> {
|
||||
self.0.iter().rev()
|
||||
}
|
||||
|
||||
|
@ -275,7 +306,11 @@ impl PayoutOrd {
|
|||
// The raw log lines will be shown instead of this struct.
|
||||
}
|
||||
|
||||
impl Default for PayoutOrd { fn default() -> Self { Self::new() } }
|
||||
impl Default for PayoutOrd {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for PayoutOrd {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
|
@ -292,8 +327,7 @@ mod test {
|
|||
#[test]
|
||||
fn update_p2pool_payout_log() {
|
||||
use crate::xmr::PayoutOrd;
|
||||
let log =
|
||||
r#"2021-12-21 01:01:01.1111 | 0.001000000000 XMR | Block 1,234,567
|
||||
let log = r#"2021-12-21 01:01:01.1111 | 0.001000000000 XMR | Block 1,234,567
|
||||
2021-12-21 02:01:01.1111 | 0.002000000000 XMR | Block 2,345,678
|
||||
2021-12-21 03:01:01.1111 | 0.003000000000 XMR | Block 3,456,789
|
||||
"#;
|
||||
|
@ -306,9 +340,9 @@ r#"2021-12-21 01:01:01.1111 | 0.001000000000 XMR | Block 1,234,567
|
|||
|
||||
#[test]
|
||||
fn push_to_payout_ord() {
|
||||
use crate::xmr::PayoutOrd;
|
||||
use crate::xmr::AtomicUnit;
|
||||
use crate::human::HumanNumber;
|
||||
use crate::xmr::AtomicUnit;
|
||||
use crate::xmr::PayoutOrd;
|
||||
let mut payout_ord = PayoutOrd::from_vec(vec![]);
|
||||
let should_be = "2022-09-08 18:42:55.4636 | 0.000000000001 XMR | Block 2,654,321\n";
|
||||
println!("BEFORE: {:#?}", payout_ord);
|
||||
|
@ -320,13 +354,25 @@ r#"2021-12-21 01:01:01.1111 | 0.001000000000 XMR | Block 1,234,567
|
|||
|
||||
#[test]
|
||||
fn sum_payout_ord_atomic_unit() {
|
||||
use crate::xmr::PayoutOrd;
|
||||
use crate::xmr::AtomicUnit;
|
||||
use crate::human::HumanNumber;
|
||||
use crate::xmr::AtomicUnit;
|
||||
use crate::xmr::PayoutOrd;
|
||||
let mut payout_ord = PayoutOrd::from_vec(vec![
|
||||
("2022-09-08 18:42:55.4636".to_string(), AtomicUnit::from_u64(1), HumanNumber::from_u64(2654321)),
|
||||
("2022-09-09 16:18:26.7582".to_string(), AtomicUnit::from_u64(1), HumanNumber::from_u64(2654322)),
|
||||
("2022-09-10 11:15:21.1272".to_string(), AtomicUnit::from_u64(1), HumanNumber::from_u64(2654323)),
|
||||
(
|
||||
"2022-09-08 18:42:55.4636".to_string(),
|
||||
AtomicUnit::from_u64(1),
|
||||
HumanNumber::from_u64(2654321),
|
||||
),
|
||||
(
|
||||
"2022-09-09 16:18:26.7582".to_string(),
|
||||
AtomicUnit::from_u64(1),
|
||||
HumanNumber::from_u64(2654322),
|
||||
),
|
||||
(
|
||||
"2022-09-10 11:15:21.1272".to_string(),
|
||||
AtomicUnit::from_u64(1),
|
||||
HumanNumber::from_u64(2654323),
|
||||
),
|
||||
]);
|
||||
println!("OG: {:#?}", payout_ord);
|
||||
let sum = PayoutOrd::atomic_unit_sum(&payout_ord);
|
||||
|
@ -336,21 +382,32 @@ r#"2021-12-21 01:01:01.1111 | 0.001000000000 XMR | Block 1,234,567
|
|||
|
||||
#[test]
|
||||
fn sort_p2pool_payout_ord() {
|
||||
use crate::xmr::PayoutOrd;
|
||||
use crate::xmr::AtomicUnit;
|
||||
use crate::human::HumanNumber;
|
||||
use crate::xmr::AtomicUnit;
|
||||
use crate::xmr::PayoutOrd;
|
||||
let mut payout_ord = PayoutOrd::from_vec(vec![
|
||||
("2022-09-08 18:42:55.4636".to_string(), AtomicUnit::from_u64(1000000000), HumanNumber::from_u64(2654321)),
|
||||
("2022-09-09 16:18:26.7582".to_string(), AtomicUnit::from_u64(2000000000), HumanNumber::from_u64(2654322)),
|
||||
("2022-09-10 11:15:21.1272".to_string(), AtomicUnit::from_u64(3000000000), HumanNumber::from_u64(2654323)),
|
||||
(
|
||||
"2022-09-08 18:42:55.4636".to_string(),
|
||||
AtomicUnit::from_u64(1000000000),
|
||||
HumanNumber::from_u64(2654321),
|
||||
),
|
||||
(
|
||||
"2022-09-09 16:18:26.7582".to_string(),
|
||||
AtomicUnit::from_u64(2000000000),
|
||||
HumanNumber::from_u64(2654322),
|
||||
),
|
||||
(
|
||||
"2022-09-10 11:15:21.1272".to_string(),
|
||||
AtomicUnit::from_u64(3000000000),
|
||||
HumanNumber::from_u64(2654323),
|
||||
),
|
||||
]);
|
||||
println!("OG: {:#?}", payout_ord);
|
||||
|
||||
// High to Low
|
||||
PayoutOrd::sort_payout_high_to_low(&mut payout_ord);
|
||||
println!("AFTER PAYOUT HIGH TO LOW: {:#?}", payout_ord);
|
||||
let should_be =
|
||||
r#"2022-09-10 11:15:21.1272 | 0.003000000000 XMR | Block 2,654,323
|
||||
let should_be = r#"2022-09-10 11:15:21.1272 | 0.003000000000 XMR | Block 2,654,323
|
||||
2022-09-09 16:18:26.7582 | 0.002000000000 XMR | Block 2,654,322
|
||||
2022-09-08 18:42:55.4636 | 0.001000000000 XMR | Block 2,654,321
|
||||
"#;
|
||||
|
@ -361,8 +418,7 @@ r#"2022-09-10 11:15:21.1272 | 0.003000000000 XMR | Block 2,654,323
|
|||
// Low to High
|
||||
PayoutOrd::sort_payout_low_to_high(&mut payout_ord);
|
||||
println!("AFTER PAYOUT LOW TO HIGH: {:#?}", payout_ord);
|
||||
let should_be =
|
||||
r#"2022-09-08 18:42:55.4636 | 0.001000000000 XMR | Block 2,654,321
|
||||
let should_be = r#"2022-09-08 18:42:55.4636 | 0.001000000000 XMR | Block 2,654,321
|
||||
2022-09-09 16:18:26.7582 | 0.002000000000 XMR | Block 2,654,322
|
||||
2022-09-10 11:15:21.1272 | 0.003000000000 XMR | Block 2,654,323
|
||||
"#;
|
||||
|
@ -373,13 +429,25 @@ r#"2022-09-08 18:42:55.4636 | 0.001000000000 XMR | Block 2,654,321
|
|||
|
||||
#[test]
|
||||
fn payout_ord_is_same() {
|
||||
use crate::xmr::PayoutOrd;
|
||||
use crate::xmr::AtomicUnit;
|
||||
use crate::human::HumanNumber;
|
||||
use crate::xmr::AtomicUnit;
|
||||
use crate::xmr::PayoutOrd;
|
||||
let mut payout_ord = PayoutOrd::from_vec(vec![
|
||||
("2022-09-08 18:42:55.4636".to_string(), AtomicUnit::from_u64(1000000000), HumanNumber::from_u64(2654321)),
|
||||
("2022-09-09 16:18:26.7582".to_string(), AtomicUnit::from_u64(2000000000), HumanNumber::from_u64(2654322)),
|
||||
("2022-09-10 11:15:21.1272".to_string(), AtomicUnit::from_u64(3000000000), HumanNumber::from_u64(2654323)),
|
||||
(
|
||||
"2022-09-08 18:42:55.4636".to_string(),
|
||||
AtomicUnit::from_u64(1000000000),
|
||||
HumanNumber::from_u64(2654321),
|
||||
),
|
||||
(
|
||||
"2022-09-09 16:18:26.7582".to_string(),
|
||||
AtomicUnit::from_u64(2000000000),
|
||||
HumanNumber::from_u64(2654322),
|
||||
),
|
||||
(
|
||||
"2022-09-10 11:15:21.1272".to_string(),
|
||||
AtomicUnit::from_u64(3000000000),
|
||||
HumanNumber::from_u64(2654323),
|
||||
),
|
||||
]);
|
||||
let payout_ord_2 = payout_ord.clone();
|
||||
println!("1: {:#?}", payout_ord);
|
||||
|
@ -394,20 +462,32 @@ r#"2022-09-08 18:42:55.4636 | 0.001000000000 XMR | Block 2,654,321
|
|||
|
||||
#[test]
|
||||
fn view_reverse_payout_ord() {
|
||||
use crate::xmr::PayoutOrd;
|
||||
use crate::xmr::AtomicUnit;
|
||||
use crate::human::HumanNumber;
|
||||
use crate::xmr::AtomicUnit;
|
||||
use crate::xmr::PayoutOrd;
|
||||
let mut payout_ord = PayoutOrd::from_vec(vec![
|
||||
("2022-09-08 18:42:55.4636".to_string(), AtomicUnit::from_u64(1000000000), HumanNumber::from_u64(2654321)),
|
||||
("2022-09-09 16:18:26.7582".to_string(), AtomicUnit::from_u64(2000000000), HumanNumber::from_u64(2654322)),
|
||||
("2022-09-10 11:15:21.1272".to_string(), AtomicUnit::from_u64(3000000000), HumanNumber::from_u64(2654323)),
|
||||
(
|
||||
"2022-09-08 18:42:55.4636".to_string(),
|
||||
AtomicUnit::from_u64(1000000000),
|
||||
HumanNumber::from_u64(2654321),
|
||||
),
|
||||
(
|
||||
"2022-09-09 16:18:26.7582".to_string(),
|
||||
AtomicUnit::from_u64(2000000000),
|
||||
HumanNumber::from_u64(2654322),
|
||||
),
|
||||
(
|
||||
"2022-09-10 11:15:21.1272".to_string(),
|
||||
AtomicUnit::from_u64(3000000000),
|
||||
HumanNumber::from_u64(2654323),
|
||||
),
|
||||
]);
|
||||
println!("OG: {:#?}", payout_ord);
|
||||
|
||||
#[allow(clippy::never_loop)]
|
||||
for (_, atomic_unit, _) in payout_ord.rev_iter() {
|
||||
if atomic_unit.to_u64() == 3000000000 {
|
||||
break
|
||||
break;
|
||||
} else {
|
||||
println!("expected: 3000000000, found: {}", atomic_unit);
|
||||
panic!("not reversed");
|
||||
|
|
147
src/xmrig.rs
147
src/xmrig.rs
|
@ -15,26 +15,14 @@
|
|||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::{
|
||||
Regexes,
|
||||
constants::*,
|
||||
disk::*,
|
||||
Process,
|
||||
PubXmrigApi,
|
||||
macros::*,
|
||||
};
|
||||
use crate::regex::REGEXES;
|
||||
use crate::{constants::*, disk::*, macros::*, Process, PubXmrigApi, Regexes};
|
||||
use egui::{
|
||||
TextEdit,SelectableLabel,ComboBox,Label,Button,RichText,Slider,Checkbox,
|
||||
TextStyle::*,
|
||||
Button, Checkbox, ComboBox, Label, RichText, SelectableLabel, Slider, TextEdit, TextStyle::*,
|
||||
};
|
||||
use std::{
|
||||
sync::{Arc,Mutex},
|
||||
};
|
||||
use regex::Regex;
|
||||
use log::*;
|
||||
use crate::regex::{
|
||||
REGEXES,
|
||||
};
|
||||
use regex::Regex;
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
impl crate::disk::Xmrig {
|
||||
#[inline(always)] // called once
|
||||
|
@ -47,7 +35,7 @@ pub fn show(
|
|||
width: f32,
|
||||
height: f32,
|
||||
_ctx: &egui::Context,
|
||||
ui: &mut egui::Ui
|
||||
ui: &mut egui::Ui,
|
||||
) {
|
||||
let text_edit = height / 25.0;
|
||||
//---------------------------------------------------------------------------------------------------- [Simple] Console
|
||||
|
@ -58,8 +46,16 @@ pub fn show(
|
|||
let width = width - SPACE;
|
||||
egui::Frame::none().fill(DARK_GRAY).show(ui, |ui| {
|
||||
ui.style_mut().override_text_style = Some(Name("MonospaceSmall".into()));
|
||||
egui::ScrollArea::vertical().stick_to_bottom(true).max_width(width).max_height(height).auto_shrink([false; 2]).show_viewport(ui, |ui, _| {
|
||||
ui.add_sized([width, height], TextEdit::multiline(&mut lock!(api).output.as_str()));
|
||||
egui::ScrollArea::vertical()
|
||||
.stick_to_bottom(true)
|
||||
.max_width(width)
|
||||
.max_height(height)
|
||||
.auto_shrink([false; 2])
|
||||
.show_viewport(ui, |ui, _| {
|
||||
ui.add_sized(
|
||||
[width, height],
|
||||
TextEdit::multiline(&mut lock!(api).output.as_str()),
|
||||
);
|
||||
});
|
||||
});
|
||||
//---------------------------------------------------------------------------------------------------- [Advanced] Console
|
||||
|
@ -68,18 +64,36 @@ pub fn show(
|
|||
let width = width - SPACE;
|
||||
egui::Frame::none().fill(DARK_GRAY).show(ui, |ui| {
|
||||
ui.style_mut().override_text_style = Some(Name("MonospaceSmall".into()));
|
||||
egui::ScrollArea::vertical().stick_to_bottom(true).max_width(width).max_height(height).auto_shrink([false; 2]).show_viewport(ui, |ui, _| {
|
||||
ui.add_sized([width, height], TextEdit::multiline(&mut lock!(api).output.as_str()));
|
||||
egui::ScrollArea::vertical()
|
||||
.stick_to_bottom(true)
|
||||
.max_width(width)
|
||||
.max_height(height)
|
||||
.auto_shrink([false; 2])
|
||||
.show_viewport(ui, |ui, _| {
|
||||
ui.add_sized(
|
||||
[width, height],
|
||||
TextEdit::multiline(&mut lock!(api).output.as_str()),
|
||||
);
|
||||
});
|
||||
});
|
||||
ui.separator();
|
||||
let response = ui.add_sized([width, text_edit], TextEdit::hint_text(TextEdit::singleline(buffer), r#"Commands: [h]ashrate, [p]ause, [r]esume, re[s]ults, [c]onnection"#)).on_hover_text(XMRIG_INPUT);
|
||||
let response = ui
|
||||
.add_sized(
|
||||
[width, text_edit],
|
||||
TextEdit::hint_text(
|
||||
TextEdit::singleline(buffer),
|
||||
r#"Commands: [h]ashrate, [p]ause, [r]esume, re[s]ults, [c]onnection"#,
|
||||
),
|
||||
)
|
||||
.on_hover_text(XMRIG_INPUT);
|
||||
// If the user pressed enter, dump buffer contents into the process STDIN
|
||||
if response.lost_focus() && ui.input(|i| i.key_pressed(egui::Key::Enter)) {
|
||||
response.request_focus(); // Get focus back
|
||||
let buffer = std::mem::take(buffer); // Take buffer
|
||||
let mut process = lock!(process); // Lock
|
||||
if process.is_alive() { process.input.push(buffer); } // Push only if alive
|
||||
if process.is_alive() {
|
||||
process.input.push(buffer);
|
||||
} // Push only if alive
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -87,12 +101,21 @@ pub fn show(
|
|||
//---------------------------------------------------------------------------------------------------- Arguments
|
||||
if !self.simple {
|
||||
debug!("XMRig Tab | Rendering [Arguments]");
|
||||
ui.group(|ui| { ui.horizontal(|ui| {
|
||||
ui.group(|ui| {
|
||||
ui.horizontal(|ui| {
|
||||
let width = (width / 10.0) - SPACE;
|
||||
ui.add_sized([width, text_edit], Label::new("Command arguments:"));
|
||||
ui.add_sized([ui.available_width(), text_edit], TextEdit::hint_text(TextEdit::singleline(&mut self.arguments), r#"--url <...> --user <...> --config <...>"#)).on_hover_text(XMRIG_ARGUMENTS);
|
||||
ui.add_sized(
|
||||
[ui.available_width(), text_edit],
|
||||
TextEdit::hint_text(
|
||||
TextEdit::singleline(&mut self.arguments),
|
||||
r#"--url <...> --user <...> --config <...>"#,
|
||||
),
|
||||
)
|
||||
.on_hover_text(XMRIG_ARGUMENTS);
|
||||
self.arguments.truncate(1024);
|
||||
})});
|
||||
})
|
||||
});
|
||||
ui.set_enabled(self.arguments.is_empty());
|
||||
//---------------------------------------------------------------------------------------------------- Address
|
||||
debug!("XMRig Tab | Rendering [Address]");
|
||||
|
@ -112,14 +135,23 @@ pub fn show(
|
|||
text = format!("Monero Address [{}/95] ❌", len);
|
||||
color = RED;
|
||||
}
|
||||
ui.add_sized([width, text_edit], Label::new(RichText::new(text).color(color)));
|
||||
ui.add_sized([width, text_edit], TextEdit::hint_text(TextEdit::singleline(&mut self.address), "4...")).on_hover_text(XMRIG_ADDRESS);
|
||||
ui.add_sized(
|
||||
[width, text_edit],
|
||||
Label::new(RichText::new(text).color(color)),
|
||||
);
|
||||
ui.add_sized(
|
||||
[width, text_edit],
|
||||
TextEdit::hint_text(TextEdit::singleline(&mut self.address), "4..."),
|
||||
)
|
||||
.on_hover_text(XMRIG_ADDRESS);
|
||||
self.address.truncate(95);
|
||||
});
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------- Threads
|
||||
if self.simple { ui.add_space(SPACE); }
|
||||
if self.simple {
|
||||
ui.add_space(SPACE);
|
||||
}
|
||||
debug!("XMRig Tab | Rendering [Threads]");
|
||||
ui.vertical(|ui| {
|
||||
let width = width / 10.0;
|
||||
|
@ -127,13 +159,24 @@ pub fn show(
|
|||
ui.spacing_mut().slider_width = width * 6.5;
|
||||
ui.spacing_mut().icon_width = width / 25.0;
|
||||
ui.horizontal(|ui| {
|
||||
ui.add_sized([text_width, text_edit], Label::new(format!("Threads [1-{}]:", self.max_threads)));
|
||||
ui.add_sized([width, text_edit], Slider::new(&mut self.current_threads, 1..=self.max_threads)).on_hover_text(XMRIG_THREADS);
|
||||
ui.add_sized(
|
||||
[text_width, text_edit],
|
||||
Label::new(format!("Threads [1-{}]:", self.max_threads)),
|
||||
);
|
||||
ui.add_sized(
|
||||
[width, text_edit],
|
||||
Slider::new(&mut self.current_threads, 1..=self.max_threads),
|
||||
)
|
||||
.on_hover_text(XMRIG_THREADS);
|
||||
});
|
||||
#[cfg(not(target_os = "linux"))] // Pause on active isn't supported on Linux
|
||||
ui.horizontal(|ui| {
|
||||
ui.add_sized([text_width, text_edit], Label::new(format!("Pause on active [0-255]:")));
|
||||
ui.add_sized([width, text_edit], Slider::new(&mut self.pause, 0..=255)).on_hover_text(format!("{} [{}] seconds.", XMRIG_PAUSE, self.pause));
|
||||
ui.add_sized(
|
||||
[text_width, text_edit],
|
||||
Label::new(format!("Pause on active [0-255]:")),
|
||||
);
|
||||
ui.add_sized([width, text_edit], Slider::new(&mut self.pause, 0..=255))
|
||||
.on_hover_text(format!("{} [{}] seconds.", XMRIG_PAUSE, self.pause));
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -357,7 +400,8 @@ pub fn show(
|
|||
|
||||
debug!("XMRig Tab | Rendering [API] TextEdits");
|
||||
// [HTTP API IP/Port]
|
||||
ui.group(|ui| { ui.horizontal(|ui| {
|
||||
ui.group(|ui| {
|
||||
ui.horizontal(|ui| {
|
||||
ui.vertical(|ui| {
|
||||
let width = width / 10.0;
|
||||
ui.spacing_mut().text_edit_width = width * 2.39;
|
||||
|
@ -370,7 +414,10 @@ pub fn show(
|
|||
text = format!("HTTP API IP [{}/255]➖", len);
|
||||
color = LIGHT_GRAY;
|
||||
incorrect_input = true;
|
||||
} else if self.api_ip == "localhost" || REGEXES.ipv4.is_match(&self.api_ip) || REGEXES.domain.is_match(&self.api_ip) {
|
||||
} else if self.api_ip == "localhost"
|
||||
|| REGEXES.ipv4.is_match(&self.api_ip)
|
||||
|| REGEXES.domain.is_match(&self.api_ip)
|
||||
{
|
||||
text = format!("HTTP API IP [{}/255]✔", len);
|
||||
color = GREEN;
|
||||
} else {
|
||||
|
@ -378,8 +425,12 @@ pub fn show(
|
|||
color = RED;
|
||||
incorrect_input = true;
|
||||
}
|
||||
ui.add_sized([width, text_edit], Label::new(RichText::new(text).color(color)));
|
||||
ui.text_edit_singleline(&mut self.api_ip).on_hover_text(XMRIG_API_IP);
|
||||
ui.add_sized(
|
||||
[width, text_edit],
|
||||
Label::new(RichText::new(text).color(color)),
|
||||
);
|
||||
ui.text_edit_singleline(&mut self.api_ip)
|
||||
.on_hover_text(XMRIG_API_IP);
|
||||
self.api_ip.truncate(255);
|
||||
});
|
||||
ui.horizontal(|ui| {
|
||||
|
@ -398,8 +449,12 @@ pub fn show(
|
|||
color = RED;
|
||||
incorrect_input = true;
|
||||
}
|
||||
ui.add_sized([width, text_edit], Label::new(RichText::new(text).color(color)));
|
||||
ui.text_edit_singleline(&mut self.api_port).on_hover_text(XMRIG_API_PORT);
|
||||
ui.add_sized(
|
||||
[width, text_edit],
|
||||
Label::new(RichText::new(text).color(color)),
|
||||
);
|
||||
ui.text_edit_singleline(&mut self.api_port)
|
||||
.on_hover_text(XMRIG_API_PORT);
|
||||
self.api_port.truncate(5);
|
||||
});
|
||||
});
|
||||
|
@ -417,9 +472,17 @@ pub fn show(
|
|||
// style.spacing.icon_width = width / 6.0;
|
||||
// style.spacing.icon_spacing = 20.0;
|
||||
// ctx.set_style(style);
|
||||
ui.add_sized([width, height], Checkbox::new(&mut self.tls, "TLS Connection")).on_hover_text(XMRIG_TLS);
|
||||
ui.add_sized(
|
||||
[width, height],
|
||||
Checkbox::new(&mut self.tls, "TLS Connection"),
|
||||
)
|
||||
.on_hover_text(XMRIG_TLS);
|
||||
ui.separator();
|
||||
ui.add_sized([width, height], Checkbox::new(&mut self.keepalive, "Keepalive")).on_hover_text(XMRIG_KEEPALIVE);
|
||||
ui.add_sized(
|
||||
[width, height],
|
||||
Checkbox::new(&mut self.keepalive, "Keepalive"),
|
||||
)
|
||||
.on_hover_text(XMRIG_KEEPALIVE);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue