-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- add some annotations to fix lints
- Loading branch information
Showing
7 changed files
with
103 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 25 additions & 9 deletions
34
app/src/main/java/vn/vhn/vhscode/chromebrowser/webclient/VSCodeWebClient.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,35 @@ | ||
package vn.vhn.vhscode.chromebrowser.webclient | ||
|
||
import android.graphics.Bitmap | ||
import android.util.Log | ||
import android.view.KeyEvent | ||
import android.webkit.WebView | ||
import android.webkit.WebViewClient | ||
import vn.vhn.vhscode.CodeServerService | ||
|
||
class VSCodeWebClient : WebViewClient() { | ||
override fun onPageFinished(view: WebView?, url: String?) { | ||
super.onPageFinished(view, url) | ||
val HOME = CodeServerService.homePath(view!!.context) | ||
CodeServerService.getBootjs(view!!.context) | ||
view!!.context | ||
view!!.evaluateJavascript(CodeServerService.getBootjs(view!!.context) | ||
, null | ||
); | ||
companion object { | ||
val TAG = "VSCodeWebClient" | ||
} | ||
|
||
var resource_html = Regex("\\.html?(\\?|\$)") | ||
override fun onPageStarted(view: WebView?, url: String?, favicon: Bitmap?) { | ||
super.onPageStarted(view, url, favicon) | ||
view?.apply { | ||
CodeServerService.getBootjs(context) | ||
context | ||
evaluateJavascript( | ||
CodeServerService.getBootjs(context) | ||
, null | ||
) | ||
} | ||
} | ||
|
||
|
||
override fun onLoadResource(view: WebView?, url: String?) { | ||
super.onLoadResource(view, url) | ||
if (url != null && url.contains(resource_html)) { | ||
Log.d(TAG, "Loading url $url") | ||
view!!.evaluateJavascript("setTimeout(window.vscode_boot_frames,500)", null) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,33 @@ | ||
(function(){ | ||
if(!window.vscodeOrigKeyboardEventDescriptorCode) window.vscodeOrigKeyboardEventDescriptorCode = Object.getOwnPropertyDescriptor(KeyboardEvent.prototype, 'code'); | ||
var codeGetter = window.vscodeOrigKeyboardEventDescriptorCode.get; | ||
// if(!window.vscodeOrigKeyboardEventDescriptorShift) window.vscodeOrigKeyboardEventDescriptorShift = Object.getOwnPropertyDescriptor(KeyboardEvent.prototype, 'shiftKey'); | ||
// var shiftGetter = window.vscodeOrigKeyboardEventDescriptorShift.get; | ||
var customMapper = { | ||
27: 'Escape' | ||
}; | ||
var customKeyRemapper = { | ||
'Backspace': 'Backspace', | ||
'Control': 'ControlLeft', | ||
'Alt': 'AltLeft', | ||
}; | ||
var prepareCustomProps = function() { | ||
if(this._vscode_modded) return; | ||
this._vscode_modded = true; | ||
var orig = codeGetter.apply(this); | ||
if (this.key == 'Alt') { | ||
this._vscodeCode = ""; | ||
} else if (this.key === 'Shift') { | ||
this._vscodeCode = "ShiftLeft"; | ||
} else if (this.which in customMapper) { | ||
this._vscodeCode = customMapper[this.which]; | ||
} else if (orig === "" && typeof this.key === "string" && this.key.length) { | ||
if (this.key in customKeyRemapper) this._vscodeCode = customKeyRemapper[this.key]; | ||
else if(this.key>="a" && this.key<="z") this._vscodeCode = "Key" + this.key.toUpperCase(); | ||
} else this._vscodeCode = orig; | ||
} | ||
Object.defineProperty(KeyboardEvent.prototype, 'code', { | ||
get(){ | ||
prepareCustomProps.apply(this); | ||
return this._vscodeCode; | ||
} | ||
}); | ||
})() | ||
if(!window.vscodeOrigKeyboardEventDescriptorCode) window.vscodeOrigKeyboardEventDescriptorCode = Object.getOwnPropertyDescriptor(window.KeyboardEvent.prototype, 'code'); | ||
var codeGetter = window.vscodeOrigKeyboardEventDescriptorCode.get; | ||
// if(!window.vscodeOrigKeyboardEventDescriptorShift) window.vscodeOrigKeyboardEventDescriptorShift = Object.getOwnPropertyDescriptor(KeyboardEvent.prototype, 'shiftKey'); | ||
// var shiftGetter = window.vscodeOrigKeyboardEventDescriptorShift.get; | ||
var customMapper = { | ||
27: 'Escape' | ||
}; | ||
var customKeyRemapper = { | ||
'Backspace': 'Backspace', | ||
'Control': 'ControlLeft', | ||
'Alt': 'AltLeft', | ||
}; | ||
var prepareCustomProps = function() { | ||
if(this._vscode_modded) return; | ||
this._vscode_modded = true; | ||
var orig = codeGetter.apply(this); | ||
if (this.key == 'Alt') { | ||
this._vscodeCode = ""; | ||
} else if (this.key === 'Shift') { | ||
this._vscodeCode = "ShiftLeft"; | ||
} else if (this.which in customMapper) { | ||
this._vscodeCode = customMapper[this.which]; | ||
} else if (orig === "" && typeof this.key === "string" && this.key.length) { | ||
if (this.key in customKeyRemapper) this._vscodeCode = customKeyRemapper[this.key]; | ||
else if(this.key>="a" && this.key<="z") this._vscodeCode = "Key" + this.key.toUpperCase(); | ||
} else this._vscodeCode = orig; | ||
} | ||
Object.defineProperty(window.KeyboardEvent.prototype, 'code', { | ||
get(){ | ||
prepareCustomProps.apply(this); | ||
return this._vscodeCode; | ||
} | ||
}); |