Browse Source

Merge 26113c7d6c into b5ca5d4dc1

pull/638/merge
Roman Sedaikin 2 weeks ago committed by GitHub
parent
commit
f061178b18
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 15
      debug-writer/.gitignore
  2. 21
      debug-writer/.run/desktop.run.xml
  3. 4
      debug-writer/README.md
  4. 35
      debug-writer/build.gradle.kts
  5. 4
      debug-writer/gradle.properties
  6. BIN
      debug-writer/gradle/wrapper/gradle-wrapper.jar
  7. 5
      debug-writer/gradle/wrapper/gradle-wrapper.properties
  8. 183
      debug-writer/gradlew
  9. 100
      debug-writer/gradlew.bat
  10. 11
      debug-writer/settings.gradle.kts
  11. 110
      debug-writer/src/main/kotlin/debugwriter/Main.kt
  12. 63
      debug-writer/src/main/kotlin/debugwriter/Utils.kt
  13. 73
      debug-writer/src/main/kotlin/debugwriter/decoration/Components.kt
  14. 69
      debug-writer/src/main/kotlin/debugwriter/decoration/Theme.kt

15
debug-writer/.gitignore vendored

@ -0,0 +1,15 @@
*.iml
.gradle
/local.properties
/.idea
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
.DS_Store
build/
/captures
.externalNativeBuild
.cxx

21
debug-writer/.run/desktop.run.xml

@ -0,0 +1,21 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="desktop" type="GradleRunConfiguration" factoryName="Gradle">
<ExternalSystemSettings>
<option name="executionName" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="externalSystemIdString" value="GRADLE" />
<option name="scriptParameters" value="" />
<option name="taskDescriptions">
<list />
</option>
<option name="taskNames">
<list>
<option value="run" />
</list>
</option>
<option name="vmOptions" value="" />
</ExternalSystemSettings>
<GradleScriptDebugEnabled>true</GradleScriptDebugEnabled>
<method v="2" />
</configuration>
</component>

4
debug-writer/README.md

@ -0,0 +1,4 @@
Compose Desktop Application
- `./gradlew run` - run application
- `./gradlew package` - package native distribution into `build/compose/binaries`

35
debug-writer/build.gradle.kts

@ -0,0 +1,35 @@
import org.jetbrains.compose.compose
import org.jetbrains.compose.desktop.application.dsl.TargetFormat
plugins {
kotlin("jvm")
id("org.jetbrains.compose")
}
repositories {
mavenLocal()
mavenCentral()
maven("https://maven.pkg.jetbrains.space/public/p/compose/dev")
google()
}
dependencies {
// Note, if you develop a library, you should use compose.desktop.common.
// compose.desktop.currentOs should be used in launcher-sourceSet
// (in a separate module for demo project and in testMain).
// With compose.desktop.common you will also lose @Preview functionality
//implementation("org.jetbrains.skiko:skiko-awt-runtime-windows-x64:0.7.0-dev")
implementation(compose.desktop.currentOs)
}
compose.desktop {
application {
mainClass = "debugwriter.MainKt"
nativeDistributions {
targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb)
packageName = "DebugWriter"
packageVersion = "1.0.0"
}
}
}

4
debug-writer/gradle.properties

@ -0,0 +1,4 @@
org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
kotlin.code.style=official
kotlin.version=1.6.10
compose.version=1.0.1

BIN
debug-writer/gradle/wrapper/gradle-wrapper.jar vendored

Binary file not shown.

5
debug-writer/gradle/wrapper/gradle-wrapper.properties vendored

@ -0,0 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.6-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

183
debug-writer/gradlew vendored

