Skip to content

Commit

Permalink
switch to latest commit, change warning into error, add Digital Asset…
Browse files Browse the repository at this point in the history
…s Link info
  • Loading branch information
RikudouSage committed Aug 10, 2020
1 parent 5790a36 commit 997a6e0
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 7 deletions.
2 changes: 1 addition & 1 deletion androidprojectmodifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ QString AndroidProjectModifier::resizeImage(const QHash<QString, QString> 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();
Expand Down
71 changes: 71 additions & 0 deletions coloredstring.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#include "coloredstring.h"

QMap<QString, QString> ColoredString::map = QMap<QString, QString>({
{"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();
}
20 changes: 20 additions & 0 deletions coloredstring.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#ifndef COLOREDSTRING_H
#define COLOREDSTRING_H

#include <QString>
#include <QMap>

class ColoredString
{
public:
explicit ColoredString(const QString text);
QString toString() const;

operator QString() const;

private:
QString m_text;
static QMap<QString, QString> map;
};

#endif // COLOREDSTRING_H
2 changes: 1 addition & 1 deletion githelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
Expand Down
20 changes: 15 additions & 5 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@
#include "githelper.h"
#include "websiteparser.h"
#include "androidprojectmodifier.h"
#include "coloredstring.h"

int main(int argc, char *argv[])
{
InputOutput io;
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");
Expand All @@ -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;
}
Expand Down Expand Up @@ -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 <green>" + url + "/.well-known/assetlinks.json</>:"));
io.writeln(ColoredString(
"[{ \n"
" \"relation\": [\"delegate_permission/common.handle_all_urls\"], \n"
" \"target\": {\"namespace\": \"android_app\", \"package_name\": \"<green>" + packageName + "</>\", \n"
" \"sha256_cert_fingerprints\": [\"<green>hash_of_app_certificate</>\"]} \n"
"}]"
));

return 0;
} catch (QString e) {
Expand Down
2 changes: 2 additions & 0 deletions pwa-to-twa.pro
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ DEFINES += QT_DEPRECATED_WARNINGS

SOURCES += \
androidprojectmodifier.cpp \
coloredstring.cpp \
githelper.cpp \
inputoutput.cpp \
main.cpp \
Expand All @@ -36,6 +37,7 @@ else: unix:!android: target.path = /opt/$${TARGET}/bin

HEADERS += \
androidprojectmodifier.h \
coloredstring.h \
githelper.h \
inputoutput.h \
websiteparser.h

0 comments on commit 997a6e0

Please sign in to comment.