|
|
|
@ -15,6 +15,8 @@ import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"image/color"
|
|
|
|
|
"io"
|
|
|
|
|
"os/exec"
|
|
|
|
|
"runtime"
|
|
|
|
|
"sync"
|
|
|
|
|
|
|
|
|
|
"math"
|
|
|
|
@ -208,6 +210,51 @@ func main() {
|
|
|
|
|
log.Error("main:", r)
|
|
|
|
|
}
|
|
|
|
|
}()
|
|
|
|
|
//登陆的时候看是否有相同的进程,如果是鼠标点击打开的弹窗提示,如果是通过命令打开的杀掉当前的。
|
|
|
|
|
|
|
|
|
|
if len(os.Args) > 1 && os.Args[1] == "--auto-restart" {
|
|
|
|
|
fmt.Println("程序由命令行自动重启")
|
|
|
|
|
|
|
|
|
|
// 获取程序名称
|
|
|
|
|
programName := os.Args[0] // 使用当前程序的路径
|
|
|
|
|
// 获取当前线程 ID
|
|
|
|
|
pid := os.Getpid()
|
|
|
|
|
fmt.Println(pid)
|
|
|
|
|
// 查找是否有相同进程正在运行
|
|
|
|
|
|
|
|
|
|
// D:\workspace\go\src\Door\flx.exe
|
|
|
|
|
// programName = "d:\\workspace\\go\\src\\Door\\flx.exe"
|
|
|
|
|
|
|
|
|
|
runningProc, err := findProcessByName(programName[strings.LastIndex(programName, "\\")+1:])
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Println("Error while checking running process: %v", err)
|
|
|
|
|
fmt.Println("Error while checking running process: %v", err)
|
|
|
|
|
}
|
|
|
|
|
fmt.Println("-----------------------------------------------")
|
|
|
|
|
log.Error("main:", programName)
|
|
|
|
|
fmt.Println(programName)
|
|
|
|
|
// 如果进程已经在运行,关闭它
|
|
|
|
|
if runningProc != nil {
|
|
|
|
|
if runningProc.Pid != pid {
|
|
|
|
|
|
|
|
|
|
fmt.Println("==========================================================")
|
|
|
|
|
fmt.Println("Process %s is already running, attempting to kill it...\n", programName)
|
|
|
|
|
err = killProcess(runningProc)
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Fatalf("Failed to kill process: %v", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 等待旧进程关闭
|
|
|
|
|
time.Sleep(2 * time.Second) // 等待进程关闭的时间,具体时间可根据情况调整
|
|
|
|
|
fmt.Println("Process %s terminated. Proceeding to start new instance...\n", programName)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
fmt.Println("+++++++++++++++++++++++++++++++++++++++++++++++")
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
fmt.Println("程序由用户手动启动")
|
|
|
|
|
// Common.ShowSimpleAlert("程序已启动")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Common.InitLog("./log/", "", "gb18030")
|
|
|
|
|
log.WithFields(log.Fields{"animal": "walrus"}).Info("A walrus appears")
|
|
|
|
@ -312,7 +359,7 @@ func MainWindowControl() {
|
|
|
|
|
MainWindow.SetCloseIntercept(func() {
|
|
|
|
|
fmt.Println("正在执行自定义操作...")
|
|
|
|
|
// 此处添加业务逻辑
|
|
|
|
|
closeChromeWindow(ChromeCmd)
|
|
|
|
|
Common.CloseChromeWindow(localcache.ChromeCmd)
|
|
|
|
|
MainWindow.Close()
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
@ -628,7 +675,7 @@ func DefaultLayout() fyne.CanvasObject {
|
|
|
|
|
btnPersonManage.Move(fyne.NewPos(1400*BigPara, 1000*BigPara))
|
|
|
|
|
//退出
|
|
|
|
|
btnClose := widget.NewButton("退出", func() {
|
|
|
|
|
closeChromeWindow(ChromeCmd)
|
|
|
|
|
Common.CloseChromeWindow(localcache.ChromeCmd)
|
|
|
|
|
MainWindow.Close()
|
|
|
|
|
// GPersonlist.Refresh()
|
|
|
|
|
})
|
|
|
|
@ -1150,7 +1197,7 @@ func ReportLayout() fyne.CanvasObject {
|
|
|
|
|
SetCongressStatus(3)
|
|
|
|
|
} else {
|
|
|
|
|
MainWindow.Close()
|
|
|
|
|
closeChromeWindow(ChromeCmd)
|
|
|
|
|
Common.CloseChromeWindow(localcache.ChromeCmd)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
btnRClose.Resize(fyne.NewSize(200*BigPara, 50*BigPara))
|
|
|
|
@ -1630,33 +1677,41 @@ func OnDeviceEventHandler(eventSource FLXDevice.EventArgSource, eventType FLXDev
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// OnCheckInOne(person)
|
|
|
|
|
|
|
|
|
|
// case FlxNetworkComPara.Data_Down_Control:
|
|
|
|
|
// switch (arg.Value_ExtraInt){
|
|
|
|
|
case FLXNetworkController.FlxNetworkComPara_Data_Down_ControlShutDown: //关机
|
|
|
|
|
var cmd *exec.Cmd
|
|
|
|
|
if runtime.GOOS == "windows" {
|
|
|
|
|
cmd = exec.Command("shutdown", "/s", "/t", "0")
|
|
|
|
|
} else {
|
|
|
|
|
cmd = exec.Command("shutdown", "-h", "now")
|
|
|
|
|
}
|
|
|
|
|
cmd.Run()
|
|
|
|
|
break
|
|
|
|
|
// case FLXNetworkController.Data_Down_Control:
|
|
|
|
|
// switch arg.Value_ExtraInt {
|
|
|
|
|
// case FlxNetworkComPara.Data_Down_ControlShutDown: //关机
|
|
|
|
|
// WindowsContols.PowerOff();
|
|
|
|
|
// break;
|
|
|
|
|
// WindowsContols.PowerOff()
|
|
|
|
|
// break
|
|
|
|
|
// case FlxNetworkComPara.Data_Down_ControlRestart: //重启
|
|
|
|
|
// WindowsContols.Reboot();
|
|
|
|
|
// break;
|
|
|
|
|
// WindowsContols.Reboot()
|
|
|
|
|
// break
|
|
|
|
|
// case FlxNetworkComPara.CMD_Control_RestartProgram: //软件重启
|
|
|
|
|
// PaperNetCtrler.StopClient();
|
|
|
|
|
// Process p = new Process();
|
|
|
|
|
// p.StartInfo.FileName = System.AppDomain.CurrentDomain.BaseDirectory + "Philisense.Congress.CheckInDoor.exe";
|
|
|
|
|
// p.StartInfo.UseShellExecute = false;
|
|
|
|
|
// p.Start();
|
|
|
|
|
// break;
|
|
|
|
|
// // PaperNetCtrler.StopClient();
|
|
|
|
|
// // Process p = new Process();
|
|
|
|
|
// // p.StartInfo.FileName = System.AppDomain.CurrentDomain.BaseDirectory + "Philisense.Congress.CheckInDoor.exe";
|
|
|
|
|
// // p.StartInfo.UseShellExecute = false;
|
|
|
|
|
// // p.Start();
|
|
|
|
|
// // break;
|
|
|
|
|
// case FlxNetworkComPara.Data_Down_BarSub_Hide: //隐藏
|
|
|
|
|
// WindowsContols.HideTaskBar();
|
|
|
|
|
// break;
|
|
|
|
|
// WindowsContols.HideTaskBar()
|
|
|
|
|
// break
|
|
|
|
|
// case FlxNetworkComPara.Data_Down_BarSub_Show: //显示
|
|
|
|
|
// WindowsContols.ShowTaskBar();
|
|
|
|
|
// break;
|
|
|
|
|
// WindowsContols.ShowTaskBar()
|
|
|
|
|
// break
|
|
|
|
|
// case FlxNetworkComPara.CMD_Control_ExitProgram: //软件关闭
|
|
|
|
|
// Process Current = Process.GetCurrentProcess();
|
|
|
|
|
// Process processesByID = Process.GetProcessById(Current.Id);
|
|
|
|
|
// processesByID.Kill();
|
|
|
|
|
// break;
|
|
|
|
|
// // Process Current = Process.GetCurrentProcess();
|
|
|
|
|
// // Process processesByID = Process.GetProcessById(Current.Id);
|
|
|
|
|
// // processesByID.Kill();
|
|
|
|
|
// // break;
|
|
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
}
|
|
|
|
|