Skip to content

Commit

Permalink
1. 增加首次使用的引导功能
Browse files Browse the repository at this point in the history
2. 增加多开微信可选择导出功能
3. 增加多账号数据可以切换查看功能

Signed-off-by: HAL <[email protected]>
  • Loading branch information
git-jiadong committed Sep 22, 2024
1 parent e6d8ab9 commit ae932bb
Show file tree
Hide file tree
Showing 7 changed files with 785 additions and 102 deletions.
146 changes: 115 additions & 31 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,17 @@ const (
defaultConfig = "config"
configDefaultUserKey = "userConfig.defaultUser"
configUsersKey = "userConfig.users"
appVersion = "v1.0.2"
appVersion = "v1.0.3"
)

// App struct
type App struct {
ctx context.Context
info wechat.WeChatInfo
infoList *wechat.WeChatInfoList
provider *wechat.WechatDataProvider
defaultUser string
users []string
firstStart bool
}

type WeChatInfo struct {
Expand All @@ -39,6 +40,17 @@ type WeChatInfo struct {
DBKey string `json:"DBkey"`
}

type WeChatInfoList struct {
Info []WeChatInfo `json:"Info"`
Total int `json:"Total"`
}

type WeChatAccountInfos struct {
CurrentAccount string `json:"CurrentAccount"`
Info []wechat.WeChatAccountInfo `json:"Info"`
Total int `json:"Total"`
}

// NewApp creates a new App application struct
func NewApp() *App {
a := &App{}
Expand All @@ -52,6 +64,7 @@ func NewApp() *App {
// log.Println(a.defaultUser)
// log.Println(a.users)
} else {
a.firstStart = true
log.Println("not config exist")
}

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

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

if err != nil || dialog == "Yes" {
if a.provider != nil {
a.provider.WechatWechatDataProviderClose()
a.provider = nil
return false
}

return true
return false

}

func (a *App) GetWeChatAllInfo() string {
a.info, _ = wechat.GetWeChatAllInfo()

var info WeChatInfo
info.ProcessID = a.info.ProcessID
info.FilePath = a.info.FilePath
info.AcountName = a.info.AcountName
info.Version = a.info.Version
info.Is64Bits = a.info.Is64Bits
info.DBKey = a.info.DBKey

infoStr, _ := json.Marshal(info)
log.Println(string(infoStr))
infoList := WeChatInfoList{}
infoList.Info = make([]WeChatInfo, 0)
infoList.Total = 0

a.infoList = wechat.GetWeChatAllInfo()
for i := range a.infoList.Info {
var info WeChatInfo
info.ProcessID = a.infoList.Info[i].ProcessID
info.FilePath = a.infoList.Info[i].FilePath
info.AcountName = a.infoList.Info[i].AcountName
info.Version = a.infoList.Info[i].Version
info.Is64Bits = a.infoList.Info[i].Is64Bits
info.DBKey = a.infoList.Info[i].DBKey
infoList.Info = append(infoList.Info, info)
infoList.Total += 1
log.Printf("ProcessID %d, FilePath %s, AcountName %s, Version %s, Is64Bits %t", info.ProcessID, info.FilePath, info.AcountName, info.Version, info.Is64Bits)
}
infoStr, _ := json.Marshal(infoList)
// log.Println(string(infoStr))

return string(infoStr)
}

func (a *App) ExportWeChatAllData(full bool) {
func (a *App) ExportWeChatAllData(full bool, acountName string) {

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

progress := make(chan string)
go func() {
var pInfo *wechat.WeChatInfo
for i := range a.infoList.Info {
if a.infoList.Info[i].AcountName == acountName {
pInfo = &a.infoList.Info[i]
break
}
}

if pInfo == nil {
close(progress)
runtime.EventsEmit(a.ctx, "exportData", fmt.Sprintf("{\"status\":\"error\", \"result\":\"%s error\"}", acountName))
return
}

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

expPath := ".\\User\\" + a.info.AcountName
expPath := ".\\User\\" + pInfo.AcountName
_, err = os.Stat(expPath)
if err == nil {
if !full {
Expand All @@ -127,26 +155,23 @@ func (a *App) ExportWeChatAllData(full bool) {
os.Mkdir(expPath, os.ModeDir)
}

go wechat.ExportWeChatAllData(a.info, expPath, progress)
go wechat.ExportWeChatAllData(*pInfo, expPath, progress)

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

if len(a.defaultUser) == 0 {
a.defaultUser = a.info.AcountName
}

a.defaultUser = pInfo.AcountName
hasUser := false
for _, user := range a.users {
if user == a.info.AcountName {
if user == pInfo.AcountName {
hasUser = true
break
}
}
if !hasUser {
a.users = append(a.users, a.info.AcountName)
a.users = append(a.users, pInfo.AcountName)
}
a.setCurrentConfig()
}()
Expand All @@ -158,6 +183,12 @@ func (a *App) createWechatDataProvider(resPath string) error {
return nil
}

if a.provider != nil {
a.provider.WechatWechatDataProviderClose()
a.provider = nil
log.Println("createWechatDataProvider WechatWechatDataProviderClose")
}

provider, err := wechat.CreateWechatDataProvider(resPath)
if err != nil {
log.Println("CreateWechatDataProvider failed:", resPath)
Expand Down Expand Up @@ -256,6 +287,10 @@ func (a *App) setCurrentConfig() {
err := viper.SafeWriteConfig()
if err != nil {
log.Println(err)
err = viper.WriteConfig()
if err != nil {
log.Println(err)
}
}
}

Expand Down Expand Up @@ -302,3 +337,52 @@ func (a *App) GetWeChatRoomUserList(roomId string) string {
func (a *App) GetAppVersion() string {
return appVersion
}

func (a *App) GetAppIsFirstStart() bool {
defer func() { a.firstStart = false }()
return a.firstStart
}

func (a *App) GetWechatLocalAccountInfo() string {
infos := WeChatAccountInfos{}
infos.Info = make([]wechat.WeChatAccountInfo, 0)
infos.Total = 0
infos.CurrentAccount = a.defaultUser
for i := range a.users {
resPath := ".\\User\\" + a.users[i]
if _, err := os.Stat(resPath); err != nil {
log.Println("GetWechatLocalAccountInfo:", resPath, err)
continue
}

info, err := wechat.WechatGetAccountInfo(resPath, a.users[i])
if err != nil {
log.Println("GetWechatLocalAccountInfo", err)
continue
}

infos.Info = append(infos.Info, *info)
infos.Total += 1
}

infoString, _ := json.Marshal(infos)
log.Println(string(infoString))

return string(infoString)
}

func (a *App) WechatSwitchAccount(account string) bool {
for i := range a.users {
if a.users[i] == account {
if a.provider != nil {
a.provider.WechatWechatDataProviderClose()
a.provider = nil
}
a.defaultUser = account
a.setCurrentConfig()
return true
}
}

return false
}
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## v1.0.3
1. 增加首次使用的引导功能
2. 增加多开微信可选择导出功能
3. 增加多账号数据可以切换查看功能

## v1.0.2
1. 对话列表按照导出时微信显示顺序显示
2. 增加版本更新检测按钮
Expand Down
503 changes: 503 additions & 0 deletions frontend/dist/assets/index.425764f5.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions frontend/dist/assets/index.b10575d2.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit ae932bb

Please sign in to comment.