diff --git a/androidprojectmodifier.cpp b/androidprojectmodifier.cpp index 5e7519b..60da22f 100644 --- a/androidprojectmodifier.cpp +++ b/androidprojectmodifier.cpp @@ -147,7 +147,7 @@ QString AndroidProjectModifier::resizeImage(const QHash imageD convert.waitForFinished(); if (convert.exitCode() != 0) { - qWarning() << "Warning: could not resize the image. Do you have the 'convert' utility installed?"; + throw QString("Warning: could not resize the image. Do you have the 'convert' utility installed?"); } return tmpFile.fileName(); diff --git a/coloredstring.cpp b/coloredstring.cpp new file mode 100644 index 0000000..edd4cb7 --- /dev/null +++ b/coloredstring.cpp @@ -0,0 +1,71 @@ +#include "coloredstring.h" + +QMap ColoredString::map = QMap({ + {"green", "32"} +}); + +ColoredString::ColoredString(const QString text) +{ + m_text = text; +} + +QString ColoredString::toString() const +{ + enum Mode { // todo come up with better names + String, + Tag, + TagString, + TagTag + }; + QString out; + + auto mode = Mode::String; + QString currentTag; + + for (int i = 0; i < m_text.length(); ++i) { + auto letter = m_text.at(i); + switch (mode) { + case String: + if (letter == "<") { + mode = Tag; + continue; + } + out += letter; + break; + case Tag: + if (letter == ">") { + if (!map.contains(currentTag)) { + mode = String; + continue; + } + out += "\033[0;" + map.value(currentTag) + "m"; + mode = TagString; + } else { + currentTag += letter; + } + break; + case TagString: + if (letter == "<") { + mode = TagTag; + continue; + } + out += letter; + break; + case TagTag: + if (letter != ">") { + continue; + } + out += "\033[0m"; + currentTag = ""; + mode = String; + break; + } + } + + return out; +} + +ColoredString::operator QString() const +{ + return toString(); +} diff --git a/coloredstring.h b/coloredstring.h new file mode 100644 index 0000000..6991062 --- /dev/null +++ b/coloredstring.h @@ -0,0 +1,20 @@ +#ifndef COLOREDSTRING_H +#define COLOREDSTRING_H + +#include +#include + +class ColoredString +{ +public: + explicit ColoredString(const QString text); + QString toString() const; + + operator QString() const; + +private: + QString m_text; + static QMap map; +}; + +#endif // COLOREDSTRING_H diff --git a/githelper.h b/githelper.h index 41a1ddc..900f62a 100644 --- a/githelper.h +++ b/githelper.h @@ -26,7 +26,7 @@ class GitHelper private: const QString URL = "https://github.com/GoogleChromeLabs/svgomg-twa"; - const QString COMMIT = "a6ccc67577f335bda13532257138ef68cac901d8"; + const QString COMMIT = "55a8c47056085638e99de307b66e0df9bb81bccf"; void gitError(int status); }; diff --git a/main.cpp b/main.cpp index 8567597..953a3ef 100644 --- a/main.cpp +++ b/main.cpp @@ -4,6 +4,7 @@ #include "githelper.h" #include "websiteparser.h" #include "androidprojectmodifier.h" +#include "coloredstring.h" int main(int argc, char *argv[]) { @@ -11,8 +12,8 @@ int main(int argc, char *argv[]) try { QCoreApplication app(argc, argv); - if(app.arguments().count() < 4 || app.arguments().contains("--help")) { - const QString binaryName = app.arguments().at(0); + if (app.arguments().count() < 4 || app.arguments().contains("--help")) { + const auto binaryName = app.arguments().at(0); io.writeError("Usage: " + binaryName + " androidPackageName pwaUrl outputPath [--manifest path-to-manifest]"); io.writeError("Example: " + binaryName + " com.vendor.pwa https://pwa.vendor.com ./my-cool-pwa"); @@ -22,9 +23,9 @@ int main(int argc, char *argv[]) QString manifestPath; - if(app.arguments().contains("--manifest")) { - int index = app.arguments().indexOf("--manifest") + 1; - if(app.arguments().count() <= index) { + if (app.arguments().contains("--manifest")) { + auto index = app.arguments().indexOf("--manifest") + 1; + if (app.arguments().count() <= index) { qCritical() << "You must set a value for --manifest"; return 1; } @@ -55,6 +56,15 @@ int main(int argc, char *argv[]) gitHelper.initialCommit(outputDirectory); io.writeln("Successfully created, you can now open the project in Android Studio and build the apk"); + io.writeln(""); + io.writeln(ColoredString("Don't forget to include the Digital Asset Link on your website at " + url + "/.well-known/assetlinks.json:")); + io.writeln(ColoredString( + "[{ \n" + " \"relation\": [\"delegate_permission/common.handle_all_urls\"], \n" + " \"target\": {\"namespace\": \"android_app\", \"package_name\": \"" + packageName + "\", \n" + " \"sha256_cert_fingerprints\": [\"hash_of_app_certificate\"]} \n" + "}]" + )); return 0; } catch (QString e) { diff --git a/pwa-to-twa.pro b/pwa-to-twa.pro index d9a4bae..ffc55fc 100644 --- a/pwa-to-twa.pro +++ b/pwa-to-twa.pro @@ -24,6 +24,7 @@ DEFINES += QT_DEPRECATED_WARNINGS SOURCES += \ androidprojectmodifier.cpp \ + coloredstring.cpp \ githelper.cpp \ inputoutput.cpp \ main.cpp \ @@ -36,6 +37,7 @@ else: unix:!android: target.path = /opt/$${TARGET}/bin HEADERS += \ androidprojectmodifier.h \ + coloredstring.h \ githelper.h \ inputoutput.h \ websiteparser.h