From 25a3467cb32833647895d20ee2972181f356d751 Mon Sep 17 00:00:00 2001 From: Vladimir Tanakov Date: Mon, 23 Dec 2019 23:12:35 +0300 Subject: [PATCH] Add crash reporting controller and email sending on android (#1509) --- .../translationsByLanguage/Czech.properties | 2 + .../translationsByLanguage/Dutch.properties | 2 + .../translationsByLanguage/English.properties | 4 +- .../translationsByLanguage/French.properties | 2 + .../translationsByLanguage/German.properties | 2 + .../translationsByLanguage/Italian.properties | 2 + .../translationsByLanguage/Korean.properties | 2 + .../translationsByLanguage/Malay.properties | 4 +- .../translationsByLanguage/Polish.properties | 2 + .../Portuguese.properties | 2 + .../Romanian.properties | 4 +- .../translationsByLanguage/Russian.properties | 1 + .../Simplified_Chinese.properties | 2 + .../translationsByLanguage/Spanish.properties | 2 + .../Traditional_Chinese.properties | 2 + .../Ukrainian.properties | 2 + .../template.properties | 1 + android/src/com/unciv/app/AndroidLauncher.kt | 7 +- .../com/unciv/app/UncivCrashReportSender.kt | 46 +++++++++++++ core/src/com/unciv/UncivGame.kt | 12 +++- core/src/com/unciv/models/CrashReport.kt | 7 ++ .../src/com/unciv/ui/utils/CrashController.kt | 69 +++++++++++++++++++ .../com/unciv/ui/utils/CrashReportSender.kt | 8 +++ .../com/unciv/ui/worldscreen/WorldScreen.kt | 29 +++----- ios/src/com/unciv/app/IOSLauncher.java | 2 +- .../gdxtesting/examples/BasicTests.java | 4 +- 26 files changed, 189 insertions(+), 33 deletions(-) create mode 100644 android/src/com/unciv/app/UncivCrashReportSender.kt create mode 100644 core/src/com/unciv/models/CrashReport.kt create mode 100644 core/src/com/unciv/ui/utils/CrashController.kt create mode 100644 core/src/com/unciv/ui/utils/CrashReportSender.kt diff --git a/android/assets/jsons/translationsByLanguage/Czech.properties b/android/assets/jsons/translationsByLanguage/Czech.properties index 3b20a2894b..516b99cb72 100644 --- a/android/assets/jsons/translationsByLanguage/Czech.properties +++ b/android/assets/jsons/translationsByLanguage/Czech.properties @@ -18,6 +18,8 @@ Move an air unit!\nSelect an air unit > select another city withing range > \nMo See your stats breakdown!\nEnter the Overview screen (top right corner) >\nClick on 'Stats' = Zobraz statistiku!\nVstup do Přehledové obrazovky (pravý horní roh) >\nKlikni na 'Statistika' Oh no! It looks like something went DISASTROUSLY wrong! This is ABSOLUTELY not supposed to happen! Please send me (yairm210@hotmail.com) an email with the game information (menu -> save game -> copy game info -> paste into email) and I'll try to fix it as fast as I can! = Hrom do čepice! Vypadá to, že se něco HÓÓÓDNĚ pokaziloTohle by se v ŽÁDNÉM PŘÍPADĚ nemělo stávat! Prosím pošlete mi (yairm210@hotmail.com) email s informacemi o hře (menu -> uložit hru -> kopírovat herní info -> vložit do emailu) a já se to pokusím opravit jak nejrychleji budu umět! + # Requires translation! +Oh no! It looks like something went DISASTROUSLY wrong! This is ABSOLUTELY not supposed to happen! Please send us an report and we'll try to fix it as fast as we can! = # Buildings diff --git a/android/assets/jsons/translationsByLanguage/Dutch.properties b/android/assets/jsons/translationsByLanguage/Dutch.properties index df9c4fa837..9ba3396ffd 100644 --- a/android/assets/jsons/translationsByLanguage/Dutch.properties +++ b/android/assets/jsons/translationsByLanguage/Dutch.properties @@ -32,6 +32,8 @@ See your stats breakdown!\nEnter the Overview screen (top right corner) >\nClick # Requires translation! Oh no! It looks like something went DISASTROUSLY wrong! This is ABSOLUTELY not supposed to happen! Please send me (yairm210@hotmail.com) an email with the game information (menu -> save game -> copy game info -> paste into email) and I'll try to fix it as fast as I can! = + # Requires translation! +Oh no! It looks like something went DISASTROUSLY wrong! This is ABSOLUTELY not supposed to happen! Please send us an report and we'll try to fix it as fast as we can! = # Buildings diff --git a/android/assets/jsons/translationsByLanguage/English.properties b/android/assets/jsons/translationsByLanguage/English.properties index 1a0970b48f..f5bb9d9650 100644 --- a/android/assets/jsons/translationsByLanguage/English.properties +++ b/android/assets/jsons/translationsByLanguage/English.properties @@ -31,7 +31,9 @@ Move an air unit!\nSelect an air unit > select another city withing range > \nMo See your stats breakdown!\nEnter the Overview screen (top right corner) >\nClick on 'Stats' = # Requires translation! -Oh no! It looks like something went DISASTROUSLY wrong! This is ABSOLUTELY not supposed to happen! Please send me (yairm210@hotmail.com) an email with the game information (menu -> save game -> copy game info -> paste into email) and I'll try to fix it as fast as I can! = +Oh no! It looks like something went DISASTROUSLY wrong! This is ABSOLUTELY not supposed to happen! Please send me (yairm210@hotmail.com) an email with the game information (menu -> save game -> copy game info -> paste into email) and I'll try to fix it as fast as I can! = + # Requires translation! +Oh no! It looks like something went DISASTROUSLY wrong! This is ABSOLUTELY not supposed to happen! Please send us an report and we'll try to fix it as fast as we can! = # Buildings diff --git a/android/assets/jsons/translationsByLanguage/French.properties b/android/assets/jsons/translationsByLanguage/French.properties index 23b6e48243..9294e5bf70 100644 --- a/android/assets/jsons/translationsByLanguage/French.properties +++ b/android/assets/jsons/translationsByLanguage/French.properties @@ -17,6 +17,8 @@ Move an air unit!\nSelect an air unit > select another city withing range > \nMo See your stats breakdown!\nEnter the Overview screen (top right corner) >\nClick on 'Stats' = Observez vos statistiques en détail !\n Allez dans la vue d'ensemble (dans le coin en haut à droite) >\nCliquez sur 'Statistiques' Oh no! It looks like something went DISASTROUSLY wrong! This is ABSOLUTELY not supposed to happen! Please send me (yairm210@hotmail.com) an email with the game information (menu -> save game -> copy game info -> paste into email) and I'll try to fix it as fast as I can! = Oh non ! On dirait que quelque chose ne s'est ABSOLUMENT pas passé comme prévu ! Ce n'est pas censé arriver ! S'il vous plaît, envoyez un mail à yairm210@hotmail.com avec les informations de la partie (Menu (en haut à gauche) -> Charger une partie -> Copy saved game to clipboard -> Copier dans le mail) et j'essayerai de régler cela aussi vite que possible ! + # Requires translation! +Oh no! It looks like something went DISASTROUSLY wrong! This is ABSOLUTELY not supposed to happen! Please send us an report and we'll try to fix it as fast as we can! = # Buildings diff --git a/android/assets/jsons/translationsByLanguage/German.properties b/android/assets/jsons/translationsByLanguage/German.properties index e1df5d7d49..d35f003162 100644 --- a/android/assets/jsons/translationsByLanguage/German.properties +++ b/android/assets/jsons/translationsByLanguage/German.properties @@ -18,6 +18,8 @@ See your stats breakdown!\nEnter the Overview screen (top right corner) >\nClick # Requires translation! Oh no! It looks like something went DISASTROUSLY wrong! This is ABSOLUTELY not supposed to happen! Please send me (yairm210@hotmail.com) an email with the game information (menu -> save game -> copy game info -> paste into email) and I'll try to fix it as fast as I can! = + # Requires translation! +Oh no! It looks like something went DISASTROUSLY wrong! This is ABSOLUTELY not supposed to happen! Please send us an report and we'll try to fix it as fast as we can! = # Buildings diff --git a/android/assets/jsons/translationsByLanguage/Italian.properties b/android/assets/jsons/translationsByLanguage/Italian.properties index b7c1652b16..7e39c17827 100644 --- a/android/assets/jsons/translationsByLanguage/Italian.properties +++ b/android/assets/jsons/translationsByLanguage/Italian.properties @@ -17,6 +17,8 @@ Move an air unit!\nSelect an air unit > select another city withing range > \nMo See your stats breakdown!\nEnter the Overview screen (top right corner) >\nClick on 'Stats' = Visualizza le tue statistiche!\nEntra nella tua schermata Panoramica (in alto a sinistra)\nClicca su 'Statistiche' Oh no! It looks like something went DISASTROUSLY wrong! This is ABSOLUTELY not supposed to happen! Please send me (yairm210@hotmail.com) an email with the game information (menu -> save game -> copy game info -> paste into email) and I'll try to fix it as fast as I can! = Santi numi! Pare che qualcosa sia andato disastrosamente storto! Quello che è successo non era assolutamente previsto! Mandami un'email all'indirizzo yairm210@hotmail.com con l'info della partita (menu -> salva partita -> copia info partita -> incolla su email) e proverò a riparare il guasto il più in fretta possibile! + # Requires translation! +Oh no! It looks like something went DISASTROUSLY wrong! This is ABSOLUTELY not supposed to happen! Please send us an report and we'll try to fix it as fast as we can! = # Buildings diff --git a/android/assets/jsons/translationsByLanguage/Korean.properties b/android/assets/jsons/translationsByLanguage/Korean.properties index 492560c9eb..39c58d733d 100644 --- a/android/assets/jsons/translationsByLanguage/Korean.properties +++ b/android/assets/jsons/translationsByLanguage/Korean.properties @@ -31,6 +31,8 @@ Move an air unit!\nSelect an air unit > select another city withing range > \nMo See your stats breakdown!\nEnter the Overview screen (top right corner) >\nClick on 'Stats' = Oh no! It looks like something went DISASTROUSLY wrong! This is ABSOLUTELY not supposed to happen! Please send me (yairm210@hotmail.com) an email with the game information (menu -> save game -> copy game info -> paste into email) and I'll try to fix it as fast as I can! = 이런, 뭔가 심각한 일이 일어난 것 같군요! 원래라면 일어나지 않아야 하는 일인데 말이죠! (yairm210@hotmail.com) 이메일로 게임 정보를 함께 보내주세요. (메뉴 -> 게임 저장 -> 게임 정보 복사 -> 이메일에 붙여넣기) 하루빨리 찾아서 이런 일이 일어나지 않도록 하겠습니다! + # Requires translation! +Oh no! It looks like something went DISASTROUSLY wrong! This is ABSOLUTELY not supposed to happen! Please send us an report and we'll try to fix it as fast as we can! = # Buildings diff --git a/android/assets/jsons/translationsByLanguage/Malay.properties b/android/assets/jsons/translationsByLanguage/Malay.properties index 0d8460d318..6eb646014c 100644 --- a/android/assets/jsons/translationsByLanguage/Malay.properties +++ b/android/assets/jsons/translationsByLanguage/Malay.properties @@ -31,7 +31,9 @@ Move an air unit!\nSelect an air unit > select another city withing range > \nMo See your stats breakdown!\nEnter the Overview screen (top right corner) >\nClick on 'Stats' = # Requires translation! -Oh no! It looks like something went DISASTROUSLY wrong! This is ABSOLUTELY not supposed to happen! Please send me (yairm210@hotmail.com) an email with the game information (menu -> save game -> copy game info -> paste into email) and I'll try to fix it as fast as I can! = +Oh no! It looks like something went DISASTROUSLY wrong! This is ABSOLUTELY not supposed to happen! Please send me (yairm210@hotmail.com) an email with the game information (menu -> save game -> copy game info -> paste into email) and I'll try to fix it as fast as I can! =\ + # Requires translation! +Oh no! It looks like something went DISASTROUSLY wrong! This is ABSOLUTELY not supposed to happen! Please send us an report and we'll try to fix it as fast as we can! = # Buildings diff --git a/android/assets/jsons/translationsByLanguage/Polish.properties b/android/assets/jsons/translationsByLanguage/Polish.properties index 53d9413b8d..6096efd804 100644 --- a/android/assets/jsons/translationsByLanguage/Polish.properties +++ b/android/assets/jsons/translationsByLanguage/Polish.properties @@ -18,6 +18,8 @@ Move an air unit!\nSelect an air unit > select another city withing range > \nMo See your stats breakdown!\nEnter the Overview screen (top right corner) >\nClick on 'Stats' = Zobacz rozkład statystyk!\nWejdź w 'Przegląd' (górny prawy róg) >\nKliknij na 'Statystyki' Oh no! It looks like something went DISASTROUSLY wrong! This is ABSOLUTELY not supposed to happen! Please send me (yairm210@hotmail.com) an email with the game information (menu -> save game -> copy game info -> paste into email) and I'll try to fix it as fast as I can! = O nie! Wygląda na to że coś przegapiłem! To absolutnie nie powinno się wydarzyć! Wyślij mi proszę (yairm210@hotmail.com) maila z informacją o grze (menu -> zapisz grę -> skopiuj informacje o grze -> wklej do maila) a ja postaram się to naprawić. Dziękuję za pomoc. + # Requires translation! +Oh no! It looks like something went DISASTROUSLY wrong! This is ABSOLUTELY not supposed to happen! Please send us an report and we'll try to fix it as fast as we can! = # Buildings diff --git a/android/assets/jsons/translationsByLanguage/Portuguese.properties b/android/assets/jsons/translationsByLanguage/Portuguese.properties index 6a751aa3a9..26f963f273 100644 --- a/android/assets/jsons/translationsByLanguage/Portuguese.properties +++ b/android/assets/jsons/translationsByLanguage/Portuguese.properties @@ -32,6 +32,8 @@ See your stats breakdown!\nEnter the Overview screen (top right corner) >\nClick # Requires translation! Oh no! It looks like something went DISASTROUSLY wrong! This is ABSOLUTELY not supposed to happen! Please send me (yairm210@hotmail.com) an email with the game information (menu -> save game -> copy game info -> paste into email) and I'll try to fix it as fast as I can! = + # Requires translation! +Oh no! It looks like something went DISASTROUSLY wrong! This is ABSOLUTELY not supposed to happen! Please send us an report and we'll try to fix it as fast as we can! = # Buildings diff --git a/android/assets/jsons/translationsByLanguage/Romanian.properties b/android/assets/jsons/translationsByLanguage/Romanian.properties index 6ac7b613f0..022ecb6e8b 100644 --- a/android/assets/jsons/translationsByLanguage/Romanian.properties +++ b/android/assets/jsons/translationsByLanguage/Romanian.properties @@ -31,7 +31,9 @@ Move an air unit!\nSelect an air unit > select another city withing range > \nMo See your stats breakdown!\nEnter the Overview screen (top right corner) >\nClick on 'Stats' = # Requires translation! -Oh no! It looks like something went DISASTROUSLY wrong! This is ABSOLUTELY not supposed to happen! Please send me (yairm210@hotmail.com) an email with the game information (menu -> save game -> copy game info -> paste into email) and I'll try to fix it as fast as I can! = +Oh no! It looks like something went DISASTROUSLY wrong! This is ABSOLUTELY not supposed to happen! Please send me (yairm210@hotmail.com) an email with the game information (menu -> save game -> copy game info -> paste into email) and I'll try to fix it as fast as I can! = + # Requires translation! +Oh no! It looks like something went DISASTROUSLY wrong! This is ABSOLUTELY not supposed to happen! Please send us an report and we'll try to fix it as fast as we can! = # Buildings diff --git a/android/assets/jsons/translationsByLanguage/Russian.properties b/android/assets/jsons/translationsByLanguage/Russian.properties index e7448a3efc..d243ec0dd6 100644 --- a/android/assets/jsons/translationsByLanguage/Russian.properties +++ b/android/assets/jsons/translationsByLanguage/Russian.properties @@ -17,6 +17,7 @@ Move an air unit!\nSelect an air unit > select another city withing range > \nMo See your stats breakdown!\nEnter the Overview screen (top right corner) >\nClick on 'Stats' = Посмотрите вашу статистику!\nОткройте экран обзора (верхний правый угол) >\nНажмите на 'Статистика' Oh no! It looks like something went DISASTROUSLY wrong! This is ABSOLUTELY not supposed to happen! Please send me (yairm210@hotmail.com) an email with the game information (menu -> save game -> copy game info -> paste into email) and I'll try to fix it as fast as I can! = О нет! Кажется всё что-то пошло КАТАСТРОФИЧЕСКИ плохо! Это АБСОЛЮТНО не должно было произойти! Пожалуйста отправьте мне (yairm210@hotmail.com) емейл с информацией об игре (меню -> сохранить игру -> скопируйте информацию об игре -> вставьте в емейл) и я попытаюсь это исправить настолько быстро как я могу! +Oh no! It looks like something went DISASTROUSLY wrong! This is ABSOLUTELY not supposed to happen! Please send us an report and we'll try to fix it as fast as we can! =О нет! Кажется всё что-то пошло КАТАСТРОФИЧЕСКИ плохо! Это АБСОЛЮТНО не должно было произойти! Пожалуйста отправьте нам отчет об ошибке и мы попытаемся это исправить как можно скорее! # Buildings diff --git a/android/assets/jsons/translationsByLanguage/Simplified_Chinese.properties b/android/assets/jsons/translationsByLanguage/Simplified_Chinese.properties index c80d37edba..3ffc7f2947 100644 --- a/android/assets/jsons/translationsByLanguage/Simplified_Chinese.properties +++ b/android/assets/jsons/translationsByLanguage/Simplified_Chinese.properties @@ -17,6 +17,8 @@ Move an air unit!\nSelect an air unit > select another city withing range > \nMo See your stats breakdown!\nEnter the Overview screen (top right corner) >\nClick on 'Stats' = 查看当前文明详细信息!\n点击概览按钮(右上角) >\n点击"统计" Oh no! It looks like something went DISASTROUSLY wrong! This is ABSOLUTELY not supposed to happen! Please send me (yairm210@hotmail.com) an email with the game information (menu -> save game -> copy game info -> paste into email) and I'll try to fix it as fast as I can! = NO!看起来游戏好像出现了灾难性的Bug! 这绝对不应该发生! 请将游戏存档信息发送给我,方法如下:依次点击“菜单->保存游戏->复制当前游戏数据到剪贴板”,将剪贴板的内容通过email发送给我。我的email地址:yairm210@hotmail.com。我会尽快处理! +# Requires translation! +Oh no! It looks like something went DISASTROUSLY wrong! This is ABSOLUTELY not supposed to happen! Please send us an report and we'll try to fix it as fast as we can! = # Buildings diff --git a/android/assets/jsons/translationsByLanguage/Spanish.properties b/android/assets/jsons/translationsByLanguage/Spanish.properties index dcf9818307..74ae2c6f18 100644 --- a/android/assets/jsons/translationsByLanguage/Spanish.properties +++ b/android/assets/jsons/translationsByLanguage/Spanish.properties @@ -17,6 +17,8 @@ Move an air unit!\nSelect an air unit > select another city withing range > \nMo See your stats breakdown!\nEnter the Overview screen (top right corner) >\nClick on 'Stats' = ¡Mira tus estadísticas!\nEntra en la ventana de Visión general (arriba a la derecha) >\nHaz clic en 'Estadísticas' Oh no! It looks like something went DISASTROUSLY wrong! This is ABSOLUTELY not supposed to happen! Please send me (yairm210@hotmail.com) an email with the game information (menu -> save game -> copy game info -> paste into email) and I'll try to fix it as fast as I can! = Oh no! Parece que algo se ha roto! Esto no debería haber ocurrido! Mánda me un email (yairm210@hotmail.com , sólo en Inglés) con la información de la partida (menú -> guardar partida -> copiar información de la partida -> copiar en el email) intentaré solucionarlo lo antes posible! + # Requires translation! +Oh no! It looks like something went DISASTROUSLY wrong! This is ABSOLUTELY not supposed to happen! Please send us an report and we'll try to fix it as fast as we can! = # Buildings diff --git a/android/assets/jsons/translationsByLanguage/Traditional_Chinese.properties b/android/assets/jsons/translationsByLanguage/Traditional_Chinese.properties index d0e33d0692..72793c05a7 100644 --- a/android/assets/jsons/translationsByLanguage/Traditional_Chinese.properties +++ b/android/assets/jsons/translationsByLanguage/Traditional_Chinese.properties @@ -17,6 +17,8 @@ Move an air unit!\nSelect an air unit > select another city withing range > \nMo See your stats breakdown!\nEnter the Overview screen (top right corner) >\nClick on 'Stats' = 查看當前文明詳細信息!\n點擊概覽按鈕(右上角) >\n點擊"統計" Oh no! It looks like something went DISASTROUSLY wrong! This is ABSOLUTELY not supposed to happen! Please send me (yairm210@hotmail.com) an email with the game information (menu -> save game -> copy game info -> paste into email) and I'll try to fix it as fast as I can! = NO!看起来游戏好像出现了灾难性的Bug!这绝对不应该发生!请将游戏存档信息发送给我,方法如下:依次点击“菜单->保存游戏->复制当前游戏数据到剪贴板”,将剪贴板的内容通过email发送给我。我的email地址:yairm210@hotmail.com。我会尽快处理! +# Requires translation! +Oh no! It looks like something went DISASTROUSLY wrong! This is ABSOLUTELY not supposed to happen! Please send us an report and we'll try to fix it as fast as we can! = # Buildings diff --git a/android/assets/jsons/translationsByLanguage/Ukrainian.properties b/android/assets/jsons/translationsByLanguage/Ukrainian.properties index 93933f55df..c9dd3b742f 100644 --- a/android/assets/jsons/translationsByLanguage/Ukrainian.properties +++ b/android/assets/jsons/translationsByLanguage/Ukrainian.properties @@ -18,6 +18,8 @@ Move an air unit!\nSelect an air unit > select another city withing range > \nMo See your stats breakdown!\nEnter the Overview screen (top right corner) >\nClick on 'Stats' = Подивіться статистику\nУвійдіть до екрану огляну (верхній правий вугол) >\nНатисніть на «Статистика» Oh no! It looks like something went DISASTROUSLY wrong! This is ABSOLUTELY not supposed to happen! Please send me (yairm210@hotmail.com) an email with the game information (menu -> save game -> copy game info -> paste into email) and I'll try to fix it as fast as I can! = Трясця! Схоже щось пішло КАТАСТРОФІЧНО неправильно! Цього АБСОЛЮТНО НЕ ПОВИННО БУЛО СТАТИСЯ! Будь ласка, надішліть мені (yairm210@hotmail.com) електронний лист з ігровою інформацією (меню -> зберегти гру -> копіювати інформацію про гру -> вставити до email) і я спробую виправити якнайшвидше! +# Requires translation! +Oh no! It looks like something went DISASTROUSLY wrong! This is ABSOLUTELY not supposed to happen! Please send us an report and we'll try to fix it as fast as we can! = # Buildings diff --git a/android/assets/jsons/translationsByLanguage/template.properties b/android/assets/jsons/translationsByLanguage/template.properties index 2c2e56f01a..d75a37d046 100644 --- a/android/assets/jsons/translationsByLanguage/template.properties +++ b/android/assets/jsons/translationsByLanguage/template.properties @@ -17,6 +17,7 @@ Move an air unit!\nSelect an air unit > select another city withing range > \nMo See your stats breakdown!\nEnter the Overview screen (top right corner) >\nClick on 'Stats' = Oh no! It looks like something went DISASTROUSLY wrong! This is ABSOLUTELY not supposed to happen! Please send me (yairm210@hotmail.com) an email with the game information (menu -> save game -> copy game info -> paste into email) and I'll try to fix it as fast as I can! = +Oh no! It looks like something went DISASTROUSLY wrong! This is ABSOLUTELY not supposed to happen! Please send us an report and we'll try to fix it as fast as we can! = # Buildings diff --git a/android/src/com/unciv/app/AndroidLauncher.kt b/android/src/com/unciv/app/AndroidLauncher.kt index 86832c1e0f..2d24064e4b 100644 --- a/android/src/com/unciv/app/AndroidLauncher.kt +++ b/android/src/com/unciv/app/AndroidLauncher.kt @@ -8,9 +8,8 @@ import com.unciv.UncivGame class AndroidLauncher : AndroidApplication() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - val config = AndroidApplicationConfiguration() - val version = BuildConfig.VERSION_NAME - config.useImmersiveMode = true - initialize(UncivGame(version), config) + val config = AndroidApplicationConfiguration().apply { useImmersiveMode = true } + val game = UncivGame(BuildConfig.VERSION_NAME, UncivCrashReportSender(this)) + initialize(game, config) } } \ No newline at end of file diff --git a/android/src/com/unciv/app/UncivCrashReportSender.kt b/android/src/com/unciv/app/UncivCrashReportSender.kt new file mode 100644 index 0000000000..7e40beff5a --- /dev/null +++ b/android/src/com/unciv/app/UncivCrashReportSender.kt @@ -0,0 +1,46 @@ +package com.unciv.app + +import android.app.Activity +import android.content.ActivityNotFoundException +import android.content.Intent +import android.os.Build +import android.widget.Toast +import com.unciv.models.CrashReport +import com.unciv.ui.utils.CrashReportSender + +class UncivCrashReportSender(private val activity: Activity) : CrashReportSender { + + companion object { + private const val EMAIL_TO = "yairm210@hotmail.com" + private const val CHOOSER_TITLE = "Send mail" + private const val CANNOT_SEND_EMAIL = "There are no email clients installed." + private const val EMAIL_TITLE = "Crash report" + private const val EMAIL_BODY = "\n--------------------------------\n" + + "Game version: %s\n" + + "OS version: %s\n" + + "Device model: %s\n" + + "Game data: %s\n" + + "Game settings: %s" + } + + override fun sendReport(report: CrashReport) { + activity.runOnUiThread { + try { + activity.startActivity(Intent.createChooser(prepareIntent(report), CHOOSER_TITLE)) + } catch (ex: ActivityNotFoundException) { + Toast.makeText(activity, CANNOT_SEND_EMAIL, Toast.LENGTH_SHORT).show() + } + } + } + + private fun prepareIntent(report: CrashReport) = Intent(Intent.ACTION_SEND).apply { + type = "message/rfc822" + putExtra(Intent.EXTRA_EMAIL, arrayOf(EMAIL_TO)) + putExtra(Intent.EXTRA_SUBJECT, EMAIL_TITLE) + putExtra(Intent.EXTRA_TEXT, buildEmailBody(report)) + addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) + } + + private fun buildEmailBody(report: CrashReport): String = + EMAIL_BODY.format(report.version, Build.VERSION.SDK_INT, Build.MODEL, report.gameInfo, report.gameSettings) +} \ No newline at end of file diff --git a/core/src/com/unciv/UncivGame.kt b/core/src/com/unciv/UncivGame.kt index 7959b842da..fb108f7d20 100644 --- a/core/src/com/unciv/UncivGame.kt +++ b/core/src/com/unciv/UncivGame.kt @@ -18,16 +18,21 @@ import com.unciv.models.translations.TranslationFileReader import com.unciv.models.translations.Translations import com.unciv.ui.LanguagePickerScreen import com.unciv.ui.utils.CameraStageBaseScreen +import com.unciv.ui.utils.CrashController +import com.unciv.ui.utils.CrashReportSender import com.unciv.ui.utils.ImageGetter import com.unciv.ui.utils.center import com.unciv.ui.worldscreen.WorldScreen -import java.util.* +import java.util.UUID import kotlin.concurrent.thread -class UncivGame(val version: String) : Game() { +class UncivGame( + val version: String, + private val crashReportSender: CrashReportSender? = null +) : Game() { lateinit var gameInfo: GameInfo lateinit var settings : GameSettings - + lateinit var crashController: CrashController /** * This exists so that when debugging we can see the entire map. * Remember to turn this to false before commit and upload! @@ -88,6 +93,7 @@ class UncivGame(val version: String) : Game() { isInitialized = true } } + crashController = CrashController.Impl(crashReportSender) } fun autoLoadGame(){ diff --git a/core/src/com/unciv/models/CrashReport.kt b/core/src/com/unciv/models/CrashReport.kt new file mode 100644 index 0000000000..152135befe --- /dev/null +++ b/core/src/com/unciv/models/CrashReport.kt @@ -0,0 +1,7 @@ +package com.unciv.models + +data class CrashReport( + val gameInfo: String, + val gameSettings: String, + val version: String +) \ No newline at end of file diff --git a/core/src/com/unciv/ui/utils/CrashController.kt b/core/src/com/unciv/ui/utils/CrashController.kt new file mode 100644 index 0000000000..f404ccf294 --- /dev/null +++ b/core/src/com/unciv/ui/utils/CrashController.kt @@ -0,0 +1,69 @@ +package com.unciv.ui.utils + +import com.badlogic.gdx.utils.Json +import com.unciv.UncivGame +import com.unciv.models.CrashReport +import com.unciv.ui.saves.Gzip +import com.unciv.ui.worldscreen.optionstable.PopupTable + +interface CrashController { + + fun crashOccurred() + fun showDialogIfNeeded() + + class Impl(private val crashReportSender: CrashReportSender?) : CrashController { + + companion object { + private const val MESSAGE = "Oh no! It looks like something went DISASTROUSLY wrong!" + + " This is ABSOLUTELY not supposed to happen! Please send us an report" + + " and we'll try to fix it as fast as we can!" + private const val MESSAGE_FALLBACK = "Oh no! It looks like something went DISASTROUSLY wrong!" + + " This is ABSOLUTELY not supposed to happen! Please send me (yairm210@hotmail.com)" + + " an email with the game information (menu -> save game -> copy game info -> paste into email)" + + " and I'll try to fix it as fast as I can!" + } + + override fun crashOccurred() { + UncivGame.Current.settings.run { + hasCrashedRecently = true + save() + } + } + + override fun showDialogIfNeeded() { + UncivGame.Current.settings.run { + if (hasCrashedRecently) { + prepareDialog().open() + hasCrashedRecently = false + save() + } + } + } + + private fun prepareDialog(): PopupTable { + return if (crashReportSender == null) { + PopupTable(UncivGame.Current.worldScreen).apply { + addGoodSizedLabel(MESSAGE_FALLBACK).row() + addCloseButton() + } + } else { + PopupTable(UncivGame.Current.worldScreen).apply { + addGoodSizedLabel(MESSAGE).row() + addButton("Send report") { + crashReportSender.sendReport(buildReport()) + close() + } + addCloseButton() + } + } + } + + private fun buildReport(): CrashReport { + return UncivGame.Current.run { + val zippedGameInfo = Json().toJson(gameInfo).let { Gzip.zip(it) } + val zippedGameSettings = Json().toJson(settings).let { Gzip.zip(it) } + CrashReport(zippedGameInfo, zippedGameSettings, version) + } + } + } +} \ No newline at end of file diff --git a/core/src/com/unciv/ui/utils/CrashReportSender.kt b/core/src/com/unciv/ui/utils/CrashReportSender.kt new file mode 100644 index 0000000000..1c00aa9889 --- /dev/null +++ b/core/src/com/unciv/ui/utils/CrashReportSender.kt @@ -0,0 +1,8 @@ +package com.unciv.ui.utils + +import com.unciv.models.CrashReport + +interface CrashReportSender { + + fun sendReport(report: CrashReport) +} \ No newline at end of file diff --git a/core/src/com/unciv/ui/worldscreen/WorldScreen.kt b/core/src/com/unciv/ui/worldscreen/WorldScreen.kt index 589ff712f0..955e50f0ab 100644 --- a/core/src/com/unciv/ui/worldscreen/WorldScreen.kt +++ b/core/src/com/unciv/ui/worldscreen/WorldScreen.kt @@ -47,7 +47,7 @@ class WorldScreen(val viewingCiv:CivilizationInfo) : CameraStageBaseScreen() { val battleTable = BattleTable(this) val unitActionsTable = UnitActionsTable(this) - private val techPolicyandVictoryHolder = Table() + private val techPolicyAndVictoryHolder = Table() private val techButtonHolder = Table() private val diplomacyButtonWrapper = Table() private val nextTurnButton = createNextTurnButton() @@ -73,21 +73,21 @@ class WorldScreen(val viewingCiv:CivilizationInfo) : CameraStageBaseScreen() { techButtonHolder.onClick("paper") { game.setScreen(TechPickerScreen(viewingCiv)) } - techPolicyandVictoryHolder.add(techButtonHolder) + techPolicyAndVictoryHolder.add(techButtonHolder) // Don't show policies until they become relevant if(viewingCiv.policies.adoptedPolicies.isNotEmpty() || viewingCiv.policies.canAdoptPolicy()) { val policyScreenButton = Button(skin) policyScreenButton.add(ImageGetter.getImage("PolicyIcons/Constitution")).size(30f).pad(15f) policyScreenButton.onClick { game.setScreen(PolicyPickerScreen(this)) } - techPolicyandVictoryHolder.add(policyScreenButton).pad(10f) + techPolicyAndVictoryHolder.add(policyScreenButton).pad(10f) } stage.addActor(tileMapHolder) stage.addActor(minimapWrapper) stage.addActor(topBar) stage.addActor(nextTurnButton) - stage.addActor(techPolicyandVictoryHolder) + stage.addActor(techPolicyAndVictoryHolder) stage.addActor(notificationsScroll) stage.addActor(tutorialTaskTable) @@ -193,8 +193,8 @@ class WorldScreen(val viewingCiv:CivilizationInfo) : CameraStageBaseScreen() { topBar.update(viewingCiv) updateTechButton() - techPolicyandVictoryHolder.pack() - techPolicyandVictoryHolder.setPosition(10f, topBar.y - techPolicyandVictoryHolder.height - 5f) + techPolicyAndVictoryHolder.pack() + techPolicyAndVictoryHolder.setPosition(10f, topBar.y - techPolicyAndVictoryHolder.height - 5f) updateDiplomacyButton(viewingCiv) @@ -261,17 +261,7 @@ class WorldScreen(val viewingCiv:CivilizationInfo) : CameraStageBaseScreen() { } private fun displayTutorialsOnUpdate() { - if (UncivGame.Current.settings.hasCrashedRecently) { - val crashPopup = PopupTable(this) - crashPopup.addGoodSizedLabel("Oh no! It looks like something went DISASTROUSLY wrong!" + - " This is ABSOLUTELY not supposed to happen! Please send me (yairm210@hotmail.com)" + - " an email with the game information (menu -> save game -> copy game info -> paste into email)" + - " and I'll try to fix it as fast as I can!").row() - crashPopup.addCloseButton() - crashPopup.open() - UncivGame.Current.settings.hasCrashedRecently = false - UncivGame.Current.settings.save() - } + UncivGame.Current.crashController.showDialogIfNeeded() displayTutorials("Introduction") if (!UncivGame.Current.settings.tutorialsShown.contains("_EnemyCityNeedsConqueringWithMeleeUnit")) { @@ -305,7 +295,7 @@ class WorldScreen(val viewingCiv:CivilizationInfo) : CameraStageBaseScreen() { diplomacyButtonWrapper.add(btn) } diplomacyButtonWrapper.pack() - diplomacyButtonWrapper.y = techPolicyandVictoryHolder.y -20 - diplomacyButtonWrapper.height + diplomacyButtonWrapper.y = techPolicyAndVictoryHolder.y - 20 - diplomacyButtonWrapper.height } private fun updateTechButton() { @@ -402,8 +392,7 @@ class WorldScreen(val viewingCiv:CivilizationInfo) : CameraStageBaseScreen() { } } } catch (ex: Exception) { - game.settings.hasCrashedRecently = true - game.settings.save() + UncivGame.Current.crashController.crashOccurred() throw ex } diff --git a/ios/src/com/unciv/app/IOSLauncher.java b/ios/src/com/unciv/app/IOSLauncher.java index de09d695e6..6c9e80d43c 100644 --- a/ios/src/com/unciv/app/IOSLauncher.java +++ b/ios/src/com/unciv/app/IOSLauncher.java @@ -10,7 +10,7 @@ class IOSLauncher extends IOSApplication.Delegate { @Override protected IOSApplication createApplication() { IOSApplicationConfiguration config = new IOSApplicationConfiguration(); - return new IOSApplication(new com.unciv.UncivGame("IOS"), config); + return new IOSApplication(new com.unciv.UncivGame("IOS", null), config); } public static void main(String[] argv) { diff --git a/tests/src/de/tomgrill/gdxtesting/examples/BasicTests.java b/tests/src/de/tomgrill/gdxtesting/examples/BasicTests.java index 972d6dd77a..d5ddd05cb8 100644 --- a/tests/src/de/tomgrill/gdxtesting/examples/BasicTests.java +++ b/tests/src/de/tomgrill/gdxtesting/examples/BasicTests.java @@ -36,8 +36,8 @@ public class BasicTests { @Test public void gameIsNotRunWithDebugModes() { assertTrue("This test will only pass if the game is not run with debug modes", - !new UncivGame("").getSuperchargedForDebug() - && !new UncivGame("").getViewEntireMapForDebug()); + !new UncivGame("", null).getSuperchargedForDebug() + && !new UncivGame("", null).getViewEntireMapForDebug()); } // If there's a unit that obsoletes with no upgrade then when it obsoletes