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

telegram-desktop: build on Darwin
This commit is contained in:
Nick Cao
2023-11-20 13:55:26 -05:00
committed by GitHub
4 changed files with 167 additions and 24 deletions
@@ -60,6 +60,9 @@
, mm-common
, rlottie
, stdenv
, darwin
, lld
, libicns
, nix-update-script
}:
@@ -72,6 +75,7 @@
let
tg_owt = callPackage ./tg_owt.nix {
inherit stdenv;
abseil-cpp = abseil-cpp.override {
cxxStandard = "20";
};
@@ -100,6 +104,7 @@ let
perlPackages.XMLParser
];
});
mainProgram = if stdenv.isLinux then "telegram-desktop" else "Telegram";
in
stdenv.mkDerivation rec {
pname = "telegram-desktop";
@@ -114,6 +119,7 @@ stdenv.mkDerivation rec {
};
patches = [
./macos.patch
# the generated .desktop files contains references to unwrapped tdesktop, breaking scheme handling
# and the scheme handler is already registered in the packaged .desktop file, rendering this unnecessary
# see https://github.com/NixOS/nixpkgs/issues/218370
@@ -123,7 +129,7 @@ stdenv.mkDerivation rec {
})
];
postPatch = ''
postPatch = lib.optionalString stdenv.isLinux ''
substituteInPlace Telegram/ThirdParty/libtgvoip/os/linux/AudioInputALSA.cpp \
--replace '"libasound.so.2"' '"${alsa-lib}/lib/libasound.so.2"'
substituteInPlace Telegram/ThirdParty/libtgvoip/os/linux/AudioOutputALSA.cpp \
@@ -143,39 +149,45 @@ stdenv.mkDerivation rec {
cmake
ninja
python3
wrapQtAppsHook
] ++ lib.optionals stdenv.isLinux [
gobject-introspection
wrapGAppsHook
wrapQtAppsHook
extra-cmake-modules
] ++ lib.optionals stdenv.isDarwin [
lld
];
buildInputs = [
qtbase
qtwayland
qtsvg
qtimageformats
gtk3
boost
fmt
libdbusmenu
lz4
xxHash
ffmpeg
openalSoft
minizip
libopus
range-v3
tl-expected
rnnoise
protobuf
tg_owt
microsoft-gsl
rlottie
] ++ lib.optionals stdenv.isLinux [
qtwayland
gtk3
fmt
libdbusmenu
alsa-lib
libpulseaudio
pipewire
range-v3
tl-expected
hunspell
glibmm
webkitgtk_6_0
jemalloc
rnnoise
protobuf
tg_owt
# Transitive dependencies:
util-linuxMinimal # Required for libmount thus not nativeBuildInputs.
pcre
@@ -192,9 +204,44 @@ stdenv.mkDerivation rec {
libsysprof-capture
libpsl
brotli
microsoft-gsl
rlottie
];
] ++ lib.optionals stdenv.isDarwin (with darwin.apple_sdk_11_0.frameworks; [
Cocoa
CoreFoundation
CoreServices
CoreText
CoreGraphics
CoreMedia
OpenGL
AudioUnit
ApplicationServices
Foundation
AGL
Security
SystemConfiguration
Carbon
AudioToolbox
VideoToolbox
VideoDecodeAcceleration
AVFoundation
CoreAudio
CoreVideo
CoreMediaIO
QuartzCore
AppKit
CoreWLAN
WebKit
IOKit
GSS
MediaPlayer
IOSurface
Metal
NaturalLanguage
libicns
]);
env = lib.optionalAttrs stdenv.isDarwin {
NIX_CFLAGS_LINK = "-fuse-ld=lld";
};
cmakeFlags = [
"-Ddisable_autoupdate=ON"
@@ -210,13 +257,21 @@ stdenv.mkDerivation rec {
export GI_GIR_PATH="$XDG_DATA_DIRS"
'';
postFixup = ''
installPhase = lib.optionalString stdenv.isDarwin ''
mkdir -p $out/Applications
cp -r ${mainProgram}.app $out/Applications
ln -s $out/{Applications/${mainProgram}.app/Contents/MacOS,bin}
'';
postFixup = lib.optionalString stdenv.isLinux ''
# This is necessary to run Telegram in a pure environment.
# We also use gappsWrapperArgs from wrapGAppsHook.
wrapProgram $out/bin/telegram-desktop \
wrapProgram $out/bin/${mainProgram} \
"''${gappsWrapperArgs[@]}" \
"''${qtWrapperArgs[@]}" \
--suffix PATH : ${lib.makeBinPath [ xdg-utils ]}
'' + lib.optionalString stdenv.isDarwin ''
wrapQtApp $out/Applications/${mainProgram}.app/Contents/MacOS/${mainProgram}
'';
passthru = {
@@ -231,10 +286,9 @@ stdenv.mkDerivation rec {
the MTProto secure protocol.
'';
license = licenses.gpl3Only;
platforms = platforms.linux;
homepage = "https://desktop.telegram.org/";
changelog = "https://github.com/telegramdesktop/tdesktop/releases/tag/v${version}";
maintainers = with maintainers; [ nickcao ];
mainProgram = "telegram-desktop";
inherit mainProgram;
};
}
@@ -0,0 +1,69 @@
diff --git a/Telegram/SourceFiles/platform/mac/overlay_widget_mac.mm b/Telegram/SourceFiles/platform/mac/overlay_widget_mac.mm
index ef544803e9..69c61b3139 100644
--- a/Telegram/SourceFiles/platform/mac/overlay_widget_mac.mm
+++ b/Telegram/SourceFiles/platform/mac/overlay_widget_mac.mm
@@ -97,9 +97,11 @@ void MacOverlayWidgetHelper::updateStyles(bool fullscreen) {
[window setTitleVisibility:NSWindowTitleHidden];
[window setTitlebarAppearsTransparent:YES];
[window setStyleMask:[window styleMask] | NSWindowStyleMaskFullSizeContentView];
+#if 0
if (@available(macOS 12.0, *)) {
_data->topNotchSkip = [[window screen] safeAreaInsets].top;
}
+#endif
}
void MacOverlayWidgetHelper::refreshButtons(bool fullscreen) {
Submodule Telegram/lib_base contains modified content
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
index 7ce90d3..dac3c2c 100644
--- a/Telegram/lib_base/base/platform/mac/base_battery_saving_mac.mm
+++ b/Telegram/lib_base/base/platform/mac/base_battery_saving_mac.mm
@@ -138,6 +138,7 @@ BatterySaving::BatterySaving(Fn<void()> changedCallback) {
_observer = [[LowPowerModeObserver alloc] initWithCallback:std::move(wrapped)];
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
+#if 0
if (@available(macOS 12.0, *)) {
[center
addObserver: _observer
@@ -145,6 +146,7 @@ BatterySaving::BatterySaving(Fn<void()> changedCallback) {
name: NSProcessInfoPowerStateDidChangeNotification
object: nil];
}
+#endif
[center
addObserver: _observer
selector: @selector(powerStateChanged:)
@@ -178,11 +180,13 @@ std::optional<bool> BatterySaving::enabled() const {
return std::nullopt;
}
NSProcessInfo *info = [NSProcessInfo processInfo];
+#if 0
if (@available(macOS 12.0, *)) {
if ([info isLowPowerModeEnabled]) {
return true;
}
}
+#endif
const auto state = DetectBatteryState();
if (!state.has || !state.draining) {
return false;
Submodule Telegram/lib_webview contains modified content
diff --git a/Telegram/lib_webview/webview/platform/mac/webview_mac.mm b/Telegram/lib_webview/webview/platform/mac/webview_mac.mm
index 738e574..80ff5f0 100644
--- a/Telegram/lib_webview/webview/platform/mac/webview_mac.mm
+++ b/Telegram/lib_webview/webview/platform/mac/webview_mac.mm
@@ -254,10 +254,12 @@ void *Instance::winId() {
}
void Instance::setOpaqueBg(QColor opaqueBg) {
+#if 0
if (@available(macOS 12.0, *)) {
[_webview setValue: @NO forKey: @"drawsBackground"];
[_webview setUnderPageBackgroundColor:[NSColor clearColor]];
}
+#endif
}
void Instance::resizeToWindow() {
@@ -4,7 +4,7 @@
, openh264, usrsctp, libevent, libvpx
, libX11, libXtst, libXcomposite, libXdamage, libXext, libXrender, libXrandr, libXi
, glib, abseil-cpp, pcre, util-linuxMinimal, libselinux, libsepol, pipewire
, mesa, libepoxy, libglvnd, unstableGitUpdater
, mesa, libepoxy, libglvnd, unstableGitUpdater, darwin
}:
stdenv.mkDerivation {
@@ -24,12 +24,28 @@ stdenv.mkDerivation {
nativeBuildInputs = [ pkg-config cmake ninja yasm ];
buildInputs = [
libjpeg libopus ffmpeg alsa-lib libpulseaudio protobuf
openh264 usrsctp libevent libvpx
libjpeg libopus ffmpeg protobuf openh264 usrsctp libevent libvpx abseil-cpp
] ++ lib.optionals stdenv.isLinux [
libX11 libXtst libXcomposite libXdamage libXext libXrender libXrandr libXi
glib abseil-cpp pcre util-linuxMinimal libselinux libsepol pipewire
glib pcre util-linuxMinimal libselinux libsepol pipewire alsa-lib libpulseaudio
mesa libepoxy libglvnd
];
] ++ lib.optionals stdenv.isDarwin (with darwin.apple_sdk.frameworks; [
Cocoa
AppKit
IOKit
IOSurface
Foundation
AVFoundation
CoreMedia
VideoToolbox
CoreGraphics
CoreVideo
OpenGL
Metal
MetalKit
CoreFoundation
ApplicationServices
]);
patches = [
# GCC 12 Fix
+5 -1
View File
@@ -35705,7 +35705,11 @@ with pkgs;
taskopen = callPackage ../applications/misc/taskopen { };
telegram-desktop = qt6Packages.callPackage ../applications/networking/instant-messengers/telegram/telegram-desktop { };
telegram-desktop = qt6Packages.callPackage ../applications/networking/instant-messengers/telegram/telegram-desktop {
stdenv = if stdenv.isDarwin
then overrideSDK stdenv "11.0"
else stdenv;
};
telegram-bot-api = callPackage ../servers/telegram-bot-api { };