Merge pull request #268592 from ilya-fedin/telegram-darwin

telegram-desktop: build on Darwin

authored by

Nick Cao and committed by
GitHub
af76d9e3 5d08323d

+167 -24
+72 -18
pkgs/applications/networking/instant-messengers/telegram/telegram-desktop/default.nix
··· 60 60 , mm-common 61 61 , rlottie 62 62 , stdenv 63 + , darwin 64 + , lld 65 + , libicns 63 66 , nix-update-script 64 67 }: 65 68 ··· 72 75 73 76 let 74 77 tg_owt = callPackage ./tg_owt.nix { 78 + inherit stdenv; 75 79 abseil-cpp = abseil-cpp.override { 76 80 cxxStandard = "20"; 77 81 }; ··· 100 104 perlPackages.XMLParser 101 105 ]; 102 106 }); 107 + mainProgram = if stdenv.isLinux then "telegram-desktop" else "Telegram"; 103 108 in 104 109 stdenv.mkDerivation rec { 105 110 pname = "telegram-desktop"; ··· 114 119 }; 115 120 116 121 patches = [ 122 + ./macos.patch 117 123 # the generated .desktop files contains references to unwrapped tdesktop, breaking scheme handling 118 124 # and the scheme handler is already registered in the packaged .desktop file, rendering this unnecessary 119 125 # see https://github.com/NixOS/nixpkgs/issues/218370 ··· 123 129 }) 124 130 ]; 125 131 126 - postPatch = '' 132 + postPatch = lib.optionalString stdenv.isLinux '' 127 133 substituteInPlace Telegram/ThirdParty/libtgvoip/os/linux/AudioInputALSA.cpp \ 128 134 --replace '"libasound.so.2"' '"${alsa-lib}/lib/libasound.so.2"' 129 135 substituteInPlace Telegram/ThirdParty/libtgvoip/os/linux/AudioOutputALSA.cpp \ ··· 143 149 cmake 144 150 ninja 145 151 python3 152 + wrapQtAppsHook 153 + ] ++ lib.optionals stdenv.isLinux [ 146 154 gobject-introspection 147 155 wrapGAppsHook 148 - wrapQtAppsHook 149 156 extra-cmake-modules 157 + ] ++ lib.optionals stdenv.isDarwin [ 158 + lld 150 159 ]; 151 160 152 161 buildInputs = [ 153 162 qtbase 154 - qtwayland 155 163 qtsvg 156 164 qtimageformats 157 - gtk3 158 165 boost 159 - fmt 160 - libdbusmenu 161 166 lz4 162 167 xxHash 163 168 ffmpeg 164 169 openalSoft 165 170 minizip 166 171 libopus 172 + range-v3 173 + tl-expected 174 + rnnoise 175 + protobuf 176 + tg_owt 177 + microsoft-gsl 178 + rlottie 179 + ] ++ lib.optionals stdenv.isLinux [ 180 + qtwayland 181 + gtk3 182 + fmt 183 + libdbusmenu 167 184 alsa-lib 168 185 libpulseaudio 169 186 pipewire 170 - range-v3 171 - tl-expected 172 187 hunspell 173 188 glibmm 174 189 webkitgtk_6_0 175 190 jemalloc 176 - rnnoise 177 - protobuf 178 - tg_owt 179 191 # Transitive dependencies: 180 192 util-linuxMinimal # Required for libmount thus not nativeBuildInputs. 181 193 pcre ··· 192 204 libsysprof-capture 193 205 libpsl 194 206 brotli 195 - microsoft-gsl 196 - rlottie 197 - ]; 207 + ] ++ lib.optionals stdenv.isDarwin (with darwin.apple_sdk_11_0.frameworks; [ 208 + Cocoa 209 + CoreFoundation 210 + CoreServices 211 + CoreText 212 + CoreGraphics 213 + CoreMedia 214 + OpenGL 215 + AudioUnit 216 + ApplicationServices 217 + Foundation 218 + AGL 219 + Security 220 + SystemConfiguration 221 + Carbon 222 + AudioToolbox 223 + VideoToolbox 224 + VideoDecodeAcceleration 225 + AVFoundation 226 + CoreAudio 227 + CoreVideo 228 + CoreMediaIO 229 + QuartzCore 230 + AppKit 231 + CoreWLAN 232 + WebKit 233 + IOKit 234 + GSS 235 + MediaPlayer 236 + IOSurface 237 + Metal 238 + NaturalLanguage 239 + libicns 240 + ]); 241 + 242 + env = lib.optionalAttrs stdenv.isDarwin { 243 + NIX_CFLAGS_LINK = "-fuse-ld=lld"; 244 + }; 198 245 199 246 cmakeFlags = [ 200 247 "-Ddisable_autoupdate=ON" ··· 210 257 export GI_GIR_PATH="$XDG_DATA_DIRS" 211 258 ''; 212 259 213 - postFixup = '' 260 + installPhase = lib.optionalString stdenv.isDarwin '' 261 + mkdir -p $out/Applications 262 + cp -r ${mainProgram}.app $out/Applications 263 + ln -s $out/{Applications/${mainProgram}.app/Contents/MacOS,bin} 264 + ''; 265 + 266 + postFixup = lib.optionalString stdenv.isLinux '' 214 267 # This is necessary to run Telegram in a pure environment. 215 268 # We also use gappsWrapperArgs from wrapGAppsHook. 216 - wrapProgram $out/bin/telegram-desktop \ 269 + wrapProgram $out/bin/${mainProgram} \ 217 270 "''${gappsWrapperArgs[@]}" \ 218 271 "''${qtWrapperArgs[@]}" \ 219 272 --suffix PATH : ${lib.makeBinPath [ xdg-utils ]} 273 + '' + lib.optionalString stdenv.isDarwin '' 274 + wrapQtApp $out/Applications/${mainProgram}.app/Contents/MacOS/${mainProgram} 220 275 ''; 221 276 222 277 passthru = { ··· 231 286 the MTProto secure protocol. 232 287 ''; 233 288 license = licenses.gpl3Only; 234 - platforms = platforms.linux; 235 289 homepage = "https://desktop.telegram.org/"; 236 290 changelog = "https://github.com/telegramdesktop/tdesktop/releases/tag/v${version}"; 237 291 maintainers = with maintainers; [ nickcao ]; 238 - mainProgram = "telegram-desktop"; 292 + inherit mainProgram; 239 293 }; 240 294 }
+69
pkgs/applications/networking/instant-messengers/telegram/telegram-desktop/macos.patch
··· 1 + diff --git a/Telegram/SourceFiles/platform/mac/overlay_widget_mac.mm b/Telegram/SourceFiles/platform/mac/overlay_widget_mac.mm 2 + index ef544803e9..69c61b3139 100644 3 + --- a/Telegram/SourceFiles/platform/mac/overlay_widget_mac.mm 4 + +++ b/Telegram/SourceFiles/platform/mac/overlay_widget_mac.mm 5 + @@ -97,9 +97,11 @@ void MacOverlayWidgetHelper::updateStyles(bool fullscreen) { 6 + [window setTitleVisibility:NSWindowTitleHidden]; 7 + [window setTitlebarAppearsTransparent:YES]; 8 + [window setStyleMask:[window styleMask] | NSWindowStyleMaskFullSizeContentView]; 9 + +#if 0 10 + if (@available(macOS 12.0, *)) { 11 + _data->topNotchSkip = [[window screen] safeAreaInsets].top; 12 + } 13 + +#endif 14 + } 15 + 16 + void MacOverlayWidgetHelper::refreshButtons(bool fullscreen) { 17 + Submodule Telegram/lib_base contains modified content 18 + diff --git a/Telegram/lib_base/base/platform/mac/base_battery_saving_mac.mm b/Telegram/lib_base/base/platform/mac/base_battery_saving_mac.mm 19 + index 7ce90d3..dac3c2c 100644 20 + --- a/Telegram/lib_base/base/platform/mac/base_battery_saving_mac.mm 21 + +++ b/Telegram/lib_base/base/platform/mac/base_battery_saving_mac.mm 22 + @@ -138,6 +138,7 @@ BatterySaving::BatterySaving(Fn<void()> changedCallback) { 23 + _observer = [[LowPowerModeObserver alloc] initWithCallback:std::move(wrapped)]; 24 + 25 + NSNotificationCenter *center = [NSNotificationCenter defaultCenter]; 26 + +#if 0 27 + if (@available(macOS 12.0, *)) { 28 + [center 29 + addObserver: _observer 30 + @@ -145,6 +146,7 @@ BatterySaving::BatterySaving(Fn<void()> changedCallback) { 31 + name: NSProcessInfoPowerStateDidChangeNotification 32 + object: nil]; 33 + } 34 + +#endif 35 + [center 36 + addObserver: _observer 37 + selector: @selector(powerStateChanged:) 38 + @@ -178,11 +180,13 @@ std::optional<bool> BatterySaving::enabled() const { 39 + return std::nullopt; 40 + } 41 + NSProcessInfo *info = [NSProcessInfo processInfo]; 42 + +#if 0 43 + if (@available(macOS 12.0, *)) { 44 + if ([info isLowPowerModeEnabled]) { 45 + return true; 46 + } 47 + } 48 + +#endif 49 + const auto state = DetectBatteryState(); 50 + if (!state.has || !state.draining) { 51 + return false; 52 + Submodule Telegram/lib_webview contains modified content 53 + diff --git a/Telegram/lib_webview/webview/platform/mac/webview_mac.mm b/Telegram/lib_webview/webview/platform/mac/webview_mac.mm 54 + index 738e574..80ff5f0 100644 55 + --- a/Telegram/lib_webview/webview/platform/mac/webview_mac.mm 56 + +++ b/Telegram/lib_webview/webview/platform/mac/webview_mac.mm 57 + @@ -254,10 +254,12 @@ void *Instance::winId() { 58 + } 59 + 60 + void Instance::setOpaqueBg(QColor opaqueBg) { 61 + +#if 0 62 + if (@available(macOS 12.0, *)) { 63 + [_webview setValue: @NO forKey: @"drawsBackground"]; 64 + [_webview setUnderPageBackgroundColor:[NSColor clearColor]]; 65 + } 66 + +#endif 67 + } 68 + 69 + void Instance::resizeToWindow() {
+21 -5
pkgs/applications/networking/instant-messengers/telegram/telegram-desktop/tg_owt.nix
··· 4 4 , openh264, usrsctp, libevent, libvpx 5 5 , libX11, libXtst, libXcomposite, libXdamage, libXext, libXrender, libXrandr, libXi 6 6 , glib, abseil-cpp, pcre, util-linuxMinimal, libselinux, libsepol, pipewire 7 - , mesa, libepoxy, libglvnd, unstableGitUpdater 7 + , mesa, libepoxy, libglvnd, unstableGitUpdater, darwin 8 8 }: 9 9 10 10 stdenv.mkDerivation { ··· 24 24 nativeBuildInputs = [ pkg-config cmake ninja yasm ]; 25 25 26 26 buildInputs = [ 27 - libjpeg libopus ffmpeg alsa-lib libpulseaudio protobuf 28 - openh264 usrsctp libevent libvpx 27 + libjpeg libopus ffmpeg protobuf openh264 usrsctp libevent libvpx abseil-cpp 28 + ] ++ lib.optionals stdenv.isLinux [ 29 29 libX11 libXtst libXcomposite libXdamage libXext libXrender libXrandr libXi 30 - glib abseil-cpp pcre util-linuxMinimal libselinux libsepol pipewire 30 + glib pcre util-linuxMinimal libselinux libsepol pipewire alsa-lib libpulseaudio 31 31 mesa libepoxy libglvnd 32 - ]; 32 + ] ++ lib.optionals stdenv.isDarwin (with darwin.apple_sdk.frameworks; [ 33 + Cocoa 34 + AppKit 35 + IOKit 36 + IOSurface 37 + Foundation 38 + AVFoundation 39 + CoreMedia 40 + VideoToolbox 41 + CoreGraphics 42 + CoreVideo 43 + OpenGL 44 + Metal 45 + MetalKit 46 + CoreFoundation 47 + ApplicationServices 48 + ]); 33 49 34 50 patches = [ 35 51 # GCC 12 Fix
+5 -1
pkgs/top-level/all-packages.nix
··· 35705 35705 35706 35706 taskopen = callPackage ../applications/misc/taskopen { }; 35707 35707 35708 - telegram-desktop = qt6Packages.callPackage ../applications/networking/instant-messengers/telegram/telegram-desktop { }; 35708 + telegram-desktop = qt6Packages.callPackage ../applications/networking/instant-messengers/telegram/telegram-desktop { 35709 + stdenv = if stdenv.isDarwin 35710 + then overrideSDK stdenv "11.0" 35711 + else stdenv; 35712 + }; 35709 35713 35710 35714 telegram-bot-api = callPackage ../servers/telegram-bot-api { }; 35711 35715