@electerm/electerm-react 3.15.39 → 3.15.41

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,7 +2,7 @@ const {
2
2
  openDialog
3
3
  } = window.api
4
4
 
5
- export async function chooseSaveDirectory () {
5
+ export async function chooseSaveDirectory (opts) {
6
6
  const savePaths = await openDialog({
7
7
  title: 'Choose a folder to save file(s)',
8
8
  message: 'Choose a folder to save file(s)',
@@ -13,7 +13,8 @@ export async function chooseSaveDirectory () {
13
13
  'noResolveAliases',
14
14
  'treatPackageAsDirectory',
15
15
  'dontAddToRecent'
16
- ]
16
+ ],
17
+ ...opts
17
18
  })
18
19
  if (!savePaths || !savePaths.length) {
19
20
  return undefined
@@ -6,23 +6,11 @@ import ShowItem from '../components/common/show-item'
6
6
  import { chooseSaveDirectory } from './choose-save-folder'
7
7
  import { DownloadOutlined } from '@ant-design/icons'
8
8
 
9
- // function downloadForBrowser (filename, text) {
10
- // const blob = new Blob([text], { type: 'text/plain;charset=utf-8' })
11
- // const url = URL.createObjectURL(blob)
12
- // const a = document.createElement('a')
13
- // a.href = url
14
- // a.download = filename
15
- // document.body.appendChild(a)
16
- // a.click()
17
- // document.body.removeChild(a)
18
- // URL.revokeObjectURL(url)
19
- // }
20
-
21
9
  export default async function download (filename, text) {
22
- // if (window.et.isWebApp) {
23
- // return downloadForBrowser(filename, text)
24
- // }
25
- const savePath = await chooseSaveDirectory()
10
+ const opts = window.et.isWebApp
11
+ ? { filename, content: text }
12
+ : undefined
13
+ const savePath = await chooseSaveDirectory(opts)
26
14
  if (!savePath) {
27
15
  return
28
16
  }
@@ -26,8 +26,9 @@ export default function renderAuth (props) {
26
26
  profileFilter = (d) => d
27
27
  } = props
28
28
  const commonBeforeUpload = (fieldName) => async (file) => {
29
- const filePath = file.filePath
30
- const content = await window.fs.readFile(filePath)
29
+ const content = file.fileContent !== undefined
30
+ ? file.fileContent
31
+ : await window.fs.readFile(file.filePath)
31
32
  form.setFieldsValue({
32
33
  [fieldName]: content
33
34
  })
@@ -8,6 +8,7 @@ import { getLocalFileInfo } from '../sftp/file-read'
8
8
 
9
9
  /**
10
10
  * Open a single file select dialog
11
+ * Supports browser upload in web app mode
11
12
  * @returns {Promise<Object|null>} - File object with path info or null if cancelled
12
13
  */
13
14
  const openFileSelect = async () => {
@@ -23,7 +24,14 @@ const openFileSelect = async () => {
23
24
  message: 'Choose a file',
24
25
  properties
25
26
  }).catch(() => false)
26
- if (!files || !files.length) {
27
+ if (!files) {
28
+ return null
29
+ }
30
+ // Browser upload returns { fileContent, fileName }
31
+ if (files.fileContent !== undefined) {
32
+ return files
33
+ }
34
+ if (!files.length) {
27
35
  return null
28
36
  }
29
37
  const filePath = files[0]
@@ -7,8 +7,9 @@ export default class QmTransport extends BookmarkTransport {
7
7
  name = 'quickCommands'
8
8
  beforeUpload = async (file) => {
9
9
  const { store } = this.props
10
- const filePath = file.filePath
11
- const txt = await window.fs.readFile(filePath)
10
+ const txt = file.fileContent !== undefined
11
+ ? file.fileContent
12
+ : await window.fs.readFile(file.filePath)
12
13
  try {
13
14
  const arr = JSON.parse(txt)
14
15
  const state = store[this.name]
@@ -233,7 +233,8 @@ export class FileTransferManager {
233
233
  const savePath = await window.api.openDialog({
234
234
  title: `Save ${fileInfo.name}`,
235
235
  message: `Choose where to save ${fileInfo.name}`,
236
- properties: ['openDirectory', 'createDirectory']
236
+ properties: ['openDirectory', 'createDirectory'],
237
+ noBrowserTransfer: true
237
238
  }).catch((err) => {
238
239
  this.log(`Save dialog error: ${err.message}`, 'error')
239
240
  return false
@@ -562,7 +562,8 @@ export default class RdpSession extends PureComponent {
562
562
  const files = await window.api.openDialog({
563
563
  title: 'Choose files to upload to remote desktop',
564
564
  message: 'Choose files to upload',
565
- properties
565
+ properties,
566
+ noBrowserTransfer: true
566
567
  }).catch((err) => {
567
568
  this.log(`File dialog error: ${err.message}`, 'error')
568
569
  return false
@@ -6,8 +6,9 @@ export default class KeywordsTransport extends BookmarkTransport {
6
6
  name = 'keywords-highlight'
7
7
  beforeUpload = async (file) => {
8
8
  const { store } = this.props
9
- const filePath = file.filePath
10
- const txt = await window.fs.readFile(filePath)
9
+ const txt = file.fileContent !== undefined
10
+ ? file.fileContent
11
+ : await window.fs.readFile(file.filePath)
11
12
  try {
12
13
  store.setConfig({
13
14
  keywords: JSON.parse(txt)
@@ -264,6 +264,9 @@ export default class SettingTerminal extends Component {
264
264
  const after = (
265
265
  <Upload
266
266
  beforeUpload={(file) => {
267
+ if (file.fileContent !== undefined) {
268
+ return
269
+ }
267
270
  const filePath = file.filePath
268
271
  this.onChangeValue(filePath, name)
269
272
  }}
@@ -32,6 +32,9 @@ export default function TerminalBackgroundConfig ({
32
32
  const after = (
33
33
  <Upload
34
34
  beforeUpload={(file) => {
35
+ if (file.fileContent !== undefined) {
36
+ return
37
+ }
35
38
  const filePath = file.filePath
36
39
  onChangeValue(filePath, name)
37
40
  }}
@@ -89,6 +89,7 @@ function renderAddonAfter (isLoadingRemote, onGoto, GoIcon, type, handleUploadFr
89
89
  ? (
90
90
  <PlusOutlined
91
91
  className='mg1r'
92
+ title={e('uploadFromBrowser')}
92
93
  onClick={(e) => {
93
94
  e.stopPropagation()
94
95
  handleUploadFromBrowser()
@@ -1068,7 +1068,7 @@ export default class FileSection extends React.Component {
1068
1068
  res.push({
1069
1069
  func: 'downloadFromBrowser',
1070
1070
  icon: 'DownloadOutlined',
1071
- text: 'Download from browser'
1071
+ text: e('downloadFromBrowser')
1072
1072
  })
1073
1073
  }
1074
1074
  if (showEdit) {
@@ -203,11 +203,11 @@ export class TransferClientBase {
203
203
  'treatPackageAsDirectory',
204
204
  'dontAddToRecent'
205
205
  ]
206
-
207
206
  files = await window.api.openDialog({
208
207
  title,
209
208
  message,
210
- properties
209
+ properties,
210
+ noBrowserTransfer: true
211
211
  }).catch(() => false)
212
212
  }
213
213
 
@@ -253,7 +253,8 @@ export class TransferClientBase {
253
253
  'noResolveAliases',
254
254
  'treatPackageAsDirectory',
255
255
  'dontAddToRecent'
256
- ]
256
+ ],
257
+ noBrowserTransfer: true
257
258
  }).catch(() => false)
258
259
 
259
260
  if (!savePaths || !savePaths.length) {
@@ -154,8 +154,9 @@ export default function ThemeForm (props) {
154
154
  }
155
155
 
156
156
  async function beforeUpload (file) {
157
- const filePath = file.filePath
158
- const txt = await window.fs.readFile(filePath)
157
+ const txt = file.fileContent !== undefined
158
+ ? file.fileContent
159
+ : await window.fs.readFile(file.filePath)
159
160
  const { name, themeConfig, uiThemeConfig } = convertTheme(txt)
160
161
  const tt = convertThemeToText({
161
162
  themeConfig, uiThemeConfig
@@ -25,8 +25,9 @@ export const bookmarkUpload = action(async (file) => {
25
25
  const { store } = window
26
26
  const { bookmarks, bookmarkGroups } = store
27
27
 
28
- const filePath = file.filePath
29
- const txt = await window.fs.readFile(filePath)
28
+ const txt = file.fileContent !== undefined
29
+ ? file.fileContent
30
+ : await window.fs.readFile(file.filePath)
30
31
 
31
32
  const content = JSON.parse(txt)
32
33
  let bookmarkGroups1 = []
@@ -565,9 +565,9 @@ export default (Store) => {
565
565
  }
566
566
 
567
567
  Store.prototype.importAll = async function (file) {
568
- const filePath = file.filePath
569
- const txt = await window.fs
570
- .readFile(filePath)
568
+ const txt = file.fileContent !== undefined
569
+ ? file.fileContent
570
+ : await window.fs.readFile(file.filePath)
571
571
  const { store } = window
572
572
  const objs = JSON.parse(txt)
573
573
  const { names } = store.getDataSyncNames(true)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@electerm/electerm-react",
3
- "version": "3.15.39",
3
+ "version": "3.15.41",
4
4
  "description": "react components src for electerm",
5
5
  "main": "./client/components/main/main.jsx",
6
6
  "license": "MIT",