mirror of
https://github.com/TonyJiangWJ/Auto.js.git
synced 2026-06-21 21:01:43 +08:00
sync
This commit is contained in:
parent
26d2ce972f
commit
af0dbcefb7
@ -67,11 +67,17 @@ editor.setOption("hintOptions", {
|
||||
completeSingle: false,
|
||||
globalScope: autoJsGlobalScope()
|
||||
});
|
||||
var id = null;
|
||||
editor.on("keyup", function(editor, event)
|
||||
{
|
||||
if (!ExcludedIntelliSenseTriggerKeys[(event.keyCode || event.which).toString()] )
|
||||
{
|
||||
editor.execCommand("autocomplete");
|
||||
if(id != null){
|
||||
clearTimeout(id);
|
||||
}
|
||||
id = setTimeout(function(){
|
||||
editor.execCommand("autocomplete");
|
||||
}, 100);
|
||||
}
|
||||
});
|
||||
editor.setCursor({line: 0, ch: 0});
|
||||
|
||||
@ -8,16 +8,15 @@ import com.jakewharton.retrofit2.adapter.rxjava2.HttpException;
|
||||
import com.jakewharton.retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
|
||||
import com.stardust.scriptdroid.R;
|
||||
import com.stardust.scriptdroid.network.api.ConfigApi;
|
||||
import com.stardust.scriptdroid.network.entity.config.Config;
|
||||
import com.stardust.scriptdroid.network.util.WebkitCookieManagerProxy;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
import io.reactivex.Observable;
|
||||
import io.reactivex.Scheduler;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.ResponseBody;
|
||||
import retrofit2.Response;
|
||||
import retrofit2.Retrofit;
|
||||
import retrofit2.converter.gson.GsonConverterFactory;
|
||||
|
||||
@ -30,8 +29,7 @@ public class NodeBB {
|
||||
public static final String BASE_URL = "http://www.autojs.org/";
|
||||
private static final NodeBB sInstance = new NodeBB();
|
||||
private static final String LOG_TAG = "NodeBB";
|
||||
private Config mConfig;
|
||||
|
||||
private Map<String, String> mXCsrfToken;
|
||||
|
||||
private Retrofit mRetrofit;
|
||||
|
||||
@ -56,18 +54,17 @@ public class NodeBB {
|
||||
return mRetrofit;
|
||||
}
|
||||
|
||||
public Observable<Config> getConfig() {
|
||||
if (mConfig == null) {
|
||||
return mRetrofit.create(ConfigApi.class)
|
||||
.getConfig()
|
||||
.doOnNext(config -> mConfig = config);
|
||||
}
|
||||
return Observable.just(mConfig);
|
||||
|
||||
public Observable<Map<String, String>> getXCsrfToken() {
|
||||
if (mXCsrfToken != null)
|
||||
return Observable.just(mXCsrfToken);
|
||||
return mRetrofit.create(ConfigApi.class)
|
||||
.getConfig()
|
||||
.map(config -> mXCsrfToken = Collections.singletonMap("x-csrf-token", config.getCsrfToken()));
|
||||
}
|
||||
|
||||
public void invalidateConfig() {
|
||||
mConfig = null;
|
||||
public void invalidateXCsrfToken() {
|
||||
mXCsrfToken = null;
|
||||
}
|
||||
|
||||
public static String getErrorMessage(Throwable e, Context context, String defaultMsg) {
|
||||
|
||||
@ -10,7 +10,6 @@ import org.greenrobot.eventbus.EventBus;
|
||||
import java.util.Collections;
|
||||
|
||||
import io.reactivex.Observable;
|
||||
import io.reactivex.disposables.Disposable;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
import io.reactivex.subjects.PublishSubject;
|
||||
import okhttp3.ResponseBody;
|
||||
@ -37,10 +36,12 @@ public class UserService {
|
||||
|
||||
private static final UserService sInstance = new UserService();
|
||||
private final Retrofit mRetrofit;
|
||||
private UserApi mUserApi;
|
||||
private volatile User mUser;
|
||||
|
||||
UserService() {
|
||||
mRetrofit = NodeBB.getInstance().getRetrofit();
|
||||
mUserApi = mRetrofit.create(UserApi.class);
|
||||
}
|
||||
|
||||
public static UserService getInstance() {
|
||||
@ -49,14 +50,12 @@ public class UserService {
|
||||
|
||||
public Observable<ResponseBody> login(String userName, final String password) {
|
||||
return NodeBB.getInstance()
|
||||
.getConfig()
|
||||
.flatMap(config ->
|
||||
mRetrofit.create(UserApi.class)
|
||||
.login(Collections.singletonMap("x-csrf-token", config.getCsrfToken()),
|
||||
userName, password)
|
||||
.getXCsrfToken()
|
||||
.flatMap(token ->
|
||||
mUserApi.login(token, userName, password)
|
||||
.doOnError(error -> {
|
||||
if (error instanceof HttpException && ((HttpException) error).code() == 403) {
|
||||
NodeBB.getInstance().invalidateConfig();
|
||||
NodeBB.getInstance().invalidateXCsrfToken();
|
||||
}
|
||||
}))
|
||||
.doOnComplete(this::refreshOnlineStatus);
|
||||
@ -66,10 +65,8 @@ public class UserService {
|
||||
|
||||
public Observable<ResponseBody> register(String email, String userName, String password) {
|
||||
return NodeBB.getInstance()
|
||||
.getConfig()
|
||||
.flatMap(config -> mRetrofit.create(UserApi.class)
|
||||
.register(Collections.singletonMap("x-csrf-token", config.getCsrfToken()),
|
||||
email, userName, password, password));
|
||||
.getXCsrfToken()
|
||||
.flatMap(token -> mUserApi.register(token, email, userName, password, password));
|
||||
}
|
||||
|
||||
public boolean isOnline() {
|
||||
@ -81,7 +78,7 @@ public class UserService {
|
||||
mUser = user;
|
||||
if (!Objects.equals(old, mUser)) {
|
||||
if (user == null) {
|
||||
NodeBB.getInstance().invalidateConfig();
|
||||
NodeBB.getInstance().invalidateXCsrfToken();
|
||||
}
|
||||
EventBus.getDefault().post(new LoginStateChange(user != null));
|
||||
}
|
||||
@ -106,11 +103,8 @@ public class UserService {
|
||||
|
||||
public Observable<ResponseBody> logout() {
|
||||
return NodeBB.getInstance()
|
||||
.getConfig()
|
||||
.flatMap(config ->
|
||||
mRetrofit.create(UserApi.class)
|
||||
.logout(Collections.singletonMap("x-csrf-token", config.getCsrfToken()))
|
||||
)
|
||||
.getXCsrfToken()
|
||||
.flatMap(mUserApi::logout)
|
||||
.doOnError(Throwable::printStackTrace)
|
||||
.doOnComplete(this::refreshOnlineStatus);
|
||||
}
|
||||
|
||||
@ -172,7 +172,7 @@ public class CodeMirrorEditor extends FrameLayout {
|
||||
@Override
|
||||
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
|
||||
InputConnection connection = super.onCreateInputConnection(outAttrs);
|
||||
return connection == null ? null : new MyInputConnection(connection);
|
||||
return connection;// == null ? null : new MyInputConnection(connection);
|
||||
}
|
||||
};
|
||||
setupWebSettings();
|
||||
@ -446,12 +446,7 @@ public class CodeMirrorEditor extends FrameLayout {
|
||||
if (mCallback == null) {
|
||||
return;
|
||||
}
|
||||
mWebView.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mCallback.onChange();
|
||||
}
|
||||
});
|
||||
mWebView.post(() -> mCallback.onChange());
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
@ -459,12 +454,7 @@ public class CodeMirrorEditor extends FrameLayout {
|
||||
if (mCallback == null) {
|
||||
return;
|
||||
}
|
||||
mWebView.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mCallback.updateCodeCompletion(fromLine, fromCh, toLine, toCh, list, urls);
|
||||
}
|
||||
});
|
||||
mWebView.post(() -> mCallback.updateCodeCompletion(fromLine, fromCh, toLine, toCh, list, urls));
|
||||
}
|
||||
|
||||
}
|
||||
@ -500,12 +490,7 @@ public class CodeMirrorEditor extends FrameLayout {
|
||||
private void showRenamePrompt(String name, String defaultValue, final JsPromptResult result) {
|
||||
new ThemeColorMaterialDialogBuilder(getContext())
|
||||
.title(getResources().getString(R.string.text_rename) + name)
|
||||
.input("", defaultValue, new MaterialDialog.InputCallback() {
|
||||
@Override
|
||||
public void onInput(@android.support.annotation.NonNull MaterialDialog dialog, CharSequence input) {
|
||||
result.confirm(input.toString());
|
||||
}
|
||||
})
|
||||
.input("", defaultValue, (dialog, input) -> result.confirm(input.toString()))
|
||||
.show();
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user