@electerm/electerm-react 1.34.30

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.
Files changed (273) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +31 -0
  3. package/client/common/auto-complete-data-mapper.js +6 -0
  4. package/client/common/byte-format.js +14 -0
  5. package/client/common/class.js +52 -0
  6. package/client/common/clipboard.js +49 -0
  7. package/client/common/constants.js +308 -0
  8. package/client/common/create-lang-edit-link.js +7 -0
  9. package/client/common/create-title.js +29 -0
  10. package/client/common/db-fix.js +24 -0
  11. package/client/common/db.js +155 -0
  12. package/client/common/download-mirrors.js +10 -0
  13. package/client/common/download.js +16 -0
  14. package/client/common/error-handler.jsx +27 -0
  15. package/client/common/fetch-from-server.js +47 -0
  16. package/client/common/fetch.jsx +71 -0
  17. package/client/common/find-bookmark-group-id.js +15 -0
  18. package/client/common/find-parent.js +30 -0
  19. package/client/common/form-layout.js +27 -0
  20. package/client/common/fs.js +21 -0
  21. package/client/common/get-proxy.js +8 -0
  22. package/client/common/id-with-stamp.js +10 -0
  23. package/client/common/index-sorter.js +4 -0
  24. package/client/common/init-setting-item.js +32 -0
  25. package/client/common/is-absolute-path.js +3 -0
  26. package/client/common/is-ip.js +16 -0
  27. package/client/common/is-valid-path.js +7 -0
  28. package/client/common/key-control-pressed.js +13 -0
  29. package/client/common/key-pressed.js +13 -0
  30. package/client/common/key-shift-pressed.js +7 -0
  31. package/client/common/mode2permission.js +81 -0
  32. package/client/common/new-terminal.js +31 -0
  33. package/client/common/parse-int10.js +3 -0
  34. package/client/common/parse-json-safe.js +11 -0
  35. package/client/common/pass-enc.js +25 -0
  36. package/client/common/post-msg.js +3 -0
  37. package/client/common/pre.js +156 -0
  38. package/client/common/promise-timeout.js +27 -0
  39. package/client/common/resolve.js +31 -0
  40. package/client/common/run-idle.js +1 -0
  41. package/client/common/safe-local-storage.js +35 -0
  42. package/client/common/safe-name.js +19 -0
  43. package/client/common/sftp.js +74 -0
  44. package/client/common/terminal-theme.js +158 -0
  45. package/client/common/test-connection.js +12 -0
  46. package/client/common/time.js +30 -0
  47. package/client/common/to-simple-obj.js +5 -0
  48. package/client/common/track.js +7 -0
  49. package/client/common/transfer.js +76 -0
  50. package/client/common/trzsz.js +62 -0
  51. package/client/common/ui-theme.js +44 -0
  52. package/client/common/uid.js +5 -0
  53. package/client/common/update-check.js +79 -0
  54. package/client/common/upgrade.js +68 -0
  55. package/client/common/wait.js +8 -0
  56. package/client/common/ws.js +161 -0
  57. package/client/components/batch-op/batch-op.jsx +650 -0
  58. package/client/components/bookmark-form/bookmark-form.styl +8 -0
  59. package/client/components/bookmark-form/bookmark-group-tree-format.js +39 -0
  60. package/client/components/bookmark-form/encodes.js +44 -0
  61. package/client/components/bookmark-form/form-ssh-common.jsx +208 -0
  62. package/client/components/bookmark-form/form-tabs.jsx +69 -0
  63. package/client/components/bookmark-form/index.jsx +159 -0
  64. package/client/components/bookmark-form/local-form-ui.jsx +152 -0
  65. package/client/components/bookmark-form/local-form.jsx +16 -0
  66. package/client/components/bookmark-form/proxy.jsx +49 -0
  67. package/client/components/bookmark-form/quick-command-list.jsx +31 -0
  68. package/client/components/bookmark-form/quick-command.jsx +228 -0
  69. package/client/components/bookmark-form/render-auth-ssh.jsx +104 -0
  70. package/client/components/bookmark-form/render-connection-hopping.jsx +229 -0
  71. package/client/components/bookmark-form/render-delayed-scripts.jsx +88 -0
  72. package/client/components/bookmark-form/render-ssh-tunnel.jsx +116 -0
  73. package/client/components/bookmark-form/serial-form-ui.jsx +311 -0
  74. package/client/components/bookmark-form/serial-form.jsx +20 -0
  75. package/client/components/bookmark-form/sftp-enable.jsx +33 -0
  76. package/client/components/bookmark-form/ssh-form-ui.jsx +100 -0
  77. package/client/components/bookmark-form/ssh-form.jsx +348 -0
  78. package/client/components/bookmark-form/telnet-form-ui.jsx +154 -0
  79. package/client/components/bookmark-form/telnet-form.jsx +16 -0
  80. package/client/components/bookmark-form/tree-delete.jsx +87 -0
  81. package/client/components/bookmark-form/use-form-funcs.jsx +50 -0
  82. package/client/components/bookmark-form/use-quick-commands.jsx +83 -0
  83. package/client/components/bookmark-form/use-submit.jsx +77 -0
  84. package/client/components/bookmark-form/use-ui.jsx +82 -0
  85. package/client/components/bookmark-form/x11.jsx +23 -0
  86. package/client/components/common/animate-text.jsx +37 -0
  87. package/client/components/common/animate-text.styl +54 -0
  88. package/client/components/common/external-link.jsx +28 -0
  89. package/client/components/common/help-icon.jsx +25 -0
  90. package/client/components/common/highlight.jsx +23 -0
  91. package/client/components/common/highlight.styl +3 -0
  92. package/client/components/common/input-auto-focus.jsx +68 -0
  93. package/client/components/common/input-confirm.jsx +66 -0
  94. package/client/components/common/logo-elem.jsx +22 -0
  95. package/client/components/common/markdown.jsx +27 -0
  96. package/client/components/common/react-subx.jsx +1 -0
  97. package/client/components/common/resize-wrap.jsx +222 -0
  98. package/client/components/common/resize-wrap.styl +9 -0
  99. package/client/components/common/search.jsx +9 -0
  100. package/client/components/common/show-item.jsx +27 -0
  101. package/client/components/context-menu/boomarks.jsx +15 -0
  102. package/client/components/context-menu/context-menu.jsx +340 -0
  103. package/client/components/context-menu/context-menu.styl +90 -0
  104. package/client/components/context-menu/history.jsx +27 -0
  105. package/client/components/context-menu/icon-holder.jsx +5 -0
  106. package/client/components/context-menu/menu-btn.jsx +224 -0
  107. package/client/components/context-menu/sub-tab-menu.jsx +23 -0
  108. package/client/components/context-menu/tabs.jsx +22 -0
  109. package/client/components/context-menu/zoom.jsx +40 -0
  110. package/client/components/footer/batch-input.jsx +177 -0
  111. package/client/components/footer/footer-entry.jsx +141 -0
  112. package/client/components/footer/footer.styl +47 -0
  113. package/client/components/icons/match-case.jsx +10 -0
  114. package/client/components/icons/match-whole-word.jsx +13 -0
  115. package/client/components/icons/regular-exp.jsx +10 -0
  116. package/client/components/main/css-overwrite.jsx +92 -0
  117. package/client/components/main/error-wrapper.jsx +59 -0
  118. package/client/components/main/index.jsx +11 -0
  119. package/client/components/main/loading.jsx +25 -0
  120. package/client/components/main/main.jsx +149 -0
  121. package/client/components/main/term-fullscreen-control.jsx +21 -0
  122. package/client/components/main/term-fullscreen.styl +27 -0
  123. package/client/components/main/ui-theme.jsx +31 -0
  124. package/client/components/main/upgrade.jsx +351 -0
  125. package/client/components/main/upgrade.styl +27 -0
  126. package/client/components/main/wrapper.styl +41 -0
  127. package/client/components/quick-commands/qm.styl +29 -0
  128. package/client/components/quick-commands/quick-command-item.jsx +36 -0
  129. package/client/components/quick-commands/quick-command-transport-mod.jsx +54 -0
  130. package/client/components/quick-commands/quick-command-transport.jsx +12 -0
  131. package/client/components/quick-commands/quick-commands-box.jsx +233 -0
  132. package/client/components/quick-commands/quick-commands-form-elem.jsx +119 -0
  133. package/client/components/quick-commands/quick-commands-form.jsx +33 -0
  134. package/client/components/quick-commands/quick-commands-list.jsx +128 -0
  135. package/client/components/quick-commands/quick-commands-select.jsx +38 -0
  136. package/client/components/session/session.jsx +533 -0
  137. package/client/components/session/session.styl +53 -0
  138. package/client/components/session/sessions.jsx +445 -0
  139. package/client/components/setting-panel/bookmark-transport.jsx +148 -0
  140. package/client/components/setting-panel/bookmark-tree-list.jsx +14 -0
  141. package/client/components/setting-panel/col.jsx +18 -0
  142. package/client/components/setting-panel/list.jsx +186 -0
  143. package/client/components/setting-panel/list.styl +33 -0
  144. package/client/components/setting-panel/on-tree-drop.js +222 -0
  145. package/client/components/setting-panel/setting-modal.jsx +163 -0
  146. package/client/components/setting-panel/setting-wrap.jsx +37 -0
  147. package/client/components/setting-panel/setting-wrap.styl +52 -0
  148. package/client/components/setting-panel/setting.jsx +858 -0
  149. package/client/components/setting-panel/setting.styl +4 -0
  150. package/client/components/setting-panel/start-session-select.jsx +91 -0
  151. package/client/components/setting-panel/tab-bookmarks.jsx +37 -0
  152. package/client/components/setting-panel/tab-history.jsx +44 -0
  153. package/client/components/setting-panel/tab-quick-commands.jsx +38 -0
  154. package/client/components/setting-panel/tab-settings.jsx +42 -0
  155. package/client/components/setting-panel/tab-themes.jsx +34 -0
  156. package/client/components/setting-panel/tree-list.jsx +978 -0
  157. package/client/components/setting-panel/tree-list.styl +57 -0
  158. package/client/components/setting-sync/data-import.jsx +65 -0
  159. package/client/components/setting-sync/setting-sync-form.jsx +271 -0
  160. package/client/components/setting-sync/setting-sync.jsx +81 -0
  161. package/client/components/setting-sync/sync.styl +7 -0
  162. package/client/components/sftp/address-bar.jsx +139 -0
  163. package/client/components/sftp/address-bookmark-item.jsx +47 -0
  164. package/client/components/sftp/address-bookmark.jsx +81 -0
  165. package/client/components/sftp/address-bookmark.styl +8 -0
  166. package/client/components/sftp/confirm-modal.jsx +184 -0
  167. package/client/components/sftp/file-icon.jsx +22 -0
  168. package/client/components/sftp/file-item.jsx +1226 -0
  169. package/client/components/sftp/file-mode-modal.jsx +205 -0
  170. package/client/components/sftp/file-props-modal.jsx +211 -0
  171. package/client/components/sftp/file-read.js +81 -0
  172. package/client/components/sftp/list-table-ui.jsx +547 -0
  173. package/client/components/sftp/owner-list.js +97 -0
  174. package/client/components/sftp/paged-list.jsx +60 -0
  175. package/client/components/sftp/permission-render.jsx +42 -0
  176. package/client/components/sftp/sftp-entry.jsx +1069 -0
  177. package/client/components/sftp/sftp.styl +217 -0
  178. package/client/components/sftp/transfer-common.js +9 -0
  179. package/client/components/sftp/transfer-conflict.jsx +315 -0
  180. package/client/components/sftp/transfer-speed-format.js +60 -0
  181. package/client/components/sftp/transfer-tag.jsx +40 -0
  182. package/client/components/sftp/transfer-tag.styl +11 -0
  183. package/client/components/sftp/transfer.styl +55 -0
  184. package/client/components/sftp/transport-action.jsx +410 -0
  185. package/client/components/sftp/transport-entry.jsx +108 -0
  186. package/client/components/sftp/transport-types.js +8 -0
  187. package/client/components/sftp/transports-action.jsx +111 -0
  188. package/client/components/sftp/transports-ui.jsx +93 -0
  189. package/client/components/sftp/zip.js +42 -0
  190. package/client/components/sidebar/bookmark-select.jsx +48 -0
  191. package/client/components/sidebar/bookmark.jsx +82 -0
  192. package/client/components/sidebar/history.jsx +66 -0
  193. package/client/components/sidebar/index.jsx +230 -0
  194. package/client/components/sidebar/info-modal.jsx +250 -0
  195. package/client/components/sidebar/info.styl +27 -0
  196. package/client/components/sidebar/side-icon.jsx +25 -0
  197. package/client/components/sidebar/sidebar.styl +128 -0
  198. package/client/components/sidebar/transfer-history-modal.jsx +110 -0
  199. package/client/components/sidebar/transfer-history.styl +3 -0
  200. package/client/components/sidebar/transfer-list-control.jsx +205 -0
  201. package/client/components/sidebar/transfer-list.jsx +55 -0
  202. package/client/components/sidebar/transfer-modal.jsx +76 -0
  203. package/client/components/sidebar/transfer.styl +8 -0
  204. package/client/components/sidebar/transport-ui.jsx +109 -0
  205. package/client/components/tabs/index.jsx +320 -0
  206. package/client/components/tabs/tab.jsx +427 -0
  207. package/client/components/tabs/tabs.styl +220 -0
  208. package/client/components/tabs/window-control.jsx +55 -0
  209. package/client/components/terminal/attach-addon-custom.js +70 -0
  210. package/client/components/terminal/build-ls-term-id.js +5 -0
  211. package/client/components/terminal/index.jsx +1358 -0
  212. package/client/components/terminal/normal-buffer.jsx +33 -0
  213. package/client/components/terminal/term-search.jsx +224 -0
  214. package/client/components/terminal/term-search.styl +15 -0
  215. package/client/components/terminal/terminal-apis.js +31 -0
  216. package/client/components/terminal/terminal-interactive.jsx +148 -0
  217. package/client/components/terminal/terminal.styl +96 -0
  218. package/client/components/terminal/xterm-zmodem.js +48 -0
  219. package/client/components/terminal/zmodem-transfer.jsx +98 -0
  220. package/client/components/terminal/zmodem.styl +14 -0
  221. package/client/components/terminal-info/activity.jsx +54 -0
  222. package/client/components/terminal-info/base.jsx +25 -0
  223. package/client/components/terminal-info/content.jsx +101 -0
  224. package/client/components/terminal-info/data-cols-parser.jsx +50 -0
  225. package/client/components/terminal-info/disk.jsx +29 -0
  226. package/client/components/terminal-info/index.jsx +25 -0
  227. package/client/components/terminal-info/network.jsx +114 -0
  228. package/client/components/terminal-info/resource.jsx +80 -0
  229. package/client/components/terminal-info/run-cmd.jsx +273 -0
  230. package/client/components/terminal-info/terminal-info.styl +29 -0
  231. package/client/components/terminal-info/up.jsx +15 -0
  232. package/client/components/terminal-theme/index.jsx +264 -0
  233. package/client/components/terminal-theme/terminal-theme-list.styl +3 -0
  234. package/client/components/terminal-theme/theme-list.jsx +146 -0
  235. package/client/components/text-editor/text-editor-form.jsx +97 -0
  236. package/client/components/text-editor/text-editor.jsx +182 -0
  237. package/client/css/antd-overwrite.styl +14 -0
  238. package/client/css/basic.styl +38 -0
  239. package/client/css/includes/box.styl +154 -0
  240. package/client/css/includes/font-size.styl +6 -0
  241. package/client/css/includes/index.styl +3 -0
  242. package/client/css/includes/text.styl +31 -0
  243. package/client/css/includes/theme-default.styl +20 -0
  244. package/client/entry/basic.js +58 -0
  245. package/client/entry/index.jsx +15 -0
  246. package/client/entry/worker.js +137 -0
  247. package/client/store/address-bookmark.js +25 -0
  248. package/client/store/app-upgrade.js +23 -0
  249. package/client/store/batch-input-history.js +26 -0
  250. package/client/store/bookmark-group.js +128 -0
  251. package/client/store/bookmark.js +22 -0
  252. package/client/store/common.js +140 -0
  253. package/client/store/context-menu.js +23 -0
  254. package/client/store/db-upgrade.js +43 -0
  255. package/client/store/event.js +70 -0
  256. package/client/store/index.js +335 -0
  257. package/client/store/init-state.js +191 -0
  258. package/client/store/item.js +120 -0
  259. package/client/store/load-data.js +198 -0
  260. package/client/store/quick-command.js +43 -0
  261. package/client/store/session.js +54 -0
  262. package/client/store/setting.js +208 -0
  263. package/client/store/sidebar.js +48 -0
  264. package/client/store/sync.js +390 -0
  265. package/client/store/system-menu.js +120 -0
  266. package/client/store/tab.js +74 -0
  267. package/client/store/terminal-theme.js +116 -0
  268. package/client/store/transfer-history.js +27 -0
  269. package/client/store/transfer-list.js +20 -0
  270. package/client/store/ui-theme.js +71 -0
  271. package/client/store/watch.js +116 -0
  272. package/client/views/index.pug +58 -0
  273. package/package.json +34 -0
