Skip to content

Commit

Permalink
Merge branch 'master' of gitlab.com:peter-iakovlev/telegram-ios
Browse files Browse the repository at this point in the history
  • Loading branch information
laktyushin committed Nov 5, 2024
2 parents 8d44e4d + bae29f3 commit 9a46522
Show file tree
Hide file tree
Showing 32 changed files with 581 additions and 138 deletions.
83 changes: 81 additions & 2 deletions build-system/Make/BazelLocation.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,41 @@
import os
import stat
import sys
from urllib.parse import urlparse, urlunparse
import tempfile
import hashlib
import shutil

from BuildEnvironment import is_apple_silicon, resolve_executable, call_executable, BuildEnvironmentVersions
from BuildEnvironment import is_apple_silicon, resolve_executable, call_executable, run_executable_with_status, BuildEnvironmentVersions

def locate_bazel(base_path):
def transform_cache_host_into_http(grpc_url):
parsed_url = urlparse(grpc_url)

new_scheme = "http"
new_port = 8080

transformed_url = urlunparse((
new_scheme,
f"{parsed_url.hostname}:{new_port}",
parsed_url.path,
parsed_url.params,
parsed_url.query,
parsed_url.fragment
))

return transformed_url


def calculate_sha256(file_path):
sha256_hash = hashlib.sha256()
with open(file_path, "rb") as file:
# Read the file in chunks to avoid using too much memory
for byte_block in iter(lambda: file.read(4096), b""):
sha256_hash.update(byte_block)
return sha256_hash.hexdigest()


def locate_bazel(base_path, cache_host):
build_input_dir = '{}/build-input'.format(base_path)
if not os.path.isdir(build_input_dir):
os.mkdir(build_input_dir)
Expand All @@ -17,6 +48,33 @@ def locate_bazel(base_path):
bazel_name = 'bazel-{version}-{arch}'.format(version=versions.bazel_version, arch=arch)
bazel_path = '{}/build-input/{}'.format(base_path, bazel_name)

if not os.path.isfile(bazel_path):
if cache_host is not None and versions.bazel_version_sha256 is not None:
http_cache_host = transform_cache_host_into_http(cache_host)

with tempfile.NamedTemporaryFile(delete=True) as temp_output_file:
call_executable([
'curl',
'-L',
'{cache_host}/cache/cas/{hash}'.format(
cache_host=http_cache_host,
hash=versions.bazel_version_sha256
),
'--output',
temp_output_file.name
], check_result=False)
test_sha256 = calculate_sha256(temp_output_file.name)
if test_sha256 == versions.bazel_version_sha256:
shutil.copyfile(temp_output_file.name, bazel_path)


if os.path.isfile(bazel_path) and versions.bazel_version_sha256 is not None:
test_sha256 = calculate_sha256(bazel_path)
if test_sha256 != versions.bazel_version_sha256:
print(f"Bazel at {bazel_path} does not match SHA256 {versions.bazel_version_sha256}, removing")
os.remove(bazel_path)


if not os.path.isfile(bazel_path):
call_executable([
'curl',
Expand All @@ -29,6 +87,27 @@ def locate_bazel(base_path):
bazel_path
])

if os.path.isfile(bazel_path) and versions.bazel_version_sha256 is not None:
test_sha256 = calculate_sha256(bazel_path)
if test_sha256 != versions.bazel_version_sha256:
print(f"Bazel at {bazel_path} does not match SHA256 {versions.bazel_version_sha256}, removing")
os.remove(bazel_path)

if cache_host is not None and versions.bazel_version_sha256 is not None:
http_cache_host = transform_cache_host_into_http(cache_host)
print(f"Uploading bazel@{versions.bazel_version_sha256} to bazel-remote")
call_executable([
'curl',
'-X',
'PUT',
'-T',
bazel_path,
'{cache_host}/cache/cas/{hash}'.format(
cache_host=http_cache_host,
hash=versions.bazel_version_sha256
)
], check_result=False)

