Skip to content

Commit 073d586

Browse files
committed
1. 增加首次使用的引导功能
2. 增加多开微信可选择导出功能 3. 增加多账号数据可以切换查看功能
1 parent e6d8ab9 commit 073d586

File tree

7 files changed

+785
-102
lines changed

7 files changed

+785
-102
lines changed

app.go

Lines changed: 115 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,17 @@ const (
1818
defaultConfig = "config"
1919
configDefaultUserKey = "userConfig.defaultUser"
2020
configUsersKey = "userConfig.users"
21-
appVersion = "v1.0.2"
21+
appVersion = "v1.0.3"
2222
)
2323

2424
// App struct
2525
type App struct {
2626
ctx context.Context
27-
info wechat.WeChatInfo
27+
infoList *wechat.WeChatInfoList
2828
provider *wechat.WechatDataProvider
2929
defaultUser string
3030
users []string
31+
firstStart bool
3132
}
3233

3334
type WeChatInfo struct {
@@ -39,6 +40,17 @@ type WeChatInfo struct {
3940
DBKey string `json:"DBkey"`
4041
}
4142

43+
type WeChatInfoList struct {
44+
Info []WeChatInfo `json:"Info"`
45+
Total int `json:"Total"`
46+
}
47+
48+
type WeChatAccountInfos struct {
49+
CurrentAccount string `json:"CurrentAccount"`
50+
Info []wechat.WeChatAccountInfo `json:"Info"`
51+
Total int `json:"Total"`
52+
}
53+
4254
// NewApp creates a new App application struct
4355
func NewApp() *App {
4456
a := &App{}
@@ -52,6 +64,7 @@ func NewApp() *App {
5264
// log.Println(a.defaultUser)
5365
// log.Println(a.users)
5466
} else {
67+
a.firstStart = true
5568
log.Println("not config exist")
5669
}
5770

@@ -65,39 +78,41 @@ func (a *App) startup(ctx context.Context) {
6578
}
6679

6780
func (a *App) beforeClose(ctx context.Context) (prevent bool) {
68-
dialog, err := runtime.MessageDialog(ctx, runtime.MessageDialogOptions{
69-
Type: runtime.QuestionDialog,
70-
Title: "Quit?",
71-
Message: "Are you sure you want to quit?",
72-
})
7381

74-
if err != nil || dialog == "Yes" {
82+
if a.provider != nil {
7583
a.provider.WechatWechatDataProviderClose()
7684
a.provider = nil
77-
return false
7885
}
7986

80-
return true
87+
return false
88+
8189
}
8290

8391
func (a *App) GetWeChatAllInfo() string {
84-
a.info, _ = wechat.GetWeChatAllInfo()
85-
86-
var info WeChatInfo
87-
info.ProcessID = a.info.ProcessID
88-
info.FilePath = a.info.FilePath
89-
info.AcountName = a.info.AcountName
90-
info.Version = a.info.Version
91-
info.Is64Bits = a.info.Is64Bits
92-
info.DBKey = a.info.DBKey
93-
94-
infoStr, _ := json.Marshal(info)
95-
log.Println(string(infoStr))
92+
infoList := WeChatInfoList{}
93+
infoList.Info = make([]WeChatInfo, 0)
94+
infoList.Total = 0
95+
96+
a.infoList = wechat.GetWeChatAllInfo()
97+
for i := range a.infoList.Info {
98+
var info WeChatInfo
99+
info.ProcessID = a.infoList.Info[i].ProcessID
100+
info.FilePath = a.infoList.Info[i].FilePath
101+
info.AcountName = a.infoList.Info[i].AcountName
102+
info.Version = a.infoList.Info[i].Version
103+
info.Is64Bits = a.infoList.Info[i].Is64Bits
104+
info.DBKey = a.infoList.Info[i].DBKey
105+
infoList.Info = append(infoList.Info, info)
106+
infoList.Total += 1
107+
log.Printf("ProcessID %d, FilePath %s, AcountName %s, Version %s, Is64Bits %t", info.ProcessID, info.FilePath, info.AcountName, info.Version, info.Is64Bits)
108+
}
109+
infoStr, _ := json.Marshal(infoList)
110+
// log.Println(string(infoStr))
96111

97112
return string(infoStr)
98113
}
99114

100-
func (a *App) ExportWeChatAllData(full bool) {
115+
func (a *App) ExportWeChatAllData(full bool, acountName string) {
101116

102117
if a.provider != nil {
103118
a.provider.WechatWechatDataProviderClose()
@@ -106,13 +121,26 @@ func (a *App) ExportWeChatAllData(full bool) {
106121

107122
progress := make(chan string)
108123
go func() {
124+
var pInfo *wechat.WeChatInfo
125+
for i := range a.infoList.Info {
126+
if a.infoList.Info[i].AcountName == acountName {
127+
pInfo = &a.infoList.Info[i]
128+
break
129+
}
130+
}
131+
132+
if pInfo == nil {
133+
close(progress)
134+
runtime.EventsEmit(a.ctx, "exportData", fmt.Sprintf("{\"status\":\"error\", \"result\":\"%s error\"}", acountName))
135+
return
136+
}
109137

110138
_, err := os.Stat(".\\User")
111139
if err != nil {
112140
os.Mkdir(".\\User", os.ModeDir)
113141
}
114142

115-
expPath := ".\\User\\" + a.info.AcountName
143+
expPath := ".\\User\\" + pInfo.AcountName
116144
_, err = os.Stat(expPath)
117145
if err == nil {
118146
if !full {
@@ -127,26 +155,23 @@ func (a *App) ExportWeChatAllData(full bool) {
127155
os.Mkdir(expPath, os.ModeDir)
128156
}
129157

130-
go wechat.ExportWeChatAllData(a.info, expPath, progress)
158+
go wechat.ExportWeChatAllData(*pInfo, expPath, progress)
131159

132160
for p := range progress {
133161
log.Println(p)
134162
runtime.EventsEmit(a.ctx, "exportData", p)
135163
}
136164

137-
if len(a.defaultUser) == 0 {
138-
a.defaultUser = a.info.AcountName
139-
}
140-
165+
a.defaultUser = pInfo.AcountName
141166
hasUser := false
142167
for _, user := range a.users {
143-
if user == a.info.AcountName {
168+
if user == pInfo.AcountName {
144169
hasUser = true
145170
break
146171
}
147172
}
148173
if !hasUser {
149-
a.users = append(a.users, a.info.AcountName)
174+
a.users = append(a.users, pInfo.AcountName)
150175
}
151176
a.setCurrentConfig()
152177
}()
@@ -158,6 +183,12 @@ func (a *App) createWechatDataProvider(resPath string) error {
158183
return nil
159184
}
160185

186+
if a.provider != nil {
187+
a.provider.WechatWechatDataProviderClose()
188+
a.provider = nil
189+
log.Println("createWechatDataProvider WechatWechatDataProviderClose")
190+
}
191+
161192
provider, err := wechat.CreateWechatDataProvider(resPath)
162193
if err != nil {
163194
log.Println("CreateWechatDataProvider failed:", resPath)
@@ -256,6 +287,10 @@ func (a *App) setCurrentConfig() {
256287
err := viper.SafeWriteConfig()
257288
if err != nil {
258289
log.Println(err)
290+
err = viper.WriteConfig()
291+
if err != nil {
292+
log.Println(err)
293+
}
259294
}
260295
}
261296

@@ -302,3 +337,52 @@ func (a *App) GetWeChatRoomUserList(roomId string) string {
302337
func (a *App) GetAppVersion() string {
303338
return appVersion
304339
}
340+
341+
func (a *App) GetAppIsFirstStart() bool {
342+
defer func() { a.firstStart = false }()
343+
return a.firstStart
344+
}
345+
346+
func (a *App) GetWechatLocalAccountInfo() string {
347+
infos := WeChatAccountInfos{}
348+
infos.Info = make([]wechat.WeChatAccountInfo, 0)
349+
infos.Total = 0
350+
infos.CurrentAccount = a.defaultUser
351+
for i := range a.users {
352+
resPath := ".\\User\\" + a.users[i]
353+
if _, err := os.Stat(resPath); err != nil {
354+
log.Println("GetWechatLocalAccountInfo:", resPath, err)
355+
continue
356+
}
357+
358+
info, err := wechat.WechatGetAccountInfo(resPath, a.users[i])
359+
if err != nil {
360+
log.Println("GetWechatLocalAccountInfo", err)
361+
continue
362+
}
363+
364+
infos.Info = append(infos.Info, *info)
365+
infos.Total += 1
366+
}
367+
368+
infoString, _ := json.Marshal(infos)
369+
log.Println(string(infoString))
370+
371+
return string(infoString)
372+
}
373+
374+
func (a *App) WechatSwitchAccount(account string) bool {
375+
for i := range a.users {
376+
if a.users[i] == account {
377+
if a.provider != nil {
378+
a.provider.WechatWechatDataProviderClose()
379+
a.provider = nil
380+
}
381+
a.defaultUser = account
382+
a.setCurrentConfig()
383+
return true
384+
}
385+
}
386+
387+
return false
388+
}

changelog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## v1.0.3
2+
1. 增加首次使用的引导功能
3+
2. 增加多开微信可选择导出功能
4+
3. 增加多账号数据可以切换查看功能
5+
16
## v1.0.2
27
1. 对话列表按照导出时微信显示顺序显示
38
2. 增加版本更新检测按钮

frontend/dist/assets/index.425764f5.js

Lines changed: 503 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frontend/dist/assets/index.b10575d2.css

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)