@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.
- package/LICENSE +21 -0
- package/README.md +31 -0
- package/client/common/auto-complete-data-mapper.js +6 -0
- package/client/common/byte-format.js +14 -0
- package/client/common/class.js +52 -0
- package/client/common/clipboard.js +49 -0
- package/client/common/constants.js +308 -0
- package/client/common/create-lang-edit-link.js +7 -0
- package/client/common/create-title.js +29 -0
- package/client/common/db-fix.js +24 -0
- package/client/common/db.js +155 -0
- package/client/common/download-mirrors.js +10 -0
- package/client/common/download.js +16 -0
- package/client/common/error-handler.jsx +27 -0
- package/client/common/fetch-from-server.js +47 -0
- package/client/common/fetch.jsx +71 -0
- package/client/common/find-bookmark-group-id.js +15 -0
- package/client/common/find-parent.js +30 -0
- package/client/common/form-layout.js +27 -0
- package/client/common/fs.js +21 -0
- package/client/common/get-proxy.js +8 -0
- package/client/common/id-with-stamp.js +10 -0
- package/client/common/index-sorter.js +4 -0
- package/client/common/init-setting-item.js +32 -0
- package/client/common/is-absolute-path.js +3 -0
- package/client/common/is-ip.js +16 -0
- package/client/common/is-valid-path.js +7 -0
- package/client/common/key-control-pressed.js +13 -0
- package/client/common/key-pressed.js +13 -0
- package/client/common/key-shift-pressed.js +7 -0
- package/client/common/mode2permission.js +81 -0
- package/client/common/new-terminal.js +31 -0
- package/client/common/parse-int10.js +3 -0
- package/client/common/parse-json-safe.js +11 -0
- package/client/common/pass-enc.js +25 -0
- package/client/common/post-msg.js +3 -0
- package/client/common/pre.js +156 -0
- package/client/common/promise-timeout.js +27 -0
- package/client/common/resolve.js +31 -0
- package/client/common/run-idle.js +1 -0
- package/client/common/safe-local-storage.js +35 -0
- package/client/common/safe-name.js +19 -0
- package/client/common/sftp.js +74 -0
- package/client/common/terminal-theme.js +158 -0
- package/client/common/test-connection.js +12 -0
- package/client/common/time.js +30 -0
- package/client/common/to-simple-obj.js +5 -0
- package/client/common/track.js +7 -0
- package/client/common/transfer.js +76 -0
- package/client/common/trzsz.js +62 -0
- package/client/common/ui-theme.js +44 -0
- package/client/common/uid.js +5 -0
- package/client/common/update-check.js +79 -0
- package/client/common/upgrade.js +68 -0
- package/client/common/wait.js +8 -0
- package/client/common/ws.js +161 -0
- package/client/components/batch-op/batch-op.jsx +650 -0
- package/client/components/bookmark-form/bookmark-form.styl +8 -0
- package/client/components/bookmark-form/bookmark-group-tree-format.js +39 -0
- package/client/components/bookmark-form/encodes.js +44 -0
- package/client/components/bookmark-form/form-ssh-common.jsx +208 -0
- package/client/components/bookmark-form/form-tabs.jsx +69 -0
- package/client/components/bookmark-form/index.jsx +159 -0
- package/client/components/bookmark-form/local-form-ui.jsx +152 -0
- package/client/components/bookmark-form/local-form.jsx +16 -0
- package/client/components/bookmark-form/proxy.jsx +49 -0
- package/client/components/bookmark-form/quick-command-list.jsx +31 -0
- package/client/components/bookmark-form/quick-command.jsx +228 -0
- package/client/components/bookmark-form/render-auth-ssh.jsx +104 -0
- package/client/components/bookmark-form/render-connection-hopping.jsx +229 -0
- package/client/components/bookmark-form/render-delayed-scripts.jsx +88 -0
- package/client/components/bookmark-form/render-ssh-tunnel.jsx +116 -0
- package/client/components/bookmark-form/serial-form-ui.jsx +311 -0
- package/client/components/bookmark-form/serial-form.jsx +20 -0
- package/client/components/bookmark-form/sftp-enable.jsx +33 -0
- package/client/components/bookmark-form/ssh-form-ui.jsx +100 -0
- package/client/components/bookmark-form/ssh-form.jsx +348 -0
- package/client/components/bookmark-form/telnet-form-ui.jsx +154 -0
- package/client/components/bookmark-form/telnet-form.jsx +16 -0
- package/client/components/bookmark-form/tree-delete.jsx +87 -0
- package/client/components/bookmark-form/use-form-funcs.jsx +50 -0
- package/client/components/bookmark-form/use-quick-commands.jsx +83 -0
- package/client/components/bookmark-form/use-submit.jsx +77 -0
- package/client/components/bookmark-form/use-ui.jsx +82 -0
- package/client/components/bookmark-form/x11.jsx +23 -0
- package/client/components/common/animate-text.jsx +37 -0
- package/client/components/common/animate-text.styl +54 -0
- package/client/components/common/external-link.jsx +28 -0
- package/client/components/common/help-icon.jsx +25 -0
- package/client/components/common/highlight.jsx +23 -0
- package/client/components/common/highlight.styl +3 -0
- package/client/components/common/input-auto-focus.jsx +68 -0
- package/client/components/common/input-confirm.jsx +66 -0
- package/client/components/common/logo-elem.jsx +22 -0
- package/client/components/common/markdown.jsx +27 -0
- package/client/components/common/react-subx.jsx +1 -0
- package/client/components/common/resize-wrap.jsx +222 -0
- package/client/components/common/resize-wrap.styl +9 -0
- package/client/components/common/search.jsx +9 -0
- package/client/components/common/show-item.jsx +27 -0
- package/client/components/context-menu/boomarks.jsx +15 -0
- package/client/components/context-menu/context-menu.jsx +340 -0
- package/client/components/context-menu/context-menu.styl +90 -0
- package/client/components/context-menu/history.jsx +27 -0
- package/client/components/context-menu/icon-holder.jsx +5 -0
- package/client/components/context-menu/menu-btn.jsx +224 -0
- package/client/components/context-menu/sub-tab-menu.jsx +23 -0
- package/client/components/context-menu/tabs.jsx +22 -0
- package/client/components/context-menu/zoom.jsx +40 -0
- package/client/components/footer/batch-input.jsx +177 -0
- package/client/components/footer/footer-entry.jsx +141 -0
- package/client/components/footer/footer.styl +47 -0
- package/client/components/icons/match-case.jsx +10 -0
- package/client/components/icons/match-whole-word.jsx +13 -0
- package/client/components/icons/regular-exp.jsx +10 -0
- package/client/components/main/css-overwrite.jsx +92 -0
- package/client/components/main/error-wrapper.jsx +59 -0
- package/client/components/main/index.jsx +11 -0
- package/client/components/main/loading.jsx +25 -0
- package/client/components/main/main.jsx +149 -0
- package/client/components/main/term-fullscreen-control.jsx +21 -0
- package/client/components/main/term-fullscreen.styl +27 -0
- package/client/components/main/ui-theme.jsx +31 -0
- package/client/components/main/upgrade.jsx +351 -0
- package/client/components/main/upgrade.styl +27 -0
- package/client/components/main/wrapper.styl +41 -0
- package/client/components/quick-commands/qm.styl +29 -0
- package/client/components/quick-commands/quick-command-item.jsx +36 -0
- package/client/components/quick-commands/quick-command-transport-mod.jsx +54 -0
- package/client/components/quick-commands/quick-command-transport.jsx +12 -0
- package/client/components/quick-commands/quick-commands-box.jsx +233 -0
- package/client/components/quick-commands/quick-commands-form-elem.jsx +119 -0
- package/client/components/quick-commands/quick-commands-form.jsx +33 -0
- package/client/components/quick-commands/quick-commands-list.jsx +128 -0
- package/client/components/quick-commands/quick-commands-select.jsx +38 -0
- package/client/components/session/session.jsx +533 -0
- package/client/components/session/session.styl +53 -0
- package/client/components/session/sessions.jsx +445 -0
- package/client/components/setting-panel/bookmark-transport.jsx +148 -0
- package/client/components/setting-panel/bookmark-tree-list.jsx +14 -0
- package/client/components/setting-panel/col.jsx +18 -0
- package/client/components/setting-panel/list.jsx +186 -0
- package/client/components/setting-panel/list.styl +33 -0
- package/client/components/setting-panel/on-tree-drop.js +222 -0
- package/client/components/setting-panel/setting-modal.jsx +163 -0
- package/client/components/setting-panel/setting-wrap.jsx +37 -0
- package/client/components/setting-panel/setting-wrap.styl +52 -0
- package/client/components/setting-panel/setting.jsx +858 -0
- package/client/components/setting-panel/setting.styl +4 -0
- package/client/components/setting-panel/start-session-select.jsx +91 -0
- package/client/components/setting-panel/tab-bookmarks.jsx +37 -0
- package/client/components/setting-panel/tab-history.jsx +44 -0
- package/client/components/setting-panel/tab-quick-commands.jsx +38 -0
- package/client/components/setting-panel/tab-settings.jsx +42 -0
- package/client/components/setting-panel/tab-themes.jsx +34 -0
- package/client/components/setting-panel/tree-list.jsx +978 -0
- package/client/components/setting-panel/tree-list.styl +57 -0
- package/client/components/setting-sync/data-import.jsx +65 -0
- package/client/components/setting-sync/setting-sync-form.jsx +271 -0
- package/client/components/setting-sync/setting-sync.jsx +81 -0
- package/client/components/setting-sync/sync.styl +7 -0
- package/client/components/sftp/address-bar.jsx +139 -0
- package/client/components/sftp/address-bookmark-item.jsx +47 -0
- package/client/components/sftp/address-bookmark.jsx +81 -0
- package/client/components/sftp/address-bookmark.styl +8 -0
- package/client/components/sftp/confirm-modal.jsx +184 -0
- package/client/components/sftp/file-icon.jsx +22 -0
- package/client/components/sftp/file-item.jsx +1226 -0
- package/client/components/sftp/file-mode-modal.jsx +205 -0
- package/client/components/sftp/file-props-modal.jsx +211 -0
- package/client/components/sftp/file-read.js +81 -0
- package/client/components/sftp/list-table-ui.jsx +547 -0
- package/client/components/sftp/owner-list.js +97 -0
- package/client/components/sftp/paged-list.jsx +60 -0
- package/client/components/sftp/permission-render.jsx +42 -0
- package/client/components/sftp/sftp-entry.jsx +1069 -0
- package/client/components/sftp/sftp.styl +217 -0
- package/client/components/sftp/transfer-common.js +9 -0
- package/client/components/sftp/transfer-conflict.jsx +315 -0
- package/client/components/sftp/transfer-speed-format.js +60 -0
- package/client/components/sftp/transfer-tag.jsx +40 -0
- package/client/components/sftp/transfer-tag.styl +11 -0
- package/client/components/sftp/transfer.styl +55 -0
- package/client/components/sftp/transport-action.jsx +410 -0
- package/client/components/sftp/transport-entry.jsx +108 -0
- package/client/components/sftp/transport-types.js +8 -0
- package/client/components/sftp/transports-action.jsx +111 -0
- package/client/components/sftp/transports-ui.jsx +93 -0
- package/client/components/sftp/zip.js +42 -0
- package/client/components/sidebar/bookmark-select.jsx +48 -0
- package/client/components/sidebar/bookmark.jsx +82 -0
- package/client/components/sidebar/history.jsx +66 -0
- package/client/components/sidebar/index.jsx +230 -0
- package/client/components/sidebar/info-modal.jsx +250 -0
- package/client/components/sidebar/info.styl +27 -0
- package/client/components/sidebar/side-icon.jsx +25 -0
- package/client/components/sidebar/sidebar.styl +128 -0
- package/client/components/sidebar/transfer-history-modal.jsx +110 -0
- package/client/components/sidebar/transfer-history.styl +3 -0
- package/client/components/sidebar/transfer-list-control.jsx +205 -0
- package/client/components/sidebar/transfer-list.jsx +55 -0
- package/client/components/sidebar/transfer-modal.jsx +76 -0
- package/client/components/sidebar/transfer.styl +8 -0
- package/client/components/sidebar/transport-ui.jsx +109 -0
- package/client/components/tabs/index.jsx +320 -0
- package/client/components/tabs/tab.jsx +427 -0
- package/client/components/tabs/tabs.styl +220 -0
- package/client/components/tabs/window-control.jsx +55 -0
- package/client/components/terminal/attach-addon-custom.js +70 -0
- package/client/components/terminal/build-ls-term-id.js +5 -0
- package/client/components/terminal/index.jsx +1358 -0
- package/client/components/terminal/normal-buffer.jsx +33 -0
- package/client/components/terminal/term-search.jsx +224 -0
- package/client/components/terminal/term-search.styl +15 -0
- package/client/components/terminal/terminal-apis.js +31 -0
- package/client/components/terminal/terminal-interactive.jsx +148 -0
- package/client/components/terminal/terminal.styl +96 -0
- package/client/components/terminal/xterm-zmodem.js +48 -0
- package/client/components/terminal/zmodem-transfer.jsx +98 -0
- package/client/components/terminal/zmodem.styl +14 -0
- package/client/components/terminal-info/activity.jsx +54 -0
- package/client/components/terminal-info/base.jsx +25 -0
- package/client/components/terminal-info/content.jsx +101 -0
- package/client/components/terminal-info/data-cols-parser.jsx +50 -0
- package/client/components/terminal-info/disk.jsx +29 -0
- package/client/components/terminal-info/index.jsx +25 -0
- package/client/components/terminal-info/network.jsx +114 -0
- package/client/components/terminal-info/resource.jsx +80 -0
- package/client/components/terminal-info/run-cmd.jsx +273 -0
- package/client/components/terminal-info/terminal-info.styl +29 -0
- package/client/components/terminal-info/up.jsx +15 -0
- package/client/components/terminal-theme/index.jsx +264 -0
- package/client/components/terminal-theme/terminal-theme-list.styl +3 -0
- package/client/components/terminal-theme/theme-list.jsx +146 -0
- package/client/components/text-editor/text-editor-form.jsx +97 -0
- package/client/components/text-editor/text-editor.jsx +182 -0
- package/client/css/antd-overwrite.styl +14 -0
- package/client/css/basic.styl +38 -0
- package/client/css/includes/box.styl +154 -0
- package/client/css/includes/font-size.styl +6 -0
- package/client/css/includes/index.styl +3 -0
- package/client/css/includes/text.styl +31 -0
- package/client/css/includes/theme-default.styl +20 -0
- package/client/entry/basic.js +58 -0
- package/client/entry/index.jsx +15 -0
- package/client/entry/worker.js +137 -0
- package/client/store/address-bookmark.js +25 -0
- package/client/store/app-upgrade.js +23 -0
- package/client/store/batch-input-history.js +26 -0
- package/client/store/bookmark-group.js +128 -0
- package/client/store/bookmark.js +22 -0
- package/client/store/common.js +140 -0
- package/client/store/context-menu.js +23 -0
- package/client/store/db-upgrade.js +43 -0
- package/client/store/event.js +70 -0
- package/client/store/index.js +335 -0
- package/client/store/init-state.js +191 -0
- package/client/store/item.js +120 -0
- package/client/store/load-data.js +198 -0
- package/client/store/quick-command.js +43 -0
- package/client/store/session.js +54 -0
- package/client/store/setting.js +208 -0
- package/client/store/sidebar.js +48 -0
- package/client/store/sync.js +390 -0
- package/client/store/system-menu.js +120 -0
- package/client/store/tab.js +74 -0
- package/client/store/terminal-theme.js +116 -0
- package/client/store/transfer-history.js +27 -0
- package/client/store/transfer-list.js +20 -0
- package/client/store/ui-theme.js +71 -0
- package/client/store/watch.js +116 -0
- package/client/views/index.pug +58 -0
- package/package.json +34 -0
|
@@ -0,0 +1,390 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* sync data to github gist related
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { without, get, pick, debounce } from 'lodash-es'
|
|
6
|
+
import copy from 'json-deep-copy'
|
|
7
|
+
import {
|
|
8
|
+
settingMap, packInfo, syncTypes
|
|
9
|
+
} from '../common/constants'
|
|
10
|
+
import { remove, dbNames, insert, update } from '../common/db'
|
|
11
|
+
import fetch from '../common/fetch-from-server'
|
|
12
|
+
import download from '../common/download'
|
|
13
|
+
import { fixBookmarks } from '../common/db-fix'
|
|
14
|
+
import dayjs from 'dayjs'
|
|
15
|
+
|
|
16
|
+
const names = without(dbNames, settingMap.history)
|
|
17
|
+
const {
|
|
18
|
+
version: packVer
|
|
19
|
+
} = packInfo
|
|
20
|
+
|
|
21
|
+
function isJSON (str = '') {
|
|
22
|
+
return str.startsWith('[')
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async function fetchData (type, func, args, token, proxy) {
|
|
26
|
+
const data = {
|
|
27
|
+
type,
|
|
28
|
+
action: 'sync',
|
|
29
|
+
func,
|
|
30
|
+
args,
|
|
31
|
+
token,
|
|
32
|
+
proxy
|
|
33
|
+
}
|
|
34
|
+
return fetch(data)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export default (Store) => {
|
|
38
|
+
Store.prototype.updateSyncSetting = function (data) {
|
|
39
|
+
const { store } = window
|
|
40
|
+
const nd = Object.assign({}, copy(store.config.syncSetting), data)
|
|
41
|
+
if (data.giteeGistId && !data.giteeSyncPassword) {
|
|
42
|
+
delete nd.giteeSyncPassword
|
|
43
|
+
}
|
|
44
|
+
if (data.githubGistId && !data.githubSyncPassword) {
|
|
45
|
+
delete nd.githubSyncPassword
|
|
46
|
+
}
|
|
47
|
+
store.setConfig({
|
|
48
|
+
syncSetting: nd
|
|
49
|
+
})
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
Store.prototype.getSyncToken = function (type) {
|
|
53
|
+
if (type === syncTypes.custom) {
|
|
54
|
+
return ['AccessToken', 'ApiUrl', 'GistId'].map(
|
|
55
|
+
p => {
|
|
56
|
+
return get(window.store.config, 'syncSetting.' + type + p)
|
|
57
|
+
}
|
|
58
|
+
).join('####')
|
|
59
|
+
}
|
|
60
|
+
return get(window.store.config, 'syncSetting.' + type + 'AccessToken')
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
Store.prototype.getSyncPassword = function (type) {
|
|
64
|
+
return get(window.store.config, 'syncSetting.' + type + 'SyncPassword')
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
Store.prototype.getSyncGistId = function (type) {
|
|
68
|
+
return get(window.store.config, 'syncSetting.' + type + 'GistId')
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
Store.prototype.testSyncToken = async function (type) {
|
|
72
|
+
const { store } = window
|
|
73
|
+
store.isSyncingSetting = true
|
|
74
|
+
const token = store.getSyncToken(type)
|
|
75
|
+
const gist = await fetchData(
|
|
76
|
+
type,
|
|
77
|
+
'test',
|
|
78
|
+
[],
|
|
79
|
+
token,
|
|
80
|
+
store.getProxySetting()
|
|
81
|
+
).catch(
|
|
82
|
+
log.error
|
|
83
|
+
)
|
|
84
|
+
store.isSyncingSetting = false
|
|
85
|
+
return !!gist
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
Store.prototype.createGist = async function (type) {
|
|
89
|
+
const { store } = window
|
|
90
|
+
store.isSyncingSetting = true
|
|
91
|
+
const token = store.getSyncToken(type)
|
|
92
|
+
const data = {
|
|
93
|
+
description: 'sync electerm data',
|
|
94
|
+
files: {
|
|
95
|
+
'placeholder.js': {
|
|
96
|
+
content: 'placeholder'
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
public: false
|
|
100
|
+
}
|
|
101
|
+
const res = await fetchData(
|
|
102
|
+
type, 'create', [data], token, store.getProxySetting()
|
|
103
|
+
).catch(
|
|
104
|
+
store.onError
|
|
105
|
+
)
|
|
106
|
+
if (res && type !== syncTypes.custom) {
|
|
107
|
+
store.updateSyncSetting({
|
|
108
|
+
[type + 'GistId']: res.id,
|
|
109
|
+
[type + 'Url']: res.html_url
|
|
110
|
+
})
|
|
111
|
+
}
|
|
112
|
+
store.isSyncingSetting = false
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
Store.prototype.handleClearSyncSetting = async function () {
|
|
116
|
+
window.store.setConfig({
|
|
117
|
+
syncSetting: {}
|
|
118
|
+
})
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
Store.prototype.uploadSettingAll = async function () {
|
|
122
|
+
const { store, onSyncAll, syncCount = 0 } = window
|
|
123
|
+
const max = dbNames.length * 2
|
|
124
|
+
if (syncCount < max) {
|
|
125
|
+
window.syncCount = syncCount + 1
|
|
126
|
+
return
|
|
127
|
+
}
|
|
128
|
+
if (onSyncAll) {
|
|
129
|
+
return
|
|
130
|
+
}
|
|
131
|
+
window.onSyncAll = true
|
|
132
|
+
const types = Object.keys(syncTypes)
|
|
133
|
+
for (const type of types) {
|
|
134
|
+
const gistId = store.getSyncGistId(type)
|
|
135
|
+
if (gistId) {
|
|
136
|
+
await store.uploadSetting(type)
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
window.onSyncAll = false
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
Store.prototype.uploadSetting = async function (type) {
|
|
143
|
+
if (window[type + 'IsSyncing']) {
|
|
144
|
+
return false
|
|
145
|
+
}
|
|
146
|
+
window[type + 'IsSyncing'] = true
|
|
147
|
+
const { store } = window
|
|
148
|
+
store.isSyncingSetting = true
|
|
149
|
+
store.isSyncUpload = true
|
|
150
|
+
const token = store.getSyncToken(type)
|
|
151
|
+
let gistId = store.getSyncGistId(type)
|
|
152
|
+
if (!gistId) {
|
|
153
|
+
await store.createGist(type)
|
|
154
|
+
gistId = store.getSyncGistId(type)
|
|
155
|
+
}
|
|
156
|
+
if (!gistId) {
|
|
157
|
+
window.isSyncing = false
|
|
158
|
+
store.isSyncingSetting = false
|
|
159
|
+
store.isSyncUpload = false
|
|
160
|
+
return
|
|
161
|
+
}
|
|
162
|
+
const pass = store.getSyncPassword(type)
|
|
163
|
+
const objs = {}
|
|
164
|
+
for (const n of names) {
|
|
165
|
+
let str = JSON.stringify(store.getItems(n))
|
|
166
|
+
if (n === settingMap.bookmarks && pass) {
|
|
167
|
+
str = await window.pre.runGlobalAsync('encryptAsync', str, pass)
|
|
168
|
+
}
|
|
169
|
+
objs[`${n}.json`] = {
|
|
170
|
+
content: str
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
const res = await fetchData(type, 'update', [gistId, {
|
|
174
|
+
description: 'sync electerm data',
|
|
175
|
+
files: {
|
|
176
|
+
...objs,
|
|
177
|
+
'userConfig.json': {
|
|
178
|
+
content: JSON.stringify(pick(store.config, ['theme']))
|
|
179
|
+
},
|
|
180
|
+
'electerm-status.json': {
|
|
181
|
+
content: JSON.stringify({
|
|
182
|
+
lastSyncTime: Date.now(),
|
|
183
|
+
electermVersion: packVer
|
|
184
|
+
})
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}], token, store.getProxySetting()).catch(store.onError)
|
|
188
|
+
store.isSyncingSetting = false
|
|
189
|
+
store.isSyncUpload = false
|
|
190
|
+
window[type + 'IsSyncing'] = false
|
|
191
|
+
if (res) {
|
|
192
|
+
store.updateSyncSetting({
|
|
193
|
+
[type + 'LastSyncTime']: Date.now()
|
|
194
|
+
})
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
Store.prototype.downloadSetting = async function (type) {
|
|
199
|
+
const { store } = window
|
|
200
|
+
store.isSyncingSetting = true
|
|
201
|
+
store.isSyncDownload = true
|
|
202
|
+
const token = store.getSyncToken(type)
|
|
203
|
+
let gistId = store.getSyncGistId(type)
|
|
204
|
+
if (!gistId) {
|
|
205
|
+
await store.createGist(type)
|
|
206
|
+
gistId = store.getSyncGistId(type)
|
|
207
|
+
}
|
|
208
|
+
if (!gistId) {
|
|
209
|
+
return
|
|
210
|
+
}
|
|
211
|
+
const pass = store.getSyncPassword(type)
|
|
212
|
+
const gist = await fetchData(
|
|
213
|
+
type,
|
|
214
|
+
'getOne',
|
|
215
|
+
[gistId],
|
|
216
|
+
token,
|
|
217
|
+
store.getProxySetting()
|
|
218
|
+
)
|
|
219
|
+
const toInsert = []
|
|
220
|
+
for (const n of names) {
|
|
221
|
+
let str = get(gist, `files["${n}.json"].content`)
|
|
222
|
+
if (!str) {
|
|
223
|
+
store.isSyncingSetting = false
|
|
224
|
+
store.isSyncDownload = false
|
|
225
|
+
throw new Error(('Seems you have a empty gist, you can try use existing gist ID or upload first'))
|
|
226
|
+
}
|
|
227
|
+
if (!isJSON(str)) {
|
|
228
|
+
str = await window.pre.runGlobalAsync('decryptAsync', str, pass)
|
|
229
|
+
}
|
|
230
|
+
let arr = JSON.parse(
|
|
231
|
+
str
|
|
232
|
+
)
|
|
233
|
+
if (n === settingMap.terminalThemes) {
|
|
234
|
+
arr = store.fixThemes(arr)
|
|
235
|
+
} else if (n === settingMap.bookmarks) {
|
|
236
|
+
arr = fixBookmarks(arr)
|
|
237
|
+
}
|
|
238
|
+
toInsert.push({
|
|
239
|
+
name: n,
|
|
240
|
+
value: arr
|
|
241
|
+
})
|
|
242
|
+
store.setItems(n, arr)
|
|
243
|
+
}
|
|
244
|
+
const userConfig = JSON.parse(
|
|
245
|
+
get(gist, 'files["userConfig.json"].content')
|
|
246
|
+
)
|
|
247
|
+
store.setTheme(userConfig.theme)
|
|
248
|
+
const up = {
|
|
249
|
+
[type + 'LastSyncTime']: Date.now()
|
|
250
|
+
}
|
|
251
|
+
if (type !== syncTypes.custom) {
|
|
252
|
+
Object.assign(up, {
|
|
253
|
+
[type + 'GistId']: gist.id,
|
|
254
|
+
[type + 'Url']: gist.html_url
|
|
255
|
+
})
|
|
256
|
+
}
|
|
257
|
+
if (pass) {
|
|
258
|
+
up[type + 'SyncPassword'] = pass
|
|
259
|
+
}
|
|
260
|
+
store.updateSyncSetting(up)
|
|
261
|
+
for (const u of toInsert) {
|
|
262
|
+
await remove(u.name)
|
|
263
|
+
await insert(u.name, u.value)
|
|
264
|
+
}
|
|
265
|
+
store.isSyncingSetting = false
|
|
266
|
+
store.isSyncDownload = false
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
// store.syncSetting = async (syncSetting = store.config.syncSetting || {}) => {
|
|
270
|
+
// let gist = await store.getGist(syncSetting)
|
|
271
|
+
// if (!gist) {
|
|
272
|
+
// return
|
|
273
|
+
// }
|
|
274
|
+
// gist = gist.data
|
|
275
|
+
// if (!gist.files['electerm-status.json']) {
|
|
276
|
+
// return
|
|
277
|
+
// }
|
|
278
|
+
// const status = JSON.parse(gist.files['electerm-status.json'].content)
|
|
279
|
+
// if (status.lastSyncTime > store.lastUpdateTime) {
|
|
280
|
+
// store.uploadSetting()
|
|
281
|
+
// } else if (status.lastSyncTime < store.lastUpdateTime) {
|
|
282
|
+
// store.downloadSetting()
|
|
283
|
+
// }
|
|
284
|
+
// }
|
|
285
|
+
|
|
286
|
+
// store.checkSettingSync = () => {
|
|
287
|
+
// if (get(store, 'config.syncSetting.autoSync')) {
|
|
288
|
+
// store.uploadSetting()
|
|
289
|
+
// }
|
|
290
|
+
// }
|
|
291
|
+
Store.prototype.onChangeEncrypt = function (v) {
|
|
292
|
+
window.store.updateSyncSetting({
|
|
293
|
+
syncEncrypt: v
|
|
294
|
+
})
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
Store.prototype.updateLastDataUpdateTime = debounce(function () {
|
|
298
|
+
const { store } = window
|
|
299
|
+
store.lastDataUpdateTime = Date.now()
|
|
300
|
+
update('lastDataUpdateTime', store.lastDataUpdateTime)
|
|
301
|
+
}, 1000)
|
|
302
|
+
|
|
303
|
+
Store.prototype.handleExportAllData = function () {
|
|
304
|
+
const { store } = window
|
|
305
|
+
const objs = {}
|
|
306
|
+
for (const n of names) {
|
|
307
|
+
objs[n] = store.getItems(n)
|
|
308
|
+
}
|
|
309
|
+
objs.config = pick(store.config, [
|
|
310
|
+
'theme',
|
|
311
|
+
'useSystemTitleBar',
|
|
312
|
+
'defaultEditor',
|
|
313
|
+
'checkUpdateOnStart',
|
|
314
|
+
'confirmBeforeExit',
|
|
315
|
+
'ctrlOrMetaOpenTerminalLink',
|
|
316
|
+
'cursorStyle',
|
|
317
|
+
'defaultEditor',
|
|
318
|
+
'disableSshHistory',
|
|
319
|
+
'disableTransferHistory',
|
|
320
|
+
'enableGlobalProxy',
|
|
321
|
+
'execLinux',
|
|
322
|
+
'execLinuxArgs',
|
|
323
|
+
'execMac',
|
|
324
|
+
'execMacArgs',
|
|
325
|
+
'execWindows',
|
|
326
|
+
'execWindowsArgs',
|
|
327
|
+
'fontFamily',
|
|
328
|
+
'fontSize',
|
|
329
|
+
'hotkey',
|
|
330
|
+
'keepaliveCountMax',
|
|
331
|
+
'keepaliveInterval',
|
|
332
|
+
'language',
|
|
333
|
+
'opacity',
|
|
334
|
+
'pasteWhenContextMenu',
|
|
335
|
+
'proxyIp',
|
|
336
|
+
'proxyPassword',
|
|
337
|
+
'proxyPort',
|
|
338
|
+
'proxyType',
|
|
339
|
+
'proxyUsername',
|
|
340
|
+
'rendererType',
|
|
341
|
+
'rightClickSelectsWord',
|
|
342
|
+
'saveTerminalLogToFile',
|
|
343
|
+
'scrollback',
|
|
344
|
+
'sshReadyTimeout',
|
|
345
|
+
'syncSetting',
|
|
346
|
+
'terminalTimeout',
|
|
347
|
+
'terminalType',
|
|
348
|
+
'theme',
|
|
349
|
+
'useSystemTitleBar',
|
|
350
|
+
'zoom'
|
|
351
|
+
])
|
|
352
|
+
const text = JSON.stringify(objs)
|
|
353
|
+
const name = dayjs().format('YYYY-MM-DD-HH-mm-ss') + '-electerm-all-data.json'
|
|
354
|
+
download(name, text)
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
Store.prototype.importAll = async function (file) {
|
|
358
|
+
const txt = await window.fs
|
|
359
|
+
.readFileSync(file.path)
|
|
360
|
+
const { store } = window
|
|
361
|
+
const objs = JSON.parse(txt)
|
|
362
|
+
const toInsert = []
|
|
363
|
+
for (const n of names) {
|
|
364
|
+
let arr = objs[n]
|
|
365
|
+
if (n === settingMap.terminalThemes) {
|
|
366
|
+
arr = store.fixThemes(arr)
|
|
367
|
+
} else if (n === settingMap.bookmarks) {
|
|
368
|
+
arr = fixBookmarks(arr)
|
|
369
|
+
}
|
|
370
|
+
toInsert.push({
|
|
371
|
+
name: n,
|
|
372
|
+
value: arr
|
|
373
|
+
})
|
|
374
|
+
store.setItems(n, objs[n])
|
|
375
|
+
}
|
|
376
|
+
for (const u of toInsert) {
|
|
377
|
+
await remove(u.name)
|
|
378
|
+
await insert(u.name, u.value)
|
|
379
|
+
}
|
|
380
|
+
store.updateConfig(objs.config)
|
|
381
|
+
store.setTheme(objs.config.theme)
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
Store.prototype.handleAutoSync = function (v) {
|
|
385
|
+
const { store } = window
|
|
386
|
+
store.setConfig({
|
|
387
|
+
autoSync: v
|
|
388
|
+
})
|
|
389
|
+
}
|
|
390
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* system menu functions
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { Modal } from 'antd'
|
|
6
|
+
import { isFunction, isString } from 'lodash-es'
|
|
7
|
+
import getInitItem from '../common/init-setting-item'
|
|
8
|
+
import {
|
|
9
|
+
settingMap,
|
|
10
|
+
maxZoom,
|
|
11
|
+
minZoom
|
|
12
|
+
} from '../common/constants'
|
|
13
|
+
|
|
14
|
+
const { prefix } = window
|
|
15
|
+
const m = prefix('menu')
|
|
16
|
+
const c = prefix('common')
|
|
17
|
+
|
|
18
|
+
export default Store => {
|
|
19
|
+
Store.prototype.zoom = function (level = 1, plus = false, zoomOnly) {
|
|
20
|
+
let nl = plus
|
|
21
|
+
? window.pre.getZoomFactor() + level
|
|
22
|
+
: level
|
|
23
|
+
if (nl > maxZoom) {
|
|
24
|
+
nl = maxZoom
|
|
25
|
+
} else if (nl < minZoom) {
|
|
26
|
+
nl = minZoom
|
|
27
|
+
}
|
|
28
|
+
window.pre.setZoomFactor(nl)
|
|
29
|
+
if (zoomOnly) {
|
|
30
|
+
return
|
|
31
|
+
}
|
|
32
|
+
window.store.updateConfig({
|
|
33
|
+
zoom: nl
|
|
34
|
+
})
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
Store.prototype.onZoomIn = function () {
|
|
38
|
+
window.store.zoom(0.25, true)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
Store.prototype.onZoomout = function () {
|
|
42
|
+
window.store.zoom(-0.25, true)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
Store.prototype.onZoomReset = function () {
|
|
46
|
+
window.store.zoom()
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
Store.prototype.onCloseAbout = function (cb) {
|
|
50
|
+
const { store } = window
|
|
51
|
+
store.showInfoModal = false
|
|
52
|
+
if (isFunction(cb)) {
|
|
53
|
+
cb()
|
|
54
|
+
}
|
|
55
|
+
store.focus()
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
Store.prototype.openAbout = function (tab) {
|
|
59
|
+
const { store } = window
|
|
60
|
+
store.showInfoModal = true
|
|
61
|
+
if (isString(tab)) {
|
|
62
|
+
store.infoModalTab = tab
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
Store.prototype.onNewSsh = function () {
|
|
67
|
+
const { store } = window
|
|
68
|
+
store.storeAssign({
|
|
69
|
+
settingTab: settingMap.bookmarks,
|
|
70
|
+
autofocustrigger: Date.now()
|
|
71
|
+
})
|
|
72
|
+
store.setSettingItem(getInitItem([], settingMap.bookmarks))
|
|
73
|
+
store.openSettingModal()
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
Store.prototype.onNewWindow = async function () {
|
|
77
|
+
window.pre.runGlobalAsync('openNewInstance')
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
Store.prototype.confirmExit = function (type) {
|
|
81
|
+
const { store } = window
|
|
82
|
+
let mod = null
|
|
83
|
+
mod = Modal.confirm({
|
|
84
|
+
onCancel: () => mod.destroy(),
|
|
85
|
+
onOk: store.doExit,
|
|
86
|
+
title: m('quit'),
|
|
87
|
+
okText: c('ok'),
|
|
88
|
+
cancelText: c('cancel'),
|
|
89
|
+
content: ''
|
|
90
|
+
})
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
Store.prototype.exit = function () {
|
|
94
|
+
const { store } = window
|
|
95
|
+
if (
|
|
96
|
+
!store.isTransporting &&
|
|
97
|
+
!store.config.confirmBeforeExit
|
|
98
|
+
) {
|
|
99
|
+
return store.doExit()
|
|
100
|
+
}
|
|
101
|
+
store.confirmExit()
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
Store.prototype.restart = function () {
|
|
105
|
+
const { store } = window
|
|
106
|
+
if (store.isTransporting) {
|
|
107
|
+
store.confirmExit('doRestart')
|
|
108
|
+
} else {
|
|
109
|
+
store.doRestart()
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
Store.prototype.doExit = function () {
|
|
114
|
+
window.pre.runGlobalAsync('closeApp')
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
Store.prototype.doRestart = function () {
|
|
118
|
+
window.pre.runGlobalAsync('restart')
|
|
119
|
+
}
|
|
120
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* tabs related functions
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { uniq, debounce, findIndex } from 'lodash-es'
|
|
6
|
+
import {
|
|
7
|
+
tabActions
|
|
8
|
+
} from '../common/constants'
|
|
9
|
+
import postMsg from '../common/post-msg'
|
|
10
|
+
|
|
11
|
+
export default Store => {
|
|
12
|
+
Store.prototype.updateTabsStatus = function () {
|
|
13
|
+
const tabIds = uniq(
|
|
14
|
+
window.store.getTransfers().map(d => d.tabId)
|
|
15
|
+
)
|
|
16
|
+
postMsg({
|
|
17
|
+
action: tabActions.updateTabsStatus,
|
|
18
|
+
tabIds
|
|
19
|
+
})
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
Store.prototype.getTabs = function () {
|
|
23
|
+
return window.store.getItems('tabs')
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
Store.prototype.setTabs = function (list) {
|
|
27
|
+
return window.store.setItems('tabs', list)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
Store.prototype.initFirstTab = function () {
|
|
31
|
+
postMsg({
|
|
32
|
+
action: tabActions.initFirstTab
|
|
33
|
+
})
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
Store.prototype.addTab = function (
|
|
37
|
+
tab,
|
|
38
|
+
index
|
|
39
|
+
) {
|
|
40
|
+
postMsg({
|
|
41
|
+
action: tabActions.addTab,
|
|
42
|
+
tab,
|
|
43
|
+
index
|
|
44
|
+
})
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
Store.prototype.clickNextTab = debounce(function () {
|
|
48
|
+
window.store.clickBioTab(1)
|
|
49
|
+
}, 100)
|
|
50
|
+
|
|
51
|
+
Store.prototype.clickPrevTab = debounce(function () {
|
|
52
|
+
window.store.clickBioTab(-1)
|
|
53
|
+
}, 100)
|
|
54
|
+
|
|
55
|
+
Store.prototype.clickBioTab = function (diff) {
|
|
56
|
+
const tab = document.querySelector('.tabs-wrapper .tab.active')
|
|
57
|
+
if (tab) {
|
|
58
|
+
const id = tab.dataset.id
|
|
59
|
+
const { tabs } = window.store
|
|
60
|
+
const i = findIndex(tabs, t => {
|
|
61
|
+
return t.id === id
|
|
62
|
+
})
|
|
63
|
+
const len = tabs.length
|
|
64
|
+
if (i >= 0) {
|
|
65
|
+
const next = (i + diff + len) % len
|
|
66
|
+
const nextTab = tabs[next]
|
|
67
|
+
postMsg({
|
|
68
|
+
action: tabActions.changeCurrentTabId,
|
|
69
|
+
currentTabId: nextTab.id
|
|
70
|
+
})
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* theme related functions
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { message } from 'antd'
|
|
6
|
+
import { find, isEqual } from 'lodash-es'
|
|
7
|
+
import {
|
|
8
|
+
defaultTheme,
|
|
9
|
+
settingMap,
|
|
10
|
+
defaultThemeLight
|
|
11
|
+
} from '../common/constants'
|
|
12
|
+
import copy from 'json-deep-copy'
|
|
13
|
+
import { convertTheme } from '../common/terminal-theme'
|
|
14
|
+
|
|
15
|
+
const { terminalThemes } = settingMap
|
|
16
|
+
const { prefix } = window
|
|
17
|
+
const t = prefix(terminalThemes)
|
|
18
|
+
|
|
19
|
+
export default Store => {
|
|
20
|
+
Store.prototype.getTerminalThemes = function () {
|
|
21
|
+
return window.store.getItems(settingMap.terminalThemes)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
Store.prototype.setTerminalThemes = function (arr) {
|
|
25
|
+
return window.store.setItems(settingMap.terminalThemes, arr)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
Store.prototype.setTheme = function (id) {
|
|
29
|
+
window.store.updateConfig({
|
|
30
|
+
theme: id
|
|
31
|
+
})
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
Store.prototype.addTheme = function (theme) {
|
|
35
|
+
window.store.addItem(theme, settingMap.terminalThemes)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
Store.prototype.editTheme = function (id, updates) {
|
|
39
|
+
return window.store.editItem(
|
|
40
|
+
id, updates, settingMap.terminalThemes
|
|
41
|
+
)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
Store.prototype.delTheme = function ({ id }) {
|
|
45
|
+
window.store.delItem({ id }, settingMap.terminalThemes)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
Store.prototype.getThemeConfig = function () {
|
|
49
|
+
const { store } = window
|
|
50
|
+
const all = store.getSidebarList(settingMap.terminalThemes)
|
|
51
|
+
return (find(all, d => d.id === store.config.theme) || {}).themeConfig || {}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
Store.prototype.fixThemes = function (themes) {
|
|
55
|
+
return themes.map(t => {
|
|
56
|
+
const isDefaultTheme = t.id === defaultTheme.id
|
|
57
|
+
const isDefaultThemeLight = t.id === defaultThemeLight.id
|
|
58
|
+
if (isDefaultTheme) {
|
|
59
|
+
Object.assign(t, defaultTheme)
|
|
60
|
+
} else if (isDefaultThemeLight) {
|
|
61
|
+
Object.assign(t, defaultThemeLight)
|
|
62
|
+
} else if (!t.uiThemeConfig) {
|
|
63
|
+
t.uiThemeConfig = copy(defaultTheme.uiThemeConfig)
|
|
64
|
+
}
|
|
65
|
+
return t
|
|
66
|
+
})
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
Store.prototype.setItermThemes = function (arr) {
|
|
70
|
+
window.store._itermThemes = JSON.stringify(arr)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
Store.prototype.fetchItermThemes = async function () {
|
|
74
|
+
const list = await window.pre.runGlobalAsync('listItermThemes')
|
|
75
|
+
window.store.setItermThemes(
|
|
76
|
+
list.map(d => {
|
|
77
|
+
const obj = convertTheme(d)
|
|
78
|
+
return {
|
|
79
|
+
...obj,
|
|
80
|
+
id: 'iterm#' + obj.name,
|
|
81
|
+
readonly: true,
|
|
82
|
+
type: 'iterm'
|
|
83
|
+
}
|
|
84
|
+
})
|
|
85
|
+
)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
Store.prototype.checkDefaultTheme = async function (terminalThemes) {
|
|
89
|
+
const { store } = window
|
|
90
|
+
const themeId = defaultTheme.id
|
|
91
|
+
const currentDefaultTheme = find(store.terminalThemes, d => d.id === themeId)
|
|
92
|
+
if (
|
|
93
|
+
currentDefaultTheme &&
|
|
94
|
+
(
|
|
95
|
+
!isEqual(currentDefaultTheme.themeConfig, defaultTheme.themeConfig) || !isEqual(currentDefaultTheme.uiThemeConfig, defaultTheme.uiThemeConfig) ||
|
|
96
|
+
currentDefaultTheme.name !== defaultTheme.name
|
|
97
|
+
)
|
|
98
|
+
) {
|
|
99
|
+
store.editTheme(
|
|
100
|
+
themeId,
|
|
101
|
+
{
|
|
102
|
+
name: defaultTheme.name,
|
|
103
|
+
themeConfig: defaultTheme.themeConfig,
|
|
104
|
+
uiThemeConfig: defaultTheme.uiThemeConfig
|
|
105
|
+
}
|
|
106
|
+
)
|
|
107
|
+
message.info(
|
|
108
|
+
`${t('default')} ${t('themeConfig')} ${t('updated')}`
|
|
109
|
+
)
|
|
110
|
+
}
|
|
111
|
+
const hasLightTheme = find(store.getTerminalThemes(), d => d.id === defaultThemeLight.id)
|
|
112
|
+
if (!hasLightTheme) {
|
|
113
|
+
store.addTheme(defaultThemeLight)
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|