diff --git a/command.js b/command.js index 05e6d59..9e39472 100644 --- a/command.js +++ b/command.js @@ -11,6 +11,7 @@ const store = new Store() const {app} = require("electron") const dockerVersion = "gpk_fwmaker_0006" +const cmdVersion = 1 if (process.platform === 'darwin') process.env.PATH = `/usr/local/bin:${process.env.PATH}` const instance = axios.create(); @@ -71,9 +72,19 @@ const responseStreamLog = async (res, mainWindow, channel) => { const command = { upImage: async (mainWindow) => { if (!skipCheckDocker) { + const cmd = async (result) => { + const isDockerVersion = result.stdout.match(dockerVersion) + if (isDockerVersion && state.cmdVersion === cmdVersion) return "docker compose start" + else if (isDockerVersion && state.cmdVersion !== cmdVersion) { + state.cmdVersion = cmdVersion + await store.set('state', state) + return "docker compose up -d --build" + } + else return "docker compose up -d --build --force-recreate" + } + const result = await appExe("docker images") - const cmd = result.stdout.match(dockerVersion) ? "docker compose start" : "docker compose build && docker compose up -d" - const res = spawn(appSpawn(cmd), {shell: true}) + const res = spawn(appSpawn(await cmd(result)), {shell: true}) streamLog(res, mainWindow, true) } }, diff --git a/gpk_fwmaker/firmware-scripts/flaskapp.py b/gpk_fwmaker/firmware-scripts/flaskapp.py index faa1b5e..83129a4 100644 --- a/gpk_fwmaker/firmware-scripts/flaskapp.py +++ b/gpk_fwmaker/firmware-scripts/flaskapp.py @@ -5,6 +5,8 @@ from util.converters import kbd_to_keymap, kbd_to_qmk_info, kbd_to_vial, kbd_to_layout_macro, kbd_to_main_config, layout_str_to_layout_dict, keycodes_md_to_keycode_dict, generate_keycode_conversion_dict, extract_matrix_pins, via_to_kbd import json import re +import os +import datetime import requests from traceback import format_exc @@ -130,9 +132,29 @@ def run_script(): if layout_file: layout_dict = layout_str_to_layout_dict(layout_file) - # keycodes_dict = keycodes_md_to_keycode_dict(read_file('keycodes.md')) # Local fallback - link = "https://raw.githubusercontent.com/qmk/qmk_firmware/master/docs/keycodes.md" - keycodes_dict = keycodes_md_to_keycode_dict(requests.get(link).text) + + def retrieve_keycodes_md(link=None): + print('retrieving keycodes.md from github') + if not link: + link = "https://raw.githubusercontent.com/qmk/qmk_firmware/master/docs/keycodes.md" + return requests.get(link).text + + keycodes_md_path = 'keycodes.md' + + if not os.path.exists(keycodes_md_path): + write_file(keycodes_md_path, retrieve_keycodes_md()) + + timestamp = os.path.getmtime(keycodes_md_path) + datestamp = datetime.datetime.fromtimestamp(timestamp) + + # Update keycodes.md if it's old + if datestamp < datetime.datetime.now() - datetime.timedelta(weeks=104): + content = retrieve_keycodes_md() + keycodes_dict = keycodes_md_to_keycode_dict(content) + write_file(keycodes_md_path, content) + else: # Otherwise just use the cached version + keycodes_dict = keycodes_md_to_keycode_dict(read_file(keycodes_md_path)) + conversion_dict = generate_keycode_conversion_dict(read_file('deprecated_keycodes.txt')) keymap_content = kbd_to_keymap(keyboard, layers, 1, layout_dict, keycodes_dict, conversion_dict) diff --git a/gpk_fwmaker/firmware-scripts/run.py b/gpk_fwmaker/firmware-scripts/run.py index f73617a..a772f12 100644 --- a/gpk_fwmaker/firmware-scripts/run.py +++ b/gpk_fwmaker/firmware-scripts/run.py @@ -3,6 +3,8 @@ from util.converters import kbd_to_layout_macro, kbd_to_qmk_info, kbd_to_vial, kbd_to_keymap, layout_str_to_layout_dict, keycodes_md_to_keycode_dict, generate_keycode_conversion_dict, kbd_to_main_config, extract_matrix_pins import json #import requests +import os +import datetime from util.json_encoders import * # from qmk_firmware/lib/python/qmk/json_encoders.py, for generating info.json import sys @@ -36,10 +38,10 @@ layers=4 mcu_choice = "RP2040" # choose from MCU_PRESETS -#try: # KiCAD Netlist (for pins) -# netlist = read_file('slime88.net') -#except FileNotFoundError: -netlist = None +try: # KiCAD Netlist (for pins) + netlist = read_file('slime88.net') +except FileNotFoundError: + netlist = None mcu_dict = MCU_DICT[mcu_choice] mcu = mcu_dict['mcu'] @@ -81,9 +83,30 @@ keymap_c_path = 'keymap.c' #layout_dict = layout_str_to_layout_dict(read_file('vil.json')) -#link = "https://raw.githubusercontent.com/qmk/qmk_firmware/master/docs/keycodes.md" -#keycodes_dict = keycodes_md_to_keycode_dict(requests.get(link).text) -keycodes_dict = keycodes_md_to_keycode_dict(read_file('keycodes.md')) # Local fallback + +def retrieve_keycodes_md(link=None): + print('retrieving keycodes.md from github') + if not link: + link = "https://raw.githubusercontent.com/qmk/qmk_firmware/master/docs/keycodes.md" + return requests.get(link).text + +keycodes_md_path = 'keycodes.md' + +if not os.path.exists(keycodes_md_path): + write_file(keycodes_md_path, retrieve_keycodes_md()) + +timestamp = os.path.getmtime(keycodes_md_path) +datestamp = datetime.datetime.fromtimestamp(timestamp) + +# Update keycodes.md if it's old (HAVE TEMPORARILY SET TO 2 YEARS) +if datestamp < datetime.datetime.now() - datetime.timedelta(weeks=104): + content = retrieve_keycodes_md() + keycodes_dict = keycodes_md_to_keycode_dict(content) + write_file(keycodes_md_path, content) +else: # Otherwise just use the cached version + keycodes_dict = keycodes_md_to_keycode_dict(read_file(keycodes_md_path)) + + conversion_dict = generate_keycode_conversion_dict(read_file('deprecated_keycodes.txt')) keymap_c_content = kbd_to_keymap(keyboard, layers, 1, None, keycodes_dict, conversion_dict) diff --git a/gpk_fwmaker/firmware-scripts/util/util.py b/gpk_fwmaker/firmware-scripts/util/util.py index 2d3d707..4572b36 100644 --- a/gpk_fwmaker/firmware-scripts/util/util.py +++ b/gpk_fwmaker/firmware-scripts/util/util.py @@ -137,19 +137,19 @@ def extract_matrix_pins(netlist: str, if not mcu_ref: raise Exception(f"MCU Reference (eg. U2) not found in netlist!") + # Might be an issue: works on the presumption that the nets are ordered in a certain way: ie col0, col1, col2... row0, row1, row2... + # (it seems that KiCAD orders them this way, but I'm not sure if it's guaranteed) for net in tree[6]: for prop in net: if prop[0] == "name" and prop[1].lower().startswith("col"): for subprop in net: if subprop[0] == "node" and subprop[1][1] == mcu_ref: - # print(subprop[3][1]) - # print(re.findall(r"(?<="+"P"+r")\w+", subprop[3][1])[0]) - pin = '%s%s' % (output_pin_prefix, re.findall(r"(?<="+schem_pin_prefix+r")\d+", subprop[3][1])[0]) + pin = '%s%s' % (output_pin_prefix, re.findall(schem_pin_prefix+r"([A-Za-z0-9]+)", subprop[3][1])[0]) matrix_pins["cols"].append(pin) elif prop[0] == "name" and prop[1].lower().startswith("row"): for subprop in net: if subprop[0] == "node" and subprop[1][1] == mcu_ref: - pin = '%s%s' % (output_pin_prefix, re.findall(r"(?<="+schem_pin_prefix+r")\d+", subprop[3][1])[0]) + pin = '%s%s' % (output_pin_prefix, re.findall(schem_pin_prefix+r"([A-Za-z0-9]+)", subprop[3][1])[0]) matrix_pins["rows"].append(pin) return matrix_pins diff --git a/package.json b/package.json index 35dc141..db301e9 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "dist:linux": "npm run build && electron-builder -l" }, "name": "gpk_fwbuilder", - "version": "0.10.1", + "version": "0.10.2", "description": "GPK FWBuilder", "homepage": "https://github.com/darakuneko", "author": { @@ -17,31 +17,31 @@ "email": "tvkids@gmail.com" }, "devDependencies": { - "@electron/rebuild": "3.3.0", - "electron": "26.2.1", - "electron-builder": "24.6.4", + "@electron/rebuild": "3.6.0", + "electron": "29.0.0", + "electron-builder": "24.12.0", "webpack-cli": "5.1.4" }, "main": "./index.js", "dependencies": { - "@babel/core": "7.22.20", - "@babel/preset-env": "7.22.20", - "@babel/preset-react": "7.22.15", + "@babel/core": "7.23.9", + "@babel/preset-env": "7.23.9", + "@babel/preset-react": "7.23.3", "@emotion/babel-preset-css-prop": "11.11.0", - "@emotion/react": "11.11.1", + "@emotion/react": "11.11.3", "@emotion/styled": "11.11.0", - "@mui/icons-material": "5.14.9", - "@mui/material": "5.14.10", + "@mui/icons-material": "5.15.10", + "@mui/material": "5.15.10", "ansi-to-html": "0.7.2", - "axios": "1.5.0", + "axios": "1.6.7", "babel-loader": "9.1.3", "electron-store": "8.1.0", "form-data": "4.0.0", - "html-react-parser": "4.2.2", + "html-react-parser": "5.1.7", "node-loader": "2.0.0", "react": "18.2.0", "react-dom": "18.2.0", - "webpack": "5.88.2" + "webpack": "5.90.3" }, "build": { "productName": "GPK FWBuilder", diff --git a/src/context.js b/src/context.js index ce0c6d3..a9ed58d 100644 --- a/src/context.js +++ b/src/context.js @@ -12,6 +12,7 @@ export function StateProvider({children}) { const [state, _setState] = useState({ version: '', + cmdVersion: '', storePath: '', build: { fw: 'QMK', @@ -132,6 +133,7 @@ export function StateProvider({children}) { fwDir: obj.setting.fwDir }, version: obj.version, + cmdVersion: obj.cmdVersion, storePath: obj.storePath, logs: obj.logs, tabDisabled: obj.tabDisabled,