if not os.access(bazel_path, os.X_OK):
st = os.stat(bazel_path)
os.chmod(bazel_path, st.st_mode | stat.S_IEXEC)
Expand Down
2 changes: 1 addition & 1 deletion build-system/Make/BuildConfiguration.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def write_to_variables_file(self, bazel_path, use_xcode_managed_codesigning, aps

def build_configuration_from_json(path):
if not os.path.exists(path):
print('Could not load build configuration from {}'.format(path))
print('Could not load build configuration from non-existing path {}'.format(path))
sys.exit(1)
with open(path) as file:
configuration_dict = json.load(file)
Expand Down
26 changes: 25 additions & 1 deletion build-system/Make/BuildEnvironment.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,28 @@ def run_executable_with_output(path, arguments, decode=True, input=None, stderr_
return output_data


def run_executable_with_status(arguments, use_clean_environment=True):
executable_path = resolve_executable(arguments[0])
if executable_path is None:
raise Exception(f'Could not resolve {arguments[0]} to a valid executable file')

if use_clean_environment:
resolved_env = get_clean_env()
else:
resolved_env = os.environ

resolved_arguments = [executable_path] + arguments[1:]

result = subprocess.run(
resolved_arguments,
env=resolved_env,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
)

return result.returncode


def call_executable(arguments, use_clean_environment=True, check_result=True):
executable_path = resolve_executable(arguments[0])
if executable_path is None:
Expand Down Expand Up @@ -135,7 +157,9 @@ def __init__(
if configuration_dict['bazel'] is None:
raise Exception('Missing bazel version in {}'.format(configuration_path))
else:
self.bazel_version = configuration_dict['bazel']
bazel_version, bazel_version_sha256 = configuration_dict['bazel'].split(':')
self.bazel_version = bazel_version
self.bazel_version_sha256 = bazel_version_sha256
if configuration_dict['xcode'] is None:
raise Exception('Missing xcode version in {}'.format(configuration_path))
else:
Expand Down
2 changes: 1 addition & 1 deletion build-system/Make/Make.py
Original file line number Diff line number Diff line change
Expand Up @@ -985,7 +985,7 @@ def add_project_and_build_common_arguments(current_parser: argparse.ArgumentPars

bazel_path = None
if args.bazel is None:
bazel_path = locate_bazel(base_path=os.getcwd())
bazel_path = locate_bazel(base_path=os.getcwd(), cache_host=args.cacheHost)
else:
bazel_path = args.bazel

Expand Down
2 changes: 1 addition & 1 deletion build-system/Make/RemoteBuild.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def handle_ssh_credentials(credentials):
sys.exit(1)

DarwinContainers.run_remote_ssh(credentials=credentials, command='')
sys.exit(0)
#sys.exit(0)

def handle_stopped():
pass
Expand Down
Binary file not shown.
Binary file not shown.
Binary file modified build-system/fake-codesigning/profiles/Intents.mobileprovision
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified build-system/fake-codesigning/profiles/Share.mobileprovision
Binary file not shown.
Binary file modified build-system/fake-codesigning/profiles/Telegram.mobileprovision
Binary file not shown.
Binary file modified build-system/fake-codesigning/profiles/WatchApp.mobileprovision
Binary file not shown.
Binary file not shown.
Binary file modified build-system/fake-codesigning/profiles/Widget.mobileprovision
Binary file not shown.
18 changes: 16 additions & 2 deletions submodules/DebugSettingsUI/Sources/DebugController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ private enum DebugControllerEntry: ItemListNodeEntry {
case experimentalCallMute(Bool)
case liveStreamV2(Bool)
case dynamicStreaming(Bool)
case enableLocalTranslation(Bool)
case preferredVideoCodec(Int, String, String?, Bool)
case disableVideoAspectScaling(Bool)
case enableNetworkFramework(Bool)
Expand All @@ -130,7 +131,7 @@ private enum DebugControllerEntry: ItemListNodeEntry {
return DebugControllerSection.web.rawValue
case .keepChatNavigationStack, .skipReadHistory, .dustEffect, .crashOnSlowQueries, .crashOnMemoryPressure:
return DebugControllerSection.experiments.rawValue
case .clearTips, .resetNotifications, .crash, .fillLocalSavedMessageCache, .resetDatabase, .resetDatabaseAndCache, .resetHoles, .resetTagHoles, .reindexUnread, .resetCacheIndex, .reindexCache, .resetBiometricsData, .optimizeDatabase, .photoPreview, .knockoutWallpaper, .storiesExperiment, .storiesJpegExperiment, .playlistPlayback, .enableQuickReactionSwitch, .experimentalCompatibility, .enableDebugDataDisplay, .rippleEffect, .browserExperiment, .localTranscription, .enableReactionOverrides, .restorePurchases, .disableReloginTokens, .disableCallV2, .experimentalCallMute, .liveStreamV2, .dynamicStreaming:
case .clearTips, .resetNotifications, .crash, .fillLocalSavedMessageCache, .resetDatabase, .resetDatabaseAndCache, .resetHoles, .resetTagHoles, .reindexUnread, .resetCacheIndex, .reindexCache, .resetBiometricsData, .optimizeDatabase, .photoPreview, .knockoutWallpaper, .storiesExperiment, .storiesJpegExperiment, .playlistPlayback, .enableQuickReactionSwitch, .experimentalCompatibility, .enableDebugDataDisplay, .rippleEffect, .browserExperiment, .localTranscription, .enableReactionOverrides, .restorePurchases, .disableReloginTokens, .disableCallV2, .experimentalCallMute, .liveStreamV2, .dynamicStreaming, .enableLocalTranslation:
return DebugControllerSection.experiments.rawValue
case .logTranslationRecognition, .resetTranslationStates:
return DebugControllerSection.translation.rawValue
Expand Down Expand Up @@ -251,8 +252,10 @@ private enum DebugControllerEntry: ItemListNodeEntry {
return 53
case .dynamicStreaming:
return 54
case .enableLocalTranslation:
return 55
case let .preferredVideoCodec(index, _, _, _):
return 55 + index
return 56 + index
case .disableVideoAspectScaling:
return 100
case .enableNetworkFramework:
Expand Down Expand Up @@ -1361,6 +1364,16 @@ private enum DebugControllerEntry: ItemListNodeEntry {
})
}).start()
})
case let .enableLocalTranslation(value):
return ItemListSwitchItem(presentationData: presentationData, title: "Local Translation", value: value, sectionId: self.section, style: .blocks, updated: { value in
let _ = arguments.sharedContext.accountManager.transaction ({ transaction in
transaction.updateSharedData(ApplicationSpecificSharedDataKeys.experimentalUISettings, { settings in
var settings = settings?.get(ExperimentalUISettings.self) ?? ExperimentalUISettings.defaultSettings
settings.enableLocalTranslation = value
return PreferencesEntry(settings)
})
}).start()
})
case let .preferredVideoCodec(_, title, value, isSelected):
return ItemListCheckboxItem(presentationData: presentationData, title: title, style: .right, checked: isSelected, zeroSeparatorInsets: false, sectionId: self.section, action: {
let _ = arguments.sharedContext.accountManager.transaction ({ transaction in
Expand Down Expand Up @@ -1519,6 +1532,7 @@ private func debugControllerEntries(sharedContext: SharedAccountContext, present
entries.append(.experimentalCallMute(experimentalSettings.experimentalCallMute))
entries.append(.liveStreamV2(experimentalSettings.liveStreamV2))
entries.append(.dynamicStreaming(experimentalSettings.dynamicStreaming))
entries.append(.enableLocalTranslation(experimentalSettings.enableLocalTranslation))
}

/*let codecs: [(String, String?)] = [
Expand Down
14 changes: 8 additions & 6 deletions submodules/GalleryUI/Sources/GalleryController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -246,12 +246,14 @@ public func galleryItemForEntry(
} else {
if true || (file.mimeType == "video/mpeg4" || file.mimeType == "video/mov" || file.mimeType == "video/mp4") {
var isHLS = false
if NativeVideoContent.isHLSVideo(file: file) {
isHLS = true

if let data = context.currentAppConfiguration.with({ $0 }).data, let disableHLS = data["video_ignore_alt_documents"] as? Double {
if Int(disableHLS) != 0 {
isHLS = false
if #available(iOS 13.0, *) {
if NativeVideoContent.isHLSVideo(file: file) {
isHLS = true

if let data = context.currentAppConfiguration.with({ $0 }).data, let disableHLS = data["video_ignore_alt_documents"] as? Double {
if Int(disableHLS) != 0 {
isHLS = false
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2993,9 +2993,11 @@ final class UniversalVideoGalleryItemNode: ZoomableContentGalleryItemNode {
self.activePictureInPictureController = nil
self.activePictureInPictureNavigationController = nil

let previousPresentationArguments = activePictureInPictureController.presentationArguments
activePictureInPictureController.presentationArguments = nil
activePictureInPictureNavigationController.currentWindow?.present(activePictureInPictureController, on: .root, blockInteraction: false, completion: {
})
activePictureInPictureController.presentationArguments = previousPresentationArguments

activePictureInPictureController.view.alpha = 1.0
activePictureInPictureController.view.layer.animateAlpha(from: 0.0, to: 1.0, duration: 0.35, completion: { _ in
Expand Down
Loading

0 comments on commit 9a46522

Please sign in to comment.