diff --git a/.github/workflows/clean-libraries.sh b/.github/workflows/clean-libraries.sh new file mode 100644 index 0000000..2c3cd6f --- /dev/null +++ b/.github/workflows/clean-libraries.sh @@ -0,0 +1,12 @@ +#!/bin/bash +cd dist/sonix-flasher +rm libgobject-2.0.so.* \ + libgio-2.0.so.* \ + libgtk-3.so.* \ + libgdk-3.so.* \ + libharfbuzz.so.* \ + libfontconfig.so.* \ + libfreetype.so.* \ + libgpg-error.so.* \ + libstdc++.so.* \ + libglib-2.0.so.* diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index bed48af..4e98e4e 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -2,7 +2,7 @@ name: CI on: push: - branches: [ master ] + branches: [ pyinstaller-switch ] jobs: build-linux: @@ -10,12 +10,12 @@ jobs: steps: - name: Install dependencies - run: sudo apt-get install libusb-1.0-0-dev libudev-dev + run: sudo apt-get install qtbase5-dev libxcomposite-dev libxkbcommon-x11-dev libusb-1.0-0-dev libudev-dev - uses: actions/checkout@v2 - uses: actions/setup-python@v1 with: - python-version: '3.6.x' + python-version: '3.7.x' - name: Setup venv run: | @@ -28,14 +28,16 @@ jobs: - name: Build run: | source venv/bin/activate - fbs freeze - cd target - tar cfJ flasher-linux.tar.xz "Sonix Keyboard Flasher" + pyinstaller sonix-flasher.spec + chmod +x .github/workflows/clean-libraries.sh + .github/workflows/clean-libraries.sh + cd dist + tar cfJ flasher-linux.tar.xz "sonix-flasher" - uses: actions/upload-artifact@v1 with: name: flasher-linux - path: target/flasher-linux.tar.xz + path: dist/flasher-linux.tar.xz build-mac: runs-on: macos-10.15 @@ -44,7 +46,7 @@ jobs: - uses: actions/checkout@v2 - uses: actions/setup-python@v1 with: - python-version: '3.6.x' + python-version: '3.7.x' - name: Setup venv run: | @@ -56,8 +58,8 @@ jobs: - name: Build run: | source venv/bin/activate - fbs freeze - hdiutil create -volname "Sonix Keyboard Flasher" -srcfolder "target/Sonix Keyboard Flasher.app" -ov -format UDZO flasher-mac.dmg + pyinstaller --onefile -n "sonix-flasher" --windowed src/sonix-flasher/main.py + hdiutil create -volname "sonix-flasher" -srcfolder "dist/" -ov -format UDZO flasher-mac.dmg - uses: actions/upload-artifact@v1 with: @@ -71,7 +73,7 @@ jobs: - uses: actions/checkout@v2 - uses: actions/setup-python@v1 with: - python-version: '3.6.x' + python-version: '3.7.x' - name: Setup venv run: | @@ -82,8 +84,8 @@ jobs: - name: Build run: | . .\venv\Scripts\activate.ps1 - fbs freeze - Compress-Archive -Path "target\Sonix Keyboard Flasher" -DestinationPath flasher-win.zip + pyinstaller sonix-flasher.spec + Compress-Archive -Path "dist\sonix-flasher" -DestinationPath flasher-win.zip - uses: actions/upload-artifact@v1 with: diff --git a/.github/workflows/upload_release.yml b/.github/workflows/upload_release.yml index 23dd5ec..8fbd381 100644 --- a/.github/workflows/upload_release.yml +++ b/.github/workflows/upload_release.yml @@ -10,8 +10,10 @@ jobs: create-release-tag: name: Create The Release runs-on: ubuntu-latest + outputs: upload_url: ${{ steps.create_release.outputs.upload_url }} + steps: - name: Create Release id: create_release @@ -23,17 +25,19 @@ jobs: release_name: Release ${{ github.ref }} draft: false prerelease: false + build-linux: runs-on: ubuntu-18.04 needs: create-release-tag + steps: - name: Install dependencies - run: sudo apt-get install libusb-1.0-0-dev libudev-dev + run: sudo apt-get install qtbase5-dev libxcomposite-dev libxkbcommon-x11-dev libusb-1.0-0-dev libudev-dev - uses: actions/checkout@v2 - uses: actions/setup-python@v1 with: - python-version: '3.6.x' + python-version: '3.7.x' - name: Setup venv run: | @@ -46,9 +50,11 @@ jobs: - name: Build run: | source venv/bin/activate - fbs freeze - cd target - tar cfJ flasher-linux.tar.xz "Sonix Keyboard Flasher" + pyinstaller sonix-flasher.spec + chmod +x .github/workflows/clean-libraries.sh + .github/workflows/clean-libraries.sh + cd dist + tar cfJ flasher-linux.tar.xz "sonix-flasher" - name: Upload Release Asset id: upload-release-asset @@ -57,18 +63,19 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: upload_url: ${{ needs.create-release-tag.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps - asset_path: target/flasher-linux.tar.xz + asset_path: dist/flasher-linux.tar.xz asset_name: flasher-linux.tar.xz asset_content_type: application/zip build-mac: runs-on: macos-10.15 needs: create-release-tag + steps: - uses: actions/checkout@v2 - uses: actions/setup-python@v1 with: - python-version: '3.6.x' + python-version: '3.7.x' - name: Setup venv run: | @@ -80,8 +87,8 @@ jobs: - name: Build run: | source venv/bin/activate - fbs freeze - hdiutil create -volname "Sonix Keyboard Flasher" -srcfolder "target/Sonix Keyboard Flasher.app" -ov -format UDZO flasher-mac.dmg + pyinstaller --onefile -n "sonix-flasher" --windowed src/sonix-flasher/main.py + hdiutil create -volname "sonix-flasher" -srcfolder "dist/" -ov -format UDZO flasher-mac.dmg - name: Upload Release Asset id: upload-release-asset @@ -97,11 +104,12 @@ jobs: build-win: runs-on: windows-2019 needs: create-release-tag + steps: - uses: actions/checkout@v2 - uses: actions/setup-python@v1 with: - python-version: '3.6.x' + python-version: '3.7.x' - name: Setup venv run: | @@ -112,8 +120,8 @@ jobs: - name: Build run: | . .\venv\Scripts\activate.ps1 - fbs freeze - Compress-Archive -Path "target\Sonix Keyboard Flasher" -DestinationPath flasher-win.zip + pyinstaller sonix-flasher.spec + Compress-Archive -Path "dist\sonix-flasher" -DestinationPath flasher-win.zip - name: Upload Release Asset id: upload-release-asset diff --git a/.gitignore b/.gitignore index 8144c82..0365f02 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,7 @@ venv -target +build +dist __pycache__ *.pyc .idea +.vscode diff --git a/README.md b/README.md index 6fd6373..46355c7 100644 --- a/README.md +++ b/README.md @@ -1,38 +1,112 @@ # Sonix Flasher +[![CI](https://github.com/SonixQMK/sonix-flasher/actions/workflows/main.yml/badge.svg)](https://github.com/SonixQMK/sonix-flasher/actions/workflows/main.yml) -## Usage +A simple multi-platform utility for flashing QMK firmware into SONiX microcontrolers. + +Sonix Flasher +## Usage ### Entering bootloader -You must boot into bootloader to flash the firmware,you have some choices to do it +To perform firmware flashing, you need to boot your keyboard into bootloader mode. In order to do this, you can use one of the ways described below: -- for stock firmware,click “Reboot to Bootloader” if your keyboard listed in the device list -- Pulled down the BOOT pin -- If you have a jumploader ,It’s strongly recommended to flash the jumploader on SN32F260 since the 260 series can become brick if the bootloader is overrided. [See](https://github.com/SonixQMK/sonix-keyboard-bootloader#entering-the-bootloader) +* If you are on stock firmware (and your keyboard is listed in the device list), click 'Reboot to Bootloader' button +* On flashed keyboard, you should be able to press `Fn + Esc` combination to immediately boot into bootloader +* As a last resort, you can open a keyboard and briefly short BOOT pin of the MCU with GND -### Flash Firmware +**[NOTE]** It’s strongly recommended to flash the jumploader on keyboards with SN32F260 chips since the 260 series can become bricked if the bootloader is overrided. [See](https://github.com/SonixQMK/sonix-keyboard-bootloader#entering-the-bootloader) -- Set qmk_offset to 0x200 only if you have a jumploader flashed in the keyboard +### Flashing firmware -## Compile +Put your keyboard in bootloader mode, set the correct qmk offset (which should be 0x200 only if you have jumploader flashed, so basically only on 260 series chips) and press `Flash QMK...` button -``` +## Compiling +### Requirements +* Python >= 3.7 +* libusb and libudev (only in Linux) + +### Linux + +Open terminal and type: + +```sh python3 -m venv venv -. venv/bin/activate +source venv/bin/activate pip install wheel pip install -r requirements.txt -fbs run -# or "fbs freeze" to create the package +pyinstaller sonix-flasher.spec ``` -Alternatively, if you're running NixOS or have Nix installed, you can run +To run an application, type this in terminal: +`./dist/sonix-flasher/sonix-flasher` -``` +**[NOTE]** To run it for immediate use, just run `run.sh` and it'll set itself up and run. (only for Linux) + +### NixOS + +Alternatively, if you're running NixOS or have Nix installed, you can run: + +```sh nix shell fbs run ``` +### Mac OS + +Open terminal and type: + +```sh +python -m venv venv +source venv/bin/activate +pip install cython +pip install wheel +pip install -r requirements.txt +pyinstaller --onefile -n "sonix-flasher" --windowed src/sonix-flasher/main.py +``` + +To run an application, type this in terminal: +`open -n ./dist/sonix-flasher/sonix-flasher.app` -To run it for immediate use, just run `run.sh` and it'll set itself up and run. +### Windows + +Open Powershell and type: + +```powershell +python -m venv venv +. venv\Scripts\Activate.ps1 +pip install -r requirements.txt +pyinstaller sonix-flasher.spec +``` + +## Running with sudo + +It is highly recommended that instead of running Sonix Flasher with root permissions, you'll make yourself needed udev rules. + +Example of udev rule for Akko: +```sh +SUBSYSTEM=="usb", ATTR{idVendor}=="320f", ATTR{idProduct}=="5013", TAG+="uaccess", TAG+="udev-acl" +KERNEL=="hidraw*", ATTR{idVendor}=="320f", ATTR{idProduct}=="5013", TAG+="uaccess", TAG+="udev-acl" +``` + +Change `ATTR{idVendor}` and `ATTR{idProduct}` to values valid for your keyboard, save a file as `your-keyboard.rules` (name can be changed) in `/etc/udev/rules.d/`, and type in terminal as root: `udevadm control --reload` + +## Troubleshooting +### Keyboard isn't showing in device list + +Before doing anything, check if your keyboard is plugged in properly. + +If you are on Windows, download [Zadig](https://zadig.akeo.ie/) to get VID and PID (first value in USB ID is VID and the second is PID). + +On Linux and Mac OS open terminal and type `lsusb`, then find your keyboard by name to get an USB ID (like in Zadig, first value is VID and the second is PID). + +[Create a new issue](https://github.com/SonixQMK/sonix-flasher/issues/new) with a name of your keyboard and its USB ID in description. + +### Sonix Flasher is crashing with message like this: +``` +Authorization required, but no authorization protocol specified + +qt.qpa.xcb: could not connect to display :0 +qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "" even though it was found. +``` -Run with sudo to flash unless you have the correct udev rules set up. +This means that you are probably trying to run application with sudo on (X)Wayland session. (X)Wayland doesn't support running applications with sudo because of security reasons. You should refer to [Running with sudo](#running-with-sudo) section, or check [here](https://wiki.archlinux.org/title/Running_GUI_applications_as_root#Wayland) for a workaround. diff --git a/requirements.txt b/requirements.txt index 93ea466..b7c1651 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,9 +1,4 @@ -altgraph==0.17 -fbs==0.8.6 -future==0.18.2 -hidapi==0.9.0.post2 -macholib==1.14 -pefile==2019.4.18 -PyInstaller==3.4 -PyQt5==5.15.2 -sip==5.0.0 +hidapi==0.11.2 +PyInstaller +PyQt5 +sip diff --git a/run.sh b/run.sh index a81eb91..00bca7c 100755 --- a/run.sh +++ b/run.sh @@ -1,6 +1,7 @@ #!/bin/bash python3 -m venv venv -. venv/bin/activate +source venv/bin/activate pip install wheel pip install -r requirements.txt -fbs run +pyinstaller sonix-flasher.spec +./dist/sonix-flasher/sonix-flasher diff --git a/sonix-flasher.spec b/sonix-flasher.spec new file mode 100644 index 0000000..b6bdd98 --- /dev/null +++ b/sonix-flasher.spec @@ -0,0 +1,48 @@ +# -*- mode: python ; coding: utf-8 -*- + +block_cipher = None + + +a = Analysis( + ['src/sonix-flasher/main.py'], + pathex=[], + binaries=[], + datas=[], + hiddenimports=[], + hookspath=[], + hooksconfig={}, + runtime_hooks=[], + excludes=[], + win_no_prefer_redirects=False, + win_private_assemblies=False, + cipher=block_cipher, + noarchive=False) + +pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher) + +exe = EXE( + pyz, + a.scripts, + [], + exclude_binaries=True, + name='sonix-flasher', + debug=False, + bootloader_ignore_signals=False, + strip=False, + upx=False, + console=True, + disable_windowed_traceback=False, + argv_emulation=False, + target_arch=None, + codesign_identity=None, + entitlements_file=None) + +coll = COLLECT( + exe, + a.binaries, + a.zipfiles, + a.datas, + strip=False, + upx=False, + upx_exclude=[], + name='sonix-flasher') diff --git a/src/build/settings/base.json b/src/build/settings/base.json deleted file mode 100644 index 490a8ed..0000000 --- a/src/build/settings/base.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "app_name": "Sonix Keyboard Flasher", - "author": "xyz, jindaxia", - "main_module": "src/main/python/main.py", - "version": "0.1.0" -} \ No newline at end of file diff --git a/src/build/settings/linux.json b/src/build/settings/linux.json deleted file mode 100644 index 7a64c95..0000000 --- a/src/build/settings/linux.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "categories": "Utility;", - "description": "", - "author_email": "", - "url": "" -} \ No newline at end of file diff --git a/src/build/settings/mac.json b/src/build/settings/mac.json deleted file mode 100644 index f7bd610..0000000 --- a/src/build/settings/mac.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "mac_bundle_identifier": "" -} \ No newline at end of file diff --git a/src/main/icons/Icon.ico b/src/main/icons/Icon.ico deleted file mode 100644 index 3312d86..0000000 Binary files a/src/main/icons/Icon.ico and /dev/null differ diff --git a/src/main/icons/README.md b/src/main/icons/README.md deleted file mode 100644 index c6c4194..0000000 --- a/src/main/icons/README.md +++ /dev/null @@ -1,11 +0,0 @@ -![Sample app icon](linux/128.png) - -This directory contains the icons that are displayed for your app. Feel free to -change them. - -The difference between the icons on Mac and the other platforms is that on Mac, -they contain a ~5% transparent margin. This is because otherwise they look too -big (eg. in the Dock or in the app switcher). - -You can create Icon.ico from the .png files with -[an online tool](http://icoconvert.com/Multi_Image_to_one_icon/). \ No newline at end of file diff --git a/src/main/icons/base/16.png b/src/main/icons/base/16.png deleted file mode 100755 index f7d02dc..0000000 Binary files a/src/main/icons/base/16.png and /dev/null differ diff --git a/src/main/icons/base/24.png b/src/main/icons/base/24.png deleted file mode 100755 index faa6710..0000000 Binary files a/src/main/icons/base/24.png and /dev/null differ diff --git a/src/main/icons/base/32.png b/src/main/icons/base/32.png deleted file mode 100755 index 36b25e8..0000000 Binary files a/src/main/icons/base/32.png and /dev/null differ diff --git a/src/main/icons/base/48.png b/src/main/icons/base/48.png deleted file mode 100755 index 4a5dcbd..0000000 Binary files a/src/main/icons/base/48.png and /dev/null differ diff --git a/src/main/icons/base/64.png b/src/main/icons/base/64.png deleted file mode 100755 index 4b0a423..0000000 Binary files a/src/main/icons/base/64.png and /dev/null differ diff --git a/src/main/icons/linux/1024.png b/src/main/icons/linux/1024.png deleted file mode 100755 index 2248377..0000000 Binary files a/src/main/icons/linux/1024.png and /dev/null differ diff --git a/src/main/icons/linux/128.png b/src/main/icons/linux/128.png deleted file mode 100755 index 05b2b35..0000000 Binary files a/src/main/icons/linux/128.png and /dev/null differ diff --git a/src/main/icons/linux/256.png b/src/main/icons/linux/256.png deleted file mode 100755 index 578fdc7..0000000 Binary files a/src/main/icons/linux/256.png and /dev/null differ diff --git a/src/main/icons/linux/512.png b/src/main/icons/linux/512.png deleted file mode 100755 index 0fbac4f..0000000 Binary files a/src/main/icons/linux/512.png and /dev/null differ diff --git a/src/main/icons/mac/1024.png b/src/main/icons/mac/1024.png deleted file mode 100644 index c1c8691..0000000 Binary files a/src/main/icons/mac/1024.png and /dev/null differ diff --git a/src/main/icons/mac/128.png b/src/main/icons/mac/128.png deleted file mode 100644 index de9bee6..0000000 Binary files a/src/main/icons/mac/128.png and /dev/null differ diff --git a/src/main/icons/mac/256.png b/src/main/icons/mac/256.png deleted file mode 100644 index c3a68b9..0000000 Binary files a/src/main/icons/mac/256.png and /dev/null differ diff --git a/src/main/icons/mac/512.png b/src/main/icons/mac/512.png deleted file mode 100644 index b2fc07e..0000000 Binary files a/src/main/icons/mac/512.png and /dev/null differ diff --git a/src/main/python/main.py b/src/sonix-flasher/main.py similarity index 98% rename from src/main/python/main.py rename to src/sonix-flasher/main.py index dd56a65..85299f0 100644 --- a/src/main/python/main.py +++ b/src/sonix-flasher/main.py @@ -1,6 +1,5 @@ -from fbs_runtime.application_context.PyQt5 import ApplicationContext from PyQt5.QtCore import Qt, pyqtSignal -from PyQt5.QtWidgets import QWidget, QLabel, QPushButton, QVBoxLayout, QHBoxLayout, QProgressBar, QGroupBox, \ +from PyQt5.QtWidgets import QApplication, QWidget, QLabel, QPushButton, QVBoxLayout, QHBoxLayout, QProgressBar, QGroupBox, \ QComboBox, QSizePolicy, QToolButton, QMessageBox, QFileDialog, QRadioButton import sys @@ -608,7 +607,7 @@ def excepthook(exc_type, exc_value, exc_tb): else: cli_mode = False - appctxt = ApplicationContext() + app = QApplication(sys.argv) window = MainWindow() window.resize(600, 500) if get_platform() == "Linux": @@ -621,5 +620,4 @@ def excepthook(exc_type, exc_value, exc_tb): window.show() sys.excepthook = excepthook - exit_code = appctxt.app.exec_() - sys.exit(exit_code) + sys.exit(app.exec_())