Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/dev' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
LiuYi0526 committed May 7, 2024
2 parents bee7c51 + 849a869 commit 855ada6
Show file tree
Hide file tree
Showing 40 changed files with 295 additions and 17 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
.vscode/
build/
local.properties
sentry.properties
obj/
service_account_credentials.json
__pycache__/
Expand Down
145 changes: 144 additions & 1 deletion TMessagesProj/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import io.sentry.android.gradle.extensions.InstrumentationFeature
import io.sentry.android.gradle.instrumentation.logcat.LogcatLevel

apply plugin: "com.android.application"
apply plugin: "kotlin-android"
apply plugin: "io.sentry.android.gradle"

repositories {
maven {
Expand All @@ -11,7 +15,7 @@ repositories {
}

def verName = "10.12.0"
def verCode = 1172
def verCode = 1174


def officialVer = "10.12.0"
Expand Down Expand Up @@ -43,6 +47,8 @@ configurations {
def keystorePwd = null
def alias = null
def pwd = null
def sentry_token = System.getenv("SENTRY_AUTH_TOKEN")
def sentry_upload = project.rootProject.file("sentry.properties").exists()
def disableCMakeRelWithDebInfo = System.getenv("COMPILE_NATIVE") == null

Properties properties
Expand All @@ -59,6 +65,7 @@ if (properties != null) {
keystorePwd = properties.getProperty("KEYSTORE_PASS")
alias = properties.getProperty("ALIAS_NAME")
pwd = properties.getProperty("ALIAS_PASS")
sentry_token = properties.getProperty("SENTRY_AUTH_TOKEN", sentry_token)
}

keystorePwd = keystorePwd ?: System.getenv("KEYSTORE_PASS")
Expand Down Expand Up @@ -389,3 +396,139 @@ android {
}

}

sentry {
// Disables or enables debug log output, e.g. for for sentry-cli.
// Default is disabled.
debug = false

// The slug of the Sentry organization to use for uploading proguard mappings/source contexts.
org = "pagermaid"

// The slug of the Sentry project to use for uploading proguard mappings/source contexts.
projectName = "nagram"

// The authentication token to use for uploading proguard mappings/source contexts.
// WARNING: Do not expose this token in your build.gradle files, but rather set an environment
// variable and read it into this property.
authToken = sentry_token

// The url of your Sentry instance. If you're using SAAS (not self hosting) you do not have to
// set this. If you are self hosting you can set your URL here
url = null

// Disables or enables the handling of Proguard mapping for Sentry.
// If enabled the plugin will generate a UUID and will take care of
// uploading the mapping to Sentry. If disabled, all the logic
// related to proguard mapping will be excluded.
// Default is enabled.
includeProguardMapping = sentry_upload

// Whether the plugin should attempt to auto-upload the mapping file to Sentry or not.
// If disabled the plugin will run a dry-run and just generate a UUID.
// The mapping file has to be uploaded manually via sentry-cli in this case.
// Default is enabled.
autoUploadProguardMapping = sentry_upload

// Experimental flag to turn on support for GuardSquare's tools integration (Dexguard and External Proguard).
// If enabled, the plugin will try to consume and upload the mapping file produced by Dexguard and External Proguard.
// Default is disabled.
dexguardEnabled = false

// Disables or enables the automatic configuration of Native Symbols
// for Sentry. This executes sentry-cli automatically so
// you don't need to do it manually.
// Default is disabled.
uploadNativeSymbols = sentry_upload

// Whether the plugin should attempt to auto-upload the native debug symbols to Sentry or not.
// If disabled the plugin will run a dry-run.
// Default is enabled.
autoUploadNativeSymbols = sentry_upload

// Does or doesn't include the source code of native code for Sentry.
// This executes sentry-cli with the --include-sources param. automatically so
// you don't need to do it manually.
// This option has an effect only when [uploadNativeSymbols] is enabled.
// Default is disabled.
includeNativeSources = false

// Generates a JVM (Java, Kotlin, etc.) source bundle and uploads your source code to Sentry.
// This enables source context, allowing you to see your source
// code as part of your stack traces in Sentry.
includeSourceContext = sentry_upload

// Configure additional directories to be included in the source bundle which is used for
// source context. The directories should be specified relative to the Gradle module/project's
// root. For example, if you have a custom source set alongside 'main', the parameter would be
// 'src/custom/java'.
additionalSourceDirsForSourceContext = []

// Enable or disable the tracing instrumentation.
// Does auto instrumentation for specified features through bytecode manipulation.
// Default is enabled.
tracingInstrumentation {
enabled = true

// Specifies a set of instrumentation features that are eligible for bytecode manipulation.
// Defaults to all available values of InstrumentationFeature enum class.
features = [InstrumentationFeature.DATABASE, InstrumentationFeature.FILE_IO, InstrumentationFeature.OKHTTP, InstrumentationFeature.COMPOSE]

// Enable or disable logcat instrumentation through bytecode manipulation.
// Default is enabled.
logcat {
enabled = true

// Specifies a minimum log level for the logcat breadcrumb logging.
// Defaults to LogcatLevel.WARNING.
minLevel = LogcatLevel.WARNING
}

// The set of glob patterns to exclude from instrumentation. Classes matching any of these
// patterns in the project's sources and dependencies JARs won't be instrumented by the Sentry
// Gradle plugin.
//
// Don't include the file extension. Filtering is done on compiled classes and
// the .class suffix isn't included in the pattern matching.
//
// Example usage:
// ```
// excludes = ['com/example/donotinstrument/**', '**/*Test']
// ```
//
// Only supported when using Android Gradle plugin (AGP) version 7.4.0 and above.
excludes = []
}

// Enable auto-installation of Sentry components (sentry-android SDK and okhttp, timber and fragment integrations).
// Default is enabled.
// Only available v3.1.0 and above.
autoInstallation {
enabled = true

// Specifies a version of the sentry-android SDK and fragment, timber and okhttp integrations.
//
// This is also useful, when you have the sentry-android SDK already included into a transitive dependency/module and want to
// align integration versions with it (if it's a direct dependency, the version will be inferred).
//
// NOTE: if you have a higher version of the sentry-android SDK or integrations on the classpath, this setting will have no effect
// as Gradle will resolve it to the latest version.
//
// Defaults to the latest published Sentry version.
sentryVersion = '7.8.0'
}

// Disables or enables dependencies metadata reporting for Sentry.
// If enabled, the plugin will collect external dependencies and
// upload them to Sentry as part of events. If disabled, all the logic
// related to the dependencies metadata report will be excluded.
//
// Default is enabled.
includeDependenciesReport = true

// Whether the plugin should send telemetry data to Sentry.
// If disabled the plugin won't send telemetry data.
// This is auto disabled if running against a self hosted instance of Sentry.
// Default is enabled.
telemetry = true
}
2 changes: 2 additions & 0 deletions TMessagesProj/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@
android:allowAudioPlaybackCapture="true"
tools:replace="android:supportsRtl">

<meta-data android:name="io.sentry.auto-init" android:value="false" />

<activity-alias
android:enabled="true"
android:name="org.telegram.messenger.DefaultIcon"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@

import tw.nekomimi.nekogram.NekoConfig;
import tw.nekomimi.nekogram.NekoXConfig;
import tw.nekomimi.nekogram.helpers.AnalyticsHelper;
import tw.nekomimi.nekogram.parts.SignturesKt;
import tw.nekomimi.nekogram.utils.FileUtil;
import xyz.nextalone.nagram.NaConfig;
Expand Down Expand Up @@ -111,6 +112,7 @@ protected void attachBaseContext(Context base) {
}
Thread.currentThread().setUncaughtExceptionHandler((thread, error) -> {
Log.e("nekox", "from " + thread.toString(), error);
AnalyticsHelper.captureException(error);
});
}

Expand Down Expand Up @@ -297,6 +299,8 @@ public void onCreate() {

super.onCreate();

AnalyticsHelper.start(this);

if (BuildVars.LOGS_ENABLED) {
FileLog.d("app start time = " + (startTime = SystemClock.elapsedRealtime()));
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2730,11 +2730,13 @@ public void cancelLoadingForImageReceiver(final ImageReceiver imageReceiver, fin
return;
}
ArrayList<Runnable> runnables = imageReceiver.getLoadingOperations();
if (!runnables.isEmpty()) {
for (int i = 0; i < runnables.size(); i++) {
imageLoadQueue.cancelRunnable(runnables.get(i));
synchronized (runnables) {
if (!runnables.isEmpty()) {
for (int i = 0; i < runnables.size(); i++) {
imageLoadQueue.cancelRunnable(runnables.get(i));
}
runnables.clear();
}
runnables.clear();
}
imageReceiver.addLoadingImageRunnable(null);
imageLoadQueue.postRunnable(() -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import android.content.SharedPreferences;
import android.os.Build;
import android.os.IBinder;
import android.util.Log;

import androidx.core.app.NotificationCompat;

Expand All @@ -43,7 +44,11 @@ public void onCreate() {
.setSmallIcon(R.drawable.notification)
.setContentText(LocaleController.getString("NekoXPushService", R.string.NekoXPushService))
.build();
startForeground(9999, notification);
try {
startForeground(9999, notification);
} catch (Throwable e) {
Log.d("TFOSS", "Failed to start push service");
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6202,6 +6202,7 @@ protected void onPause() {
if (ApplicationLoader.applicationLoaderInstance != null) {
doNotPause = ApplicationLoader.applicationLoaderInstance.onPause();
}
ProxyUtil.unregisterNetworkCallback();
ConnectionsManager.getInstance(currentAccount).setAppPaused(!doNotPause, false);
if (PhotoViewer.hasInstance() && PhotoViewer.getInstance().isVisible()) {
PhotoViewer.getInstance().onPause();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package tw.nekomimi.nekogram.helpers;

import android.app.Application;
import android.content.Context;
import android.content.SharedPreferences;

import org.telegram.messenger.BuildConfig;
import org.telegram.messenger.BuildVars;


import io.sentry.Sentry;
import io.sentry.SentryLevel;
import io.sentry.android.core.SentryAndroid;

public class AnalyticsHelper {
public static String DSN = "https://58f21343622b885cb7ad43fee0943f77@o416616.ingest.us.sentry.io/4507212454428672";
public static boolean loaded = false;

public static void start(Application application) {
if (!getSentryStatus(application)) {
return;
}
SentryAndroid.init(application, options -> {
options.setDsn(DSN);
options.setEnvironment(BuildVars.DEBUG_VERSION ? "debug" : "release");
options.setEnableAutoSessionTracking(true);
options.setTracesSampleRate(1.0);
options.setAttachAnrThreadDump(true);
options.setRelease(BuildConfig.APPLICATION_ID + "@" + BuildConfig.VERSION_NAME + "+" + BuildConfig.VERSION_CODE);
options.setBeforeScreenshotCaptureCallback((event, hint, debounce) -> {
// always capture crashed events
if (event.isCrashed()) {
return true;
}

// if debounce is active, skip capturing
if (debounce) {
return false;
} else {
// also capture fatal events
return event.getLevel() == SentryLevel.FATAL;
}
});
});
loaded = true;
}

public static void captureException(Throwable e) {
if (loaded) {
Sentry.captureException(e);
}
}

public static boolean getSentryStatus(Application application) {
SharedPreferences preferences = application.getApplicationContext().getSharedPreferences(
"nkmrcfg",
Context.MODE_PRIVATE
);
return preferences.getBoolean("SentryAnalytics", true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,7 @@ public ArrayList<EmojiPackBase> getEmojiPacks() {

public ArrayList<EmojiPackInfo> getEmojiPacksInfo() {
return emojiPacksInfo.parallelStream()
.filter(Objects::nonNull)
.filter(e -> e instanceof EmojiPackInfo)
.map(e -> (EmojiPackInfo) e)
.filter(e -> e.getFileDocument() != null && e.getPreviewDocument() != null)
Expand All @@ -399,6 +400,7 @@ public ArrayList<EmojiPackInfo> getEmojiPacksInfo() {

public ArrayList<EmojiPackBase> getEmojiCustomPacksInfo() {
return emojiPacksInfo.parallelStream()
.filter(Objects::nonNull)
.filter(e -> !(e instanceof EmojiPackInfo))
.filter(e -> !e.getPackId().equals(pendingDeleteEmojiPackId))
.collect(Collectors.toCollection(ArrayList::new));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ fun MessageObject.toRawString(): String {
for (answer in poll.answers) {

content += "\n- "
content += answer.text
content += answer.text.text

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import org.telegram.tgnet.TLRPC
fun postPollTrans(media: TLRPC.TL_messageMediaPoll, poll: TLRPC.TL_poll) {
poll.translatedQuestion = media.poll.translatedQuestion
poll.answers.forEach { answer ->
answer.translatedText = media.poll.answers.find { it.text == answer.text }!!.translatedText
val answerF = media.poll.answers.find { it.text.text == answer.text.text }
if (answerF != null) {
answer.translatedText = answerF.translatedText
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ public class NekoGeneralSettingsActivity extends BaseNekoXSettingsActivity {
private final AbstractConfigCell doNotShareMyPhoneNumberRow = cellGroup.appendCell(new ConfigCellTextCheck(NaConfig.INSTANCE.getDoNotShareMyPhoneNumber()));
private final AbstractConfigCell disableSuggestionViewRow = cellGroup.appendCell(new ConfigCellTextCheck(NaConfig.INSTANCE.getDisableSuggestionView()));
private final AbstractConfigCell disableAutoWebLoginRow = cellGroup.appendCell(new ConfigCellTextCheck(NaConfig.INSTANCE.getDisableAutoWebLogin()));
private final AbstractConfigCell sentryAnalyticsRow = cellGroup.appendCell(new ConfigCellTextCheck(NaConfig.INSTANCE.getSentryAnalytics()));
private final AbstractConfigCell divider6 = cellGroup.appendCell(new ConfigCellDivider());

private final AbstractConfigCell header7 = cellGroup.appendCell(new ConfigCellHeader(LocaleController.getString("General")));
Expand Down Expand Up @@ -498,6 +499,8 @@ public void onItemClick(int id) {
ApplicationLoader.startPushService();
} else if (key.equals(NaConfig.INSTANCE.getPushServiceTypeUnifiedGateway().getKey())) {
restartTooltip.showWithAction(0, UndoView.ACTION_NEED_RESATRT, null, null);
} else if (key.equals(NaConfig.INSTANCE.getSentryAnalytics().getKey())) {
restartTooltip.showWithAction(0, UndoView.ACTION_NEED_RESATRT, null, null);
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ object TelegramAPITranslator : Translator {
if (res is TL_messages_translateResult && res.result.isNotEmpty()) {
it.resume(res.result[0].text)
} else {
FileLog.e(err?.text)
if (err?.text != null && err.text!!.isNotEmpty()) {
FileLog.e(err.text)
}
it.resumeWithException(RuntimeException("Failed to translate by Telegram API"))
}
}
Expand Down
Loading

0 comments on commit 855ada6

Please sign in to comment.