From 975fc47572dcf441dcb431092a6c6a5c1e2b76aa Mon Sep 17 00:00:00 2001 From: dante ruiz Date: Tue, 17 Sep 2019 12:29:48 -0700 Subject: [PATCH] fix qml urls and text fields --- launchers/qt/CMakeLists.txt | 9 + launchers/qt/resources/images/hidePass.png | Bin 0 -> 2106 bytes launchers/qt/resources/images/showPass.png | Bin 0 -> 2240 bytes launchers/qt/resources/qml/Download.qml | 4 +- .../qml/HFBase/CreateAccountBase.qml | 114 ++++++++--- .../qt/resources/qml/HFBase/LoginBase.qml | 183 ++++++++++++++++++ .../resources/qml/HFControls/HFTextField.qml | 30 +++ launchers/qt/resources/qml/Login.qml | 108 +---------- launchers/qt/resources/qml/root.qml | 12 +- launchers/qt/src/Helper.cpp | 5 + launchers/qt/src/Helper.h | 4 + launchers/qt/src/LauncherState.cpp | 8 +- launchers/qt/src/LauncherWindow.h | 5 +- launchers/qt/src/darwin/Helper.mm | 42 ++++ .../src/darwin/NSTask+NSTaskExecveAdditions.h | 9 + .../src/darwin/NSTask+NSTaskExecveAdditions.m | 75 +++++++ 16 files changed, 459 insertions(+), 149 deletions(-) create mode 100644 launchers/qt/resources/images/hidePass.png create mode 100644 launchers/qt/resources/images/showPass.png create mode 100644 launchers/qt/resources/qml/HFBase/LoginBase.qml create mode 100644 launchers/qt/src/Helper.cpp create mode 100644 launchers/qt/src/Helper.h create mode 100644 launchers/qt/src/darwin/Helper.mm create mode 100644 launchers/qt/src/darwin/NSTask+NSTaskExecveAdditions.h create mode 100644 launchers/qt/src/darwin/NSTask+NSTaskExecveAdditions.m diff --git a/launchers/qt/CMakeLists.txt b/launchers/qt/CMakeLists.txt index 9bd4436073..9896e3f5d9 100644 --- a/launchers/qt/CMakeLists.txt +++ b/launchers/qt/CMakeLists.txt @@ -130,10 +130,19 @@ set(src_files src/PathUtils.h src/Unzipper.h src/Unzipper.cpp + src/Helper.h deps/miniz/miniz.h deps/miniz/miniz.cpp ) + +if (APPLE) + set(src_files ${src_files} + src/darwin/Helper.mm + src/darwin/NSTask+NSTaskExecveAdditions.h + src/darwin/NSTask+NSTaskExecveAdditions.m + ) +endif() set(TARGET_NAME ${PROJECT_NAME}) diff --git a/launchers/qt/resources/images/hidePass.png b/launchers/qt/resources/images/hidePass.png new file mode 100644 index 0000000000000000000000000000000000000000..92500ae3f1a42cc1e366b4b5ced24eb9040439c4 GIT binary patch literal 2106 zcmV-A2*vk_P) z2vwEtId5v_i~xZy`Tzk?xJ2%bu{*}$7+7z7fg?|v{$)oWLg#uyneC?Jg+&Ds*JVl_wB6&(j`ooNXEBEI2zkz;&1#`oRt-O2AA@p$b*rTYCC6=4W* z@`3O_w z$(&PZa+0OUb3%@tXhYjP8J5wHlvG6VNUv#Mj`5}Y?bkuKj_;1~!!iEDTW9?L$JjF; zp>&v|(oc{IZJu;FEs)1!+|w3}uJh-K<#d_Pgcal`!VpTc6%9jJ6V(gzne#Q3;4UOx zwj%CO-WOrHJQ@`@j$ytyTJUwZ>{#J{!d;U+vW+;35J#TVTIhir!!S>rQ)zs-=e#@z zmiMWaAjFktxNkeIyh$_66Gzi(^E9WnaMe6p);fx?o;>G7x+;7+vZu9;7PetN!g+Zr z=Fwl#)_l~oA~%Ge-9nrW^M1y9G~EMNfEI+$sA_4aRycofE6?Q(tuU^x_j7rQgtk&*Pe{cDux6ziFX z9T}iCNzHWC`4jOG<~3cK{@Uf~(Q>I0ZZ8O7`hY#L-u0Iq9}mWoylyRzM(h!j(3Zg# zC-^9a@g__E&$2GV0(%%qyC;8nG#*(8>ybwtR3y3B`gtNF4eM8n_k65M40-w! zZ>>TUrca~;E0^7FA_Em^*blZ_kEER{U`rUna(T|p-8QU?oyhlLtvu9>pE-tf3=e>D zq_gBLkJdJiq-ndrbb!^()Q#(@ljqE4SCC>7(O1)R8*`ik?!Q!#leR3ce(8# z55G9l3Hi%I_xE9%l*iOH{iTnZ1&qm)qN+W|u*$C-=`8un(=%Le>rgaH7(%?Ex^-;B zw^mI-#X^a8C)EG=X^0a59mKpOIRuW`TFe2jB7kFIm+nQyv0`7~3f;utc<_x*^&GjZw7 zT4BBCwwC1S+_5+ie&QI$UkG}!;tVm&tC2LeoQ4`(9^=ThcS3A93q{@4D@M zPus-wF-1SWS%_E2&&T+cwto|H{B9Z{{T1e|qi>!zt!b_S;dbO{c)L)UwKQ8cVRI1j ze9R~Y+6+C@HlO7JcU4nB2OU@p~zEMK#`{qjHSp^SiqhlPhkNKMV_nS zThjA|`3&!>7cyZBfnEaA7kLW*pv{o)^G~JODxAeqCP_vj6}9 literal 0 HcmV?d00001 diff --git a/launchers/qt/resources/images/showPass.png b/launchers/qt/resources/images/showPass.png new file mode 100644 index 0000000000000000000000000000000000000000..8f1c0b14f4f89b716ede8f5b2068dc677cf36772 GIT binary patch literal 2240 zcmV;x2tW6UP)6F&h5}$|fFbw9A{j-J zWk>##?0o0k<4i_YWa+1?YgxA8g%{4?71z(r&SYn|JNs;BuiLHt{^ls%O(dVD-F`f> z-`Z`{ntuMkC&V=gNE=^8@EedYZTG zc4`_9L9%|9_Io$z9uxg-^-ABj+ZPfrJG5(pCS$o&ecn7 z6Y_paOq1f7gcrOR_Ki5Sa;;dz$@g30LMzGRO$>W6#mXogylTbpPNMs+c;VmJMk}|k zhpF0qZz6eDk^S!&XBZOVLb`L(8}=fu7}jy#@(Fq+ZMZf4dZ4D=kT%2!VNu>QP5dH} zGOQ!}6buv7hEGID1^qlu)$Wtp=n}|ZzcWlvNk0);gkfU3S|J(IE5pVnLO)bwKJmOC zn3r&vbFwzXd+D&{^R{=1`wQv8`msQTD?msWj#f}CuIXay$#dHyKf`{Adr!B(^(=2i zI=A>mWavjhx{zuvJlNJ=kP_!qoIkv*J^8*%+_#`xG(IcnhfhS>$U{1ep&MWBC6$3C(7 zp%fE_Q+o0{_tJ%sCM2z!oOPcKq1&bAoVc?Tp5KX8P;7oE)pA@`aLZ7WZ$h)C`xx~1 zg@vHKrz_SOtH5q$Z6ay4fri97uBDzm#Sl*GtRx==-9pMe5)7hiD6q4>V^Gj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Apksu?OLcX76+vK6tYB3959~$rz(VgUTbh7e)N_2vd2h^FI#w_ZhqpM};dJpV zT|h22hA`~okggbHNjx2WZrI01zqH#&F7)>COB0X}Dvk(lyEf^`^PP>qR3Lxx zJixz5vG}+K0mTrW2f+68XPll|r+BiD92&oFx4*NW7EqBiJb!KY)$ + +void launchClient(const QString& clientPath, const QString& homePath, const QString& defaultScriptOverride, + const QString& displayName, const QString& contentCachePath, const QString& loginResponseToken = QString()); diff --git a/launchers/qt/src/LauncherState.cpp b/launchers/qt/src/LauncherState.cpp index 9e1587e755..2111568780 100644 --- a/launchers/qt/src/LauncherState.cpp +++ b/launchers/qt/src/LauncherState.cpp @@ -2,6 +2,7 @@ #include "PathUtils.h" #include "Unzipper.h" +#include "Helper.h" #ifdef Q_OS_WIN #include @@ -415,14 +416,15 @@ void LauncherState::launchClient() { setApplicationState(ApplicationState::LaunchingHighFidelity); QDir installDirectory = _launcherDirectory.filePath("interface_install"); - auto clientPath = installDirectory.absoluteFilePath("interface.exe"); + auto clientPath = installDirectory.absoluteFilePath("interface.app/Contents/MacOS/interface"); QString homePath = "hifi://hq"; QString defaultScriptsPath = installDirectory.filePath("scripts/simplifiedUIBootstrapper"); QString displayName = "fixMe"; QString contentCachePath = _launcherDirectory.filePath("cache"); - // TODO Fix parameters + //::launchClient(clientPath, homePath, defaultScriptsPath, displayName, contentCachePath, _loginTokenResponse); + /* // TODO Fix parameters QString params = "--url " + homePath + " --setBookmark hqhome=\"" + homePath + "\"" + " --defaultScriptsOverride " + QDir::toNativeSeparators(defaultScriptsPath) @@ -463,7 +465,7 @@ void LauncherState::launchClient() { // TODO Implement launching of client #else #error UNSUPPORTED PLATFORM -#endif +#endif*/ } void LauncherState::setApplicationState(ApplicationState state) { diff --git a/launchers/qt/src/LauncherWindow.h b/launchers/qt/src/LauncherWindow.h index 376ab9ae7b..02012dc342 100644 --- a/launchers/qt/src/LauncherWindow.h +++ b/launchers/qt/src/LauncherWindow.h @@ -1,3 +1,4 @@ +#include "LauncherState.h" #include #include #include @@ -8,10 +9,10 @@ public: void mousePressEvent(QMouseEvent* event) override; void mouseReleaseEvent(QMouseEvent* event) override; void mouseMoveEvent(QMouseEvent* event) override; - //void setLauncherState(std::shared_ptr launcherState) { _launcherState = launcherState; } + void setLauncherStatePtr(std::shared_ptr launcherState) { _launcherState = launcherState; } private: bool _drag { false }; QPoint _previousMousePos; - ///std::shared_ptr _launcherState { nullptr }; + std::shared_ptr _launcherState { nullptr }; }; diff --git a/launchers/qt/src/darwin/Helper.mm b/launchers/qt/src/darwin/Helper.mm new file mode 100644 index 0000000000..6bc0059fc8 --- /dev/null +++ b/launchers/qt/src/darwin/Helper.mm @@ -0,0 +1,42 @@ +#include "../Helper.h" + +#import "NSTask+NSTaskExecveAdditions.h" + +#import +#include +#include + +void launchClient(const QString& clientPath, const QString& homePath, const QString& defaultScriptOverride, + const QString& displayName, const QString& contentCachePath, const QString& loginTokenResponse) { + + NSString* homeBookmark = [[NSString stringWithFormat:@"hqhome="] stringByAppendingString:homePath.toNSString()]; + NSArray* arguments; + if (!loginTokenResponse.isEmpty()) { + arguments = [NSArray arrayWithObjects: + @"--url" , homePath.toNSString(), + @"--tokens", loginTokenResponse.toNSString(), + @"--cache", contentCachePath.toNSString(), + @"--displayName", displayName.toNSString(), + @"--defaultScriptsOverride", defaultScriptOverride.toNSString(), + @"--setBookmark", homeBookmark, + @"--no-updater", + @"--no-launcher", nil]; + } else { + arguments = [NSArray arrayWithObjects: + @"--url" , homePath.toNSString(), + @"--cache", contentCachePath.toNSString(), + @"--defaultScriptsOverride", defaultScriptOverride.toNSString(), + @"--setBookmark", homeBookmark, + @"--no-updater", + @"--no-launcher", nil]; + } + + NSWorkspace *workspace = [NSWorkspace sharedWorkspace]; + NSURL *url = [NSURL fileURLWithPath:[workspace fullPathForApplication:clientPath.toNSString()]]; + NSLog(@"------> path %@: ", [url path]); + NSTask *task = [[NSTask alloc] init]; + task.launchPath = [url path]; + task.arguments = arguments; + [task replaceThisProcess]; + +} diff --git a/launchers/qt/src/darwin/NSTask+NSTaskExecveAdditions.h b/launchers/qt/src/darwin/NSTask+NSTaskExecveAdditions.h new file mode 100644 index 0000000000..f26a4021de --- /dev/null +++ b/launchers/qt/src/darwin/NSTask+NSTaskExecveAdditions.h @@ -0,0 +1,9 @@ +#import + +NS_ASSUME_NONNULL_BEGIN + +@interface NSTask (NSTaskExecveAdditions) +- (void) replaceThisProcess; +@end + +NS_ASSUME_NONNULL_END diff --git a/launchers/qt/src/darwin/NSTask+NSTaskExecveAdditions.m b/launchers/qt/src/darwin/NSTask+NSTaskExecveAdditions.m new file mode 100644 index 0000000000..6cdf669247 --- /dev/null +++ b/launchers/qt/src/darwin/NSTask+NSTaskExecveAdditions.m @@ -0,0 +1,75 @@ +#import "NSTask+NSTaskExecveAdditions.h" + +#import + +char ** +toCArray(NSArray *array) +{ + // Add one to count to accommodate the NULL that terminates the array. + char **cArray = (char **) calloc([array count] + 1, sizeof(char *)); + if (cArray == NULL) { + NSException *exception = [NSException + exceptionWithName:@"MemoryException" + reason:@"malloc failed" + userInfo:nil]; + @throw exception; + } + char *str; + for (int i = 0; i < [array count]; i++) { + str = (char *) [array[i] UTF8String]; + if (str == NULL) { + NSException *exception = [NSException + exceptionWithName:@"NULLStringException" + reason:@"UTF8String was NULL" + userInfo:nil]; + @throw exception; + } + if (asprintf(&cArray[i], "%s", str) == -1) { + for (int j = 0; j < i; j++) { + free(cArray[j]); + } + free(cArray); + NSException *exception = [NSException + exceptionWithName:@"MemoryException" + reason:@"malloc failed" + userInfo:nil]; + @throw exception; + } + } + return cArray; +} + +@implementation NSTask (NSTaskExecveAdditions) + +- (void) replaceThisProcess { + char **args = toCArray([@[[self launchPath]] arrayByAddingObjectsFromArray:[self arguments]]); + + NSMutableArray *env = [[NSMutableArray alloc] init]; + NSDictionary* environvment = [[NSProcessInfo processInfo] environment]; + for (NSString* key in environvment) { + NSString* environmentVariable = [[key stringByAppendingString:@"="] stringByAppendingString:environvment[key]]; + [env addObject:environmentVariable]; + } + + char** envp = toCArray(env); + // `execve` replaces the current process with `path`. + // It will only return if it fails to replace the current process. + NSLog(@"------------>"); + chdir(dirname(args[0])); + execve(args[0], (char * const *)args, envp); + + NSLog(@"----------- FAILED "); + // If we're here `execve` failed. :( + for (int i = 0; i < [[self arguments] count]; i++) { + free((void *) args[i]); + } + free((void *) args); + + NSException *exception = [NSException + exceptionWithName:@"ExecveException" + reason:[NSString stringWithFormat:@"couldn't execve: %s", strerror(errno)] + userInfo:nil]; + @throw exception; +} + +@end