Skip to content

Commit

Permalink
Extend support command to dump log #446 (#450)
Browse files Browse the repository at this point in the history
  • Loading branch information
shech2 authored Jan 16, 2024
1 parent 1da0dec commit 4c8cee5
Show file tree
Hide file tree
Showing 12 changed files with 129 additions and 23 deletions.
3 changes: 2 additions & 1 deletion aatp/infra/redis/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
FROM redis:alpine
RUN echo "appendonly no" >> /etc/redis.conf
RUN echo 'appendonly no' > /etc/redis.conf
RUN echo 'save ""' >> /etc/redis.conf
CMD [ "redis-server", "/etc/redis.conf" ]
32 changes: 32 additions & 0 deletions aatp/peerbook_webrtc/admin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -350,4 +350,36 @@ test.describe('peerbook administration', () => {
const twr = await getTWRBuffer(page)
expect(twr).toMatch(/Logged in/)
})
test('test the support command', async ({request}) => {
await sleep(100)
await page.keyboard.type('support')
await page.keyboard.press('Enter')
await sleep(100)
let twr = await getTWRBuffer(page)
expect(twr).toMatch(/address:$/)
await page.keyboard.type('[email protected]')
await page.keyboard.press('Enter')
await sleep(100)
await page.keyboard.press('ArrowDown')
await page.evaluate(() => { terminal7.log('log line')})
await page.keyboard.press('Enter')
await sleep(100)
twr = await getTWRBuffer(page)
expect(twr).toMatch(/issue:$/)
await page.keyboard.type('test issue')
await page.keyboard.press('Enter')

let count = 0
let msg
while (count < 2) {
await sleep(100)
const res = await request.get('http://smtp:8025/api/v2/messages')
msg = await res.json()
count = msg.count
}
expect(msg.count).toBe(2)
const body = msg.items[0].Content.Body
expect(body).toMatch(/test issue/)
expect(body).toMatch(/log line/)
})
})
1 change: 1 addition & 0 deletions android/app/capacitor.build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ dependencies {
implementation project(':capacitor-camera')
implementation project(':capacitor-clipboard')
implementation project(':capacitor-device')
implementation project(':capacitor-filesystem')
implementation project(':capacitor-keyboard')
implementation project(':capacitor-network')
implementation project(':capacitor-preferences')
Expand Down
2 changes: 2 additions & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
<uses-permission android:name="android.permission.USE_BIOMETRIC" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="com.android.vending.BILLING" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<application
android:allowBackup="true"
Expand Down
4 changes: 4 additions & 0 deletions android/app/src/main/assets/capacitor.plugins.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
"pkg": "@capacitor/device",
"classpath": "com.capacitorjs.plugins.device.DevicePlugin"
},
{
"pkg": "@capacitor/filesystem",
"classpath": "com.capacitorjs.plugins.filesystem.FilesystemPlugin"
},
{
"pkg": "@capacitor/keyboard",
"classpath": "com.capacitorjs.plugins.keyboard.KeyboardPlugin"
Expand Down
3 changes: 3 additions & 0 deletions android/capacitor.settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ project(':capacitor-clipboard').projectDir = new File('../node_modules/@capacito
include ':capacitor-device'
project(':capacitor-device').projectDir = new File('../node_modules/@capacitor/device/android')

include ':capacitor-filesystem'
project(':capacitor-filesystem').projectDir = new File('../node_modules/@capacitor/filesystem/android')

include ':capacitor-keyboard'
project(':capacitor-keyboard').projectDir = new File('../node_modules/@capacitor/keyboard/android')

Expand Down
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<meta name="apple-touch-fullscreen" content="yes" />
<meta name="apple-mobile-web-app-title" content="Terminal7" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<script type="module" src="/main.ts"></script>
<script type="module" src="/main.ts" defer></script>

</head>
<body>
Expand Down
1 change: 1 addition & 0 deletions ios/App/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def capacitor_pods
pod 'CapacitorCamera', :path => '../../node_modules/@capacitor/camera'
pod 'CapacitorClipboard', :path => '../../node_modules/@capacitor/clipboard'
pod 'CapacitorDevice', :path => '../../node_modules/@capacitor/device'
pod 'CapacitorFilesystem', :path => '../../node_modules/@capacitor/filesystem'
pod 'CapacitorKeyboard', :path => '../../node_modules/@capacitor/keyboard'
pod 'CapacitorNetwork', :path => '../../node_modules/@capacitor/network'
pod 'CapacitorPreferences', :path => '../../node_modules/@capacitor/preferences'
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"@capacitor/clipboard": "^5.0.0",
"@capacitor/core": "^5.0.0",
"@capacitor/device": "^5.0.0",
"@capacitor/filesystem": "^5.2.0",
"@capacitor/ios": "^5.0.0",
"@capacitor/keyboard": "^5.0.0",
"@capacitor/network": "^5.0.0",
Expand Down Expand Up @@ -53,14 +54,14 @@
},
"devDependencies": {
"@capacitor/assets": "^2.0.4",
"native-run": "^1.7.4",
"@playwright/test": "^1.20.1",
"@types/hammerjs": "^2.0.42",
"@types/xterm": "^3.0.0",
"@typescript-eslint/eslint-plugin": "<6",
"@typescript-eslint/parser": "<6",
"eslint": "<9",
"jsdom": "^19.0.0",
"native-run": "^1.7.4",
"typescript": "<5",
"vi-canvas-mock": "^1.0.0",
"vite": "^4.5.1",
Expand Down
80 changes: 75 additions & 5 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { SSHSession, SSHChannel } from './ssh_session'
import { Failure } from './session'
import { NativeBiometric } from 'capacitor-native-biometric'
import { Capacitor } from "@capacitor/core"
import { Filesystem, Directory , Encoding} from '@capacitor/filesystem'

export type Command = {
name: string
Expand Down Expand Up @@ -712,7 +713,7 @@ async function subscribeCMD(shell: Shell) {
}
if (!terminal7.pb.isOpen()) {
if (!Capacitor.isNativePlatform()) {
loginCMD(shell);
await loginCMD(shell);
return
}
terminal7.pb.startSpinner()
Expand Down Expand Up @@ -981,10 +982,79 @@ async function configCMD(shell: Shell) {
await shell.openConfig()
}
async function supportCMD(shell: Shell) {
shell.t.write("Sorry things are not working well. Please ")
shell.t.writeln("\x1B]8;;https://github.com/tuzig/terminal7/issues/new?template=bug_report.md\x07report a bug\x1B]8;;\x07")
shell.t.writeln("or talk to us on our \x1B]8;;https://discord.gg/Puu2afdUtr\x07discord server\x1B]8;;\x07")
}
shell.t.write("Apologies. Have you tried resetting the App?\n")
shell.t.writeln("If that doesn't work, please send us a log of the error.")
const insecure = terminal7.conf.peerbook.insecure,
schema = insecure?"http":"https"

// ask for email address + check validity
let email = terminal7.conf.peerbook.email || (await shell.askValue("Enter your email address"))
while (!email.match(/^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/)) {
shell.t.writeln("Invalid email address")
email = await shell.askValue("Enter your email address")
}

// Menu to ask user if they want to send the log or Post it to mail
const fieldsNative = [
{prompt: "Copy log to clipboard"},
{prompt: "Send log to support"},
{prompt: "Save log to file"},
{prompt: "Cancel"}
]

// Ask user for choice
!Capacitor.isNativePlatform() ? fieldsNative.splice(2,1) : fieldsNative
const choice = await shell.runForm(fieldsNative,"menu" , "Choose an option")
// Switch case to handle user choice
switch (choice) {
case "Copy log to clipboard":
// Saving the log to the clipboard
const log = terminal7.dumpLog()
await Clipboard.write({string: (await log).toString()})
terminal7.notify("Log copied to clipboard.")
shell.t.writeln("Please paste into discord support channel.")
break
case "Send log to support":
const description = await shell.askValue("please describe the issue")
shell.t.writeln("Sending log to support...")
const res = await fetch(`${schema}://${terminal7.conf.net.peerbook}/support`, {
method: "POST",
body: JSON.stringify({
email,
log: await terminal7.dumpLog(),
description
}),
})
if (res.ok) {
shell.t.writeln("Log sent to support.")
} else {
shell.t.writeln("Failed to send log to support.")
shell.t.writeln("Please send us a message in discord support channel.")
}
break
case "Save log to file":
shell.t.writeln("Saving log to file...")
const log2 = terminal7.dumpLog()
// Works only on ios and android
if(Capacitor.isNativePlatform()) {
try{
await Filesystem.requestPermissions()
await Filesystem.checkPermissions()
await Filesystem.writeFile({
path: "log-" + Date.now().toString() +".txt",
data: (await log2).toString(),
directory: Directory.Documents,
encoding: Encoding.UTF8
})
} catch(e) {
terminal7.log(e)
}
}
break
case "Cancel":
break
}
}
async function loginCMD(shell: Shell) {
if (terminal7.pb.isOpen()) {
shell.t.writeln("You are already logged in")
Expand Down
16 changes: 1 addition & 15 deletions src/terminal7.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import { randomBytes } from 'ed25519-keygen/utils'

import { Capacitor } from '@capacitor/core'
import { App } from '@capacitor/app'
import { Clipboard } from '@capacitor/clipboard'
import { Network } from '@capacitor/network'
import { Preferences } from '@capacitor/preferences'
import { Device } from '@capacitor/device'
Expand Down Expand Up @@ -916,20 +915,7 @@ export class Terminal7 {
while (this.logBuffer.length > 0) {
data += this.logBuffer.shift() + "\n"
}
await Clipboard.write({string: data})
this.notify("Log copied to clipboard")
/* TODO: wwould be nice to store log to file, problme is
* Preferences pluging failes
try {
await Filesystem.writeFile({
path: path,
data: data,
directory: FilesystemDirectory.Documents
})i
} catch(e) {
terminal7.log(e)
}
*/
return data
}
onPointerCancel() {
this.pointer0 = null
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1063,6 +1063,11 @@
resolved "https://registry.yarnpkg.com/@capacitor/device/-/device-5.0.6.tgz#11322a9c737196f2df8f82abbe6d1a5b32e35fb7"
integrity sha512-tmjK0H8IKbDLMcmzZzJPbV+9yLkKJ76QOdz4A7fZAOYx2GnFHsFngxldq/wKotGAJuDX/ih3ZzHNrzVguzlv2g==

"@capacitor/filesystem@^5.2.0":
version "5.2.0"
resolved "https://registry.yarnpkg.com/@capacitor/filesystem/-/filesystem-5.2.0.tgz#6e4529eb059c85869ecc68643f25123dbe38768f"
integrity sha512-fyv+yWVFfglobPPveIRm4+ryMGI8vW27vjX63HDwB7K5fscSYajid+ie3qfwl2wkbPhlX8KTPes7IPij0lCmQg==

"@capacitor/ios@^5.0.0":
version "5.5.1"
resolved "https://registry.yarnpkg.com/@capacitor/ios/-/ios-5.5.1.tgz#e07d0752b8934215a9defc2d22a537060f2dd7f7"
Expand Down

0 comments on commit 4c8cee5

Please sign in to comment.