Skip to content

Commit

Permalink
change signatture and update md
Browse files Browse the repository at this point in the history
  • Loading branch information
puutaro committed Jul 27, 2024
1 parent 14e1ec2 commit 39f9b09
Show file tree
Hide file tree
Showing 36 changed files with 424 additions and 298 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,54 @@ class JsBroadcast(
action: String,
broadCastMapStr: String
){
val kyeSepalator = '|'
/*
Send broad cast
### action arg
Broad cast action
-> [Action Detail](https://github.com/puutaro/CommandClick/blob/master/app/src/main/java/com/puutaro/commandclick/common/variable/broadcast/scheme)
### broadcastMapStr arg
Broad cast extra key-value map contents by separated by `keySeparator`
-> [Extra Detail](https://github.com/puutaro/CommandClick/blob/master/app/src/main/java/com/puutaro/commandclick/common/variable/broadcast/extra)
### Example js version
```js.js
jsBroadcast.send(
"com.puutaro.commandclick.music_player.play",
`playMode=shuffle|onLoop=on|onTrack=on
`,
)
```
### Example js action version
```js.js
var=runMusicPlay
?func=jsBroadcast.send
?args=
&action="com.puutaro.commandclick.music_player.play"
&broadCastMapStr=`
|playMode=shuffle
|onLoop=on
|onTrack=on
`
```
*/

val keySeparator = '|'
val broadcastMap = mapOf(
BroadCastSenderSchemaForCommon.action.name to action,
BroadCastSenderSchemaForCommon.extras.name to broadCastMapStr
)
BroadcastSender.send(
context,
broadcastMap,
kyeSepalator
keySeparator
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import com.puutaro.commandclick.util.Intent.ExecBashScriptIntent
import com.puutaro.commandclick.view_model.activity.TerminalViewModel

class JsCmdIntent(
private val terminalFragment: TerminalFragment
terminalFragment: TerminalFragment
) {
private val context = terminalFragment.context
private val terminalViewModel: TerminalViewModel by terminalFragment.activityViewModels()
Expand All @@ -18,6 +18,17 @@ class JsCmdIntent(
fun run_S(
execCmdSource: String
){
/*
Run command by termux
### Example
JsCmdIntent.run_S(
"bash \"$[bash script path}\"
)
- Enable `> /dev/null` or `> /dev/null 2>&1`
*/
val outputPath = "${UsePath.cmdclickMonitorDirPath}/${terminalViewModel.currentMonitorFileName}"
val execCmd = if(
execCmdSource.endsWith("> /dev/null")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class JsCurl(

@JavascriptInterface
fun getAndSave (
path: String,
savePath: String,
mainUrl: String,
queryParameter: String,
header: String,
Expand All @@ -57,7 +57,7 @@ class JsCurl(
!CurlManager.isConnOk(it)
) return@let
FileSystems.writeFromByteArray(
path,
savePath,
it
)
}
Expand Down Expand Up @@ -167,7 +167,9 @@ class JsCurl(
}

@JavascriptInterface
fun isConnOk(res: String): Boolean {
fun isConnOk(
res: String
): Boolean {
return CurlManager.isConnOk(res.toByteArray())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ class JsDirect (
mainUrl: String,
fullPathOrFannelRawName: String,
){
/*
Get fannel from other smart phone by p2p
*/
val intent = Intent(
context,
fileDownloadService
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@ class JsHtml(
val context = terminalFragment.context

@JavascriptInterface
fun txtHtml(
fun txt2Html(
contents: String,
isScrollBottom: Boolean,
): String {
/*
Convert text to html
*/
return """
<!DOCTYPE html>
<html>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,41 +34,6 @@ class JsIntent(
)
}

// @JavascriptInterface
// fun launchFzSite(
// editPath: String,
// promptMessage: String,
// itemClickJs: String,
// itemLongClickJs: String,
// realTimeListSetJs: String
// ) {
// val jsIntent = Intent()
// jsIntent.action = BroadCastIntentSchemeTerm.FZHTML_LAUNCH.action
// jsIntent.putExtra(
// BroadCastIntentSchemeTerm.FZHTML_LAUNCH.scheme,
// editPath
// )
// jsIntent.putExtra(
// BroadCastIntentExtraForFzHtml.TEMPLATE_PROMPT_MESSAGE.scheme,
// promptMessage
// )
// jsIntent.putExtra(
// BroadCastIntentExtraForFzHtml.ITEM_CLICK_JAVASCRIPT.scheme,
// itemClickJs
// )
// jsIntent.putExtra(
// BroadCastIntentExtraForFzHtml.ITEM_LONG_CLICK_JAVASCRIPT.scheme,
// itemLongClickJs
// )
// jsIntent.putExtra(
// BroadCastIntentExtraForFzHtml.REAL_TIME_LIST_SET_JAVASCRIPT.scheme,
// realTimeListSetJs
// )
// terminalFragment.activity?.sendBroadcast(jsIntent)
// }



@JavascriptInterface
fun launchUrl(
currentPageUrl: String
Expand Down Expand Up @@ -103,7 +68,8 @@ class JsIntent(
@JavascriptInterface
fun launchShortcut(
currentAppDirPath: String,
currentScriptFileName: String
currentScriptFileName: String,
currentFannelState: String,
){
val execIntent = Intent(terminalFragment.activity, MainActivity::class.java)
execIntent
Expand All @@ -118,13 +84,20 @@ class JsIntent(
FannelInfoSetting.current_fannel_name.name,
currentScriptFileName
)
execIntent.putExtra(
FannelInfoSetting.current_fannel_state.name,
currentFannelState
)
terminalFragment.activity?.startActivity(execIntent)
}

@JavascriptInterface
fun shareImage(
imageFilePath: String,
){
/*
Launch share image intent
*/
val imageFilePathObj = File(imageFilePath)
if(
!imageFilePathObj.isFile
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,27 @@ class JsLinux(
fun runCmd(
cmdStr: String
): String {
ToastUtils.showShort(cmdStr)
/*
Run cmd by native android shell
### Example
```js.js
jsLinux.runCmd(
"ls"
)
```
### Example js action version
```js.js
var=runCmd
?func=jsLinux.runCmd
?args=
cmdStr="ls"
```
*/
val cmdOutput = LinuxCmd.execCommand(
context,
listOf("sh", "-c", cmdStr).joinToString("\t")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ class JsNetTool(

@JavascriptInterface
fun getIpv4(): String {
/*
Get IPV4 ADDRESS
*/
val ipV4Address = NetworkTool.getIpv4Address(context)
return ipV4Address
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,14 @@ class JsUbuntu(
null
)
) return String()
return Shell2Http.runScript(
val output = Shell2Http.runScript(
context,
executeShellPath,
tabSepaArgs,
2000,
null,
)
return output
}


Expand Down Expand Up @@ -79,32 +80,6 @@ class JsUbuntu(
)
}


// @JavascriptInterface
// fun execScriptBySsh(
// executeShellPath:String,
// tabSepaArgs: String,
// monitorNum: Int,
// ): String {
// if(
// context == null
// ) return String()
// if(
// !UbuntuFiles(context).ubuntuLaunchCompFile.isFile
// ) {
// ToastUtils.showShort("Launch ubuntu")
// return String()
// }
// val monitorFileName = UsePath.decideMonitorName(monitorNum)
// return SshManager.execScript(
// context,
// executeShellPath,
// tabSepaArgs,
// monitorFileName,
// true,
// )
// }

@JavascriptInterface
fun execScriptByBackground(
backgroundShellPath: String,
Expand Down Expand Up @@ -302,11 +277,53 @@ class JsUbuntu(
installOneList: String,
cautionTitleAndMessage: String,
): Boolean {
/*
Dialog prompting installation.
Mainly, used to install pkg to Ubuntu
### installStampFilePath arg
Stamp file path indicating that user has installed
### expectStampCon
Stamp file contents
### installConfirmTitleAndMessage
Install confirm title and message separated by `|`
### installOneList
Install button label
### cautionTitleAndMessage
Caution Dialog title and msg separated by `|`, when user don't install
## Example
```js.js
var=isInstall
?func=jsUbuntu.isInstall
?args=
installStampFilePath=`${cmdYoutuberInstallStampFilePath}`
&expectStampCon=`${INSTALL_STAMP_CON}`
&confirmTitleAndMsg="Press install button|"
&installOneList="install\tpuzzle"
&cautionTitleAndMsg="Caution!|Install by ⚙️ button"
```
*/
var isInstall = false
val stampCon =
ReadText(installStampFilePath).readText().trim()
if(
stampCon == expectStampCon
) return true
) {
isInstall = true
return isInstall
}
val jsDialog = JsDialog(terminalFragment)
val installTitleToMsg = makeTitleToMsg(installConfirmTitleAndMessage)
val el = jsDialog.listDialog(
Expand All @@ -316,15 +333,19 @@ class JsUbuntu(
)
if(
el.isNotEmpty()
) return false
) {
isInstall = false
return isInstall
}
val cautionTitleToMsg = makeTitleToMsg(cautionTitleAndMessage)
JsDialog(terminalFragment).listDialog(
cautionTitleToMsg.first,
cautionTitleToMsg.second,
String()
)
JsUrl(terminalFragment).exit_S()
return false
isInstall = false
return isInstall
}

private fun makeTitleToMsg(
Expand Down
Loading

0 comments on commit 39f9b09

Please sign in to comment.