Skip to content

Commit

Permalink
Merge pull request #213 from builder555/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
builder555 authored Jan 31, 2024
2 parents 6453309 + f41ca34 commit 7222b95
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 115 deletions.
4 changes: 2 additions & 2 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Why focus on soldering when you can play with the settings instead? With this ap

4. **Windows**:
* right click on the zip, properties> general, check box to Unblock, then extract ([reference](https://github.com/builder555/PineSAM/discussions/106#discussion-4960445)).
* Run `Pinesam.exe`
* Run `PineSAM.exe`
* Approve any pop-up warnings.
* Open http://localhost:8080 in your normal browser (the page will not open automatically).
* Usage guide [here](https://builder555.github.io/PineSAM/user-guide/usage/).
Expand Down Expand Up @@ -150,7 +150,7 @@ You can access the settings remotely once the app is running on the main PC/lapt
* possible reason: you paired your Pinecil using system settings. solution: unpair it from all other places.
* possible reason: using older firmware (below 2.21). solution: [flash](https://github.com/Ralim/IronOS/discussions/1518#discussioncomment-4866637) current [BLE firmware](https://github.com/Ralim/IronOS/releases/tag/v2.21); below IronOS 2.21 only BETA versions will work with PineSAM.

3. Pinecil script terminal crashes on start of script: incompatible version of IronOS, check/update firmware see above.
3. PineSAM script terminal crashes on start of script: incompatible version of IronOS, check/update firmware see above.

4. Windows Powershell issue
* windows by default does not allow any scripts to run in powershell. Make sure the zip file property is _Unblock_ ([reference](https://github.com/builder555/PineSAM/discussions/106#discussion-4960445)) and set powershell to remotesigned with:<br/>
Expand Down
65 changes: 0 additions & 65 deletions backend/bluetooth_check.py

This file was deleted.

34 changes: 20 additions & 14 deletions backend/io_utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import sys
import os
import sys
import sys
import argparse


def get_resource_path(relative_path, max_levels=3):
Expand All @@ -20,15 +19,22 @@ def get_resource_path(relative_path, max_levels=3):
return os.path.join(base_path, relative_path)


def parse_cmd_args(default_host, default_port):
host = sys.argv[1] if len(sys.argv) > 1 else default_host
port = int(sys.argv[2]) if len(sys.argv) > 2 else default_port

if len(sys.argv) > 1 and sys.argv[1] in ("-h", "--help"):
print(f"Usage: {sys.argv[0]} [host] [port]")
print(f"Example: {sys.argv[0]} 127.0.0.1 8080")
print(f"Default host: {default_host}")
print(f"Default port: {default_port}")
return None, None

return host, port
def parse_cmd_args(default_host, default_port) -> argparse.Namespace:
parser = argparse.ArgumentParser(description="PineSAM - Pinecil v2 Control")
parser.add_argument(
"host",
nargs="?",
default=default_host,
help="Host address (default: %(default)s)",
)
parser.add_argument(
"port",
nargs="?",
type=int,
default=default_port,
help="Port number (default: %(default)s)",
)
parser.add_argument(
"--no-open", action="store_true", help="Do not open browser page automatically."
)
return parser.parse_args()
32 changes: 21 additions & 11 deletions backend/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from version_checker import VersionChecker
import logging
from io_utils import parse_cmd_args, get_resource_path
from bluetooth_check import run_checks as run_bluetooth_checks
from rich.logging import RichHandler

LOG_LEVEL = os.environ.get("LOG_LEVEL", "INFO").upper()
Expand All @@ -21,18 +20,22 @@
DEFAULT_HOST = "0.0.0.0"
DEFAULT_PORT = 8080

import webbrowser


async def open_browser(url):
await asyncio.sleep(5)
webbrowser.open(url)


async def log(msg):
logging.info(msg)


async def main(stop_event=asyncio.Event()):
host, port = parse_cmd_args(DEFAULT_HOST, DEFAULT_PORT)
if not host or not port:
args = parse_cmd_args(DEFAULT_HOST, DEFAULT_PORT)
if not args.host or not args.port:
return
if sys.platform == "linux":
bt_ok, bt_errors = run_bluetooth_checks()
if not bt_ok:
logging.warning(
"Bluetooth check failed. Application may not work as expected."
)
logging.warning("\n" + "\n".join(bt_errors))
pinesam_url = "https://api.github.com/repos/builder555/PineSAM/releases/latest"
ironos_url = "https://api.github.com/repos/Ralim/IronOS/releases/latest"
app_version_manager = VersionChecker(
Expand All @@ -52,9 +55,16 @@ async def main(stop_event=asyncio.Event()):
ws_handler = WebSocketHandler(command_processor, ui_path=ui_path)
pinecil_monitor = PinecilMonitor(pinecil_finder, ws_handler.broadcast)
tasks = [
asyncio.create_task(ws_handler.serve(host, port)),
asyncio.create_task(ws_handler.serve(args.host, args.port)),
asyncio.create_task(pinecil_monitor.monitor(stop_event)),
]
if not args.no_open:
url = f"http://{args.host}:{args.port}"
tasks.append(asyncio.create_task(open_browser(url)))
else:
tasks.append(
asyncio.create_task(log(f"Open browser at http://{args.host}:{args.port}"))
)
try:
await asyncio.gather(*tasks)
except KeyboardInterrupt:
Expand Down
2 changes: 1 addition & 1 deletion ci/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ Push-Location ui
npm run build
Pop-Location

pyinstaller --onefile --name Pinecil --hidden-import=winrt.windows.foundation.collections --add-data "./version.txt;./" --add-data "./ui/dist;./gui" backend/main.py
pyinstaller --onefile --name PineSAM --hidden-import=winrt.windows.foundation.collections --add-data "./version.txt;./" --add-data "./ui/dist;./gui" backend/main.py
2 changes: 1 addition & 1 deletion ci/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ pushd ui || exit 2
npm run build
popd || exit 2

pyinstaller --onefile --name Pinecil --add-data "./version.txt:./" --add-data "./ui/dist:./gui" backend/main.py --hidden-import=typing_extensions --collect-submodules dbus_fast
pyinstaller --onefile --name PineSAM --add-data "./version.txt:./" --add-data "./ui/dist:./gui" backend/main.py --hidden-import=typing_extensions --collect-submodules dbus_fast
2 changes: 1 addition & 1 deletion ci/package.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ exit 1
$zip_path = "$(Get-Location)/$name.zip"

Push-Location dist
Compress-Archive -Path Pinecil.exe -DestinationPath $zip_path -Force
Compress-Archive -Path PineSAM.exe -DestinationPath $zip_path -Force
Pop-Location

Write-Output "asset_path=$zip_path" >> $Env:GITHUB_OUTPUT
Expand Down
2 changes: 1 addition & 1 deletion ci/package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ fi
zip_path="$(dirname "${PWD}")/${name}.zip"

pushd dist || exit
zip -r "${zip_path}" Pinecil
zip -r "${zip_path}" PineSAM

popd || exit
zip -u -j "${zip_path}" ci/start.sh
Expand Down
22 changes: 5 additions & 17 deletions ci/start.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/bash
cd "$(dirname "$0")"

# ensure Pinecil binary is present
if [ ! -f ./Pinecil ] ; then
# ensure PineSAM binary is present
if [ ! -f ./PineSAM ] ; then
echo "This file is used to run a built version of the project."
echo "Please run setup-dev.sh and use run-dev.sh to run the project"
exit
Expand All @@ -12,21 +12,9 @@ if [ "$(uname)" == "Darwin" ]; then
# for MacOS, remove the quarantine attributes
# this is needed because the mac will not execute binaries that are downloaded from the internet
# see https://developer.apple.com/library/archive/technotes/tn2459/_index.html
if xattr -p com.apple.quarantine ./Pinecil >/dev/null 2>&1; then
find ./ -name Pinecil | xargs xattr -rd com.apple.quarantine
if xattr -p com.apple.quarantine ./PineSAM >/dev/null 2>&1; then
xargs xattr -rd com.apple.quarantine ./PineSAM
fi
fi

./Pinecil &
pid1=$!

sleep 5

if [ "$(uname)" == "Darwin" ]; then
open http://localhost:8080/
else
xdg-open http://localhost:8080/
fi

trap "kill $pid1" EXIT
wait $pid1
./PineSAM
2 changes: 1 addition & 1 deletion docs/install-guide/troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
2. bleak causes Python to crash on Mac: https://github.com/hbldh/bleak/issues/768
* possible solution: give access to iTerm (or whichever terminal you use) to Bluetooth in Settings

3. Pinecil script terminal crashes on start of script: incompatible version of IronOS, check/update firmware see [](https://wiki.pine64.org/wiki/Pinecil_Firmware#Update_V2:_Windows).
3. PineSAM script terminal crashes on start of script: incompatible version of IronOS, check/update firmware see [](https://wiki.pine64.org/wiki/Pinecil_Firmware#Update_V2:_Windows).

4. Windows Powershell issue
* windows by default does not allow any scripts to run in powershell. Make sure the zip file property is _Unblock_ ([reference](https://github.com/builder555/PineSAM/discussions/106#discussion-4960445)) and set powershell to remotesigned with:<br/>
Expand Down
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.2.3
2.2.5

0 comments on commit 7222b95

Please sign in to comment.