From 90c26b3f8c81a10982ae491b81a8f2260e1a0778 Mon Sep 17 00:00:00 2001 From: Benoit Martins Date: Wed, 3 May 2023 13:37:17 +0200 Subject: [PATCH] Add Debug Popup Code for displaying and sharing LinphoneRC file (#1234# in Dialer) --- Classes/DialerView.m | 51 +++++--------- Classes/Swift/Util/Viewers/TextViewer.swift | 72 ++++++++++++++++++++ Resources/en.lproj/Localizable.strings | Bin 54584 -> 54662 bytes Resources/fr.lproj/Localizable.strings | Bin 76330 -> 76428 bytes linphone.xcodeproj/project.pbxproj | 12 ++++ 5 files changed, 102 insertions(+), 33 deletions(-) create mode 100644 Classes/Swift/Util/Viewers/TextViewer.swift diff --git a/Classes/DialerView.m b/Classes/DialerView.m index ca5b224f1..40bd4fa3b 100644 --- a/Classes/DialerView.m +++ b/Classes/DialerView.m @@ -285,16 +285,10 @@ static UICompositeViewDescription *compositeDescription = nil; - (BOOL)displayDebugPopup:(NSString *)address { LinphoneManager *mgr = LinphoneManager.instance; NSString *debugAddress = [mgr lpConfigStringForKey:@"debug_popup_magic" withDefault:@""]; - if (![debugAddress isEqualToString:@""] && [address isEqualToString:debugAddress]) { + if (TRUE) { UIAlertController *errView = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"Debug", nil) message:NSLocalizedString(@"Choose an action", nil) preferredStyle:UIAlertControllerStyleAlert]; - - UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"Cancel", nil) - style:UIAlertActionStyleDefault - handler:^(UIAlertAction * action) {}]; - - [errView addAction:defaultAction]; int debugLevel = [LinphoneManager.instance lpConfigIntForKey:@"debugenable_preference"]; BOOL debugEnabled = (debugLevel >= ORTP_DEBUG && debugLevel < ORTP_ERROR); @@ -322,31 +316,21 @@ static UICompositeViewDescription *compositeDescription = nil; }]; [errView addAction:logAction]; - UIAlertAction* remAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"Remove account(s) and self destruct", nil) - style:UIAlertActionStyleDefault - handler:^(UIAlertAction * action) { - linphone_core_clear_accounts([LinphoneManager getLc]); - linphone_core_clear_all_auth_info([LinphoneManager getLc]); - @try { - [LinphoneManager.instance destroyLinphoneCore]; - } @catch (NSException *e) { - LOGW(@"Exception while destroying linphone core: %@", e); - } @finally { - if ([NSFileManager.defaultManager - isDeletableFileAtPath:[LinphoneManager preferenceFile:@"linphonerc"]] == YES) { - [NSFileManager.defaultManager - removeItemAtPath:[LinphoneManager preferenceFile:@"linphonerc"] - error:nil]; - } -#ifdef DEBUG - [LinphoneManager instanceRelease]; -#endif - } - [UIApplication sharedApplication].keyWindow.rootViewController = nil; - // make the application crash to be sure that user restart it properly - LOGF(@"Self-destructing in 3..2..1..0!"); - }]; - [errView addAction:remAction]; + UIAlertAction* configAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"View config file", nil) + style:UIAlertActionStyleDefault + handler:^(UIAlertAction * action) { + TextViewer *view = VIEW(TextViewer); + view.textViewer = [NSString stringWithContentsOfFile:[LinphoneManager bundleFile:@"linphonerc"] encoding:NSUTF8StringEncoding error:nil]; + [PhoneMainView.instance popToView:view.compositeViewDescription]; + }]; + + [errView addAction:configAction]; + + UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"Cancel", nil) + style:UIAlertActionStyleDefault + handler:^(UIAlertAction * action) {}]; + + [errView addAction:defaultAction]; [self presentViewController:errView animated:YES completion:nil]; return true; @@ -419,7 +403,8 @@ static UICompositeViewDescription *compositeDescription = nil; } - (IBAction)onAddressChange:(id)sender { - if ([self displayDebugPopup:_addressField.text]) { + if ([_addressField.text isEqual: @"#1234#"]) { + [self displayDebugPopup:_addressField.text]; _addressField.text = @""; } LinphoneAccount *defaultAccount = linphone_core_get_default_account(LC); diff --git a/Classes/Swift/Util/Viewers/TextViewer.swift b/Classes/Swift/Util/Viewers/TextViewer.swift new file mode 100644 index 000000000..a8c137342 --- /dev/null +++ b/Classes/Swift/Util/Viewers/TextViewer.swift @@ -0,0 +1,72 @@ +// +// TextViewer.swift +// linphone +// +// Created by BenoƮt Martins on 03/05/2023. +// + +import Foundation + +@objc class TextViewer: BackNextNavigationView, UICompositeViewDelegate { + + static let compositeDescription = UICompositeViewDescription(TextViewer.self, statusBar: StatusBarView.self, tabBar: nil, sideMenu: SideMenuView.self, fullscreen: false, isLeftFragment: false,fragmentWith: nil) + static func compositeViewDescription() -> UICompositeViewDescription! { return compositeDescription } + func compositeViewDescription() -> UICompositeViewDescription! { return type(of: self).compositeDescription } + + @objc var textViewer = "" + let textViewViewer = UITextView() + + override func viewDidLoad() { + + super.viewDidLoad( + backAction: { + PhoneMainView.instance().popView(self.compositeViewDescription()) + },nextAction: { + }, + nextActionEnableCondition: MutableLiveData(false), + title:"") + super.nextButton.isHidden = true + + let shareButton = CallControlButton(buttonTheme:VoipTheme.nav_button("voip_export")) + super.topBar.addSubview(shareButton) + shareButton.alignParentRight(withMargin: side_buttons_margin).alignParentBottom(withMargin: 18).alignParentTop(withMargin: 18).done() + + shareButton.addTarget(self, action: #selector(shareTextButton), for: .touchUpInside) + + super.backButton.isHidden = UIDevice.ipad() + + textViewViewer.isScrollEnabled = true + textViewViewer.isUserInteractionEnabled = true + textViewViewer.frame = CGRect(x: 0, y: top_bar_height, width: UIScreen.main.bounds.size.width, height: UIScreen.main.bounds.size.height-top_bar_height*2-32.0) + + self.view.addSubview(textViewViewer) + + UIDeviceBridge.displayModeSwitched.readCurrentAndObserve { _ in + self.view.backgroundColor = VoipTheme.voipBackgroundBWColor.get() + self.textViewViewer.frame = CGRect(x: 0, y: self.top_bar_height, width: UIScreen.main.bounds.size.width, height: UIScreen.main.bounds.size.height - (self.top_bar_height * 2) - 32.0) + } + + } + + override func viewDidAppear(_ animated: Bool) { + textViewViewer.text = textViewer + } + + @IBAction func shareTextButton(_ sender: UIButton) { + + // text to share + let text = textViewer + + // set up activity view controller + let textToShare = [ text ] + let activityViewController = UIActivityViewController(activityItems: textToShare, applicationActivities: nil) + activityViewController.popoverPresentationController?.sourceView = self.view // so that iPads won't crash + + // exclude some activity types from the list (optional) + activityViewController.excludedActivityTypes = [ UIActivity.ActivityType.airDrop, UIActivity.ActivityType.postToFacebook ] + + // present the view controller + self.present(activityViewController, animated: true, completion: nil) + + } +} diff --git a/Resources/en.lproj/Localizable.strings b/Resources/en.lproj/Localizable.strings index d6f2e930ffe9e7d6ecfeaa2d31bef1c59e586ffc..93bb71648491366ccc9eb8696f15a5c299c39e73 100644 GIT binary patch delta 79 zcmdn7in(ny^M+pnlLbooHuDHh=n&3iNM$HzP+&-A$Y;o7NMp!kNT2K|Dk>iaWMRkv Q)qzyxFr;ptICHr*0Eqh)9RL6T delta 23 fcmZo$&Aek3^M+pnlXv(EZRQZ1(6RZ|%sJKoft?EP diff --git a/Resources/fr.lproj/Localizable.strings b/Resources/fr.lproj/Localizable.strings index bae2c8070f3cc075c18b2f1da03392daa01a5d0a..a52313e3251360671809b4f0a934b47ddb51083d 100644 GIT binary patch delta 55 zcmZ2=g{9{z%Z38Y%|)6%4Z@iWsSM=|3Jl2%`3!jsX$+YR>5~~HL?_F52uyzE#y5G1 Li^%3JE6W-H`*9Ly delta 19 bcmeCV%ChPT%Z38Y&3T%B4Vx8K