Skip to content

Commit

Permalink
Fix Tab-Editor desync, Fix some bugs, Implement some things, Add tree…
Browse files Browse the repository at this point in the history
…sitter (somewhat not working), Move & refactor some classes️
  • Loading branch information
ThatMG393 committed Mar 6, 2024
1 parent 8b3be93 commit b6cc962
Show file tree
Hide file tree
Showing 110 changed files with 4,405 additions and 453 deletions.
49 changes: 21 additions & 28 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ plugins {

android {
namespace "com.thatmg393.esmanager"
compileSdk 33
buildToolsVersion '33.0.1'

compileSdk 34

defaultConfig {
applicationId "com.thatmg393.esmanager"
minSdk 26
Expand All @@ -30,50 +29,59 @@ android {
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17

coreLibraryDesugaringEnabled true
}
}

dependencies {
def LSP_VERSION = '0.21.0'
def LSP_VERSION = '0.21.1'

// General
implementation 'androidx.appcompat:appcompat:1.7.0-alpha02'
implementation 'androidx.core:core-splashscreen:1.0.1'
implementation 'androidx.preference:preference:1.2.1'
implementation 'androidx.security:security-crypto:1.1.0-alpha06'

// UI
implementation 'androidx.core:core-splashscreen:1.0.1'
implementation 'androidx.preference:preference:1.2.1'
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.2.0-alpha01'
implementation 'androidx.viewpager2:viewpager2:1.1.0-beta02'
implementation 'com.google.android.material:material:1.9.0'
implementation 'com.google.android.material:material:1.11.0'
implementation 'com.github.delight-im:Android-AdvancedWebView:v3.2.1'
implementation 'com.github.cachapa:ExpandableLayout:2.9.2'
implementation 'com.davemorrissey.labs:subsampling-scale-image-view-androidx:3.10.0'
implementation 'com.github.haroldadmin:WhatTheStack:1.0.0-alpha04'
implementation 'com.intuit.sdp:sdp-android:1.1.0'
implementation 'com.intuit.ssp:ssp-android:1.1.0'
implementation 'io.github.amrdeveloper:treeview:1.1.4'

// Code Editor
implementation platform('io.github.Rosemoe.sora-editor:bom:0.22.0-77372aa-SNAPSHOT')
implementation platform('io.github.Rosemoe.sora-editor:bom:0.23.4-f620608-SNAPSHOT')
implementation 'io.github.Rosemoe.sora-editor:editor'
implementation 'io.github.Rosemoe.sora-editor:editor-lsp'
implementation 'io.github.Rosemoe.sora-editor:language-textmate'

implementation project(path: ':tree-sitter')
implementation project(path: ':sora-editor-treesitter')

implementation 'com.itsaky.androidide.treesitter:android-tree-sitter:4.1.0'

implementation "org.eclipse.lsp4j:org.eclipse.lsp4j:$LSP_VERSION"
implementation "org.eclipse.lsp4j:org.eclipse.lsp4j.jsonrpc:$LSP_VERSION"

// IO / Network
implementation 'com.anggrayudi:storage:1.5.5'
implementation 'com.lazygeniouz:dfc:1.0.7'
implementation 'com.lazygeniouz:dfc:1.0.8'
implementation 'com.squareup.picasso:picasso:2.8'
implementation 'commons-io:commons-io:2.11.0'
implementation 'org.java-websocket:Java-WebSocket:1.5.3'
implementation 'org.java-websocket:Java-WebSocket:1.5.4'

// Collections
implementation 'org.apache.commons:commons-collections4:4.4'

debugImplementation 'com.itsaky.androidide:logsender:2.5.1-beta-27c6ea872-SNAPSHOT'
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.0.4'
// debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.10'

implementation fileTree(dir: 'libs', include: ['*.jar'])
Expand All @@ -85,19 +93,4 @@ task updateLibs(type: Download) {
dest "$rootProject.projectDir/app/libs"
overwrite true
}
tasks.whenTaskAdded { task ->
if (task.name == 'preDebugBuild') {
task.dependsOn updateLibs
}
if (task.name == 'compileDebugJavaWithJavac') {
// Error Prone must be available in the annotation processor path
// options.annotationProcessorPath = configurations.errorprone
// Enable Error Prone
options.errorprone.enabled = true
// It can then be configured for the task
options.errorprone.disableWarningsInGeneratedCode = true
}
}
*/
2 changes: 1 addition & 1 deletion app/src/main/assets/esluastubs/es.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ function es.Quaternion.Euler(x, y, z) end
function es.Quaternion.LookRotation(v3f) end
function es.Quaternion.LookRotation(v3f, v3u) end
function es.Quaternion.ToEulerAngles(quaternion) end
function es.Quaternion.FromToRotation(v3from, v3to) end
function es.Quaternion.FromToRotation(v3f, v3t) end
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
],

"indentationRules": {
"increaseIndentPattern": "^.*([\\{\\[]|(\"(?:[^\"\\\\]|\\\\.)*\"))[^}\\]]*([\\}\\]])[ \\t]*[^ \\t\\r\\n]*$",
"increaseIndentPattern": "({+(?=((\\\\.|[^\"\\\\])*\"(\\\\.|[^\"\\\\])*\")*[^\"}]*)$)|(\\[+(?=((\\\\.|[^\"\\\\])*\"(\\\\.|[^\"\\\\])*\")*[^\"\\]]*)$)",
"decreaseIndentPattern": "^\\s*[}\\]],?\\s*$"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import android.os.Environment;

import com.thatmg393.esmanager.utils.ActivityUtils;
import com.thatmg393.esmanager.utils.StorageUtils;
import com.thatmg393.esmanager.utils.io.StorageUtils;

public final class GlobalConstants {
private static volatile GlobalConstants INSTANCE;
Expand Down
52 changes: 33 additions & 19 deletions app/src/main/java/com/thatmg393/esmanager/MainApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
import android.util.Log;

import com.thatmg393.esmanager.managers.editor.language.LanguageManager;
import com.thatmg393.esmanager.utils.EditorUtils;
import com.thatmg393.esmanager.managers.editor.themes.ThemeManager;
import com.thatmg393.esmanager.utils.sora.EditorUtils;

import com.thatmg393.esmanager.utils.FileUtils;
import com.thatmg393.esmanager.utils.logging.ErrorHandler;
import com.thatmg393.esmanager.utils.logging.Logger;
import com.thatmg393.esmanager.utils.io.FileUtils;
import io.github.rosemoe.sora.langs.textmate.registry.FileProviderRegistry;
import io.github.rosemoe.sora.langs.textmate.registry.GrammarRegistry;
import io.github.rosemoe.sora.langs.textmate.registry.provider.AssetsFileResolver;
Expand All @@ -17,26 +20,38 @@
import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.Writer;
import java.util.concurrent.CompletableFuture;

public class MainApplication extends Application {
private static final Logger LOG = new Logger("ESM/MainApplication");
private Thread.UncaughtExceptionHandler thrUEH;

@Override
public void onCreate() {
super.onCreate();
FileProviderRegistry.getInstance().addFileProvider(
new AssetsFileResolver(getAssets())
);
LOG.d("Application launched!");

try {
GrammarRegistry.getInstance().loadGrammars("tm/languages/languages.json");
EditorUtils.loadTMThemes();
LanguageManager.getInstance().registerLanguages();
} catch (Exception e) {
e.printStackTrace();
}

setUEH();
CompletableFuture.runAsync(() -> {
try {
LOG.d("Loading early editor resources in another thread");
FileProviderRegistry.getInstance().addFileProvider(
new AssetsFileResolver(getAssets())
);

GrammarRegistry.getInstance().loadGrammars("tm/languages/languages.json");

ThemeManager.getInstance().registerThemes();

LanguageManager.getInstance().registerTreeSitterLanguages(getAssets());
LanguageManager.getInstance().registerTextMateLanguages();

LOG.d("Done loading!");
} catch (Exception e) {
e.printStackTrace();
LOG.d("Error occurred!");
LOG.e(e.toString());
}
});
}

@Override
Expand All @@ -45,19 +60,18 @@ public void onTerminate() {
unsetUEH();
}


private final void setUEH() {
if (thrUEH != null) {
Log.w("BaseActivity", "Attempt to initialize 'Thread.UncaughtExceptionHandler' even though it's already initialized!");
LOG.w("Attempt to initialize 'Thread.UncaughtExceptionHandler' even though it's already initialized!");
return;
}

thrUEH = Thread.getDefaultUncaughtExceptionHandler();
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread curThr, Throwable ex) {
Log.e("BaseActivity", curThr + " made an exception! " + fullStacktrace(ex));
FileUtils.appendToFile(GlobalConstants.getInstance().getESMRootFolder() + "/crash.txt", fullStacktrace(ex));
LOG.e(curThr + " made an exception! " + fullStacktrace(ex));
ErrorHandler.writeError(ex);

android.os.Process.killProcess(android.os.Process.myPid());

Expand All @@ -77,7 +91,7 @@ public void uncaughtException(Thread curThr, Throwable ex) {

public void unsetUEH() {
if (thrUEH == null) {
Log.w("BaseActivity", "Attempt to unset 'Thread.UncaughtExceptionHandler' even though it's already unset!");
LOG.w("Attempt to unset 'Thread.UncaughtExceptionHandler' even though it's already unset!");
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import android.widget.FrameLayout;

import android.widget.LinearLayout;
import android.widget.Toast;
import androidx.appcompat.widget.Toolbar;

import com.google.android.material.bottomnavigation.BottomNavigationView;
Expand All @@ -15,12 +16,15 @@
import com.thatmg393.esmanager.fragments.main.ModsFragment;
import com.thatmg393.esmanager.fragments.main.ProjectsFragment;
import com.thatmg393.esmanager.fragments.main.SettingsFragmentActivity;
import com.thatmg393.esmanager.interfaces.IOnProcessListener;
import com.thatmg393.esmanager.managers.editor.lsp.LSPManager;
import com.thatmg393.esmanager.managers.rpc.DRPCManager;
import com.thatmg393.esmanager.utils.ActivityUtils;
import com.thatmg393.esmanager.utils.PermissionUtils;
import com.thatmg393.esmanager.utils.ProcessListener;
import com.thatmg393.esmanager.utils.SharedPreference;
import com.thatmg393.esmanager.utils.StorageUtils;
import com.thatmg393.esmanager.utils.io.AndroidFolderUtils;
import com.thatmg393.esmanager.utils.io.StorageUtils;

public class MainActivity extends BaseActivity {
private Toolbar mainToolbar;
Expand Down Expand Up @@ -67,7 +71,31 @@ public void onInit(Bundle savedInstanceState) {
}

// Shared preference stuff
if (SharedPreference.getInstance().getBool("main_rpc_active")) DRPCManager.getInstance().startDiscordRPC();
// if (SharedPreference.getInstance().getBool("main_rpc_active")) DRPCManager.getInstance().startDiscordRPC();

ProcessListener.getInstance().startService();
ProcessListener.getInstance().startListening("com.facebook.katana", new IOnProcessListener() {
@Override
public void onProcessForeground() {
System.out.println("YESSIR");
}

@Override
public void onProcessBackground() {
System.out.println("AAAAAAAAHEJEJOROR");
}
});

try {
ActivityUtils.getInstance().showToast(
AndroidFolderUtils.getDataFolder(getApplicationContext()).getFolderName(),
Toast.LENGTH_LONG
);
} catch (Exception e) {
ActivityUtils.getInstance().showToast(
e.toString(), Toast.LENGTH_SHORT
);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,18 @@
import com.thatmg393.esmanager.adapters.TabEditorAdapter;
import com.thatmg393.esmanager.fragments.project.FileTreeViewFragment;
import com.thatmg393.esmanager.fragments.project.TabEditorFragment;
import com.thatmg393.esmanager.fragments.project.base.BaseTabFragment;
import com.thatmg393.esmanager.fragments.project.base.PathedTabFragment;
import com.thatmg393.esmanager.interfaces.IOnTabUpdateListener;
import com.thatmg393.esmanager.managers.editor.EditorManager;
import com.thatmg393.esmanager.managers.editor.lsp.LSPManager;
import com.thatmg393.esmanager.managers.editor.project.ProjectManager;
import com.thatmg393.esmanager.models.ProjectModel;
import com.thatmg393.esmanager.utils.ActivityUtils;

import com.thatmg393.esmanager.utils.compat.IntentCompat;
import io.github.rosemoe.sora.lsp.editor.LspEditorManager;

import io.github.rosemoe.sora.widget.SymbolInputView;
import org.apache.commons.io.FilenameUtils;

public class ProjectActivity extends BaseActivity implements TabLayout.OnTabSelectedListener {
private DrawerLayout editorDrawerLayout;
Expand Down Expand Up @@ -66,10 +69,10 @@ public void onInit(Bundle savedInstanceState) {
editorTabLayout = findViewById(R.id.project_editors_tab);
editorTabLayout.addOnTabSelectedListener(this);
editorTabAdapter = new TabEditorAdapter(getLifecycle(), getSupportFragmentManager(), findViewById(android.R.id.content));
editorTabAdapter.addOnTabUpdateListener(new TabEditorAdapter.OnTabUpdateListener() {
editorTabAdapter.addOnTabUpdateListener(new IOnTabUpdateListener() {
@Override
public void onRemoveTab(int position) {
invalidateOptionsMenu();
supportInvalidateOptionsMenu();
}
});

Expand All @@ -87,7 +90,18 @@ public void onRemoveTab(int position) {
);

editorFileTreeViewFragment.addOnFileClickListener((path) -> {
editorTabAdapter.newTab(path);
String pathExt = FilenameUtils.getExtension(path);

switch (pathExt) {
case "png":
case "jpg":
case "gif":
editorTabAdapter.newTab(path, TabEditorAdapter.TabType.PICTURE);
break;
default:
editorTabAdapter.newTab(path, TabEditorAdapter.TabType.EDITOR);
}

if (editorDrawerLayout.isDrawerOpen(GravityCompat.END)) editorDrawerLayout.closeDrawer(GravityCompat.END);
});

Expand Down Expand Up @@ -127,8 +141,8 @@ public boolean onCreateOptionsMenu(Menu menu) {
public void invalidateOptionsMenu() {
super.invalidateOptionsMenu();

TabEditorFragment frag = EditorManager.getInstance().getFocusedTabEditor();
if (frag != null) editorSymbolInput.bindEditor(frag.getEditor());
PathedTabFragment frag = EditorManager.getInstance().getFocusedTabEditor();
if (frag != null && frag instanceof TabEditorFragment) editorSymbolInput.bindEditor(((TabEditorFragment)frag).getEditor());
}

@Override
Expand All @@ -150,22 +164,28 @@ public boolean onPrepareOptionsMenu(Menu menu) {
@Override
public boolean onOptionsItemSelected(MenuItem menuItem) {
if (menuItem.getItemId() == R.id.project_action_editor_save) {
TabEditorFragment editorFragment = EditorManager.getInstance().getFocusedTabEditor();
if (editorFragment != null) editorFragment.save();
BaseTabFragment editorFragment = EditorManager.getInstance().getFocusedTabEditor();
if (editorFragment != null) {
if (editorFragment instanceof TabEditorFragment) {
((TabEditorFragment) editorFragment).save();
}
}
return true;
} else if (menuItem.getItemId() == R.id.project_action_editor_save_all) {
editorTabAdapter.getFragmentList().forEach((fragment) -> fragment.save());
editorTabAdapter.getFragmentList().forEach((model) -> {
if (model.fragment instanceof TabEditorFragment) ((TabEditorFragment) model.fragment).save();
});
ActivityUtils.getInstance().showToast("All files saved!", Toast.LENGTH_SHORT);
return true;
} else if (menuItem.getItemId() == R.id.project_action_import_obj) {
ActivityUtils.getInstance().showToast("Function not implemented", Toast.LENGTH_SHORT);
return true;
} else if (menuItem.getItemId() == R.id.project_action_editor_undo) {
TabEditorFragment editorFragment = EditorManager.getInstance().getFocusedTabEditor();
TabEditorFragment editorFragment = (TabEditorFragment) EditorManager.getInstance().getFocusedTabEditor();
if (editorFragment != null & editorFragment.getEditor().canUndo()) editorFragment.getEditor().undo();
return true;
} else if (menuItem.getItemId() == R.id.project_action_editor_redo) {
TabEditorFragment editorFragment = EditorManager.getInstance().getFocusedTabEditor();
TabEditorFragment editorFragment = (TabEditorFragment) EditorManager.getInstance().getFocusedTabEditor();
if (editorFragment != null & editorFragment.getEditor().canRedo()) editorFragment.getEditor().redo();
return true;
} else if (menuItem.getItemId() == R.id.project_action_drawer_file_open) {
Expand Down Expand Up @@ -214,7 +234,7 @@ private void _destroy() {
.remove(editorFileTreeViewFragment)
.commit();

LspEditorManager.getOrCreateEditorManager(ProjectManager.getInstance().getCurrentProject().projectPath).closeAllEditor();
ProjectManager.getInstance().getCurrentLspProject().closeAllEditors();
LSPManager.getInstance().stopLSPForAllLanguage();
} catch (RuntimeException ignore) { }
}
Expand Down
Loading

0 comments on commit b6cc962

Please sign in to comment.