Repository: Spagett1/PineFlash
Branch: master
Commit: 897bad831b73
Files: 23
Total size: 102.2 KB
Directory structure:
gitextract_n1fhdcto/
├── .gitignore
├── .gitmodules
├── Cargo.toml
├── LICENSE
├── Package_Windows_Release.iss
├── README.md
├── assets/
│ ├── Pineflash.desktop
│ └── SFMono_Nerd_Font_Complete.otf
├── build.rs
├── docs/
│ ├── LICENSE
│ ├── html/
│ │ └── download.html
│ ├── index.html
│ └── styles/
│ └── style.css
├── generate-release.sh
├── generic_unix_install.sh
└── src/
├── .main.rs.rustfmt
├── main.rs
└── submodules/
├── connection_poller.rs
├── flash.rs
├── fonts.rs
├── main_panel.rs
├── mod.rs
└── top_panel.rs
================================================
FILE CONTENTS
================================================
================================================
FILE: .gitignore
================================================
/target
/release-out
/release-build
/tools
/PineFlash_Installer.exe
/pineflash*
/libs
================================================
FILE: .gitmodules
================================================
[submodule "blisp"]
path = blisp
url = https://github.com/pine64/blisp
================================================
FILE: Cargo.toml
================================================
[package]
name = "pineflash"
version = "0.5.5"
edition = "2021"
build = "build.rs"
[[bin]]
name = "pineflash"
path = "src/main.rs"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
egui_file = "0.17.0"
zip-extract = "0.1.1"
eframe = "0.27.2"
egui-notify = "0.14.0"
egui_extras = { version = "0.27.2", features = ["all_loaders"] }
rfd = "0.11.3"
whoami = "1.2.3"
serde = { version = "^1.0.145", features = ["derive"] }
serde_json = { version="1.0.89" }
serialport = "4.2.0"
rusb = "0.9"
confy = "0.5.1"
curl = "0.4.44"
simple-home-dir = "0.1.2"
version-compare = "0.1.1"
[build-dependencies]
winresource = "0.1.15"
[features]
appimage = []
[package.metadata.appimage]
auto_link = true
assets = ["tools/linux", "tools/appimage"]
================================================
FILE: LICENSE
================================================
The GPLv2 License (GPLv2)
Copyright (c) 2022 Spagett1
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2, as published by
the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
================================================
FILE: Package_Windows_Release.iss
================================================
; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!
#define MyAppName "PineFlash"
#define MyAppVersion "0.5.5"
#define MyAppPublisher "Spagett"
#define MyAppURL "https://github.com/Spagett1"
#define MyAppExeName "pineflash.exe"
[Setup]
; NOTE: The value of AppId uniquely identifies this application. Do not use the same AppId value in installers for other applications.
; (To generate a new GUID, click Tools | Generate GUID inside the IDE.)
AppId={{E167F410-9EB3-4AF4-9F2B-5E775FBF58ED}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName=C://Program Files/{#MyAppName}
DisableProgramGroupPage=yes
LicenseFile=Z:\home\spagett\projects\PineFlash\LICENSE
; Uncomment the following line to run in non administrative install mode (install for current user only.)
;PrivilegesRequired=lowest
OutputDir=Z:\home\spagett\projects\PineFlash
OutputBaseFilename=PineFlash_Installer
SetupIconFile=Z:\home\spagett\projects\PineFlash\assets\pine64logo.ico
Compression=lzma
SolidCompression=yes
WizardStyle=modern
[Languages]
Name: "english"; MessagesFile: "compiler:Default.isl"
[Tasks]
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked
[Files]
Source: "Z:\home\spagett\projects\PineFlash\target\x86_64-pc-windows-gnu\release\{#MyAppExeName}"; DestDir: "{app}"; Flags: ignoreversion
Source: "Z:\home\spagett\projects\PineFlash\tools\win\*"; DestDir: "{app}/tools/"; Flags: ignoreversion recursesubdirs createallsubdirs
; NOTE: Don't use "Flags: ignoreversion" on any shared system files
[Icons]
Name: "{autoprograms}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"
Name: "{autodesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: desktopicon
[Run]
Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; Flags: nowait postinstall skipifsilent
================================================
FILE: README.md
================================================
[](https://github.com/Spagett1/PineFlash/releases/)
[](https://github.com/Spagett1/PineFlash/releases/)
# PineFlash
A GUI tool to flash IronOS to the Pinecil V1, V2 and future other pine products.
If you need help, or want to help out with development, I have a [discord server](https://discord.gg/NHrXJRan7D) and a bridged [matrix space](https://matrix.to/#/#spagett's_cookhouse_of_spaghetti_code.:matrix.org).
## Features
* Auto-fetch the newest stable release of IronOS firmware.
* Allows manual installs of beta versions using a browse to file feature.
* Selectable options: pick the iron type, pick the firmware version and download it.
* Boot logo art upload supported for V1 and V2 (use custom & folder icon)
## Supported Devices
| System | Linux | MacOS| Windows|
| :-----: | :-----: | :-----: | :-----: |
| Pinecil V1 ||*| |
| Pinecil V2 | | * | |
* Pineflash on MacOS must be compiled from source.
# :desktop_computer: Install Options
1. Easy install: use premade binaries, currently only available for Linux x86 distros and Windows x86.
2. Build from Code: recommended if you are on MacOS, an ARM device, or doing development.
## :clamp: Premade Binaries
## Windows
Download the latest pineflash exe file from the [releases page](https://github.com/Spagett1/PineFlash/releases).
Then just double click it.
### RedHat distros (Fedora, Centos, Nobara, Rocky, etc.)
Download the latest pineflash .rpm file from the [releases page](https://github.com/Spagett1/PineFlash/releases).
Then just run.
```
sudo dnf install ./pineflash-*.x86_64.rpm
```
### Arch based distros (Arch, Artix, Manjaro, Endeavor, etc.)
Download the latest pineflash pkg.tar.zst file from the [releases page](https://github.com/Spagett1/PineFlash/releases).
Then simply run.
```
sudo pacman -U pineflash-*-x86_64.pkg.tar.zst
```
### Debian based distros (Debian, Ubuntu, PopOs, etc.)
Download the latest pineflash .deb file from the [releases page](https://github.com/Spagett1/PineFlash/releases).
Then just run.
```
sudo apt install ./pineflash_*_amd64.deb
```
### Other Linux x86 distro's
Download the latest pineflash .tar.xz file from the [releases page](https://github.com/Spagett1/PineFlash/releases).
Extract the file.
```
tar -xf ./pineflash-*-x86_64.tar.xz
```
And copy the contents into your system
```
doas cp -r ./usr /
```
> **_NOTE:_** Make sure you install dfu-util manually and that it is at least version 0.11 as older versions can have issues. Window manager users should ensure they have a pokit agent installed and enabled.
### MacOs
Sorry we dont have built apps for you yet, head to the build from source section and use the unix install script.
> **_NOTE:_** You will also need to run pineflash from the terminal, this is on the todo list to get fixed.
## :building_construction: Build from code
Use this build method if the premade binaries do not support your architecture or you have dev purposes.
### :bookmark_tabs: Build Dependancies
Install these if you don't have them (not needed if using the PKGBUILD).
General dependancy list
This list covers linux distros which are not named below and macos.
If your operating system has its own section, then please go there; it has package names tailored to your distro.
If you had to install more dependencies to get it to work, please open an issue to let us know the specific OS and packages you used.
```
cmake
rust
git
dfu-util - for pinecil V1 support
blisp - for pinecil V2 support
polkit - Linux only
gcc
```
Dependencies for Debian
```
cmake
rust-all (alternatively go to https://rustup.rs/)
git
dfu-util - for pinecil V1 support
policykit-1
g++
pkg-config
libglib2.0-dev
build-essential
libfontconfig-dev
fontconfig-config
libgdk3.0-cli-dev
libatk1.0-0
libatk1.0-dev
libgtk-3-dev
```
This line will install everything:
```
sudo apt install cmake rust-all git dfu-util policykit-1 g++ pkg-config libglib2.0-dev build-essential libfontconfig-dev fontconfig-config libgdk3.0-cli-dev libatk1.0-0 libatk1.0-dev libgtk-3-dev
```
Dependencies for Arch
#### Runtime dependancies
```
dfu-util - for pinecil V1 support
blisp - for pinecil V2 support, find this in the AUR
fontconfig
glibc
gtk3
polkit
```
#### Build dependancies
```
base-devel
cargo-ndk # To verify some integrity checksums of rust modules
git
optipng
pkgconf
rust
```
This line will install everything except blisp since it's in the aur.
```
sudo pacman -S --needed cmake rust git dfu-util polkit gcc pkgconf glibc base-devel fontconfig gtk3
```
### :toolbox: Build option 1, handy scripts
Handy scripts will compile and install PineFlash for you.
### Build Unix from script. (Macos and Linux)
1. To build from source code, first install build dependencies.
2. Download the source code with the following commands.
```
git clone https://github.com/Spagett1/PineFlash/
cd PineFlash
```
3. Run the `generic_unix_install.sh` file which will build and install Pineflash.
### Build on Arch based distro's (Arch, Artix, Manjaro, Endeavor, Arch Arm, etc.)
1. All dependencies will be handled by the PKGBUILD
2. PineFlash is in the aur so you can install it just like any other aur package.
```
git clone https://aur.archlinux.org/pineflash-git.git
cd pineflash-git
makepkg -si
```
3. Alternatively just use your favourite aur helper.
### :weight_lifting_man: Build option 2: manual build
Old school style, this is recommended if you have issues with the scripts or want to help develop PineFlash.
1. Install all the build dependancies listed above.
2. Download the source code.
```
git clone https://github.com/Spagett1/PineFlash/
cd PineFlash
```
4. Download blisp which is needed for pinecil V2 support, alternatively compile it if you are not on a 64 bit computer. [Instructions]("https://github.com/pine64/blisp")
In the following instructions replace `platform` with your operating system (`linux` or `macos`)
```
curl -L "https://github.com/pine64/blisp/releases/download/v0.0.3/blisp-platform64-v0.0.3.zip" -o "blisp-platform64-v0.0.3.zip"
unzip "blisp-platform-v0.0.3.zip"
sudo mv ./blisp /usr/local/bin/blisp
```
:dart: Important: Don't forget to add blisp to your path
5. Then build pineflash itself
```
cargo build --release
```
6. The resulting binary will be in `target/release/pineflash`, this can be moved into your path (`/usr/bin/pineflash`) or just run as a portable executable.
7. Then copy the `assets/Pineflash.desktop` file to `/usr/share/applications` and copy `assets/pine64logo.png` to `/usr/share/pixmaps` for the shortcut to show up in launchers. (This does not apply to MacOs, you will have to run pineflash from the terminal for now, sorry.)
8. Just run the program by typing it into the terminal.
```
pineflash
```
Alternatively just run it from your app launcher (unless your on macos).
## :runner: Run
Linux: Pineflash should appear in app launcher options. Alternatively, you can run the command:
pineflash
MacOS: Sorry, no launcher icon yet, you'll need to run this command to run pineflash.
pineflash
Windows: Just run pineflash from the start menu.
If there is error message like
```
Cannot open DFU device ... (LIBUSB_ERROR_NOT_SUPPORTED)
```
during flash operation, then `WinUSB` drivers should be installed. See [here](https://github.com/libusb/libusb/wiki/Windows#user-content-How_to_use_libusb_on_Windows) for more details.
## Boot Logo Art
- Select your Pinecil version.
- Click on the folder icon to browse to the art file you want to load.
- For the v2 you must have IronOs v2.22 installed to support boot logo.
- If you encounter errors with flashing boot logo's to the v2 ensure your blisp version is at minimum 0.0.4.
- See [IronOS-Meta](https://github.com/Ralim/IronOS-Meta/) to get premade art or details on how to make custom art.
## :electric_plug: Connect Pinecil to a PC
1. To do the firmware update, connect one end of a USB cable to the PC.
2. Then, hold down the `[-]` button **before** plugging the usb-c cable to the back of Pinecil.
3. Keep holding the `[-]` for ~10 seconds more before releasing the button. If you correctly entered flashing mode, the screen will be black/empty. If not, do it again, flip the cable, or try another cable, different port, or a different PC.
4. See [Pinecil Wiki](https://wiki.pine64.org/wiki/Pinecil_Firmware) firmware details if you get stuck.
## :spiral_calendar: Todo
- [x] Windows support.
- [ ] MacOS premade binary
- [ ] Launcher icon for macos, easier method to install
- [x] Improve UI (colors, design, workflow).
- [ ] Improve Light Mode.
- [x] In app instructions for connecting pinecil to pc.
- [ ] Flatpak and/or Appimage support for linux.
- [ ] V2 boot logo art support when blisp supports it.
## :tea: Feel like supporting me?
Well you can buy me a coffee, or rather tea bags since i dont drink coffee ;)
## :book: References
- [Blisp](https://github.com/pine64/blisp) - Backend for flashing Pinecil V2
- [Dfu-util](https://dfu-util.sourceforge.net/) - Backend for flashing Pinecil V1
- [Pinecil](https://wiki.pine64.org/wiki/Pinecil) - The Pinecil Wiki page
- [IronOS](https://github.com/Ralim/IronOS) - The firmware running on this soldering iron
- [PineSAM](https://github.com/builder555/PineSAM) - A cool Bluetooth app to control Pinecil V2 from any browser
- [Egui](https://github.com/emilk/egui) - The awesome GUI toolkit used to make this program
- [InnoSetup](https://github.com/jrsoftware/issrc) - The software i use to generate windows releases
- [FPM](https://github.com/jordansissel/fpm) - The tool i use to generate linux releases for all sorts of distros
## :dash: Stay fluxy my friends.
[Source](https://www.reddit.com/r/PINE64official/comments/xk9vxu/most_interesting_man_in_the_world_i_dont_always/)
================================================
FILE: assets/Pineflash.desktop
================================================
[Desktop Entry]
Name=PineFlash
GenericName=PineFlash
Comment=Tool to flash pine64 devices
Exec=pineflash
Icon=pine64logo
Terminal=false
Type=Application
Categories=System
X-Desktop-File-Install-Version=0.26
================================================
FILE: build.rs
================================================
extern crate winresource;
fn main() {
if std::env::var("CARGO_CFG_TARGET_OS").unwrap() == "windows" {
let mut res = winresource::WindowsResource::new();
res.set_icon("./assets/pine64logo.ico");
res.compile().unwrap();
}
}
================================================
FILE: docs/LICENSE
================================================
The GPLv2 License (GPLv2)
Copyright (c) 2022 Spagett1
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2, as published by
the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
================================================
FILE: docs/html/download.html
================================================
Pineflash is a tool for updating the firmware on the Pinecil soldering irons.
Pineflash is a fully open source project, the only official download links are this site and the github page, do not download it from unofficial sources.
================================================
FILE: docs/styles/style.css
================================================
/* {font-size:13pt;font-weight:normal;} */
@media (min-width: 64em) {
.row {
display: flex;
flex-wrap: nowrap;
flex-direction: row-reverse;
}
.col {
flex-grow: 1;
}
}
img.displayed {
display: block;
height: auto;
max-width: 90%;
margin-left: auto;
margin-right: auto
}
img.logo {
float: left;
display: block;
height: 2em;
max-width: auto%;
margin-left: 0;
margin-right: 0.5em;
}
.grid {
border-collapse: collapse;
}
.col {
border: 6px double #fb5;
padding: 1em;
}
.inner-title {
display: flex;
align-items: center;
}
.user-list {
display: flex;
flex-flow: row wrap;
justify-content: space-evenly;
list-style-type: none;
padding: 0;
}
.user-list li {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
flex: 10em;
}
.user-list::after {
content: "";
}
body {
margin: auto;
padding: 1em;
max-width: 64em;
font-family: "courier new", monospace;
color: #fb5;
background: #111;
word-wrap: break-word;
}
a {
text-decoration: none;
color: #f70;
font-weight: bold;
padding-right: 0.25em;
}
a:hover {
color: #f20;
}
hr {
border-color: #fb5;
}
.text-center {
text-align: center
}
.advisory {
background: #fc4;
color: #222;
font-weight: bold;
padding: 1em;
border-radius: 0.25em;
}
h1,
h2 {
text-transform: uppercase;
color: #fb5;
font-family: monospace;
font-size: 2em;
}
/* THEGOODS */
#fancyboi::before {
content: "$ ";
}
@media (prefers-reduced-motion: no-preference) {
@keyframes flash {
50% {
opacity: 0;
}
}
@keyframes reveal {
from {
width: 2em;
}
/* Width of ::before */
to {
width: 100%;
}
}
#fancyboi {
overflow: hidden;
white-space: nowrap;
animation: reveal 4s linear;
text-overflow: "█";
}
#fancyboi::after {
content: "█";
animation: flash 0.5s step-end infinite;
}
}
/* SDOOGEHT */
.sourceCode {
color: #008000;
}
code>span.fl {
color: #008000;
}
/* Style the navbar */
#navbar {
overflow: hidden;
background-color: #fb5;
color: #222;
z-index: 99;
position: relative;
top: 0;
left: 0;
width: 100%;
border-radius: 0.25em;
}
#navbar a:hover {
background-color: #f93;
}
/* Navbar links */
#navbar a {
float: left;
display: block;
color: black;
text-align: center;
padding: 14px;
text-decoration: none;
}
/* Page content */
.content {
padding-top: 5px;
}
input[type="text"],
textarea {
background-color: #333;
color: darkorange;
}
div.alert-warning {
background-color: darkred;
}
div.alert-success {
background-color: darkgreen;
}
blockquote {
border-left: 2px solid #fb5;
background-color: rgba(255, 187, 85, 5%);
padding: 0.5em;
}
/* Mobile */
@media (max-width: 768px) {
td {
display: block;
}
}
================================================
FILE: generate-release.sh
================================================
#!/bin/sh
#
# dev packages needed in each container
# Packages-redhatbased: glib2-devel gcc atk-devel openssl-devel gtk3-devel systemd-devel gem rpm-build
# Packages-debianbased: gcc libglib2.0-dev libgtk-3-dev libssl-dev ruby libudev-dev
# Packages-archbased: gtk3 rubygems
#
#
# Remove old versions
. "$HOME/.cargo/env"
PATH=$PATH:/home/spagett/.local/share/gem/ruby/3.0.0/bin:/home/spagett/bin
rm pineflash*{.deb,.rpm,.exe,.tar*,.AppImage} 2> /dev/null
ver=$(grep "^version " Cargo.toml | cut -d\" -f2)
# files=target/release/pineflash=/usr/bin/pineflash assets/Pineflash.desktop=/usr/share/applications/Pineflash.desktop assets/pine64logo.png=/usr/share/pixmaps/pine64logo.png LICENSE=/usr/share/licenses/pineflash/LICENSE
arch="x86_64"
cargo clean
cargo build --target x86_64-pc-windows-gnu --release
cargo appimage --features=appimage
mv target/appimage/pineflash.AppImage "./pineflash-$ver-$arch.AppImage"
# Generate windows release
# Update version number
sed -i "s/#define MyAppVersion.*/#define MyAppVersion \"$ver\"/g" ./Package_Windows_Release.iss
wine /home/spagett/.wine/drive_c/Program\ Files\ \(x86\)/Inno\ Setup\ 6/ISCC.exe ./Package_Windows_Release.iss
mv PineFlash_Installer.exe pineflash-$ver-win64.exe
# Cleans for new environment
cargo clean
# Generate rpm release
distrobox enter --name fedora-dev -- cargo build --release
distrobox enter --name fedora-dev -- fpm -s dir -t rpm \
--name pineflash \
--license gpl2 \
--version $ver \
--architecture $arch \
--depends polkit \
--depends dfu-util \
-p "pineflash-fedora-$ver-$arch.rpm" \
--description "flashing tool for pinecil soldering irons." \
--url "https://github.com/spagett1/pineflash" \
--maintainer "spagett " \
target/release/pineflash=/usr/bin/pineflash assets/Pineflash.desktop=/usr/share/applications/Pineflash.desktop assets/pine64logo.png=/usr/share/pixmaps/pine64logo.png LICENSE=/usr/share/licenses/pineflash/LICENSE tools/linux/blisp=/usr/bin/blisp
# Cleans for new environment
cargo clean
# Generate rpm release for rhel
# distrobox enter --name rhel-dev -- cargo build --release
# distrobox enter --name rhel-dev -- fpm -s dir -t rpm \
# --name pineflash \
# --license gpl2 \
# --version $ver \
# --architecture $arch \
# --depends polkit \
# --depends dfu-util \
# -p "pineflash-rhel9-$ver-$arch.rpm" \
# --description "flashing tool for pinecil soldering irons." \
# --url "https://github.com/spagett1/pineflash" \
# --maintainer "spagett " \
# target/release/pineflash=/usr/bin/pineflash assets/Pineflash.desktop=/usr/share/applications/Pineflash.desktop assets/pine64logo.png=/usr/share/pixmaps/pine64logo.png LICENSE=/usr/share/licenses/pineflash/LICENSE tools/linux/blisp=/usr/bin/blisp
# Cleans for new environment
# cargo clean
distrobox enter --name debian-dev -- cargo build --release
distrobox enter --name debian-dev -- fpm -s dir -t deb \
--name pineflash \
--license gpl2 \
--version $ver \
--architecture $arch \
--depends policykit-1 \
--depends dfu-util \
--depends libxkbcommon0 \
--description "Flashing tool for pinecil soldering irons." \
--url "https://github.com/Spagett1/PineFlash" \
--maintainer "Spagett " \
target/release/pineflash=/usr/bin/pineflash assets/Pineflash.desktop=/usr/share/applications/Pineflash.desktop assets/pine64logo.png=/usr/share/pixmaps/pine64logo.png LICENSE=/usr/share/licenses/pineflash/LICENSE tools/linux/blisp=/usr/bin/blisp
# Cleans for new environment
cargo clean
# # Generate arch release
distrobox enter --name arch-dev -- cargo build --release
distrobox enter --name arch-dev -- fpm -s dir -t pacman \
--name pineflash \
--license gpl2 \
--version $ver \
--architecture $arch \
--depends polkit \
--depends libxkbcommon \
--depends dfu-util \
--description "Flashing tool for pinecil soldering irons." \
--url "https://github.com/Spagett1/PineFlash" \
--maintainer "Spagett " \
target/release/pineflash=/usr/bin/pineflash assets/Pineflash.desktop=/usr/share/applications/Pineflash.desktop assets/pine64logo.png=/usr/share/pixmaps/pine64logo.png LICENSE=/usr/share/licenses/pineflash/LICENSE tools/linux/blisp=/usr/bin/blisp
# # Generate generic release
# fpm -s dir -t tar \
# --name pineflash \
# --license gpl2 \
# --version $ver \
# --architecture $arch \
# --depends polkit \
# --description "Flashing tool for pinecil soldering irons." \
# --url "https://github.com/Spagett1/PineFlash" \
# --maintainer "Spagett " \
# target/release/pineflash=/usr/bin/pineflash assets/Pineflash.desktop=/usr/share/applications/Pineflash.desktop assets/pine64logo.png=/usr/share/pixmaps/pine64logo.png LICENSE=/usr/share/licenses/pineflash/LICENSE
# mv pineflash.tar pineflash-$ver-1-x86_64.tar
# xz pineflash-$ver-1-x86_64.tar
#
================================================
FILE: generic_unix_install.sh
================================================
#!/bin/bash
if command -v doas >> /dev/null; then
root=doas
else
root=sudo
fi
# Ensure cargo is installed before trying to proceed
if ! command -v cargo > /dev/null 2>&1; then
echo "cargo command is not installed. Cannot proceed. Please ensure cargo is installed and on the PATH"
exit 1
fi
cargo build --release
if [ "$(uname)" == "Darwin" ]; then
curl -L "https://github.com/pine64/blisp/releases/download/v0.0.4/blisp-apple-x86_64-v0.0.4.zip" -o "blisp-apple-x86_64-v0.0.4.zip"
unzip "blisp-apple-x86_64-v0.0.4.zip"
chmod +x ./blisp
$root cp ./blisp /usr/local/bin/blisp
$root chmod +x /usr/local/bin/blisp
$root cp ./target/release/pineflash /usr/local/bin/
elif [ "$(uname -m)" == "x86_64" ]; then
curl -L "https://github.com/pine64/blisp/releases/download/v0.0.4/blisp-linux-x86_64-v0.0.4.zip" -o "blisp-linux64-v0.0.4.zip"
unzip "blisp-linux64-v0.0.4.zip"
$root cp ./blisp /usr/local/bin/blisp
$root chmod +x /usr/local/bin/blisp
$root cp ./assets/Pineflash.desktop /usr/share/applications/Pineflash.desktop
$root cp ./assets/pine64logo.png /usr/share/pixmaps/pine64logo.png
$root cp ./target/release/pineflash /usr/bin/pineflash
else
git clone --recursive "https://github.com/pine64/blisp.git"
cd blisp
git submodule update --init --recursive
mkdir build && cd build
cmake -DBLISP_BUILD_CLI=ON ..
cmake --build .
$root cp ./blisp/build/tools/blisp/blisp /usr/local/bin/blisp
$root chmod +x /usr/local/bin/blisp
cd ../..
$root cp ./assets/Pineflash.desktop /usr/share/applications/Pineflash.desktop
$root cp ./assets/pine64logo.png /usr/share/pixmaps/pine64logo.png
$root cp ./target/release/pineflash /usr/bin/pineflash
fi
================================================
FILE: src/.main.rs.rustfmt
================================================
#![windows_subsystem = "windows"]
use std::{
collections::HashMap,
env,
fs::{self, File},
io::{Cursor, Read},
path::PathBuf,
time::Duration,
};
use curl::easy::Easy;
use eframe::egui;
use eframe::{
emath,
epaint::{Color32, Rounding, Stroke},
CreationContext,
};
mod submodules;
use egui::Context;
use egui_extras::RetainedImage;
use egui_file::FileDialog;
use egui_notify::{Anchor, Toasts};
use serde::{Deserialize, Serialize};
use serde_json::Value;
const ICON: &[u8] = include_bytes!("../assets/pine64logo.ico");
#[derive(Serialize, Deserialize)]
struct Language {
language_code: String,
language_name: String,
}
#[derive(Serialize, Deserialize)]
struct YourValue {
contents: HashMap,
}
struct FlasherConfig {
iron: String,
int_name: String,
version: String,
fancy_names: Vec,
code_names: Vec,
lang: String,
versions_checked: bool,
vers: Vec,
download_metadata: bool,
blisp_version: String,
run_once_vers: bool,
download: bool,
picked_path: Option,
download_versions: bool,
download_firm_notify: bool,
ready_to_flash: bool,
logs: String,
json: String,
iron_connected: Option,
check_count: i32,
flash: bool,
flash_notified_count: i32,
v2_serial_path: Option,
connection_guide_image: [RetainedImage; 3],
current_step: usize,
json_checked: bool,
metadata_path: PathBuf,
open_file_dialog: Option,
}
#[derive(Serialize, Deserialize)]
struct FlashSavedConfig {
pub dark_mode: bool,
}
impl Default for FlashSavedConfig {
fn default() -> Self {
Self { dark_mode: true }
}
}
struct Flasher {
config: FlasherConfig,
saved_config: FlashSavedConfig,
toasts: Toasts,
}
impl Default for FlasherConfig {
fn default() -> Self {
Self {
iron: "Pinecil V2".to_string(),
int_name: "Pinecilv2".to_string(),
version: "Select".to_string(),
fancy_names: vec![],
code_names: vec![],
lang: "EN".to_string(),
versions_checked: false,
vers: vec![],
download_metadata: false,
run_once_vers: true,
json_checked: false,
download: false,
blisp_version: "".to_string(),
download_versions: true,
download_firm_notify: true,
picked_path: None,
ready_to_flash: false,
#[cfg(feature = "appimage")]
logs: format!("Pineflash v{} Linux Appimage\n", env!("CARGO_PKG_VERSION")),
#[cfg(not(feature = "appimage"))]
#[cfg(target_os = "linux")]
logs: format!("Pineflash v{} Linux Native\n", env!("CARGO_PKG_VERSION")),
#[cfg(target_os = "windows")]
logs: format!("Pineflash v{} Windows\n", env!("CARGO_PKG_VERSION")),
#[cfg(target_os = "macos")]
logs: format!("Pineflash v{} MacOs\n", env!("CARGO_PKG_VERSION")),
json: "".to_string(),
iron_connected: None,
check_count: 0,
flash: false,
flash_notified_count: 0,
v2_serial_path: None,
connection_guide_image: [
RetainedImage::from_svg_bytes("Step1", include_bytes!("../assets/Step1.svg"))
.unwrap(),
RetainedImage::from_svg_bytes("Step2", include_bytes!("../assets/Step2.svg"))
.unwrap(),
RetainedImage::from_svg_bytes("Step3", include_bytes!("../assets/Step3.svg"))
.unwrap(),
],
current_step: 0,
metadata_path: [std::env::temp_dir(), "metadata.json".into()]
.iter()
.collect(),
open_file_dialog: None,
}
}
}
impl Flasher {
fn new(cc: &CreationContext) -> Flasher {
let config: FlasherConfig = FlasherConfig::default();
// Flasher::configure_fonts(&cc.egui_ctx);
let saved_config: FlashSavedConfig = confy::load("PineFlash", None).unwrap_or_default();
let toasts = Toasts::default()
.with_anchor(Anchor::TopRight)
.with_margin(emath::vec2(0.0, 120.0));
let mut style: egui::Style = (*cc.egui_ctx.style()).clone();
style.spacing.item_spacing = egui::vec2(5.0, 10.0);
cc.egui_ctx.set_style(style);
let new_style = egui::style::WidgetVisuals {
bg_fill: Color32::from_rgb(17, 17, 17),
weak_bg_fill: Color32::from_rgb(17, 17, 17),
ddd
rounding: Rounding {
nw: 4.,
djiwjd
ne: 4.,
sw: 4.,
se: 4.,
},
bg_stroke: Stroke {
width: 1.,
color: Color32::from_rgb(140, 140, 140),
},
fg_stroke: Stroke {
width: 1.,
color: Color32::from_rgb(140, 140, 140),
},
expansion: 2.,
};
let new_hovered_style = egui::style::WidgetVisuals {
bg_fill: Color32::from_rgb(17, 17, 17),
weak_bg_fill: Color32::from_rgb(17, 17, 17),
rounding: Rounding {
nw: 4.,
ne: 4.,
sw: 4.,
se: 4.,
},
bg_stroke: Stroke {
width: 1.5,
color: egui::Color32::from_rgb(56, 55, 55),
},
fg_stroke: Stroke {
width: 1.,
color: Color32::from_rgb(140, 140, 140),
},
expansion: 2.,
};
cc.egui_ctx.set_visuals(egui::style::Visuals {
widgets: egui::style::Widgets {
active: new_style,
inactive: new_style,
hovered: new_hovered_style,
noninteractive: new_style,
open: new_hovered_style,
},
..Default::default()
});
if !saved_config.dark_mode {
cc.egui_ctx.set_visuals(egui::Visuals::light());
}
Flasher::configure_fonts(cc.egui_ctx.clone());
Flasher {
config,
toasts,
saved_config,
}
}
}
impl eframe::App for Flasher {
fn update(&mut self, ctx: &Context, _frame: &mut eframe::Frame) {
// always repaint to have accurate pinecil detection
ctx.request_repaint();
ctx.set_pixels_per_point(1.8);
if self.config.check_count < 180 {
self.config.check_count += 1
} else {
self.config.iron_connected = Flasher::check_connections(self);
self.config.check_count = 0
}
if self.config.download_versions {
let _ = std::fs::remove_file(self.config.metadata_path.clone());
self.config.download_versions = !self.config.download_versions;
self.toasts
.info("Fetching versions")
.set_duration(None)
.set_closable(false);
std::thread::spawn(|| {
let mut data = Vec::new();
let mut handle = Easy::new();
let mut internet = true;
handle
.url("https://api.github.com/repos/Ralim/IronOS/releases")
.unwrap();
handle.useragent("PineFlash").unwrap();
{
let mut transfer = handle.transfer();
transfer
.write_function(|new_data| {
data.extend_from_slice(new_data);
Ok(new_data.len())
})
.unwrap();
if transfer.perform().is_err() {
internet = false;
}
}
let path: PathBuf = [std::env::temp_dir(), "metadata.json".into()]
.iter()
.collect();
if internet {
let json = String::from_utf8(data).unwrap();
std::fs::write(path, json).unwrap();
} else {
std::fs::write(path, "No Internet").unwrap();
}
});
} else if self.config.metadata_path.exists()
&& !self.config.versions_checked
&& !String::from_utf8(std::fs::read(self.config.metadata_path.clone()).unwrap())
.unwrap()
.contains("No Internet")
{
self.toasts.dismiss_all_toasts();
self.toasts
.info("Versions Found")
.set_duration(Some(Duration::from_secs(5)))
.set_closable(false);
self.config
.logs
.push_str("PineFlash: Versions successfully fetched.\n");
self.config.json_checked = !self.config.json_checked;
let string =
String::from_utf8(std::fs::read(self.config.metadata_path.clone()).unwrap())
.unwrap();
let json: Result = serde_json::from_str(string.as_str());
if json.is_err() {
self.toasts.dismiss_all_toasts();
self.toasts
.error("Could not access github, Online Files Will be Unavailable")
.set_duration(Some(Duration::from_secs(5)))
.set_closable(false);
self.config
.logs
.push_str("PineFlash: Invalid json downloaded, could not fetch versions.\n");
self.config.versions_checked = true;
} else {
for i in 0..3 {
let version = json.as_ref().unwrap()[i]["tag_name"].as_str().unwrap();
self.config.vers.push(version.to_string());
}
self.config.versions_checked = true;
self.config.download_metadata = true;
}
} else if !self.config.versions_checked
&& self.config.metadata_path.exists()
&& String::from_utf8(std::fs::read(self.config.metadata_path.clone()).unwrap())
.unwrap()
.contains("No Internet")
{
self.toasts.dismiss_all_toasts();
self.toasts
.error("No Internet, Online Files Will be Unavailable")
.set_duration(Some(Duration::from_secs(5)))
.set_closable(false);
self.config
.logs
.push_str("PineFlash: No internet, could not fetch versions.\n");
self.config.versions_checked = true;
}
Flasher::render_header(self, ctx);
Flasher::render_main_windows(self, ctx);
if self.config.download {
let path: PathBuf = [
std::env::temp_dir(),
format!("{}-{}.zip", self.config.version, self.config.int_name).into(),
]
.iter()
.collect();
let pathlock: PathBuf = [std::env::temp_dir(), "firmware.lock".into()]
.iter()
.collect();
if self.config.download_firm_notify {
let _ = std::fs::write(pathlock, "Locked");
self.toasts
.info("Downloading")
.set_duration(None)
.set_closable(false);
self.config.logs.push_str(
format!(
"PineFlash: Downloading Firmware {} {}.\n",
self.config.int_name, self.config.version
)
.as_str(),
);
let _ = std::fs::remove_file(path);
let version = self.config.version.clone();
let int_name = self.config.int_name.clone();
std::thread::spawn(move || {
let mut data = Vec::new();
let mut handle = Easy::new();
let path: PathBuf = [
std::env::temp_dir(),
format!("{}-{}.zip", version, int_name).into(),
]
.iter()
.collect();
let pathlock: PathBuf = [std::env::temp_dir(), "firmware.lock".into()]
.iter()
.collect();
let _ = handle.url(
format!(
"https://github.com/Ralim/IronOS/releases/download/{}/{}.zip",
version, int_name
)
.as_str(),
);
let _ = handle.follow_location(true);
handle.useragent("PineFlash").unwrap();
{
let mut transfer = handle.transfer();
transfer
.write_function(|new_data| {
data.extend_from_slice(new_data);
Ok(new_data.len())
})
.unwrap();
transfer.perform().unwrap()
}
let zip = data.as_slice();
if std::fs::write(path, zip).is_err() {
println!("Could not write zip file")
};
if std::fs::remove_file(pathlock).is_err() {
println!("Could not remove lockfile")
};
});
self.config.download_firm_notify = false
} else if !self.config.download_firm_notify && !pathlock.exists() {
self.toasts.dismiss_all_toasts();
self.config.logs.push_str("PineFlash: Download Complete.\n");
self.toasts
.info("Flashing.")
.set_duration(None)
.set_closable(false);
self.config.download = false;
self.config.flash = true;
}
}
if !self.config.version.contains("Select")
&& !self.config.version.contains("Custom")
&& self.config.download_metadata
{
let path: PathBuf = [std::env::temp_dir(), "langs.zip".into()].iter().collect();
let pathlock: PathBuf = [std::env::temp_dir(), "langs.lock".into()].iter().collect();
if self.config.run_once_vers {
self.toasts
.info("Downloading Language information.")
.set_duration(None)
.set_closable(false);
let _ = std::fs::remove_file(path);
let _ = std::fs::write(pathlock, "Locked");
let version = self.config.version.clone();
std::thread::spawn(move || {
let mut data = Vec::new();
let mut handle = Easy::new();
let path: PathBuf = [std::env::temp_dir(), "langs.zip".into()].iter().collect();
let pathlock: PathBuf =
[std::env::temp_dir(), "langs.lock".into()].iter().collect();
let _ = std::fs::remove_file(path.clone());
let _ = handle.follow_location(true);
handle
.url(
format!(
"https://github.com/Ralim/IronOS/releases/download/{}/metadata.zip",
version
)
.as_str(),
)
.unwrap();
handle.useragent("PineFlash").unwrap();
{
let mut transfer = handle.transfer();
transfer
.write_function(|new_data| {
data.extend_from_slice(new_data);
Ok(new_data.len())
})
.unwrap();
transfer.perform().unwrap();
}
let zip = data.as_slice();
if std::fs::write(path, zip).is_err() {
println!("Could not write zip file")
};
if std::fs::remove_file(pathlock).is_err() {
println!("Could not remove lockfile")
};
});
self.config.run_once_vers = false;
} else if !pathlock.exists() {
let path: PathBuf = [std::env::temp_dir(), "langs.zip".into()].iter().collect();
self.toasts.dismiss_all_toasts();
self.config
.logs
.push_str("PineFlash: Download of Language Info Complete.\n");
self.toasts
.info("Languages Downloaded.")
.set_duration(Some(Duration::from_secs(3)))
.set_closable(false);
let mut file = File::open(path).unwrap();
let mut data = Vec::new();
file.read_to_end(&mut data).unwrap();
let target_dir: PathBuf =
[std::env::temp_dir(), "metadata".into()].iter().collect();
zip_extract::extract(Cursor::new(data), &target_dir, false).unwrap();
let json_path: PathBuf = [
std::env::temp_dir(),
"metadata".into(),
format!("{}.json", self.config.int_name).into(),
]
.iter()
.collect();
self.config.json = fs::read_to_string(json_path).unwrap();
self.config.download_metadata = false;
let value: YourValue = serde_json::from_str(self.config.json.as_str()).unwrap();
for i in value.contents {
if !i.0.contains(".hex") {
let a = i.1;
self.config.fancy_names.push(a.language_name);
self.config.code_names.push(a.language_code);
}
}
self.config.download_metadata = false;
}
}
if self.config.flash {
if self.config.flash_notified_count < 60 {
self.config.flash_notified_count += 1
} else {
Flasher::flash(self);
}
}
}
}
fn main() {
let options = eframe::NativeOptions {
decorated: true,
follow_system_theme: true,
icon_data: Some(eframe::IconData {
rgba: (ICON.to_vec()),
width: (32),
height: (32),
}),
resizable: true,
initial_window_size: Some(emath::Vec2 { x: 780., y: 680. }),
min_window_size: Some(emath::Vec2 { x: 780., y: 280. }),
..Default::default()
};
match eframe::run_native(
"PineFlash",
options,
Box::new(|cc| Box::new(Flasher::new(cc))),
) {
Ok(_) => (),
Err(_) => println!("A massive error occured, not sure whats goin on here."),
}
}
================================================
FILE: src/main.rs
================================================
#![windows_subsystem = "windows"]
use std::{
collections::HashMap,
env,
fs::{self, File},
io::{Cursor, Read},
path::PathBuf,
time::Duration,
};
use curl::easy::Easy;
use eframe::{egui::{self, ImageSource}, epaint::ColorImage};
use eframe::{
emath,
epaint::{Color32, Rounding, Stroke},
CreationContext,
};
mod submodules;
use egui::Context;
use egui_file::FileDialog;
use egui_notify::{Anchor, Toasts};
use serde::{Deserialize, Serialize};
use serde_json::Value;
const ICON: &[u8] = include_bytes!("../assets/pine64logo.ico");
#[derive(Serialize, Deserialize)]
struct Language {
language_code: String,
language_name: String,
}
#[derive(Serialize, Deserialize)]
struct YourValue {
contents: HashMap,
}
struct FlasherConfig {
iron: String,
int_name: String,
version: String,
fancy_names: Vec,
code_names: Vec,
lang: String,
versions_checked: bool,
vers: Vec, download_metadata: bool,
blisp_version: String,
run_once_vers: bool,
download: bool,
picked_path: Option,
download_versions: bool,
download_firm_notify: bool,
ready_to_flash: bool,
logs: String,
json: String,
iron_connected: Option,
check_count: i32,
flash: bool,
flash_notified_count: i32,
v2_serial_path: Option,
// connection_guide_image: Vec,
current_step: usize,
json_checked: bool,
metadata_path: PathBuf,
open_file_dialog: Option,
}
#[derive(Serialize, Deserialize)]
struct FlashSavedConfig {
pub dark_mode: bool,
}
impl Default for FlashSavedConfig {
fn default() -> Self {
Self { dark_mode: true }
}
}
struct Flasher {
config: FlasherConfig,
saved_config: FlashSavedConfig,
toasts: Toasts,
}
impl Default for FlasherConfig {
fn default() -> Self {
Self {
iron: "Pinecil V2".to_string(),
int_name: "Pinecilv2".to_string(),
version: "Select".to_string(),
fancy_names: vec![],
code_names: vec![],
lang: "EN".to_string(),
versions_checked: false,
vers: vec![],
download_metadata: false,
run_once_vers: true,
json_checked: false,
download: false,
blisp_version: "".to_string(),
download_versions: true,
download_firm_notify: true,
picked_path: None,
ready_to_flash: false,
#[cfg(feature = "appimage")]
logs: format!("Pineflash v{} Linux Appimage\n", env!("CARGO_PKG_VERSION")),
#[cfg(not(feature = "appimage"))]
#[cfg(target_os = "linux")]
logs: format!("Pineflash v{} Linux Native\n", env!("CARGO_PKG_VERSION")),
#[cfg(target_os = "windows")]
logs: format!("Pineflash v{} Windows\n", env!("CARGO_PKG_VERSION")),
#[cfg(target_os = "macos")]
logs: format!("Pineflash v{} MacOs\n", env!("CARGO_PKG_VERSION")),
json: "".to_string(),
iron_connected: None,
check_count: 0,
flash: false,
flash_notified_count: 0,
v2_serial_path: None,
// connection_guide_image: [
//
// RetainedImage::from_svg_bytes("Step1", include_bytes!("../assets/Step1.svg"))
// .unwrap(),
// RetainedImage::from_svg_bytes("Step2", include_bytes!("../assets/Step2.svg"))
// .unwrap(),
// RetainedImage::from_svg_bytes("Step3", include_bytes!("../assets/Step3.svg"))
// .unwrap(),
// ],
current_step: 0,
metadata_path: [std::env::temp_dir(), "metadata.json".into()]
.iter()
.collect(),
open_file_dialog: None,
}
}
}
impl Flasher {
fn new(cc: &CreationContext) -> Flasher {
let config: FlasherConfig = FlasherConfig::default();
// Flasher::configure_fonts(&cc.egui_ctx);
let saved_config: FlashSavedConfig = confy::load("PineFlash", None).unwrap_or_default();
let toasts = Toasts::default()
.with_anchor(Anchor::TopRight)
.with_margin(emath::vec2(0.0, 120.0));
let mut style: egui::Style = (*cc.egui_ctx.style()).clone();
style.spacing.item_spacing = egui::vec2(5.0, 10.0);
cc.egui_ctx.set_style(style);
let new_style = egui::style::WidgetVisuals {
bg_fill: Color32::from_rgb(17, 17, 17),
weak_bg_fill: Color32::from_rgb(17, 17, 17),
rounding: Rounding {
nw: 4.,
ne: 4.,
sw: 4.,
se: 4.,
},
bg_stroke: Stroke {
width: 1.,
color: Color32::from_rgb(140, 140, 140),
},
fg_stroke: Stroke {
width: 1.,
color: Color32::from_rgb(140, 140, 140),
},
expansion: 2.,
};
let new_hovered_style = egui::style::WidgetVisuals {
bg_fill: Color32::from_rgb(17, 17, 17),
weak_bg_fill: Color32::from_rgb(17, 17, 17),
rounding: Rounding {
nw: 4.,
ne: 4.,
sw: 4.,
se: 4.,
},
bg_stroke: Stroke {
width: 1.5,
color: egui::Color32::from_rgb(56, 55, 55),
},
fg_stroke: Stroke {
width: 1.,
color: Color32::from_rgb(140, 140, 140),
},
expansion: 2.,
};
cc.egui_ctx.set_visuals(egui::style::Visuals {
widgets: egui::style::Widgets {
active: new_style,
inactive: new_style,
hovered: new_hovered_style,
noninteractive: new_style,
open: new_hovered_style,
},
..Default::default()
});
if !saved_config.dark_mode {
cc.egui_ctx.set_visuals(egui::Visuals::light());
}
Flasher::configure_fonts(cc.egui_ctx.clone());
Flasher {
config,
toasts,
saved_config,
}
}
}
impl eframe::App for Flasher {
fn update(&mut self, ctx: &Context, _frame: &mut eframe::Frame) {
// always repaint to have accurate pinecil detection
ctx.request_repaint();
ctx.set_pixels_per_point(1.8);
if self.config.check_count < 180 {
self.config.check_count += 1
} else {
self.config.iron_connected = Flasher::check_connections(self);
self.config.check_count = 0
}
if self.config.download_versions {
let _ = std::fs::remove_file(self.config.metadata_path.clone());
self.config.download_versions = !self.config.download_versions;
self.toasts
.info("Fetching versions")
.set_duration(None)
.set_closable(false);
std::thread::spawn(|| {
let mut data = Vec::new();
let mut handle = Easy::new();
let mut internet = true;
handle
.url("https://api.github.com/repos/Ralim/IronOS/releases")
.unwrap();
handle.useragent("PineFlash").unwrap();
{
let mut transfer = handle.transfer();
transfer
.write_function(|new_data| {
data.extend_from_slice(new_data);
Ok(new_data.len())
})
.unwrap();
if transfer.perform().is_err() {
internet = false;
}
}
let path: PathBuf = [std::env::temp_dir(), "metadata.json".into()]
.iter()
.collect();
if internet {
let json = String::from_utf8(data).unwrap();
std::fs::write(path, json).unwrap();
} else {
std::fs::write(path, "No Internet").unwrap();
}
});
} else if self.config.metadata_path.exists()
&& !self.config.versions_checked
&& !String::from_utf8(std::fs::read(self.config.metadata_path.clone()).unwrap())
.unwrap()
.contains("No Internet")
{
self.toasts.dismiss_all_toasts();
self.toasts
.info("Versions Found")
.set_duration(Some(Duration::from_secs(5)))
.set_closable(false);
self.config
.logs
.push_str("PineFlash: Versions successfully fetched.\n");
self.config.json_checked = !self.config.json_checked;
let string =
String::from_utf8(std::fs::read(self.config.metadata_path.clone()).unwrap())
.unwrap();
let json: Result = serde_json::from_str(string.as_str());
if json.is_err() {
self.toasts.dismiss_all_toasts();
self.toasts
.error("Could not access github, Online Files Will be Unavailable")
.set_duration(Some(Duration::from_secs(5)))
.set_closable(false);
self.config
.logs
.push_str("PineFlash: Invalid json downloaded, could not fetch versions.\n");
self.config.versions_checked = true;
} else {
for i in 0..3 {
let version = json.as_ref().unwrap()[i]["tag_name"].as_str().unwrap();
self.config.vers.push(version.to_string());
}
self.config.versions_checked = true;
self.config.download_metadata = true;
}
} else if !self.config.versions_checked
&& self.config.metadata_path.exists()
&& String::from_utf8(std::fs::read(self.config.metadata_path.clone()).unwrap())
.unwrap()
.contains("No Internet")
{
self.toasts.dismiss_all_toasts();
self.toasts
.error("No Internet, Online Files Will be Unavailable")
.set_duration(Some(Duration::from_secs(5)))
.set_closable(false);
self.config
.logs
.push_str("PineFlash: No internet, could not fetch versions.\n");
self.config.versions_checked = true;
}
Flasher::render_header(self, ctx);
Flasher::render_main_windows(self, ctx);
if self.config.download {
let path: PathBuf = [
std::env::temp_dir(),
format!("{}-{}.zip", self.config.version, self.config.int_name).into(),
]
.iter()
.collect();
let pathlock: PathBuf = [std::env::temp_dir(), "firmware.lock".into()]
.iter()
.collect();
if self.config.download_firm_notify {
let _ = std::fs::write(pathlock, "Locked");
self.toasts
.info("Downloading")
.set_duration(None)
.set_closable(false);
self.config.logs.push_str(
format!(
"PineFlash: Downloading Firmware {} {}.\n",
self.config.int_name, self.config.version
)
.as_str(),
);
let _ = std::fs::remove_file(path);
let version = self.config.version.clone();
let int_name = self.config.int_name.clone();
std::thread::spawn(move || {
let mut data = Vec::new();
let mut handle = Easy::new();
let path: PathBuf = [
std::env::temp_dir(),
format!("{}-{}.zip", version, int_name).into(),
]
.iter()
.collect();
let pathlock: PathBuf = [std::env::temp_dir(), "firmware.lock".into()]
.iter()
.collect();
let _ = handle.url(
format!(
"https://github.com/Ralim/IronOS/releases/download/{}/{}.zip",
version, int_name
)
.as_str(),
);
let _ = handle.follow_location(true);
handle.useragent("PineFlash").unwrap();
{
let mut transfer = handle.transfer();
transfer
.write_function(|new_data| {
data.extend_from_slice(new_data);
Ok(new_data.len())
})
.unwrap();
transfer.perform().unwrap()
}
let zip = data.as_slice();
if std::fs::write(path, zip).is_err() {
println!("Could not write zip file")
};
if std::fs::remove_file(pathlock).is_err() {
println!("Could not remove lockfile")
};
});
self.config.download_firm_notify = false
} else if !self.config.download_firm_notify && !pathlock.exists() {
self.toasts.dismiss_all_toasts();
self.config.logs.push_str("PineFlash: Download Complete.\n");
self.toasts
.info("Flashing.")
.set_duration(None)
.set_closable(false);
self.config.download = false;
self.config.flash = true;
}
}
if !self.config.version.contains("Select")
&& !self.config.version.contains("Custom")
&& self.config.download_metadata
{
let path: PathBuf = [std::env::temp_dir(), "langs.zip".into()].iter().collect();
let pathlock: PathBuf = [std::env::temp_dir(), "langs.lock".into()].iter().collect();
if self.config.run_once_vers {
self.toasts
.info("Downloading Language information.")
.set_duration(None)
.set_closable(false);
let _ = std::fs::remove_file(path);
let _ = std::fs::write(pathlock, "Locked");
let version = self.config.version.clone();
std::thread::spawn(move || {
let mut data = Vec::new();
let mut handle = Easy::new();
let path: PathBuf = [std::env::temp_dir(), "langs.zip".into()].iter().collect();
let pathlock: PathBuf =
[std::env::temp_dir(), "langs.lock".into()].iter().collect();
let _ = std::fs::remove_file(path.clone());
let _ = handle.follow_location(true);
handle
.url(
format!(
"https://github.com/Ralim/IronOS/releases/download/{}/metadata.zip",
version
)
.as_str(),
)
.unwrap();
handle.useragent("PineFlash").unwrap();
{
let mut transfer = handle.transfer();
transfer
.write_function(|new_data| {
data.extend_from_slice(new_data);
Ok(new_data.len())
})
.unwrap();
transfer.perform().unwrap();
}
let zip = data.as_slice();
if std::fs::write(path, zip).is_err() {
println!("Could not write zip file")
};
if std::fs::remove_file(pathlock).is_err() {
println!("Could not remove lockfile")
};
});
self.config.run_once_vers = false;
} else if !pathlock.exists() {
let path: PathBuf = [std::env::temp_dir(), "langs.zip".into()].iter().collect();
self.toasts.dismiss_all_toasts();
self.config
.logs
.push_str("PineFlash: Download of Language Info Complete.\n");
self.toasts
.info("Languages Downloaded.")
.set_duration(Some(Duration::from_secs(3)))
.set_closable(false);
let mut file = File::open(path).unwrap();
let mut data = Vec::new();
file.read_to_end(&mut data).unwrap();
let target_dir: PathBuf =
[std::env::temp_dir(), "metadata".into()].iter().collect();
zip_extract::extract(Cursor::new(data), &target_dir, false).unwrap();
let json_path: PathBuf = [
std::env::temp_dir(),
"metadata".into(),
format!("{}.json", self.config.int_name).into(),
]
.iter()
.collect();
self.config.json = fs::read_to_string(json_path).unwrap();
self.config.download_metadata = false;
let value: YourValue = serde_json::from_str(self.config.json.as_str()).unwrap();
for i in value.contents {
if !i.0.contains(".hex") {
let a = i.1;
self.config.fancy_names.push(a.language_name);
self.config.code_names.push(a.language_code);
}
}
self.config.download_metadata = false;
}
}
if self.config.flash {
if self.config.flash_notified_count < 60 {
self.config.flash_notified_count += 1
} else {
Flasher::flash(self);
}
}
}
}
fn main() {
let options = eframe::NativeOptions::default();
// let options = eframe::NativeOptions {
// decorated: true,
// follow_system_theme: true,
// icon_data: Some(eframe::IconData {
// rgba: (ICON.to_vec()),
// width: (32),
// height: (32),
// }),
// resizable: true,
// initial_window_size: Some(emath::Vec2 { x: 780., y: 680. }),
// min_window_size: Some(emath::Vec2 { x: 780., y: 280. }),
// ..Default::default()
// };
match eframe::run_native(
"PineFlash",
options,
// Box::new(|cc| Box::new(egui_extras::install_image_loaders(&cc.egui_ctx) Flasher::new(cc))),
//
Box::new(|cc| {
// This gives us image support:
egui_extras::install_image_loaders(&cc.egui_ctx);
Box::new(Flasher::new(cc))
}),
) {
Ok(_) => (),
Err(error) => panic!("A massive error occured, not sure whats goin on here: \n {}", error),
}
}
================================================
FILE: src/submodules/connection_poller.rs
================================================
use crate::Flasher;
use serialport::SerialPortType::UsbPort;
impl Flasher {
pub fn check_connections(&mut self) -> Option {
let ports = serialport::available_ports().expect("No ports found!");
let mut type_of_pinecil: Option = None;
let mut v1: bool = false;
let mut v2: bool = false;
for device in rusb::devices().unwrap().iter() {
let device_info = device.device_descriptor().unwrap();
if device_info.vendor_id() == 10473 && device_info.product_id() == 393 {
// pinecil v1 connected
v1 = true;
type_of_pinecil = Some("Pinecil".to_string())
}
}
for device in ports {
if let UsbPort(info) = device.port_type {
if let Some(serial_number) = info.serial_number {
if serial_number.contains("000000020000") {
// pinecil v2 connected
v2 = true;
self.config.v2_serial_path = Some(device.port_name.clone());
type_of_pinecil = Some("Pinecilv2".to_string())
}
}
}
}
if v1 && v2 && self.config.iron_connected.as_ref() != Some(&"Both".to_string()) {
type_of_pinecil = Some("Both".to_string());
self.config.logs.push_str("Both v1 and v2 are detected")
} else if self.config.iron_connected.is_none() && type_of_pinecil.is_some() {
self.config.logs.push_str(
format!("Pineflash: {} detected\n", type_of_pinecil.clone().unwrap()).as_str(),
);
if v2 {
self.config.logs.push_str(
format!(
"PineFlash: Serial port is {} \n",
self.config.v2_serial_path.clone().unwrap()
)
.as_str(),
);
}
} else if self.config.iron_connected.is_some() && type_of_pinecil.is_none() {
self.config.logs.push_str(
format!(
"Pineflash: {} disconnected\n",
self.config.iron_connected.clone().unwrap()
)
.as_str(),
);
}
type_of_pinecil
}
}
================================================
FILE: src/submodules/flash.rs
================================================
use std::fs::File;
use std::io::{Cursor, Read};
#[cfg(target_os = "windows")]
use std::os::windows::process::CommandExt;
use std::path::PathBuf;
use std::process::Command;
use std::time::Duration;
use crate::Flasher;
impl Flasher {
pub fn flash(&mut self) {
let mut firmware_path = "".to_string();
if self.config.version != *"Custom" {
let path: PathBuf = [
std::env::temp_dir(),
format!("{}-{}.zip", self.config.version, self.config.int_name)
.as_str()
.into(),
]
.iter()
.collect();
let target: PathBuf = [
std::env::temp_dir(),
format!("{}-{}", self.config.version, self.config.int_name)
.as_str()
.into(),
]
.iter()
.collect();
let mut file = File::open(path).unwrap();
let mut data = Vec::new();
file.read_to_end(&mut data).unwrap();
zip_extract::extract(Cursor::new(data), &target, true).unwrap();
self.config
.logs
.push_str("PineFlash: File extracted successfully\n");
if cfg!(unix) && self.config.int_name == "Pinecil" {
firmware_path = format!(
"{}/{}_{}.dfu",
target.as_os_str().to_str().unwrap(),
self.config.int_name,
self.config.lang
);
} else if cfg!(unix) && self.config.int_name == "Pinecilv2" {
firmware_path = format!(
"{}/{}_{}.bin",
target.as_os_str().to_str().unwrap(),
self.config.int_name,
self.config.lang
);
} else if cfg!(windows) && self.config.int_name == "Pinecil" {
// Do windows functionality here.
firmware_path = format!(
"{}\\{}_{}.dfu",
target.as_os_str().to_str().unwrap(),
self.config.int_name,
self.config.lang
);
} else if cfg!(windows) && self.config.int_name == "Pinecilv2" {
firmware_path = format!(
"{}\\{}_{}.bin",
target.as_os_str().to_str().unwrap(),
self.config.int_name,
self.config.lang
);
}
} else if self.config.picked_path.is_some() {
firmware_path = self.config.picked_path.as_ref().unwrap().to_string();
} else {
self.toasts
.error("Please select a file or firmware version");
}
self.config.logs.push_str(
format!(
"PineFlash: Attempting to flash {} with the firmware {}\n",
self.config.int_name, firmware_path
)
.as_str(),
);
if self.config.int_name == "Pinecil" {
#[cfg(feature = "appimage")]
let path = format!(
"{}/appimage/dfu-util",
std::env::current_dir().unwrap().to_str().unwrap()
);
#[cfg(feature = "appimage")]
let tool_path: PathBuf = [std::env::temp_dir(), "flash_tools".into()]
.iter()
.collect();
#[cfg(feature = "appimage")]
let _ = std::fs::create_dir(tool_path.clone());
#[cfg(feature = "appimage")]
let dfupath: PathBuf = [tool_path, "dfu-util".into()].iter().collect();
#[cfg(feature = "appimage")]
std::fs::copy(path, dfupath.clone()).unwrap();
// println!("{}", path);
#[cfg(not(feature = "appimage"))]
#[cfg(target_os = "linux")]
let dfupath = "dfu-util";
#[cfg(target_os = "linux")]
let command = Command::new("pkexec")
// .env("PATH", path)
.arg(dfupath)
.arg("-D")
.arg(firmware_path)
.arg("-a 0")
.output()
.expect("Could not flash soldering iron");
#[cfg(target_os = "macos")]
let command = Command::new("dfu-util")
.arg("-D")
.arg(firmware_path)
.arg("-a 0")
.output()
.expect("Could not flash soldering iron");
#[cfg(target_os = "windows")]
let command: PathBuf = [
std::env::current_dir().unwrap(),
"tools".into(),
"dfu-util.exe".into(),
]
.iter()
.collect();
#[cfg(target_os = "windows")]
let command = Command::new(command)
.creation_flags(0x00000008)
.arg("-D")
.arg(firmware_path)
.arg("-a 0")
.output()
.expect("Could not flash soldering iron");
let output: String = String::from_utf8(command.stdout).unwrap();
let output_err: String = String::from_utf8(command.stderr).unwrap();
self.toasts.dismiss_all_toasts();
if command.status.success() {
self.toasts
.info("Flashing completed")
.set_duration(Some(Duration::from_secs(5)))
.set_closable(false);
} else {
self.toasts
.error("Flashing failed, is your pinecil plugged in?")
.set_duration(Some(Duration::from_secs(5)))
.set_closable(false);
}
self.config
.logs
.push_str(format!("Dfu-Util: {}{}\n", output, output_err).as_str());
} else if self.config.int_name == "Pinecilv2" {
#[cfg(feature = "appimage")]
let path = format!(
"{}/linux/blisp",
std::env::current_dir().unwrap().to_str().unwrap()
);
#[cfg(feature = "appimage")]
let tool_path: PathBuf = [std::env::temp_dir(), "flash_tools".into()]
.iter()
.collect();
#[cfg(feature = "appimage")]
let _ = std::fs::create_dir(tool_path.clone());
#[cfg(feature = "appimage")]
let blisppath: PathBuf = [tool_path, "blisp".into()].iter().collect();
#[cfg(feature = "appimage")]
std::fs::copy(path, blisppath.clone()).unwrap();
// println!("{}", path);
#[cfg(not(feature = "appimage"))]
#[cfg(target_os = "linux")]
let blisppath = "blisp";
#[cfg(target_os = "linux")]
let command = Command::new("pkexec")
.env("PATH", "/usr/local/sbin:/usr/local/bin:/usr/bin:/bin:linux")
.arg(blisppath)
.arg("write")
.arg("-c")
.arg("bl70x")
.arg("-p")
.arg(self.config.v2_serial_path.clone().unwrap())
.arg("--reset")
.arg(firmware_path)
.output()
.expect("Could not flash soldering iron");
#[cfg(target_os = "macos")]
let command = Command::new("blisp")
.arg("write")
.arg("-c")
.arg("bl70x")
.arg("--reset")
.arg(firmware_path)
.output()
.expect("Could not flash soldering iron");
#[cfg(target_family = "windows")]
let command: PathBuf = [
std::env::current_dir().unwrap(),
"tools".into(),
"blisp.exe".into(),
]
.iter()
.collect();
#[cfg(target_os = "windows")]
let command = Command::new(command)
.creation_flags(0x00000008)
.arg("write")
.arg("-c")
.arg("bl70x")
.arg("-p")
.arg(self.config.v2_serial_path.clone().unwrap())
.arg("--reset")
.arg(firmware_path)
.output()
.expect("Could not flash soldering iron");
let output: String = String::from_utf8(command.stdout).unwrap();
let output_err: String = String::from_utf8(command.stderr).unwrap();
self.toasts.dismiss_all_toasts();
if !output_err.as_str().contains("Device not found")
&& !output_err.as_str().contains("Failed")
&& !output_err.as_str().contains("Error")
{
self.toasts
.info("Flashing completed")
.set_duration(Some(Duration::from_secs(4)))
.set_closable(false);
} else if output_err.as_str().contains("Not authorized") {
self.toasts
.error("Could not run command as admin,\n was your password wrong?")
.set_duration(Some(Duration::from_secs(4)))
.set_closable(false);
} else {
self.toasts
.error("Flashing failed,\n your device may have been disconnected.")
.set_duration(Some(Duration::from_secs(4)))
.set_closable(false);
}
self.config
.logs
.push_str(format!("Blisp: {}{}\n", output, output_err).as_str());
}
// Very ugly way of reseting the program
self.config.version = "Select".to_string();
self.config.fancy_names = vec![];
self.config.code_names = vec![];
// self.config.versions_checked = false;
// self.config.vers = vec![];
// self.config.promise = None;
// self.config.promise_2 = None;
// self.config.promise_3 = None;
// self.config.download_metadata = false;
self.config.download = false;
self.config.run_once_vers = true;
self.config.download_firm_notify = true;
self.config.picked_path = None;
self.config.ready_to_flash = false;
self.config.flash_notified_count = 0;
self.config.flash = false;
}
}
================================================
FILE: src/submodules/fonts.rs
================================================
use eframe::{
egui::{self, FontData, FontDefinitions},
epaint::FontFamily,
};
use crate::Flasher;
impl Flasher {
pub fn configure_fonts(cc: egui::Context) {
let mut fonts = FontDefinitions::default();
fonts.font_data.insert(
"Chinese".to_owned(),
FontData::from_static(include_bytes!("../../assets/XiaolaiSC-Regular.ttf")),
);
fonts
.families
.get_mut(&FontFamily::Proportional)
.unwrap()
.push("Chinese".to_owned());
// Use meslolgs for icons
fonts.font_data.insert(
"MesloLGS".to_owned(),
FontData::from_static(include_bytes!("../../assets/SFMono_Nerd_Font_Complete.otf")),
);
fonts
.families
.get_mut(&FontFamily::Proportional)
.unwrap()
.push("MesloLGS".to_owned());
cc.set_fonts(fonts);
}
}
================================================
FILE: src/submodules/main_panel.rs
================================================
use std::time::Duration;
#[cfg(target_family = "windows")]
use std::os::windows::process::CommandExt;
#[cfg(target_family = "windows")]
use std::path::PathBuf;
#[cfg(feature = "appimage")]
use std::path::PathBuf;
use eframe::{
egui::{self, Button, CentralPanel, Image, RichText, ScrollArea},
epaint::{Color32, Rounding},
};
use egui::emath;
use egui::Context;
use egui::Vec2;
use egui_file::FileDialog;
use simple_home_dir::home_dir;
use std::process::Command;
use version_compare::Version;
use crate::Flasher;
impl Flasher {
pub fn render_main_windows(&mut self, ctx: &Context) {
CentralPanel::default().show(ctx, |ui|{
ui.horizontal(|ui| {
if self.config.iron_connected.is_none() {
ui.colored_label(Color32::RED, RichText::new("").heading());
ui.label("Soldering Iron Disconnected");
} else {
ui.colored_label(Color32::GREEN, RichText::new("").heading());
ui.label("Soldering Iron Connected");
}
});
ui.horizontal(|ui| {
// Disable strokes except for hovered
ui.visuals_mut().widgets.active.bg_stroke = eframe::epaint::Stroke{ width: 0., color: egui::Color32::RED};
ui.visuals_mut().widgets.inactive.bg_stroke = eframe::epaint::Stroke{ width: 0., color: egui::Color32::RED};
let width = ui.available_width();
ui.vertical(|ui| {
ui.label("Select your Soldering Iron");
egui::ComboBox::from_label(" ")
.selected_text(self.config.iron.to_string())
.show_ui(ui, |ui| {
ui.selectable_value(&mut self.config.iron, "Pinecil V1".to_string(), "Pinecil V1");
ui.selectable_value(&mut self.config.iron, "Pinecil V2".to_string(), "Pinecil V2");
}
);
if self.config.iron == "Pinecil V1" {
self.config.int_name = "Pinecil".to_string();
} else if self.config.iron == "Pinecil V2" {
self.config.int_name = "Pinecilv2".to_string();
}
});
let width_now = ui.available_width();
ui.add_space(width / 2. - ((width - width_now) * 1.3));
ui.vertical(|ui| {
ui.label("Specify Version");
ui.horizontal(|ui| {
ui.add_enabled_ui(self.config.versions_checked, |ui|{
egui::ComboBox::from_label("")
.selected_text(self.config.version.to_string())
.show_ui(ui, |ui| {
if self.config.versions_checked {
for i in &self.config.vers {
ui.selectable_value(&mut self.config.version, i.clone(), i);
}
ui.selectable_value(&mut self.config.version, "Custom".to_string(), "Custom");
}
}
);
});
if ui.button(RichText::new(" ").size(15.)).clicked() {
let mut dialog = FileDialog::open_file(home_dir()).default_size(emath::Vec2 {x:264., y: 262.});
dialog.open();
self.config.open_file_dialog = Some(dialog);
}
if let Some(dialog) = &mut self.config.open_file_dialog {
if dialog.show(ctx).selected() {
if let Some(file) = dialog.path() {
if self.config.int_name == "Pinecilv2" {
#[cfg(feature = "appimage")]
let path = format!(
"{}/linux/blisp",
std::env::current_dir().unwrap().to_str().unwrap()
);
#[cfg(feature = "appimage")]
let tool_path: PathBuf = [std::env::temp_dir(), "flash_tools".into()]
.iter()
.collect();
#[cfg(feature = "appimage")]
let _ = std::fs::create_dir(tool_path.clone());
#[cfg(feature = "appimage")]
let blisppath: PathBuf = [tool_path, "blisp".into()].iter().collect();
#[cfg(feature = "appimage")]
std::fs::copy(path, blisppath.clone()).unwrap();
#[cfg(not(feature = "appimage"))]
#[cfg(target_family = "unix")]
let blisppath = "blisp";
#[cfg(target_family = "unix")]
let blisp_version = String::from_utf8( Command::new(blisppath)
.env("PATH", "/usr/local/sbin:/usr/local/bin:/usr/bin:/bin")
.arg("--version").output().expect("Could not find blisp").stdout).unwrap();
#[cfg(target_family = "windows")]
let blisp: PathBuf = [
std::env::current_dir().unwrap(),
"tools".into(),
"blisp.exe".into(),
]
.iter()
.collect();
#[cfg(target_os = "windows")]
let blisp_version = String::from_utf8( Command::new(blisp)
.creation_flags(0x00000008)
.arg("--version").output().expect("Could not find blisp").stdout).unwrap();
let ver = blisp_version.split("\n");
for i in ver {
if i.contains("v") {
for ii in i.split("v") {
if ii.contains(".") {
self.config.blisp_version = ii.to_string();
}
}
}
}
}
if !file.display().to_string().contains("dfu") && self.config.int_name == "Pinecil" || self.config.int_name == "Pinecilv2" && !file.display().to_string().contains("bin") && !file.display().to_string().contains("dfu") {
self.toasts.dismiss_all_toasts();
self.toasts.error("File has the incorrect format").set_duration(Some(Duration::from_secs(4))).set_closable(false);
self.config.logs.push_str("PineFlash: Incorrect filetype selected.\n");
self.config.picked_path = None;
} else if Version::from(self.config.blisp_version.as_str()).unwrap() < Version::from("0.0.4").unwrap() && file.display().to_string().contains("dfu") && self.config.int_name == "Pinecilv2" {
self.toasts.dismiss_all_toasts();
self.toasts.error("Your version of blisp can not flash boot image files.\nPlease update it to version 0.0.4 or higher").set_duration(Some(Duration::from_secs(4))).set_closable(false);
self.config.logs.push_str(format!("PineFlash: Old blisp version {}.\n", self.config.blisp_version).as_str());
self.config.picked_path = None;
}
else {
self.config.picked_path = Some(file.display().to_string());
self.config.version = "Custom".to_string();
self.toasts.dismiss_all_toasts();
self.toasts.info("Custom file selected").set_duration(Some(Duration::from_secs(4))).set_closable(false);
self.config.logs.push_str("PineFlash: Custom file selected.\n");
}
}
}
}
});
});
ui.add_space(ui.available_width() - ((width - width_now) / 1.2));
ui.vertical(|ui| {
ui.label("Select Your Language.");
ui.add_enabled_ui({
self.config.version != *"Select" &&
!self.config.download_metadata
}, |ui|{
ui.horizontal(|ui| {
ui.add_space(10.);
egui::ComboBox::from_label(" ")
.selected_text(self.config.lang.to_string())
.show_ui(ui, |ui| {
for i in 0..self.config.code_names.len() {
let code_name = &self.config.code_names[i];
let fancy_name = &self.config.fancy_names[i];
ui.selectable_value(&mut self.config.lang, code_name.to_string(), fancy_name);
}
}
);
})
});
})
});
if self.config.picked_path.is_some() &&
self.config.iron_connected.as_ref() == Some(&self.config.int_name) ||
self.config.iron_connected.as_ref() == Some(&"Both".to_string()) ||
self.config.version != *"Custom" &&
self.config.version != *"Select" &&
!self.config.download &&
self.config.iron_connected.as_ref() == Some(&self.config.int_name) ||
self.config.iron_connected.as_ref() == Some(&"Both".to_string())
{
self.config.ready_to_flash = true
} else {
self.config.ready_to_flash = false
}
ui.add_space(25.);
// Disable strokes except for hovered
ui.visuals_mut().widgets.active.bg_stroke = eframe::epaint::Stroke{ width: 0., color: egui::Color32::RED};
ui.visuals_mut().widgets.inactive.bg_stroke = eframe::epaint::Stroke{ width: 0., color: egui::Color32::RED};
if !self.config.ready_to_flash {
ui.add_enabled_ui(false, |ui| {
ui.add_sized([80., 10.], egui::Button::new("Update!")).on_disabled_hover_text(
// Tell user why they can not flash
if self.config.iron_connected.as_ref() == Some(&self.config.int_name) ||
self.config.iron_connected.as_ref() == Some(&"Both".to_string())
{ "Select a firmware version or a custom file." }
else if self.config.iron_connected.is_some() &&
self.config.iron_connected.as_ref() != Some(&self.config.int_name) &&
self.config.iron_connected.as_ref() != Some(&"Both".to_string())
{"The selected soldering iron does \nnot match the one currently plugged in."}
else if self.config.version != *"Custom" ||
self.config.picked_path.is_some() &&
self.config.version != *"Select"
{"Connect your soldering iron and \nmake sure it is in flashing mode."}
else
{"Please select a firmware version and\nplug your soldering iron in whilst in flashing mode."}
)
});
} else if ui.add_sized([80., 10.], Button::new("Update")).clicked() {
if self.config.version != *"Custom" {
self.config.download = true;
} else {
self.toasts.dismiss_all_toasts();
self.toasts.info("Flashing.").set_duration(None).set_closable(false);
self.config.flash = true;
}
};
ui.separator();
egui::CollapsingHeader::new("Connection Guide")
.default_open(false)
.show_unindented(ui, |ui|
{
ui.horizontal(|ui|{
ui.add_space(10.);
egui::Frame::none()
.fill(egui::Color32::from_rgb(17, 17, 17))
.rounding(Rounding { nw: 4., ne: 4., sw: 4., se: 4. })
.show(ui, |ui|
{
ui.vertical(|ui|{
// ui.image(self.config.connection_guide_image[self.config.current_step].texture_id(ctx), Vec2 { x: ui.available_width() - 10., y: (ui.available_width() - 10.) / 3.4 });
// let image = Image::from_uri(self.config.connection_guide_image[self.config.current_step]);
if self.config.current_step == 0 {
ui.add(Image::new(egui::include_image!("../../assets/Step1.svg")).fit_to_exact_size(Vec2 { x: ui.available_width() - 10., y: (ui.available_width() - 10.) / 3.4 }));
} else if self.config.current_step == 1 {
ui.add(Image::new(egui::include_image!("../../assets/Step2.svg")).fit_to_exact_size(Vec2 { x: ui.available_width() - 10., y: (ui.available_width() - 10.) / 3.4 }));
} else if self.config.current_step == 2 {
ui.add(Image::new(egui::include_image!("../../assets/Step3.svg")).fit_to_exact_size(Vec2 { x: ui.available_width() - 10., y: (ui.available_width() - 10.) / 3.4 }));
}
ui.horizontal(|ui|{
ui.with_layout(egui::Layout::left_to_right(eframe::emath::Align::TOP), |ui| {
ui.add_space(10.);
if self.config.current_step == 0 {
ui.add_enabled_ui(false, |ui|{
ui.add_sized([80., 10.], Button::new("Previous").fill(egui::Color32::from_rgb(27, 27, 27)))
});
} else if ui.add_sized([80., 10.], Button::new("Previous").fill(egui::Color32::from_rgb(27, 27, 27))).clicked() {
self.config.current_step -= 1;
}
});
ui.with_layout(egui::Layout::right_to_left(eframe::emath::Align::TOP), |ui| {
ui.add_space(10.);
if self.config.current_step == 2 {
ui.add_enabled_ui(false, |ui|{
ui.add_sized([80., 10.], Button::new("Next").fill(egui::Color32::from_rgb(27, 27, 27)))
});
} else if ui.add_sized([80., 10.], Button::new("Next").fill(egui::Color32::from_rgb(27, 27, 27))).clicked() {
self.config.current_step += 1;
}
});
});
ui.add_space(5.);
});
});
});
});
egui::CollapsingHeader::new("Logs")
.default_open(false)
.show_unindented(ui, |ui|
{
ui.horizontal(|ui|{
ui.add_space(10.);
egui::Frame::none()
.fill(egui::Color32::from_rgb(17, 17, 17))
.rounding(Rounding { nw: 4., ne: 4., sw: 4., se: 4. })
.show(ui, |ui|
{
ui.vertical(|ui|{
ui.add_space(10.);
ui.horizontal(|ui|{
ui.add_space(10.);
if ui.add(Button::new("Copy Log").fill(egui::Color32::from_rgb(27, 27, 27))).clicked() {
// ui.output().copied_text = self.config.logs.clone();
ui.output_mut(|i| i.copied_text = self.config.logs.clone());
}
});
ScrollArea::vertical().auto_shrink([false, false]).stick_to_bottom(true).show(ui, |ui|{
ui.horizontal(|ui|{
ui.add_space(10.);
ui.vertical(|ui|{
ui.monospace(self.config.logs.clone());
});
ui.add_space(5.);
});
});
});
});
})
});
self.toasts.show(ctx);
});
}
}
================================================
FILE: src/submodules/mod.rs
================================================
mod connection_poller;
mod flash;
mod main_panel;
mod top_panel;
// mod download;
mod fonts; // will be used for styling the final thing
================================================
FILE: src/submodules/top_panel.rs
================================================
use eframe::egui::{self, menu, Button, TopBottomPanel};
use crate::{FlashSavedConfig, Flasher};
impl Flasher {
pub fn render_header(&mut self, ctx: &egui::Context) {
TopBottomPanel::top("top_panel").show(ctx, |ui| {
menu::bar(ui, |ui| {
ui.vertical_centered(|ui| ui.heading("PineFlash"));
// ui.with_layout(Layout::align(), |ui| {
ui.with_layout(egui::Layout::right_to_left(egui::Align::TOP), |ui| {
ui.add_space(5.);
if ui
.add(Button::new(if self.saved_config.dark_mode {
" "
} else {
" "
}))
.clicked()
{
if self.saved_config.dark_mode {
ctx.set_visuals(egui::Visuals::light());
} else {
ctx.set_visuals(egui::Visuals::dark());
}
self.saved_config.dark_mode = !self.saved_config.dark_mode;
if let Err(..) = confy::store(
"PineFlash",
None,
FlashSavedConfig {
dark_mode: self.saved_config.dark_mode,
},
) {
self.config
.logs
.push_str("Pineflash: Failed to save the app state.")
}
}
})
// })
});
});
}
}