@ -0,0 +1,183 @@
#!/usr/bin/env sh
#
# Copyright 2015 the original author or authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
##############################################################################
##
## Gradle start up script for UN*X
##
##############################################################################
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null
APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
warn () {
echo "$*"
}
die () {
echo
echo "$*"
echo
exit 1
}
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
nonstop=false
case "`uname`" in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MINGW* )
msys=true
;;
NONSTOP* )
nonstop=true
;;
esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD="java"
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
MAX_FD="$MAX_FD_LIMIT"
fi
ulimit -n $MAX_FD
if [ $? -ne 0 ] ; then
warn "Could not set maximum file descriptor limit: $MAX_FD"
fi
else
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
fi
fi
# For Darwin, add options to specify how the application appears in the dock
if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi
# For Cygwin or MSYS, switch paths to Windows format before running java
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`
# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
SEP=""
for dir in $ROOTDIRSRAW ; do
ROOTDIRS="$ROOTDIRS$SEP$dir"
SEP="|"
done
OURCYGPATTERN="(^($ROOTDIRS))"
# Add a user-defined pattern to the cygpath arguments
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
fi
# Now convert the arguments - kludge to limit ourselves to /bin/sh
i=0
for arg in "$@" ; do
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
else
eval `echo args$i`="\"$arg\""
fi
i=`expr $i + 1`
done
case $i in
0) set -- ;;
1) set -- "$args0" ;;
2) set -- "$args0" "$args1" ;;
3) set -- "$args0" "$args1" "$args2" ;;
4) set -- "$args0" "$args1" "$args2" "$args3" ;;
5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi
# Escape application args
save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
APP_ARGS=`save "$@"`
# Collect all arguments for the java command, following the shell quoting and substitution rules
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
exec "$JAVACMD" "$@"

100
debug-writer/gradlew.bat vendored

@ -0,0 +1,100 @@
@rem
@rem Copyright 2015 the original author or authors.
@rem
@rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem https://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto init
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:init
@rem Get command-line arguments, handling Windows variants
if not "%OS%" == "Windows_NT" goto win9xME_args
:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2
:win9xME_args_slurp
if "x%~1" == "x" goto execute
set CMD_LINE_ARGS=%*
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega

11
debug-writer/settings.gradle.kts

@ -0,0 +1,11 @@
pluginManagement {
repositories {
gradlePluginPortal()
maven("https://maven.pkg.jetbrains.space/public/p/compose/dev")
}
plugins {
kotlin("jvm").version(extra["kotlin.version"] as String)
id("org.jetbrains.compose").version(extra["compose.version"] as String)
}
}

110
debug-writer/src/main/kotlin/debugwriter/Main.kt

@ -0,0 +1,110 @@
package debugwriter
import androidx.compose.ui.window.application
import androidx.compose.ui.window.rememberWindowState
import androidx.compose.ui.window.Window
import androidx.compose.ui.window.WindowState
import androidx.compose.ui.window.WindowPosition
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material.Text
import androidx.compose.material.Button
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Surface
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.DpSize
import androidx.compose.ui.unit.IntSize
import debugwriter.decoration.AppTheme
import kotlinx.coroutines.delay
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.async
private val fileName = "${System.getProperty("user.home")}/.debug-writer/debug-info.txt"
private var output by mutableStateOf("")
private var isReady by mutableStateOf(true)
fun main() {
val result = enableDebugWritingTo(fileName)
if (!result) {
output = "Failed to cteate file: $fileName"
}
try {
application {
val closed = remember { mutableStateOf(false) }
if (!closed.value) {
Window(
onCloseRequest = ::exitApplication,
title = "DebugWriter",
state = WindowState(
position = WindowPosition.Aligned(Alignment.Center),
size = DpSize(650.dp, 450.dp)
)
) {
AppTheme {
Surface(
modifier = Modifier.fillMaxSize()
) {
Box(
modifier = Modifier.fillMaxSize().padding(20.dp),
contentAlignment = Alignment.Center
) {
Column {
Header("Click [Refresh] to refresh info or [Open file] to see the output file.")
if (isReady) {
TextBox(output, Modifier.weight(1f).padding(start = 30.dp, end = 30.dp))
} else {
Loader(Modifier.weight(1f).fillMaxWidth())
}
Row(modifier = Modifier.fillMaxWidth()) {
Button("Refresh", Modifier.weight(1f), { writeDebugInfo() })
Button(
text = "Open file",
modifier = Modifier.weight(1f),
action = {
if(!revealDebugOutput(fileName)) {
output = "Failed to open file: $fileName"
}
}
)
Button("Close", Modifier.weight(1f), { closed.value = true })
}
}
}
}
}
if (result) {
writeDebugInfo()
}
}
}
}
}
catch(e: Exception) {
writeException(fileName, e)
System.exit(0)
}
}
private fun writeDebugInfo() {
isReady = false
GlobalScope.async {
delay(2000L)
isReady = true
val result = readDebugOutput(fileName)
output = if (result.isEmpty())
"Something went wrong and $fileName is empty."
else result
}
}

63
debug-writer/src/main/kotlin/debugwriter/Utils.kt

@ -0,0 +1,63 @@
package debugwriter
import java.awt.Desktop
import java.io.File
import java.io.FileOutputStream
import java.io.InputStream
import java.io.PrintStream
import java.nio.file.Paths
import org.jetbrains.skiko.hostOs
import org.jetbrains.skiko.OS
fun enableDebugWritingTo(fileName: String = "output.txt"): Boolean {
System.setProperty("skiko.hardwareInfo.enabled", "true")
try {
val directory = File(Paths.get(fileName).getParent().toString())
if (!directory.exists()) {
directory.mkdir()
}
val stream = PrintStream(FileOutputStream("$fileName"))
System.setOut(stream)
return true
} catch(e: Exception) {
return false
}
}
fun writeException(fileName: String = "output.txt", e: Exception) {
try {
val directory = File(Paths.get(fileName).getParent().toString())
if (!directory.exists()) {
directory.mkdir()
}
val stream = PrintStream(FileOutputStream("$fileName"))
e.printStackTrace(stream)
revealDebugOutput(fileName)
} catch(e: Exception) {
}
}
fun readDebugOutput(fileName: String = "output.txt"): String {
val file = File("$fileName")
if (!file.exists()) {
return "File $fileName does not exist."
}
val inputStream: InputStream = file.inputStream()
return inputStream.bufferedReader().use { it.readText() }
}
fun revealDebugOutput(fileName: String = "output.txt"): Boolean {
val file = File(fileName)
if (!file.exists()) {
return false
}
try {
if (Desktop.isDesktopSupported()) {
Desktop.getDesktop().open(file)
}
return true
} catch(e: Exception) {
return false
}
}

73
debug-writer/src/main/kotlin/debugwriter/decoration/Components.kt

@ -0,0 +1,73 @@
package debugwriter
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.material.Button
import androidx.compose.material.CircularProgressIndicator
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
@Composable
internal fun Button(text: String, modifier: Modifier, action: () -> Unit) {
Box(
modifier = modifier,
contentAlignment = Alignment.Center
) {
Button(
modifier = Modifier.size(150.dp, 35.dp),
onClick = action
) {
Text(text)
}
}
}
@Composable
internal fun TextBox(text: String, modifier: Modifier) {
Box(
modifier = modifier,
contentAlignment = Alignment.Center
) {
Text(text)
}
}
@Composable
internal fun Header(text: String) {
Box(
modifier = Modifier.padding(start = 30.dp, end = 30.dp).fillMaxWidth(),
contentAlignment = Alignment.Center
) {
Text(
text = text,
textAlign = TextAlign.Center,
style = TextStyle(
fontFamily = FontFamily.Default,
fontWeight = FontWeight.Normal,
fontSize = 20.sp,
color = Color.Gray
)
)
}
}
@Composable
internal fun Loader(modifier: Modifier) {
Box(
modifier = modifier,
contentAlignment = Alignment.Center
) {
CircularProgressIndicator(modifier = Modifier.size(100.dp))
}
}

69
debug-writer/src/main/kotlin/debugwriter/decoration/Theme.kt

@ -0,0 +1,69 @@
package debugwriter.decoration
import androidx.compose.material.darkColors
import androidx.compose.material.lightColors
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Typography
import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.unit.sp
private val colorPalette = darkColors(
primary = Color(0xffa5d6a7),
primaryVariant = Color(0xff388e3c),
secondary = Color(0xff80deea),
surface = Color(0xff323232),
background = Color(0xff323232),
onPrimary = Color.Black,
onSecondary = Color.White,
error = Color.Red,
)
val typography = Typography(
body1 = TextStyle(
fontFamily = FontFamily.Default,
fontWeight = FontWeight.Normal,
fontSize = 16.sp
),
body2 = TextStyle(
fontFamily = FontFamily.Default,
fontWeight = FontWeight.Normal,
fontSize = 14.sp
),
button = TextStyle(
fontFamily = FontFamily.Default,
fontWeight = FontWeight.W500,
fontSize = 14.sp
),
caption = TextStyle(
fontFamily = FontFamily.Default,
fontWeight = FontWeight.Normal,
fontSize = 12.sp,
),
subtitle1 = TextStyle(
fontFamily = FontFamily.Default,
fontWeight = FontWeight.Normal,
fontSize = 16.sp,
color = Color.Gray
),
subtitle2 = TextStyle(
fontFamily = FontFamily.Default,
fontWeight = FontWeight.Normal,
fontSize = 14.sp,
color = Color.Gray
),
)
@Composable
fun AppTheme(
content: @Composable() () -> Unit,
) {
MaterialTheme(
colors = colorPalette,
typography = typography,
content = content
)
}
Loading…
Cancel
Save