@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,198 @@
1
+ /**
2
+ * load data from db
3
+ */
4
+
5
+ import { dbNames, update, getData, fetchInitData, insert, remove } from '../common/db'
6
+ import initWatch from './watch'
7
+ import parseInt10 from '../common/parse-int10'
8
+ import { infoTabs, statusMap, defaultEnvLang } from '../common/constants'
9
+ import fs from '../common/fs'
10
+ import generate from '../common/uid'
11
+ import defaultSettings from '../../app/common/default-setting'
12
+ import encodes from '../components/bookmark-form/encodes'
13
+ import runIdle from '../common/run-idle'
14
+ import { initWsCommon } from '../common/fetch-from-server'
15
+
16
+ function getHost (argv, opts) {
17
+ const arr = argv
18
+ let i = arr.length - 1
19
+ const reg = /^(?:([\w\d-_]+)@)?([\w\d-_]+\.[\w\d-_.]+)(?::([\d]+))?$/
20
+ for (; i >= 0; i--) {
21
+ const str = arr[i]
22
+ const mt = str.match(reg)
23
+ if (mt) {
24
+ const port = mt[3]
25
+ const user = mt[1]
26
+ return {
27
+ host: mt[2],
28
+ username: user,
29
+ port: port ? parseInt10(port) : 22
30
+ }
31
+ }
32
+ }
33
+ return {}
34
+ }
35
+
36
+ export async function addTabFromCommandLine (store, opts) {
37
+ log.debug('command line params', opts)
38
+ if (!opts) {
39
+ return false
40
+ }
41
+ const {
42
+ isHelp,
43
+ helpInfo,
44
+ options,
45
+ argv
46
+ } = opts
47
+ store.commandLineHelp = helpInfo
48
+ if (isHelp) {
49
+ return store.openAbout(infoTabs.cmd)
50
+ }
51
+ const conf = getHost(argv, options)
52
+ const update = {
53
+ passphrase: options.passphrase,
54
+ password: options.password,
55
+ // port: options.port ? parseInt(options.port, 10) : 22,
56
+ type: 'remote',
57
+ status: statusMap.processing,
58
+ id: generate(),
59
+ encode: encodes[0],
60
+ envLang: defaultEnvLang,
61
+ enableSsh: !options.sftpOnly,
62
+ authType: 'password',
63
+ pane: 'terminal',
64
+ term: defaultSettings.terminalType
65
+ }
66
+ if (options.setEnv) {
67
+ update.setEnv = options.setEnv
68
+ }
69
+ if (options.title) {
70
+ update.title = options.title
71
+ }
72
+ if (options.user) {
73
+ update.username = options.user
74
+ }
75
+ if (options.port && parseInt10(options.port)) {
76
+ update.port = parseInt10(options.port)
77
+ }
78
+ Object.assign(conf, update)
79
+ if (options.privateKeyPath) {
80
+ conf.privateKey = await fs.readFile(options.privateKeyPath)
81
+ }
82
+ log.debug('command line opts', conf)
83
+ if (conf.username && conf.host) {
84
+ store.addTab(conf)
85
+ }
86
+ if (options && options.batchOp) {
87
+ window.store.runBatchOp(options.batchOp)
88
+ }
89
+ }
90
+
91
+ export default (Store) => {
92
+ Store.prototype.batchDbUpdate = async function (updates) {
93
+ runIdle(() => {
94
+ for (const u of updates) {
95
+ update(u.id, u.update, u.db, u.upsert)
96
+ }
97
+ })
98
+ }
99
+ Store.prototype.batchDbAdd = async function (adds) {
100
+ runIdle(() => {
101
+ for (const u of adds) {
102
+ insert(u.db, u.obj)
103
+ }
104
+ })
105
+ }
106
+ Store.prototype.batchDbDel = async function (dels) {
107
+ runIdle(() => {
108
+ for (const u of dels) {
109
+ remove(u.db, u.id)
110
+ }
111
+ })
112
+ }
113
+ Store.prototype.openInitSessions = function () {
114
+ const { store } = window
115
+ const arr = store.config.onStartSessions || []
116
+ for (const s of arr) {
117
+ store.onSelectBookmark(s)
118
+ }
119
+ if (!arr.length && store.config.initDefaultTabOnStart) {
120
+ store.initFirstTab()
121
+ }
122
+ setTimeout(store.confirmLoad, 1300)
123
+ const { initTime, loadTime } = window.pre.runSync('getLoadTime')
124
+ if (loadTime) {
125
+ store.loadTime = loadTime
126
+ } else {
127
+ const finishLoadTime = Date.now()
128
+ store.loadTime = finishLoadTime - initTime
129
+ window.pre.runSync('setLoadTime', store.loadTime)
130
+ }
131
+ }
132
+ Store.prototype.fetchSshConfigItems = async function () {
133
+ const arr = await window.pre.runGlobalAsync('loadSshConfig')
134
+ .catch((err) => {
135
+ console.log('fetchSshConfigItems error', err)
136
+ return []
137
+ })
138
+ window.store._sshConfigItems = JSON.stringify(arr)
139
+ }
140
+ Store.prototype.confirmLoad = function () {
141
+ window.store.configLoaded = true
142
+ }
143
+ Store.prototype.initApp = async function () {
144
+ const { store } = window
145
+ const globs = await window.pre.runGlobalAsync('init')
146
+ window.langMap = globs.langMap
147
+ store.installSrc = globs.installSrc
148
+ store.appPath = globs.appPath
149
+ store.exePath = globs.exePath
150
+ store.isPortable = globs.isPortable
151
+ store._config = JSON.stringify(
152
+ globs.config
153
+ )
154
+ store._langs = JSON.stringify(
155
+ globs.langs
156
+ )
157
+ store.zoom(store.config.zoom, false, true)
158
+ initWsCommon()
159
+ }
160
+ Store.prototype.initData = async function () {
161
+ const { store } = window
162
+ await store.initApp()
163
+ const ext = {}
164
+ const all = dbNames.map(async name => {
165
+ const data = await fetchInitData(name)
166
+ return {
167
+ name,
168
+ data
169
+ }
170
+ })
171
+ await Promise.all(all)
172
+ .then(arr => {
173
+ for (const { name, data } of arr) {
174
+ ext['_' + name] = data
175
+ }
176
+ })
177
+ ext.lastDataUpdateTime = await getData('lastDataUpdateTime') || 0
178
+ Object.assign(store, ext)
179
+
180
+ store.checkDefaultTheme()
181
+ store.loadFontList()
182
+ store.fetchItermThemes()
183
+ store.openInitSessions()
184
+ store.fetchSshConfigItems()
185
+ initWatch(store)
186
+ store.initCommandLine().catch(store.onError)
187
+ if (store.config.checkUpdateOnStart) {
188
+ store.onCheckUpdate()
189
+ }
190
+ }
191
+ Store.prototype.initCommandLine = async function () {
192
+ const opts = await window.pre.runGlobalAsync('initCommandLine')
193
+ addTabFromCommandLine(window.store, opts)
194
+ }
195
+ Store.prototype.addTabFromCommandLine = (event, opts) => {
196
+ addTabFromCommandLine(window.store, opts)
197
+ }
198
+ }
@@ -0,0 +1,43 @@
1
+ /**
2
+ * quick command related functions
3
+ */
4
+
5
+ import {
6
+ settingMap,
7
+ terminalActions
8
+ } from '../common/constants'
9
+ import postMessage from '../common/post-msg'
10
+
11
+ export default Store => {
12
+ Store.prototype.getQuickCommands = function () {
13
+ return window.store.getItems(settingMap.quickCommands)
14
+ }
15
+
16
+ Store.prototype.setQuickCommands = function (list) {
17
+ return window.store.setItems(settingMap.quickCommands, list)
18
+ }
19
+
20
+ Store.prototype.addQuickCommand = function (
21
+ qm
22
+ ) {
23
+ window.store.addItem(qm, settingMap.quickCommands)
24
+ }
25
+
26
+ Store.prototype.editQuickCommand = function (id, update) {
27
+ window.store.editItem(id, update, settingMap.quickCommands)
28
+ }
29
+
30
+ Store.prototype.delQuickCommand = function ({ id }) {
31
+ window.store.delItem({ id }, settingMap.quickCommands)
32
+ }
33
+
34
+ Store.prototype.runQuickCommand = function (cmd, inputOnly = false) {
35
+ const { activeTerminalId } = window.store
36
+ postMessage({
37
+ action: terminalActions.quickCommand,
38
+ cmd,
39
+ inputOnly,
40
+ activeSplitId: activeTerminalId
41
+ })
42
+ }
43
+ }
@@ -0,0 +1,54 @@
1
+ /**
2
+ * sessions not proper closed related functions
3
+ */
4
+
5
+ import { isMac, terminalActions } from '../common/constants'
6
+ import { debounce } from 'lodash-es'
7
+ import postMsg from '../common/post-msg'
8
+
9
+ export default Store => {
10
+ Store.prototype.onMouseWheel = function (event) {
11
+ if (
12
+ (isMac && event.metaKey) ||
13
+ (!isMac && event.ctrlKey)
14
+ ) {
15
+ event.stopPropagation()
16
+ if (window.store.inActiveTerminal) {
17
+ window.store.zoomTerminal(event.wheelDeltaY)
18
+ } else {
19
+ const plus = event.wheelDeltaY > 0 ? 0.2 : -0.2
20
+ window.store.zoom(plus, true)
21
+ }
22
+ }
23
+ }
24
+
25
+ Store.prototype.onKeyDown = function (event) {
26
+ if (
27
+ event.key === '=' &&
28
+ (
29
+ (isMac && event.metaKey) ||
30
+ (!isMac && event.ctrlKey)
31
+ )
32
+ ) {
33
+ event.stopPropagation()
34
+ window.store.zoom(0.25, true)
35
+ } else if (
36
+ event.key === '-' &&
37
+ (
38
+ (isMac && event.metaKey) ||
39
+ (!isMac && event.ctrlKey)
40
+ )
41
+ ) {
42
+ event.stopPropagation()
43
+ window.store.zoom(-0.25, true)
44
+ }
45
+ }
46
+
47
+ Store.prototype.zoomTerminal = debounce(function (delta) {
48
+ postMsg({
49
+ action: terminalActions.zoom,
50
+ zoomValue: delta > 0 ? 1 : -1,
51
+ activeSplitId: window.store.activeTerminalId
52
+ })
53
+ }, 500)
54
+ }
@@ -0,0 +1,208 @@
1
+ /**
2
+ * setting modal
3
+ */
4
+
5
+ import { find, isEqual, pick, without, findIndex } from 'lodash-es'
6
+ import {
7
+ message
8
+ } from 'antd'
9
+ import generate from '../common/uid'
10
+ import copy from 'json-deep-copy'
11
+ import {
12
+ settingMap,
13
+ settingCommonId,
14
+ modals
15
+ } from '../common/constants'
16
+ import { buildNewTheme } from '../common/terminal-theme'
17
+ import getInitItem from '../common/init-setting-item'
18
+ import newTerm from '../common/new-terminal'
19
+
20
+ const { prefix } = window
21
+ const m = prefix('menu')
22
+
23
+ export default Store => {
24
+ Store.prototype.setConfig = function (conf) {
25
+ const { store } = window
26
+ store._config = JSON.stringify(
27
+ {
28
+ ...store.config,
29
+ ...conf
30
+ }
31
+ )
32
+ }
33
+ Store.prototype.setSftpSortSetting = function (conf) {
34
+ const { store } = window
35
+ const base = copy(store.sftpSortSetting)
36
+ store._sftpSortSetting = JSON.stringify(
37
+ {
38
+ ...base,
39
+ ...conf
40
+ }
41
+ )
42
+ }
43
+ Store.prototype.handleEditHistory = function () {
44
+ const { store } = window
45
+ const all = store.getItems('history')
46
+ store.storeAssign({
47
+ settingTab: settingMap.history,
48
+ autofocustrigger: Date.now()
49
+ })
50
+ store.setSettingItem(all[0] || getInitItem([], settingMap.history))
51
+ store.openSettingModal()
52
+ }
53
+
54
+ Store.prototype.openBookmarkEdit = function (item) {
55
+ const { store } = window
56
+ store.storeAssign({
57
+ settingTab: settingMap.bookmarks,
58
+ autofocustrigger: Date.now()
59
+ })
60
+ store.setSettingItem(item)
61
+ store.openSettingModal()
62
+ }
63
+
64
+ Store.prototype.handleOpenQuickCommandsSetting = function () {
65
+ const { store } = window
66
+ store.storeAssign({
67
+ settingTab: settingMap.quickCommands,
68
+ autofocustrigger: Date.now()
69
+ })
70
+ store.setSettingItem(getInitItem([], settingMap.quickCommands))
71
+ store.openSettingModal()
72
+ }
73
+
74
+ Store.prototype.onSelectHistory = function (id) {
75
+ const { store } = window
76
+ const history = store.getItems('history')
77
+ const item = find(history, it => it.id === id)
78
+ store.addTab({
79
+ ...copy(item),
80
+ from: 'history',
81
+ srcId: item.id,
82
+ ...newTerm(true)
83
+ })
84
+ }
85
+
86
+ Store.prototype.onSelectBookmark = function (id) {
87
+ const { store } = window
88
+ const history = store.getItems('history')
89
+ const bookmarks = store.getBookmarks()
90
+ const item = copy(
91
+ find(bookmarks, it => it.id === id) ||
92
+ find(store.sshConfigItems, it => it.id === id)
93
+ )
94
+ if (!item) {
95
+ return
96
+ }
97
+ store.addTab({
98
+ ...item,
99
+ from: 'bookmarks',
100
+ srcId: item.id,
101
+ ...newTerm(true)
102
+ })
103
+ item.id = generate()
104
+ if (store.config.disableSshHistory) {
105
+ return
106
+ }
107
+ const existItem = find(history, j => {
108
+ const keysj = Object.keys(j)
109
+ const keysi = Object.keys(item)
110
+ return isEqual(
111
+ pick(item, without(keysi, 'id')),
112
+ pick(j, without(keysj, 'id'))
113
+ )
114
+ })
115
+ if (!existItem) {
116
+ store.addItem(item, settingMap.history)
117
+ } else {
118
+ const index = findIndex(history, f => f.id === existItem.id)
119
+ history.splice(index, 1)
120
+ history.unshift(existItem)
121
+ store.setItems('history', history)
122
+ }
123
+ }
124
+
125
+ Store.prototype.openSetting = function () {
126
+ const { store } = window
127
+ if (
128
+ store.settingTab === settingMap.setting &&
129
+ store.settingItem.id === settingCommonId &&
130
+ store.showModal === modals.setting
131
+ ) {
132
+ return store.hideSettingModal()
133
+ }
134
+ store.storeAssign({
135
+ settingTab: settingMap.setting
136
+ })
137
+ store.setSettingItem(getInitItem([], settingMap.setting))
138
+ store.openSettingModal()
139
+ }
140
+
141
+ Store.prototype.openSettingSync = function () {
142
+ const { store } = window
143
+ if (
144
+ store.settingTab === settingMap.setting &&
145
+ store.settingItem.id === store.setting[0].id &&
146
+ store.showModal === modals.setting
147
+ ) {
148
+ return store.hideSettingModal()
149
+ }
150
+ store.storeAssign({
151
+ settingTab: settingMap.setting
152
+ })
153
+ store.setSettingItem(copy(store.setting[0]))
154
+ store.openSettingModal()
155
+ }
156
+
157
+ Store.prototype.openTerminalThemes = function () {
158
+ const { store } = window
159
+ if (
160
+ store.settingTab === settingMap.terminalThemes &&
161
+ store.settingItem.id === ''
162
+ ) {
163
+ return store.hideSettingModal()
164
+ }
165
+ store.storeAssign({
166
+ settingTab: settingMap.terminalThemes,
167
+ autofocustrigger: Date.now()
168
+ })
169
+ store.setSettingItem(buildNewTheme())
170
+ store.openSettingModal()
171
+ }
172
+
173
+ Store.prototype.openSettingModal = function () {
174
+ const { store } = window
175
+ if (store.isSencondInstance) {
176
+ return message.warning(
177
+ m('sencondInstanceTip')
178
+ )
179
+ }
180
+ store.showModal = modals.setting
181
+ }
182
+
183
+ Store.prototype.hideSettingModal = function () {
184
+ const { store } = window
185
+ store.showModal = modals.hide
186
+ store.setSettingItem({})
187
+ }
188
+
189
+ Store.prototype.loadFontList = async function () {
190
+ const fonts = await window.pre.runGlobalAsync('loadFontList')
191
+ .catch(err => {
192
+ console.log('loadFontList error', err)
193
+ return []
194
+ })
195
+ window.store._fonts = JSON.stringify(fonts)
196
+ }
197
+
198
+ Store.prototype.handleChangeSettingTab = function (settingTab) {
199
+ const { store } = window
200
+ const arr = store.getItems(settingTab)
201
+ const item = getInitItem(arr, settingTab)
202
+ store.storeAssign({
203
+ autofocustrigger: Date.now(),
204
+ settingTab
205
+ })
206
+ store.setSettingItem(item)
207
+ }
208
+ }
@@ -0,0 +1,48 @@
1
+ /**
2
+ * sidebar
3
+ */
4
+
5
+ import {
6
+ settingMap,
7
+ openedSidebarKey,
8
+ sidebarPinnedKey
9
+ } from '../common/constants'
10
+ import * as ls from '../common/safe-local-storage'
11
+
12
+ export default Store => {
13
+ Store.prototype.expandBookmarks = function () {
14
+ const { store } = window
15
+ window.store.setState(
16
+ 'expandedKeys',
17
+ store.getBookmarkGroupsTotal().map(g => g.id)
18
+ )
19
+ }
20
+
21
+ Store.prototype.collapseBookmarks = function () {
22
+ const { store } = window
23
+ store.setState(
24
+ 'expandedKeys',
25
+ []
26
+ )
27
+ }
28
+
29
+ Store.prototype.setOpenedSideBar = function (bar) {
30
+ ls.setItem(openedSidebarKey, bar)
31
+ window.store.openedSideBar = bar
32
+ }
33
+
34
+ Store.prototype.handlePin = function (pinned) {
35
+ const { store } = window
36
+ const current = !store.pinned
37
+ ls.setItem(sidebarPinnedKey, current + '')
38
+ store.pinned = current
39
+ }
40
+
41
+ Store.prototype.onClickBookmark = function () {
42
+ window.store.onNewSsh()
43
+ }
44
+
45
+ Store.prototype.onClickHistory = function () {
46
+ window.store.handleChangeSettingTab(settingMap.history)
47
+ }
48
+ }