@@ -0,0 +1,156 @@
1
+ const {
2
+ runSync,
3
+ ipcOnEvent,
4
+ ipcOffEvent,
5
+ runGlobalAsync,
6
+ getZoomFactor,
7
+ setZoomFactor
8
+ } = window.api
9
+
10
+ const props = runSync('getConstants')
11
+
12
+ props.env = JSON.parse(props.env)
13
+ props.versions = JSON.parse(props.versions)
14
+
15
+ // Encoding function
16
+ function encodeUint8Array (uint8Array) {
17
+ let str = ''
18
+ const len = uint8Array.byteLength
19
+
20
+ for (let i = 0; i < len; i++) {
21
+ str += String.fromCharCode(uint8Array[i])
22
+ }
23
+
24
+ return btoa(str)
25
+ }
26
+
27
+ // Decoding function
28
+ function decodeBase64String (base64String) {
29
+ const str = atob(base64String)
30
+ const len = str.length
31
+
32
+ const uint8Array = new Uint8Array(len)
33
+
34
+ for (let i = 0; i < len; i++) {
35
+ uint8Array[i] = str.charCodeAt(i)
36
+ }
37
+
38
+ return uint8Array
39
+ }
40
+
41
+ window.log = {
42
+ debug: (...args) => runSync('debug', ...args),
43
+ log: (...args) => runSync('log', ...args),
44
+ error: (...args) => runSync('error', ...args),
45
+ info: (...args) => runSync('info', ...args)
46
+ }
47
+
48
+ window.pre = {
49
+ readClipboard: () => {
50
+ return runSync('readClipboard')
51
+ },
52
+
53
+ writeClipboard: str => {
54
+ return runSync('writeClipboard', str)
55
+ },
56
+
57
+ resolve: (...args) => runSync('resolve', ...args),
58
+ join: (...args) => runSync('join', ...args),
59
+ basename: (...args) => runSync('basename', ...args),
60
+ showItemInFolder: (href) => runSync('showItemInFolder', href),
61
+ ...props,
62
+ ipcOnEvent,
63
+ ipcOffEvent,
64
+
65
+ getZoomFactor,
66
+ setZoomFactor,
67
+ openExternal: (url) => runSync('openExternal', url),
68
+
69
+ osInfo: () => runSync('osInfo'),
70
+ runGlobalAsync,
71
+ runSync
72
+ }
73
+
74
+ const path = {
75
+ resolve: window.pre.resolve,
76
+ join: window.pre.join,
77
+ basename: window.pre.basename
78
+ }
79
+
80
+ const fs = {
81
+ stat: (path, cb) => {
82
+ window.fs.statCustom(path)
83
+ .catch(err => cb(err))
84
+ .then(obj => {
85
+ obj.isDirectory = () => obj.isD
86
+ obj.isFile = () => obj.isF
87
+ cb(undefined, obj)
88
+ })
89
+ },
90
+ access: (...args) => {
91
+ const cb = args.pop()
92
+ window.fs.access(...args)
93
+ .then((data) => cb(undefined, data))
94
+ .catch((err) => cb(err))
95
+ },
96
+ open: (...args) => {
97
+ const cb = args.pop()
98
+ window.fs.openCustom(...args)
99
+ .then((data) => cb(undefined, data))
100
+ .catch((err) => cb(err))
101
+ },
102
+ read: (p1, arr, ...args) => {
103
+ const cb = args.pop()
104
+ window.fs.readCustom(
105
+ p1,
106
+ encodeUint8Array(arr),
107
+ ...args
108
+ )
109
+ .then((data) => {
110
+ const { n, newArr } = data
111
+ const newArr1 = decodeBase64String(newArr)
112
+ cb(undefined, n, newArr1)
113
+ })
114
+ .catch(err => cb(err))
115
+ },
116
+ close: (fd, cb) => {
117
+ window.fs.closeCustom(fd)
118
+ .then((data) => cb(undefined, data))
119
+ .catch((err) => cb(err))
120
+ },
121
+ readdir: (p, cb) => {
122
+ window.fs.readdir(p)
123
+ .then((data) => cb(undefined, data))
124
+ .catch((err) => cb(err))
125
+ },
126
+ mkdir: (...args) => {
127
+ const cb = args.pop()
128
+ window.fs.mkdir(...args)
129
+ .then((data) => cb(undefined, data))
130
+ .catch((err) => cb(err))
131
+ },
132
+ write: (p1, buf, cb) => {
133
+ window.fs.writeCustom(p1, encodeUint8Array(buf))
134
+ .then((data) => cb(undefined, data))
135
+ .catch((err) => cb(err))
136
+ },
137
+ realpath: (p, cb) => {
138
+ window.fs.realpath(p)
139
+ .then((data) => cb(undefined, data))
140
+ .catch((err) => cb(err))
141
+ },
142
+ constants: runSync('getFsContants')
143
+ }
144
+
145
+ window.reqs = {
146
+ path,
147
+ fs
148
+ }
149
+
150
+ function require (name) {
151
+ return window.reqs[name]
152
+ }
153
+
154
+ require.resolve = name => name
155
+
156
+ window.require = require
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Promise support timeout
3
+ */
4
+
5
+ export class NewPromise extends Promise {
6
+ constructor (executor, timeout = 30000) {
7
+ let timeoutId
8
+
9
+ super((resolve, reject) => {
10
+ const wrappedResolve = (value) => {
11
+ clearTimeout(timeoutId)
12
+ resolve(value)
13
+ }
14
+
15
+ const wrappedReject = (reason) => {
16
+ clearTimeout(timeoutId)
17
+ reject(reason)
18
+ }
19
+
20
+ timeoutId = setTimeout(() => {
21
+ wrappedReject(new Error('Promise timed out'))
22
+ }, timeout)
23
+
24
+ executor(wrappedResolve, wrappedReject)
25
+ })
26
+ }
27
+ }
@@ -0,0 +1,31 @@
1
+ /**
2
+ * smart resolve function
3
+ * @param {String} basePath
4
+ * @param {String} nameOrDot
5
+ * @return {String}
6
+ */
7
+
8
+ export default (basePath, nameOrDot) => {
9
+ const sep = basePath.includes('\\') || basePath.includes(':')
10
+ ? '\\'
11
+ : '/'
12
+ if (nameOrDot === '..') {
13
+ const arr = basePath.split(sep)
14
+ const { length } = arr
15
+ if (length === 1) {
16
+ return '/'
17
+ }
18
+ const res = arr.slice(0, length - 1).join(sep)
19
+ return res || '/'
20
+ }
21
+ const pre = nameOrDot.includes(':') && basePath === '/'
22
+ ? ''
23
+ : basePath
24
+ return pre +
25
+ (basePath.endsWith(sep) ? '' : sep) +
26
+ nameOrDot
27
+ }
28
+
29
+ export const osResolve = (...args) => {
30
+ return window.pre.resolve(...args)
31
+ }
@@ -0,0 +1 @@
1
+ export default (...args) => window.requestIdleCallback(...args)
@@ -0,0 +1,35 @@
1
+ import { termLSPrefix } from './constants'
2
+
3
+ function clear () {
4
+ const keys = Object.keys(window.localStorage)
5
+ for (const key of keys) {
6
+ if (key.startsWith(termLSPrefix)) {
7
+ window.localStorage.removeItem(key)
8
+ }
9
+ }
10
+ }
11
+
12
+ export function setItem (id, str) {
13
+ try {
14
+ window.localStorage.setItem(id, str)
15
+ } catch (e) {
16
+ console.log(e)
17
+ console.log('maybe local storage full, lets reset')
18
+ clear()
19
+ window.localStorage.setItem(id, str)
20
+ }
21
+ }
22
+
23
+ export function getItem (id) {
24
+ return window.localStorage.getItem(id) || ''
25
+ }
26
+
27
+ export function getItemJSON (id, defaultValue) {
28
+ const str = window.localStorage.getItem(id) || ''
29
+ return str ? JSON.parse(str) : defaultValue
30
+ }
31
+
32
+ export function setItemJSON (id, obj) {
33
+ const str = JSON.stringify(obj)
34
+ return setItem(id, str)
35
+ }
@@ -0,0 +1,19 @@
1
+ /**
2
+ * convert string to safe name
3
+ * from https://github.com/Jaliborc/safe-filename/blob/master/index.js
4
+ */
5
+
6
+ export default (name) => {
7
+ return name
8
+ .replace(/\.$/, '')
9
+ .replace('?', '❓')
10
+ .replace('\\', ' ⃥')
11
+ .replace('/', '⟋')
12
+ .replace('|', '│')
13
+ .replace(':', '꞉')
14
+ .replace('<', 'ᐸ')
15
+ .replace('>', 'ᐳ')
16
+ .replace('>', 'ᐳ')
17
+ .replace('"', 'ᐦ')
18
+ .replace('*', '꘎')
19
+ }
@@ -0,0 +1,74 @@
1
+ /**
2
+ * sftp through ws
3
+ */
4
+
5
+ import generate from './uid'
6
+ import Transfer from './transfer'
7
+ import { transferTypeMap } from './constants'
8
+ import initWs from './ws'
9
+ import { instSftpKeys as keys } from '../../app/common/constants'
10
+
11
+ const transferKeys = Object.keys(transferTypeMap)
12
+
13
+ class Sftp {
14
+ async init (sessionId) {
15
+ const id = generate()
16
+ const ws = await initWs('sftp', id, sessionId)
17
+ this.ws = ws
18
+ this.id = id
19
+ this.sessionId = sessionId
20
+ ws.s({
21
+ action: 'sftp-new',
22
+ id,
23
+ sessionId
24
+ })
25
+ const th = this
26
+ this.ws = ws
27
+ keys.forEach(func => {
28
+ th[func] = async (...args) => {
29
+ if (transferKeys.includes(func)) {
30
+ return Transfer({
31
+ sftpId: id,
32
+ ...args[0],
33
+ sessionId,
34
+ type: func
35
+ })
36
+ }
37
+ const uid = func + ':' + id
38
+ // let ws = await initWs()
39
+ return new Promise((resolve, reject) => {
40
+ ws.s({
41
+ action: 'sftp-func',
42
+ id,
43
+ func,
44
+ args,
45
+ sessionId
46
+ })
47
+ ws.once((arg) => {
48
+ if (arg.error) {
49
+ log.debug('sftp error', arg.error.message)
50
+ return reject(new Error(arg.error.message))
51
+ }
52
+ resolve(arg.data)
53
+ }, uid)
54
+ })
55
+ }
56
+ })
57
+ }
58
+
59
+ async destroy () {
60
+ const { ws } = this
61
+ ws.s({
62
+ action: 'sftp-destroy',
63
+ id: this.id,
64
+ sessionId: this.sessionId
65
+ })
66
+ ws.close()
67
+ }
68
+ }
69
+
70
+ export default async (sessionId) => {
71
+ const sftp = new Sftp()
72
+ await sftp.init(sessionId)
73
+ return sftp
74
+ }
@@ -0,0 +1,158 @@
1
+ /**
2
+ * theme control
3
+ */
4
+
5
+ import { defaultTheme, settingMap } from '../common/constants'
6
+ import download from '../common/download'
7
+ import copy from 'json-deep-copy'
8
+ const { prefix } = window
9
+ const t = prefix('terminalThemes')
10
+ const terminalPrefix = 'terminal:'
11
+ export const requiredThemeProps = [
12
+ 'main',
13
+ 'main-dark',
14
+ 'main-light',
15
+ 'text',
16
+ 'text-light',
17
+ 'text-dark',
18
+ 'text-disabled',
19
+ 'primary',
20
+ 'info',
21
+ 'success',
22
+ 'error',
23
+ 'warn',
24
+ 'terminal:foreground',
25
+ 'terminal:background',
26
+ 'terminal:cursor',
27
+ 'terminal:cursorAccent',
28
+ 'terminal:selectionBackground',
29
+ 'terminal:black',
30
+ 'terminal:red',
31
+ 'terminal:green',
32
+ 'terminal:yellow',
33
+ 'terminal:blue',
34
+ 'terminal:magenta',
35
+ 'terminal:cyan',
36
+ 'terminal:white',
37
+ 'terminal:brightBlack',
38
+ 'terminal:brightRed',
39
+ 'terminal:brightGreen',
40
+ 'terminal:brightYellow',
41
+ 'terminal:brightBlue',
42
+ 'terminal:brightMagenta',
43
+ 'terminal:brightCyan',
44
+ 'terminal:brightWhite'
45
+ ]
46
+ export const validThemeProps = [
47
+ ...requiredThemeProps,
48
+ 'name'
49
+ ]
50
+ /**
51
+ * build default themes
52
+ */
53
+ export const buildDefaultThemes = () => {
54
+ return {
55
+ [defaultTheme.id]: defaultTheme
56
+ }
57
+ }
58
+
59
+ /**
60
+ * build new theme
61
+ */
62
+ export const buildNewTheme = (theme = defaultTheme) => {
63
+ return Object.assign(
64
+ copy(theme),
65
+ {
66
+ id: '',
67
+ name: t('newTheme')
68
+ }
69
+ )
70
+ }
71
+
72
+ /**
73
+ * convert theme object to themeText
74
+ * @param {object} themeObj
75
+ * @param {boolean} withName
76
+ * @return {string}
77
+ */
78
+ export const convertThemeToText = (themeObj = {}, withName = false) => {
79
+ const theme = themeObj || {}
80
+ const { themeConfig = {}, name, uiThemeConfig = {} } = theme
81
+ const begin = withName
82
+ ? `themeName=${name}\n`
83
+ : ''
84
+ const res = Object.keys(uiThemeConfig).reduce((prev, key) => {
85
+ return prev +
86
+ (prev ? '\n' : '') +
87
+ key + '=' + uiThemeConfig[key]
88
+ }, begin)
89
+ return Object.keys(themeConfig).reduce((prev, key) => {
90
+ return prev +
91
+ (prev ? '\n' : '') + terminalPrefix +
92
+ key + '=' + themeConfig[key]
93
+ }, res)
94
+ }
95
+
96
+ /**
97
+ * convert themeText to themeConfig object
98
+ * @param {string} themeTxt
99
+ * @return {object}
100
+ */
101
+ export const convertTheme = (themeTxt) => {
102
+ return themeTxt.split('\n').reduce((prev, line) => {
103
+ let [key = '', value = ''] = line.split('=')
104
+ key = key.trim()
105
+ value = value.trim()
106
+ if (!key || !value) {
107
+ return prev
108
+ }
109
+ if (key === 'themeName') {
110
+ prev.name = value.slice(0, 50)
111
+ } else {
112
+ const isTerminal = key.startsWith(terminalPrefix)
113
+ key = key.replace(terminalPrefix, '')
114
+ if (key.includes('selection')) {
115
+ key = 'selectionBackground'
116
+ }
117
+ if (isTerminal) {
118
+ prev.themeConfig[key] = value
119
+ } else {
120
+ prev.uiThemeConfig[key] = value
121
+ }
122
+ }
123
+ return prev
124
+ }, {
125
+ themeConfig: {},
126
+ uiThemeConfig: {}
127
+ })
128
+ }
129
+
130
+ /**
131
+ * verify theme config
132
+ * @param {object} themeConfig
133
+ * @return {array} extra keys
134
+ */
135
+ export const verifyTheme = (themeConfig) => {
136
+ const keysRight = Object.keys(defaultTheme.themeConfig)
137
+ const keys = Object.keys(themeConfig)
138
+ const extraKeys = keys.filter(k => !keysRight.includes(k))
139
+ return extraKeys
140
+ }
141
+
142
+ /**
143
+ * export theme as txt
144
+ * @param {string} themeId
145
+ */
146
+ export const exportTheme = (themeId) => {
147
+ const themes = window.store.getSidebarList(settingMap.terminalThemes)
148
+ const theme = themes.find(d => d.id === themeId)
149
+ if (!theme) {
150
+ log.error('export error', themeId)
151
+ return
152
+ }
153
+ const text = convertThemeToText(theme, true)
154
+ download(
155
+ `${theme.name}.txt`,
156
+ text
157
+ )
158
+ }
@@ -0,0 +1,12 @@
1
+ /**
2
+ * test connection
3
+ */
4
+
5
+ import fetch from './fetch-from-server'
6
+
7
+ export default (body) => {
8
+ return fetch({
9
+ body,
10
+ action: 'test-terminal'
11
+ })
12
+ }
@@ -0,0 +1,30 @@
1
+ /**
2
+ * time formatter
3
+ */
4
+
5
+ function prefix (n) {
6
+ const str = '' + n
7
+ if (str.length < 2) {
8
+ return '0' + str
9
+ }
10
+ return str
11
+ }
12
+
13
+ export default (
14
+ time = new Date(),
15
+ format = 'YYYY-MM-DD HH:mm:ss'
16
+ ) => {
17
+ const t = new Date(time)
18
+ const d = t.getDate()
19
+ const y = t.getFullYear()
20
+ const m = t.getMonth()
21
+ const h = t.getHours()
22
+ const mm = t.getMinutes()
23
+ const s = t.getSeconds()
24
+ return format.replace('YYYY', prefix(y))
25
+ .replace('MM', prefix(m + 1))
26
+ .replace('DD', prefix(d))
27
+ .replace('HH', prefix(h))
28
+ .replace('mm', prefix(mm))
29
+ .replace('ss', prefix(s))
30
+ }
@@ -0,0 +1,5 @@
1
+ import { cloneDeep } from 'lodash-es'
2
+
3
+ export default (obj) => {
4
+ return cloneDeep(obj)
5
+ }
@@ -0,0 +1,7 @@
1
+ export default (eventName, value) => {
2
+ if (!window.gtag) {
3
+ return
4
+ }
5
+ log.debug('track data', eventName, value)
6
+ window.gtag('event', eventName, value)
7
+ }
@@ -0,0 +1,76 @@
1
+ /**
2
+ * transfer through ws
3
+ */
4
+
5
+ import generate from './uid'
6
+ import initWs from './ws'
7
+
8
+ const keys = window.pre.transferKeys
9
+
10
+ class Transfer {
11
+ async init ({
12
+ onData,
13
+ onEnd,
14
+ onError,
15
+ ...rest
16
+ }) {
17
+ const id = generate()
18
+ this.id = id
19
+ const th = this
20
+ const {
21
+ sessionId,
22
+ sftpId
23
+ } = rest
24
+ const ws = await initWs('transfer', id, sessionId, sftpId)
25
+ ws.s({
26
+ action: 'transfer-new',
27
+ ...rest,
28
+ id
29
+ })
30
+ keys.forEach(func => {
31
+ th[func] = (...args) => {
32
+ ws.s({
33
+ action: 'transfer-func',
34
+ id: th.id,
35
+ func,
36
+ sessionId,
37
+ sftpId,
38
+ args
39
+ })
40
+ if (func === 'destroy') {
41
+ th.onDestroy(ws)
42
+ }
43
+ }
44
+ })
45
+
46
+ const did = 'transfer:data:' + id
47
+ this.onData = (evt) => {
48
+ const arg = JSON.parse(evt.data)
49
+ if (did === arg.id) {
50
+ onData(arg.data)
51
+ }
52
+ }
53
+ ws.addEventListener('message', this.onData)
54
+ ws.once((arg) => {
55
+ onEnd(arg)
56
+ th.onDestroy(ws)
57
+ }, 'transfer:end:' + id)
58
+ ws.once((arg) => {
59
+ log.debug('sftp transfer error')
60
+ log.debug(arg.error.stack)
61
+ onError(new Error(arg.error.message))
62
+ th.onDestroy(ws)
63
+ }, 'transfer:err:' + id)
64
+ }
65
+
66
+ onDestroy (ws) {
67
+ ws.removeEventListener('message', this.onData)
68
+ ws.close()
69
+ }
70
+ }
71
+
72
+ export default async (props) => {
73
+ const transfer = new Transfer()
74
+ await transfer.init(props)
75
+ return transfer
76
+ }
@@ -0,0 +1,62 @@
1
+ import { TrzszFilter } from 'trzsz'
2
+
3
+ const {
4
+ openDialog
5
+ } = window.api
6
+
7
+ window.newTrzsz = function (
8
+ writeToTerminal,
9
+ sendToServer,
10
+ terminalColumns,
11
+ isWindowsShell
12
+ ) {
13
+ // create a trzsz filter
14
+ return new TrzszFilter({
15
+ // write the server output to the terminal
16
+ writeToTerminal,
17
+ // send the user input to the server
18
+ sendToServer,
19
+ // choose some files to be sent to the server
20
+ chooseSendFiles: async (directory) => {
21
+ const properties = [
22
+ 'openFile',
23
+ 'multiSelections',
24
+ 'showHiddenFiles',
25
+ 'noResolveAliases',
26
+ 'treatPackageAsDirectory',
27
+ 'dontAddToRecent'
28
+ ]
29
+ if (directory) {
30
+ properties.push('openDirectory')
31
+ }
32
+ return openDialog({
33
+ title: 'Choose some files to send',
34
+ message: 'Choose some files to send',
35
+ properties
36
+ })
37
+ },
38
+ // choose a directory to save the received files
39
+ chooseSaveDirectory: async () => {
40
+ const savePaths = await openDialog({
41
+ title: 'Choose a folder to save file(s)',
42
+ message: 'Choose a folder to save file(s)',
43
+ properties: [
44
+ 'openDirectory',
45
+ 'showHiddenFiles',
46
+ 'createDirectory',
47
+ 'noResolveAliases',
48
+ 'treatPackageAsDirectory',
49
+ 'dontAddToRecent'
50
+ ]
51
+ })
52
+ if (!savePaths || !savePaths.length) {
53
+ return undefined
54
+ }
55
+ return savePaths[0]
56
+ },
57
+ // the terminal columns
58
+ terminalColumns,
59
+ // there is a windows shell
60
+ isWindowsShell
61
+ })
62
+ }