From e1fdc254d6b362440d5e2895b33a2d4865e73e50 Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Wed, 19 Aug 2020 21:16:13 -0400 Subject: implement install extension in electron/vuetify --- electron/src/renderer/App.vue | 21 ++++- .../src/renderer/components/InstallPalettes.vue | 104 ++++++++++++++++----- lib/api/install.py | 17 ++-- 3 files changed, 110 insertions(+), 32 deletions(-) diff --git a/electron/src/renderer/App.vue b/electron/src/renderer/App.vue index 7888d968..7579d04e 100644 --- a/electron/src/renderer/App.vue +++ b/electron/src/renderer/App.vue @@ -1,15 +1,26 @@ diff --git a/electron/src/renderer/components/InstallPalettes.vue b/electron/src/renderer/components/InstallPalettes.vue index 73fd2865..728088b8 100644 --- a/electron/src/renderer/components/InstallPalettes.vue +++ b/electron/src/renderer/components/InstallPalettes.vue @@ -1,20 +1,67 @@ @@ -25,20 +72,35 @@ export default { name: "InstallPalettes", data: function () { return { - path: "", + path: null, + installing: false, + step: "pick", + error: null } }, methods: { install() { - alert("install button clicked") + this.installing = true + inkStitch.post('install/palettes', {path: this.path.path || this.path.name}).then(response => { + this.step = "done" + }).catch(error => { + this.step = "error" + this.error = error.response.data.error + }).then(() => { + this.installing = false + }) }, - cancel() { - alert("cancel button clicked") + close() { + window.close() + }, + retry() { + this.installing = false + this.step = "pick" } }, created: function () { - inkStitch.get("/install/default-path").then(response => { - this.path = response.data + inkStitch.get("install/default-path").then(response => { + this.path = new File([""], response.data, {}) }) } } diff --git a/lib/api/install.py b/lib/api/install.py index f379f142..20138973 100644 --- a/lib/api/install.py +++ b/lib/api/install.py @@ -2,19 +2,24 @@ import os import sys from glob import glob -from flask import Blueprint, request +from flask import Blueprint, jsonify, request from ..utils import get_bundled_dir, guess_inkscape_config_path install = Blueprint('install', __name__) -@install.route('/palettes') +@install.route('/palettes', methods=["POST"]) def palettes(): - base_path = request.json.get('path') or guess_inkscape_config_path() - path = os.path.join(base_path, 'palettes') - src_dir = get_bundled_dir('palettes') - copy_files(glob(os.path.join(src_dir, "*")), path) + try: + base_path = request.json.get('path') or guess_inkscape_config_path() + path = os.path.join(base_path, 'palettes') + src_dir = get_bundled_dir('palettes') + copy_files(glob(os.path.join(src_dir, "*")), path) + except Exception, exc: + return jsonify({"error": str(exc)}), 500 + + return jsonify({"status": "success"}) if sys.platform == "win32": -- cgit v1.2.3