mirror of
https://gitee.com/zhangsken/AndroidIDE.git
synced 2026-10-16 07:49:44 +08:00
refactor: remove 'Gradle daemon status' action
This commit is contained in:
@@ -1,46 +0,0 @@
|
||||
/*
|
||||
* This file is part of AndroidIDE.
|
||||
*
|
||||
* AndroidIDE is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* AndroidIDE is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with AndroidIDE. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.itsaky.androidide.actions.etc
|
||||
|
||||
import android.content.Context
|
||||
import androidx.core.content.ContextCompat
|
||||
import com.itsaky.androidide.resources.R
|
||||
import com.itsaky.androidide.actions.ActionData
|
||||
import com.itsaky.androidide.actions.EditorActivityAction
|
||||
|
||||
/** @author Akash Yadav */
|
||||
class DaemonStatusAction() : EditorActivityAction() {
|
||||
override val id: String = "editor_daemonStatus"
|
||||
override var requiresUIThread: Boolean = true
|
||||
|
||||
constructor(context: Context) : this() {
|
||||
label = context.getString(R.string.gradle_daemon_status)
|
||||
icon = ContextCompat.getDrawable(context, R.drawable.ic_info)
|
||||
}
|
||||
|
||||
override fun prepare(data: ActionData) {
|
||||
visible = true
|
||||
enabled = true
|
||||
}
|
||||
|
||||
override fun execAction(data: ActionData): Boolean {
|
||||
val context = getActivity(data) ?: return false
|
||||
context.showDaemonStatus()
|
||||
return true
|
||||
}
|
||||
}
|
||||
@@ -66,7 +66,6 @@ import com.itsaky.androidide.databinding.LayoutDiagnosticInfoBinding
|
||||
import com.itsaky.androidide.events.InstallationResultEvent
|
||||
import com.itsaky.androidide.fragments.FileTreeFragment
|
||||
import com.itsaky.androidide.fragments.SearchResultFragment
|
||||
import com.itsaky.androidide.fragments.sheets.TextSheetFragment
|
||||
import com.itsaky.androidide.handlers.EditorActivityLifecyclerObserver
|
||||
import com.itsaky.androidide.handlers.LspHandler.registerLanguageServers
|
||||
import com.itsaky.androidide.interfaces.DiagnosticClickListener
|
||||
@@ -115,7 +114,6 @@ abstract class BaseEditorActivity :
|
||||
|
||||
protected val mLifecycleObserver = EditorActivityLifecyclerObserver()
|
||||
protected var diagnosticInfoBinding: LayoutDiagnosticInfoBinding? = null
|
||||
protected var dmonStatusFragment: TextSheetFragment? = null
|
||||
protected var filesTreeFragment: FileTreeFragment? = null
|
||||
protected var editorBottomSheet: BottomSheetBehavior<out View?>? = null
|
||||
protected var isDestroying = false
|
||||
@@ -135,8 +133,6 @@ abstract class BaseEditorActivity :
|
||||
binding.root.closeDrawer(GravityCompat.END)
|
||||
} else if (binding.root.isDrawerOpen(GravityCompat.START)) {
|
||||
binding.root.closeDrawer(GravityCompat.START)
|
||||
} else if (getDaemonStatusFragment().isShowing) {
|
||||
getDaemonStatusFragment().dismiss()
|
||||
} else if (editorBottomSheet?.state != BottomSheetBehavior.STATE_COLLAPSED) {
|
||||
editorBottomSheet?.setState(BottomSheetBehavior.STATE_COLLAPSED)
|
||||
} else {
|
||||
@@ -220,8 +216,6 @@ abstract class BaseEditorActivity :
|
||||
|
||||
setSupportActionBar(binding.editorToolbar)
|
||||
|
||||
dmonStatusFragment = getDaemonStatusFragment()
|
||||
|
||||
setupDrawerToggle()
|
||||
binding.tabs.addOnTabSelectedListener(this)
|
||||
|
||||
@@ -253,13 +247,13 @@ abstract class BaseEditorActivity :
|
||||
flashError(string.msg_failed_list_files)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
override fun onStop() {
|
||||
super.onStop()
|
||||
|
||||
|
||||
checkIsDestroying()
|
||||
}
|
||||
|
||||
|
||||
override fun onDestroy() {
|
||||
checkIsDestroying()
|
||||
preDestroy()
|
||||
@@ -350,27 +344,6 @@ abstract class BaseEditorActivity :
|
||||
binding.bottomSheet.setDiagnosticsAdapter(adapter)
|
||||
}
|
||||
|
||||
open fun showDaemonStatus() {
|
||||
val shell = app.newShell { t -> getDaemonStatusFragment().append(t) }
|
||||
shell.bgAppend(String.format("echo '%s'", getString(string.msg_getting_daemom_status)))
|
||||
shell.bgAppend(
|
||||
String.format("cd '%s' && sh gradlew --status", Objects.requireNonNull(getProjectDirPath()))
|
||||
)
|
||||
|
||||
if (!getDaemonStatusFragment().isShowing) {
|
||||
getDaemonStatusFragment().show(supportFragmentManager, "daemon_status")
|
||||
}
|
||||
}
|
||||
|
||||
open fun getDaemonStatusFragment(): TextSheetFragment {
|
||||
return dmonStatusFragment
|
||||
?: TextSheetFragment().also {
|
||||
it.setTextSelectable(true)
|
||||
it.setTitleText(string.gradle_daemon_status)
|
||||
dmonStatusFragment = it
|
||||
}
|
||||
}
|
||||
|
||||
open fun hideBottomSheet() {
|
||||
if (editorBottomSheet?.state != BottomSheetBehavior.STATE_COLLAPSED) {
|
||||
editorBottomSheet?.state = BottomSheetBehavior.STATE_COLLAPSED
|
||||
@@ -431,7 +404,7 @@ abstract class BaseEditorActivity :
|
||||
viewModel.statusText = text
|
||||
viewModel.statusGravity = gravity
|
||||
}
|
||||
|
||||
|
||||
private fun checkIsDestroying() {
|
||||
if (!isDestroying && isFinishing) {
|
||||
isDestroying = true
|
||||
|
||||
@@ -16,10 +16,7 @@
|
||||
*/
|
||||
package com.itsaky.androidide.fragments.sheets;
|
||||
|
||||
import android.graphics.Color;
|
||||
import android.text.SpannableString;
|
||||
import android.text.SpannableStringBuilder;
|
||||
import android.text.style.ForegroundColorSpan;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
@@ -51,29 +48,23 @@ public class TextSheetFragment extends BaseBottomSheetFragment {
|
||||
}
|
||||
|
||||
public void append(String text) {
|
||||
append(text, -1, true);
|
||||
append(text, true);
|
||||
}
|
||||
|
||||
public void append(String text, int spanColor, boolean appendLine) {
|
||||
public void append(String text, boolean appendLine) {
|
||||
if (text != null && text.trim().length() > 0) {
|
||||
appendInternal(appendLine && !text.endsWith("\n") ? text.concat("\n") : text, spanColor);
|
||||
appendInternal(appendLine && !text.endsWith("\n") ? text.concat("\n") : text);
|
||||
}
|
||||
}
|
||||
|
||||
private void appendInternal(String text, int spanColor) {
|
||||
SpannableString str = new SpannableString(text);
|
||||
str.setSpan(
|
||||
new ForegroundColorSpan(spanColor == -1 ? Color.WHITE : spanColor),
|
||||
0,
|
||||
text.length(),
|
||||
SpannableString.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
getOutputBuilder().append(str);
|
||||
private void appendInternal(String text) {
|
||||
getOutputBuilder().append(text);
|
||||
if (mDialog != null && mDialog.isShowing()) {
|
||||
setToEditor(str);
|
||||
setToEditor(text);
|
||||
}
|
||||
}
|
||||
|
||||
private void setToEditor(SpannableString line) {
|
||||
private void setToEditor(CharSequence line) {
|
||||
if (getActivity() != null)
|
||||
getActivity()
|
||||
.runOnUiThread(
|
||||
|
||||
@@ -29,7 +29,6 @@ import com.itsaky.androidide.actions.editor.CutAction
|
||||
import com.itsaky.androidide.actions.editor.ExpandSelectionAction
|
||||
import com.itsaky.androidide.actions.editor.PasteAction
|
||||
import com.itsaky.androidide.actions.editor.SelectAllAction
|
||||
import com.itsaky.androidide.actions.etc.DaemonStatusAction
|
||||
import com.itsaky.androidide.actions.etc.FileTreeAction
|
||||
import com.itsaky.androidide.actions.etc.FindActionMenu
|
||||
import com.itsaky.androidide.actions.etc.PreviewLayoutAction
|
||||
@@ -62,7 +61,6 @@ class EditorActivityActions {
|
||||
registry.registerAction(PreviewLayoutAction(context))
|
||||
registry.registerAction(FindActionMenu(context))
|
||||
registry.registerAction(FileTreeAction(context))
|
||||
registry.registerAction(DaemonStatusAction(context))
|
||||
registry.registerAction(CancelBuildAction(context))
|
||||
registry.registerAction(ProjectSyncAction(context))
|
||||
|
||||
|
||||
@@ -31,7 +31,6 @@ import com.blankj.utilcode.util.ThrowableUtils;
|
||||
import com.itsaky.androidide.managers.PreferenceManager;
|
||||
import com.itsaky.androidide.managers.ToolsManager;
|
||||
import com.itsaky.androidide.resources.R;
|
||||
import com.itsaky.androidide.shell.ShellServer;
|
||||
import com.itsaky.androidide.utils.Environment;
|
||||
import com.itsaky.androidide.utils.FileUtil;
|
||||
import com.itsaky.androidide.utils.FlashbarUtilsKt;
|
||||
@@ -104,23 +103,7 @@ public abstract class BaseApplication extends Application {
|
||||
NotificationManager.IMPORTANCE_LOW);
|
||||
NotificationManagerCompat.from(this).createNotificationChannel(buildNotificationChannel);
|
||||
}
|
||||
|
||||
public ShellServer newShell(ShellServer.Callback callback) {
|
||||
return newShell(callback, true);
|
||||
}
|
||||
|
||||
public ShellServer newShell(ShellServer.Callback callback, boolean redirectErrors) {
|
||||
ShellServer shellServer =
|
||||
new ShellServer(
|
||||
callback,
|
||||
"sh",
|
||||
Environment.mkdirIfNotExits(getRootDir()).getAbsolutePath(),
|
||||
Environment.getEnvironment(),
|
||||
redirectErrors);
|
||||
shellServer.start();
|
||||
return shellServer;
|
||||
}
|
||||
|
||||
|
||||
public File getRootDir() {
|
||||
return new File(getIDEDataDir(), "home");
|
||||
}
|
||||
|
||||
@@ -116,7 +116,9 @@ public class CommonProcessExecutor implements IProcessExecutor {
|
||||
// Ignored
|
||||
}
|
||||
|
||||
listener.onExit(proc.exitValue());
|
||||
if (listener != null) {
|
||||
listener.onExit(proc.exitValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,162 +0,0 @@
|
||||
/************************************************************************************
|
||||
* This file is part of AndroidIDE.
|
||||
*
|
||||
*
|
||||
*
|
||||
* AndroidIDE is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* AndroidIDE is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with AndroidIDE. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
**************************************************************************************/
|
||||
package com.itsaky.androidide.shell;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.itsaky.androidide.utils.ILogger;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.Closeable;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.util.Map;
|
||||
|
||||
public class ShellServer extends Thread {
|
||||
|
||||
private static final ILogger LOG = ILogger.newInstance("ShellServer");
|
||||
private final Callback callback;
|
||||
private BufferedReader output;
|
||||
private Process process;
|
||||
|
||||
public ShellServer(
|
||||
Callback callback,
|
||||
String command,
|
||||
String dirPath,
|
||||
Map<String, String> env,
|
||||
boolean redirectErrors) {
|
||||
this.callback = callback;
|
||||
|
||||
ProcessBuilder processBuilder = new ProcessBuilder(command);
|
||||
processBuilder.directory(new File(dirPath));
|
||||
processBuilder.redirectErrorStream(redirectErrors);
|
||||
processBuilder.environment().putAll(env);
|
||||
|
||||
try {
|
||||
this.process = processBuilder.start();
|
||||
this.output = new BufferedReader(new InputStreamReader(process.getInputStream()));
|
||||
} catch (Throwable th) {
|
||||
if (callback != null) {
|
||||
String out = getFullStackTrace(th).concat("\n");
|
||||
callback.output(out);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private String getFullStackTrace(@NonNull Throwable th) {
|
||||
StringWriter sw = new StringWriter();
|
||||
th.printStackTrace(new PrintWriter(sw));
|
||||
return sw.toString();
|
||||
}
|
||||
|
||||
public InputStream getProcessInputStream() {
|
||||
return process.getInputStream();
|
||||
}
|
||||
|
||||
public OutputStream getProcessOutputStream() {
|
||||
return process.getOutputStream();
|
||||
}
|
||||
|
||||
public void bgAppend(String str) {
|
||||
append(str, false);
|
||||
}
|
||||
|
||||
public void append(String str, boolean z) {
|
||||
if (z) {
|
||||
try {
|
||||
if (str.endsWith("\n")) {
|
||||
output(str);
|
||||
} else {
|
||||
output(str.concat("\n"));
|
||||
}
|
||||
} catch (Throwable th) {
|
||||
output(th.toString().concat("\n"));
|
||||
return;
|
||||
}
|
||||
}
|
||||
try {
|
||||
this.process.getOutputStream().write(str.concat("\n").getBytes());
|
||||
this.process.getOutputStream().flush();
|
||||
} catch (Throwable e) {
|
||||
LOG.error("Unable to write to shell server", e);
|
||||
}
|
||||
}
|
||||
|
||||
public void output(String str) {
|
||||
if (this.callback != null) {
|
||||
this.callback.output(str);
|
||||
}
|
||||
}
|
||||
|
||||
public void append(@NonNull String... strArr) {
|
||||
for (String append : strArr) {
|
||||
append(append);
|
||||
}
|
||||
}
|
||||
|
||||
public void append(String str) {
|
||||
append(str, true);
|
||||
}
|
||||
|
||||
public void exit() {
|
||||
append("exit");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
while (true) {
|
||||
try {
|
||||
String readLine = this.output.readLine();
|
||||
if (readLine == null) {
|
||||
break;
|
||||
}
|
||||
output(readLine.concat("\n"));
|
||||
} catch (Throwable th) {
|
||||
output(th.toString().concat("\n"));
|
||||
}
|
||||
}
|
||||
closeIOQuietly(
|
||||
this.output,
|
||||
this.process.getInputStream(),
|
||||
this.process.getErrorStream(),
|
||||
this.process.getOutputStream());
|
||||
this.process.destroy();
|
||||
}
|
||||
|
||||
private void closeIOQuietly(@NonNull Closeable... toClose) {
|
||||
for (Closeable c : toClose) {
|
||||
try {
|
||||
c.close();
|
||||
} catch (IOException e) {
|
||||
// ignored
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public interface Callback {
|
||||
void output(String charSequence);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user