diff --git a/Telegram/SourceFiles/app.cpp b/Telegram/SourceFiles/app.cpp index 1cb5d7e69..f768299f2 100644 --- a/Telegram/SourceFiles/app.cpp +++ b/Telegram/SourceFiles/app.cpp @@ -355,8 +355,13 @@ namespace { // {fulltype} is in "{type}-{tag}-{tag}-{tag}" format // if we find "all" tag we return the restriction string - QStringList typeTags = fullRestriction.mid(0, fullTypeEnd).split('-').mid(1); - if (typeTags.contains(qsl("all"))) { + auto typeTags = fullRestriction.mid(0, fullTypeEnd).split('-').mid(1); +#ifndef OS_MAC_STORE + auto restrictionApplies = typeTags.contains(qsl("all")); +#else // OS_MAC_STORE + auto restrictionApplies = typeTags.contains(qsl("all")) || typeTags.contains(qsl("ios")); +#endif // OS_MAC_STORE + if (restrictionApplies) { return fullRestriction.midRef(fullTypeEnd + 1).trimmed().toString(); } return QString(); diff --git a/Telegram/SourceFiles/application.cpp b/Telegram/SourceFiles/application.cpp index c2eeae415..b5b1d64ed 100644 --- a/Telegram/SourceFiles/application.cpp +++ b/Telegram/SourceFiles/application.cpp @@ -92,7 +92,12 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv) { QByteArray d(QFile::encodeName(QDir(cWorkingDir()).absolutePath())); char h[33] = { 0 }; hashMd5Hex(d.constData(), d.size(), h); +#ifndef OS_MAC_STORE _localServerName = psServerPrefix() + h + '-' + cGUIDStr(); +#else // OS_MAC_STORE + h[4] = 0; // use only first 4 chars + _localServerName = psServerPrefix() + h; +#endif // OS_MAC_STORE connect(&_localSocket, SIGNAL(connected()), this, SLOT(socketConnected())); connect(&_localSocket, SIGNAL(disconnected()), this, SLOT(socketDisconnected())); diff --git a/Telegram/SourceFiles/config.h b/Telegram/SourceFiles/config.h index 6defe6349..ab0ac7de7 100644 --- a/Telegram/SourceFiles/config.h +++ b/Telegram/SourceFiles/config.h @@ -185,14 +185,22 @@ inline bool isServiceUser(uint64 id) { #ifdef Q_OS_WIN inline const GUID &cGUID() { +#ifndef OS_MAC_STORE static const GUID gGuid = { 0x87a94ab0, 0xe370, 0x4cde, { 0x98, 0xd3, 0xac, 0xc1, 0x10, 0xc5, 0x96, 0x7d } }; +#else // OS_MAC_STORE + static const GUID gGuid = { 0xe51fb841, 0x8c0b, 0x4ef9, { 0x9e, 0x9e, 0x5a, 0x0, 0x78, 0x56, 0x76, 0x27 } }; +#endif // OS_MAC_STORE return gGuid; } #endif inline const char *cGUIDStr() { +#ifndef OS_MAC_STORE static const char *gGuidStr = "{87A94AB0-E370-4cde-98D3-ACC110C5967D}"; +#else // OS_MAC_STORE + static const char *gGuidStr = "{E51FB841-8C0B-4EF9-9E9E-5A0078567627}"; +#endif // OS_MAC_STORE return gGuidStr; } diff --git a/Telegram/SourceFiles/pspecific_mac.h b/Telegram/SourceFiles/pspecific_mac.h index e62729e9a..b77374387 100644 --- a/Telegram/SourceFiles/pspecific_mac.h +++ b/Telegram/SourceFiles/pspecific_mac.h @@ -20,7 +20,11 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "pspecific_mac_p.h" inline QString psServerPrefix() { +#ifndef OS_MAC_STORE return qsl("/tmp/"); +#else // OS_MAC_STORE + return objc_documentsPath(); +#endif // OS_MAC_STORE } inline void psCheckLocalSocket(const QString &serverName) { QFile address(serverName); diff --git a/Telegram/SourceFiles/pspecific_mac_p.h b/Telegram/SourceFiles/pspecific_mac_p.h index 174aae7b6..f128ebe91 100644 --- a/Telegram/SourceFiles/pspecific_mac_p.h +++ b/Telegram/SourceFiles/pspecific_mac_p.h @@ -79,6 +79,7 @@ void objc_deleteDir(const QString &dir); double objc_appkitVersion(); +QString objc_documentsPath(); QString objc_appDataPath(); QString objc_downloadPath(); QString objc_currentCountry(); @@ -88,6 +89,7 @@ QByteArray objc_downloadPathBookmark(const QString &path); QByteArray objc_pathBookmark(const QString &path); void objc_downloadPathEnableAccess(const QByteArray &bookmark); +class objc_FileBookmarkData; class objc_FileBookmark { public: objc_FileBookmark(const QByteArray &bookmark); @@ -100,4 +102,7 @@ public: ~objc_FileBookmark(); +private: + objc_FileBookmarkData *data = nullptr; + }; diff --git a/Telegram/SourceFiles/pspecific_mac_p.mm b/Telegram/SourceFiles/pspecific_mac_p.mm index 2fc1b06f8..fd0022457 100644 --- a/Telegram/SourceFiles/pspecific_mac_p.mm +++ b/Telegram/SourceFiles/pspecific_mac_p.mm @@ -22,6 +22,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "mainwidget.h" #include "application.h" #include "playerwidget.h" +#include "localstorage.h" #include "lang.h" @@ -849,6 +850,9 @@ void objc_openFile(const QString &f, bool openwith) { alwaysRect.origin.y = selectorFrame.origin.y - alwaysRect.size.height - st::macAlwaysThisAppTop; [button setFrame:alwaysRect]; [button setAutoresizingMask:NSViewMinXMargin|NSViewMaxXMargin]; +#ifdef OS_MAC_STORE + [button setHidden:YES]; +#endif // OS_MAC_STORE NSTextField *goodLabel = [[NSTextField alloc] init]; [goodLabel setStringValue:QNSString(lng_mac_this_app_can_open(lt_file, objcString(name))).s()]; [goodLabel setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]]; @@ -1012,7 +1016,12 @@ bool objc_execUpdater() { } void objc_execTelegram(const QString &crashreport) { +#ifndef OS_MAC_STORE _execUpdater(NO, crashreport); +#else // OS_MAC_STORE + NSDictionary *conf = [NSDictionary dictionaryWithObject:[NSArray array] forKey:NSWorkspaceLaunchConfigurationArguments]; + [[NSWorkspace sharedWorkspace] launchApplicationAtURL:[NSURL fileURLWithPath:QNSString(cExeDir() + cExeName()).s()] options:NSWorkspaceLaunchAsync | NSWorkspaceLaunchNewInstance configuration:conf error:0]; +#endif // OS_MAC_STORE } void objc_activateProgram(WId winId) { @@ -1050,6 +1059,14 @@ double objc_appkitVersion() { return NSAppKitVersionNumber; } +QString objc_documentsPath() { + NSURL *url = [[NSFileManager defaultManager] URLForDirectory:NSDocumentDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:YES error:nil]; + if (url) { + return QString::fromUtf8([[url path] fileSystemRepresentation]) + '/'; + } + return QString(); +} + QString objc_appDataPath() { NSURL *url = [[NSFileManager defaultManager] URLForDirectory:NSApplicationSupportDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:YES error:nil]; if (url) { @@ -1086,37 +1103,152 @@ QString objc_convertFileUrl(const QString &url) { } QByteArray objc_downloadPathBookmark(const QString &path) { +#ifndef OS_MAC_STORE return QByteArray(); +#else // OS_MAC_STORE + NSURL *url = [NSURL fileURLWithPath:[NSString stringWithUTF8String:path.toUtf8().constData()] isDirectory:YES]; + if (!url) return QByteArray(); + + NSError *error = nil; + NSData *data = [url bookmarkDataWithOptions:NSURLBookmarkCreationWithSecurityScope includingResourceValuesForKeys:nil relativeToURL:nil error:&error]; + return data ? QByteArray::fromNSData(data) : QByteArray(); +#endif // OS_MAC_STORE } QByteArray objc_pathBookmark(const QString &path) { +#ifndef OS_MAC_STORE return QByteArray(); +#else // OS_MAC_STORE + NSURL *url = [NSURL fileURLWithPath:[NSString stringWithUTF8String:path.toUtf8().constData()]]; + if (!url) return QByteArray(); + + NSError *error = nil; + NSData *data = [url bookmarkDataWithOptions:(NSURLBookmarkCreationWithSecurityScope | NSURLBookmarkCreationSecurityScopeAllowOnlyReadAccess) includingResourceValuesForKeys:nil relativeToURL:nil error:&error]; + return data ? QByteArray::fromNSData(data) : QByteArray(); +#endif // OS_MAC_STORE } void objc_downloadPathEnableAccess(const QByteArray &bookmark) { +#ifdef OS_MAC_STORE + if (bookmark.isEmpty()) return; + + BOOL isStale = NO; + NSError *error = nil; + NSURL *url = [NSURL URLByResolvingBookmarkData:bookmark.toNSData() options:NSURLBookmarkResolutionWithSecurityScope relativeToURL:nil bookmarkDataIsStale:&isStale error:&error]; + if (!url) return; + + if ([url startAccessingSecurityScopedResource]) { + if (_downloadPathUrl) { + [_downloadPathUrl stopAccessingSecurityScopedResource]; + } + _downloadPathUrl = url; + + cSetDownloadPath(objcString([_downloadPathUrl path]) + '/'); + if (isStale) { + NSData *data = [_downloadPathUrl bookmarkDataWithOptions:NSURLBookmarkCreationWithSecurityScope includingResourceValuesForKeys:nil relativeToURL:nil error:&error]; + if (data) { + cSetDownloadPathBookmark(QByteArray::fromNSData(data)); + Local::writeUserSettings(); + } + } + } +#endif // OS_MAC_STORE } +#ifdef OS_MAC_STORE +namespace { + QMutex _bookmarksMutex; +} + +class objc_FileBookmarkData { +public: + ~objc_FileBookmarkData() { + if (url) [url release]; + } + NSURL *url = nil; + QString name; + QByteArray bookmark; + int counter = 0; +}; +#endif // OS_MAC_STORE + objc_FileBookmark::objc_FileBookmark(const QByteArray &bookmark) { +#ifdef OS_MAC_STORE + if (bookmark.isEmpty()) return; + + BOOL isStale = NO; + NSError *error = nil; + NSURL *url = [NSURL URLByResolvingBookmarkData:bookmark.toNSData() options:NSURLBookmarkResolutionWithSecurityScope relativeToURL:nil bookmarkDataIsStale:&isStale error:&error]; + if (!url) return; + + if ([url startAccessingSecurityScopedResource]) { + data = new objc_FileBookmarkData(); + data->url = [url retain]; + data->name = objcString([url path]); + data->bookmark = bookmark; + [url stopAccessingSecurityScopedResource]; + } +#endif // OS_MAC_STORE } bool objc_FileBookmark::valid() const { - return true; + if (enable()) { + disable(); + return true; + } + return false; } bool objc_FileBookmark::enable() const { +#ifndef OS_MAC_STORE return true; +#else // OS_MAC_STORE + if (!data) return false; + + QMutexLocker lock(&_bookmarksMutex); + if (data->counter > 0 || [data->url startAccessingSecurityScopedResource] == YES) { + ++data->counter; + return true; + } + return false; +#endif // OS_MAC_STORE } void objc_FileBookmark::disable() const { +#ifdef OS_MAC_STORE + if (!data) return; + + QMutexLocker lock(&_bookmarksMutex); + if (data->counter > 0) { + --data->counter; + if (!data->counter) { + [data->url stopAccessingSecurityScopedResource]; + } + } +#endif // OS_MAC_STORE } const QString &objc_FileBookmark::name(const QString &original) const { +#ifndef OS_MAC_STORE return original; +#else // OS_MAC_STORE + return (data && !data->name.isEmpty()) ? data->name : original; +#endif // OS_MAC_STORE } QByteArray objc_FileBookmark::bookmark() const { +#ifndef OS_MAC_STORE return QByteArray(); +#else // OS_MAC_STORE + return data ? data->bookmark : QByteArray(); +#endif // OS_MAC_STORE } objc_FileBookmark::~objc_FileBookmark() { +#ifdef OS_MAC_STORE + if (data && data->counter > 0) { + LOG(("Did not disable() bookmark, counter: %1").arg(data->counter)); + [data->url stopAccessingSecurityScopedResource]; + } +#endif // OS_MAC_STORE } diff --git a/Telegram/SourceFiles/settings.cpp b/Telegram/SourceFiles/settings.cpp index 89e3de785..98257dbf9 100644 --- a/Telegram/SourceFiles/settings.cpp +++ b/Telegram/SourceFiles/settings.cpp @@ -176,7 +176,11 @@ void settingsParseArgs(int argc, char *argv[]) { break; case dbipMac: gUpdateURL = QUrl(qsl("http://tdesktop.com/mac/tupdates/current")); +#ifndef OS_MAC_STORE gPlatformString = qsl("MacOS"); +#else // OS_MAC_STORE + gPlatformString = qsl("MacAppStore"); +#endif // OS_MAC_STORE gCustomNotifies = false; break; case dbipMacOld: diff --git a/Telegram/SourceFiles/stdafx.h b/Telegram/SourceFiles/stdafx.h index f366d554c..d4c7ed621 100644 --- a/Telegram/SourceFiles/stdafx.h +++ b/Telegram/SourceFiles/stdafx.h @@ -49,6 +49,10 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #define OS_MAC_OLD #endif // QT_VERSION < 5.5.0 +#ifdef OS_MAC_STORE +#define MAC_USE_BREAKPAD +#endif // OS_MAC_STORE + #include #include diff --git a/Telegram/build/build.sh b/Telegram/build/build.sh index f3ce676f7..bc3538f7d 100755 --- a/Telegram/build/build.sh +++ b/Telegram/build/build.sh @@ -21,8 +21,6 @@ Error () { exit 1 } -FastParam="$1" - if [ ! -f "$FullScriptPath/target" ]; then Error "Build target not found!" fi @@ -70,13 +68,13 @@ elif [ "$BuildTarget" == "mac" ]; then echo "Building version $AppVersionStrFull for OS X 10.8+.." UpdateFile="tmacupd$AppVersion" SetupFile="tsetup.$AppVersionStrFull.dmg" - ReleasePath="$HomePath/../Mac/Release" + ReleasePath="$HomePath/../out/Release" BinaryName="Telegram" elif [ "$BuildTarget" == "mac32" ]; then echo "Building version $AppVersionStrFull for OS X 10.6 and 10.7.." UpdateFile="tmac32upd$AppVersion" SetupFile="tsetup32.$AppVersionStrFull.dmg" - ReleasePath="$HomePath/../Mac/Release" + ReleasePath="$HomePath/../out/Release" BinaryName="Telegram" elif [ "$BuildTarget" == "macstore" ]; then if [ "$BetaVersion" != "0" ]; then @@ -84,7 +82,7 @@ elif [ "$BuildTarget" == "macstore" ]; then fi echo "Building version $AppVersionStrFull for Mac App Store.." - ReleasePath="$HomePath/../Mac/Release" + ReleasePath="$HomePath/../out/Release" BinaryName="Telegram Desktop" DropboxPath="/Volumes/Storage/Dropbox/Telegram/deploy/$AppVersionStrMajor" DropboxDeployPath="$DropboxPath/$AppVersionStrFull" @@ -214,10 +212,8 @@ if [ "$BuildTarget" == "mac" ] || [ "$BuildTarget" == "mac32" ] || [ "$BuildTarg Error "Dropbox path not found!" fi - if [ "$FastParam" != "fast" ]; then - touch "./Resources/telegram.qrc" - touch "./Telegram.plist" - fi + gyp/refresh.sh + cd ../ xcodebuild -project Telegram.xcodeproj -alltargets -configuration Release build if [ ! -d "$ReleasePath/$BinaryName.app" ]; then @@ -229,9 +225,17 @@ if [ "$BuildTarget" == "mac" ] || [ "$BuildTarget" == "mac32" ] || [ "$BuildTarg fi if [ "$BuildTarget" == "mac" ] || [ "$BuildTarget" == "mac32" ]; then - echo "Removing Updater debug symbols.." - rm -rf "$ReleasePath/$BinaryName.app/Contents/Frameworks/Updater.dSYM" - echo "Done!" + if [ ! -f "$ReleasePath/$BinaryName.app/Contents/Frameworks/Updater" ]; then + Error "Updater not found!" + fi + if [ ! -f "$ReleasePath/$BinaryName.app/Contents/Helpers/crashpad_handler" ]; then + Error "crashpad_handler not found!" + fi + fi + if [ "$BuildTarget" == "macstore" ]; then + if [ ! -d "$ReleasePath/$BinaryName.app/Contents/Frameworks/Breakpad.framework" ]; then + Error "Breakpad.framework not found!" + fi fi echo "Dumping debug symbols.." @@ -246,7 +250,9 @@ if [ "$BuildTarget" == "mac" ] || [ "$BuildTarget" == "mac32" ] || [ "$BuildTarg if [ "$BuildTarget" == "mac" ] || [ "$BuildTarget" == "mac32" ]; then codesign --force --deep --sign "Developer ID Application: John Preston" "$ReleasePath/$BinaryName.app" elif [ "$BuildTarget" == "macstore" ]; then - codesign --force --deep --sign "3rd Party Mac Developer Application: TELEGRAM MESSENGER LLP (6N38VWS5BX)" "$ReleasePath/$BinaryName.app" --entitlements "Telegram/Telegram Desktop.entitlements" + codesign --force --deep --sign "3rd Party Mac Developer Application: TELEGRAM MESSENGER LLP (6N38VWS5BX)" "$ReleasePath/$BinaryName.app" --entitlements "$HomePath/Telegram/Telegram Desktop.entitlements" + echo "Making an installer.." + productbuild --sign "3rd Party Mac Developer Installer: TELEGRAM MESSENGER LLP (6N38VWS5BX)" --component "$ReleasePath/$BinaryName.app" /Applications "$ReleasePath/$BinaryName.pkg" fi echo "Done!" diff --git a/Telegram/build/set_version.sh b/Telegram/build/set_version.sh index 3cb3c49be..ba667a757 100755 --- a/Telegram/build/set_version.sh +++ b/Telegram/build/set_version.sh @@ -106,11 +106,6 @@ repl "\(AppVersion [ ]*=\) \([ ]*\)[0-9][0-9]*" "\1\2 $VersionFull" "$VersionHea repl "\(AppVersionStr [ ]*=\) \([ ]*\)[^;][^;]*" "\1\2 \"$VersionStrSmall\"" "$VersionHeaderPath" repl "\(AppAlphaVersion [ ]*=\) \([ ]*\)[a-z][a-z]*" "\1\2 $VersionAlphaBool" "$VersionHeaderPath" -echo "Patching project.pbxproj..." -TelegramProjectPath="$FullScriptPath/../Telegram.xcodeproj/project.pbxproj" -repl "\(TDESKTOP_MAJOR_VERSION [ ]*=\) \([ ]*\)[^;][^;]*" "\1\2 $VersionMajor.$VersionMinor" "$TelegramProjectPath" -repl "\(TDESKTOP_VERSION [ ]*=\) \([ ]*\)[^;][^;]*" "\1\2 $VersionStrSmall" "$TelegramProjectPath" - echo "Patching Telegram.rc..." ResourcePath="$FullScriptPath/../Resources/winrc/Telegram.rc" repl "\(FILEVERSION\) \([ ]*\)[0-9][0-9]*,[0-9][0-9]*,[0-9][0-9]*,[0-9][0-9]*" "\1\2 $VersionMajor,$VersionMinor,$VersionPatch,$VersionBeta" "$ResourcePath" diff --git a/Telegram/gyp/Telegram.gyp b/Telegram/gyp/Telegram.gyp index 3be6f5f32..4a55288d4 100644 --- a/Telegram/gyp/Telegram.gyp +++ b/Telegram/gyp/Telegram.gyp @@ -95,6 +95,7 @@ '<(src_loc)/application.h', '<(src_loc)/autoupdater.cpp', '<(src_loc)/autoupdater.h', + '<(src_loc)/config.h', '<(src_loc)/dialogswidget.cpp', '<(src_loc)/dialogswidget.h', '<(src_loc)/dropdown.cpp', diff --git a/Telegram/gyp/print_version.sh b/Telegram/gyp/print_version.sh new file mode 100755 index 000000000..cb9de94a6 --- /dev/null +++ b/Telegram/gyp/print_version.sh @@ -0,0 +1,14 @@ +set -e +FullExecPath=$PWD +pushd `dirname $0` > /dev/null +FullScriptPath=`pwd` +popd > /dev/null + +while IFS='' read -r line || [[ -n "$line" ]]; do + set $line + eval $1="$2" +done < "$FullScriptPath/../build/version" + +echo $AppVersionStr +exit + diff --git a/Telegram/gyp/telegram_mac.gypi b/Telegram/gyp/telegram_mac.gypi index e13f72a43..a2f2e5a43 100644 --- a/Telegram/gyp/telegram_mac.gypi +++ b/Telegram/gyp/telegram_mac.gypi @@ -23,7 +23,7 @@ 'GCC_PREFIX_HEADER': '<(src_loc)/stdafx.h', 'GCC_PRECOMPILE_PREFIX_HEADER': 'YES', 'INFOPLIST_FILE': '../Telegram.plist', - 'CURRENT_PROJECT_VERSION': '0.10.2', + 'CURRENT_PROJECT_VERSION': '