Set application name correctly, mac version now executes helper on startup if needed.

This commit is contained in:
Adam Ierymenko 2013-11-20 12:19:37 -05:00
parent bf02c6661a
commit 14b0639181
2 changed files with 23 additions and 10 deletions

View file

@ -8,7 +8,7 @@ QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = ZeroTierUI TARGET = "ZeroTier One"
TEMPLATE = app TEMPLATE = app
# ZeroTier One must be built before building this, since it links in the # ZeroTier One must be built before building this, since it links in the
@ -25,7 +25,7 @@ HEADERS += mainwindow.h \
aboutwindow.h \ aboutwindow.h \
../node/Node.hpp \ ../node/Node.hpp \
../node/Utils.hpp \ ../node/Utils.hpp \
../node/Defaults.hpp ../node/Defaults.hpp
FORMS += mainwindow.ui \ FORMS += mainwindow.ui \
network.ui \ network.ui \

View file

@ -14,6 +14,8 @@
#include <QFile> #include <QFile>
#include <QMessageBox> #include <QMessageBox>
#include <QDebug> #include <QDebug>
#include <QProcess>
#include <QStringList>
static std::map< unsigned long,std::vector<std::string> > ztReplies; static std::map< unsigned long,std::vector<std::string> > ztReplies;
static QMutex ztReplies_m; static QMutex ztReplies_m;
@ -38,40 +40,51 @@ MainWindow::MainWindow(QWidget *parent) :
ui(new Ui::MainWindow) ui(new Ui::MainWindow)
{ {
ui->setupUi(this); ui->setupUi(this);
this->startTimer(500); this->startTimer(1000);
this->setEnabled(false); // first timer actually enables controls this->setEnabled(false); // gets enabled when updates are received
} }
MainWindow::~MainWindow() MainWindow::~MainWindow()
{ {
delete ui; delete ui;
delete zeroTierClient;
zeroTierClient = (ZeroTier::Node::LocalClient *)0;
} }
void MainWindow::timerEvent(QTimerEvent *event) void MainWindow::timerEvent(QTimerEvent *event)
{ {
QMainWindow::timerEvent(event); QMainWindow::timerEvent(event);
if (!this->isEnabled())
this->setEnabled(true);
if (!zeroTierClient) { if (!zeroTierClient) {
std::string dotAuthFile((QDir::homePath() + QDir::separator() + ".zeroTierOneAuthToken").toStdString()); std::string dotAuthFile((QDir::homePath() + QDir::separator() + ".zeroTierOneAuthToken").toStdString());
std::string authToken; std::string authToken;
if (!ZeroTier::Utils::readFile(dotAuthFile.c_str(),authToken)) { if (!ZeroTier::Utils::readFile(dotAuthFile.c_str(),authToken)) {
#ifdef __APPLE__ #ifdef __APPLE__
QString authHelperPath(QCoreApplication::applicationDirPath() + "/../Applications/ZeroTier One (Authenticate).app"); // Run the little AppleScript hack that asks for admin credentials and
// then installs the auth token file in the current user's home.
QString authHelperPath(QCoreApplication::applicationDirPath() + "/../Resources/helpers/mac/ZeroTier One (Authenticate).app/Contents/MacOS/applet");
if (!QFile::exists(authHelperPath)) { if (!QFile::exists(authHelperPath)) {
// Allow this to also work from the source tree if it's run from there. // Allow this to also work from the source tree if it's run from there.
// This is for debugging purposes but shouldn't harm the live release // This is for debugging purposes and shouldn't harm the live release
// in any way. // in any way.
//authHelperPath = QCoreApplication::applicationFilePath() + "/../ZeroTierUI/helpers/mac/ZeroTier One (Authenticate).app"; authHelperPath = QCoreApplication::applicationDirPath() + "/../../../../ZeroTierUI/helpers/mac/ZeroTier One (Authenticate).app/Contents/MacOS/applet";
if (!QFile::exists(authHelperPath)) { if (!QFile::exists(authHelperPath)) {
QMessageBox::critical(this,"Unable to Locate Helper","Unable to locate authorization helper, cannot obtain authentication token.",QMessageBox::Ok,QMessageBox::NoButton); QMessageBox::critical(this,"Unable to Locate Helper","Unable to locate authorization helper, cannot obtain authentication token.",QMessageBox::Ok,QMessageBox::NoButton);
QApplication::exit(1); QApplication::exit(1);
return;
} }
} }
QProcess::execute(authHelperPath,QStringList());
#endif #endif
if (!ZeroTier::Utils::readFile(dotAuthFile.c_str(),authToken)) {
QMessageBox::critical(this,"Cannot Authorize","Unable to authorize this user to administrate ZeroTier One.\n\nTo do so manually, copy 'authtoken.secret' from the ZeroTier One home directory to '.zeroTierOneAuthToken' in your home directory and set file modes on this file to only be readable by you (e.g. 0600 on Mac or Linux systems).",QMessageBox::Ok,QMessageBox::NoButton);
QApplication::exit(1);
return;
}
} }
zeroTierClient = new ZeroTier::Node::LocalClient(authToken.c_str(),0,&handleZTMessage,this);
} }
} }