Commit a1c55cd3 authored by dmknght's avatar dmknght

Add native start / stop button for gui

parent 0ec40b6d
Pipeline #1190 canceled with stages
......@@ -123,7 +123,6 @@ proc main =
mainBoard = newWindow()
boxMainWindow = newBox(Orientation.vertical, 3)
# mainBoard.setTitlebar(makeTitleBar())
mainBoard.setResizable(false)
mainBoard.title = "AnonSurf GUI"
mainBoard.setIcon(surfIcon)
......
import gintro / [gtk, glib, vte]
import .. / modules / [myip, changeid]
import .. / displays / noti
import .. / modules / [myip, changeid, runsurf]
import .. / displays / [noti, askKill]
import strutils
import system
import os
......@@ -46,7 +46,6 @@ proc onClickCheckIP*(b: Button) =
Show the information in system's notification
]#
sendNotify("My IP", "Getting data from server", "dialog-information")
# channel.open()
createThread(worker, doCheckIP)
......@@ -55,9 +54,24 @@ proc onClickRun*(b: Button) =
Create condition to Start / Stop AnonSurf when click on btn1
]#
if b.label == "Start":
discard spawnCommandLineAsync("gksudo /usr/bin/anonsurf start")
initAskDialog()
createThread(worker, start)
else:
discard spawnCommandLineAsync("gksudo /usr/bin/anonsurf stop")
createThread(worker, stop)
initAskDialog()
proc onClickRestart*(b: Button) =
#[
Run anonsurf restart
]#
# if spawnCommandLineAsync("gksudo /usr/bin/anonsurf restart"):
# let imgStatus = newImageFromIconName("system-restart-panel", 3)
# b.setImage(imgStatus)
# else:
# discard
# discard spawnCommandLineAsync("gksudo /usr/sbin/service anonsurfd restart")
createThread(worker, restart)
proc onClickChangeID*(b: Button) =
......@@ -116,15 +130,3 @@ proc onClickTorStatus*(b: Button) =
statusArea.packStart(nyxTerm, false, true, 3)
statusDialog.showAll()
proc onClickRestart*(b: Button) =
#[
Run anonsurf restart
]#
# if spawnCommandLineAsync("gksudo /usr/bin/anonsurf restart"):
# let imgStatus = newImageFromIconName("system-restart-panel", 3)
# b.setImage(imgStatus)
# else:
# discard
discard spawnCommandLineAsync("gksudo /usr/sbin/service anonsurfd restart")
......@@ -15,5 +15,5 @@ proc doKillAppsFromCli*(): int =
if cliUserAsk():
return doKillApp()
else:
initAskDialog()
initAsk()
return -1
......@@ -20,7 +20,20 @@ proc onClickNo(b: Button) =
mainQuit()
proc boxAskKillApps*(): Box =
proc onClickYesGtk(b: Button, d: Dialog) =
let killResult = doKillApp()
if killResult == 0:
sendNotify("AnonSurf", "Killed dangerous application", "security-high")
elif killResult != -1:
sendNotify("AnonSurf", "Error while trying to kill applications", "security-medium")
d.destroy()
proc onClickNoGtk(b: Button, d: Dialog) =
d.destroy()
proc boxAskKillAppsCli(): Box =
let
retBox = newBox(Orientation.vertical, 3)
boxButtons = newBox(Orientation.horizontal, 3)
......@@ -36,19 +49,47 @@ proc boxAskKillApps*(): Box =
return retBox
proc initAskDialog*() =
proc initAsk*() =
gtk.init()
let
mainBoard = newWindow()
boxMainWindow = boxAskKillApps()
boxMainWindow = boxAskKillAppsCli()
mainBoard.setResizable(false)
mainBoard.title = "Kill dangerous application"
mainBoard.setPosition(WindowPosition.center)
mainBoard.add(boxMainWindow)
mainBoard.setBorderWidth(3)
mainBoard.setTitle("Data cleaner")
mainBoard.showAll()
mainBoard.connect("destroy", onExit)
gtk.main()
proc boxAskKillAppsGtk(d: Dialog): Box =
let
retBox = newBox(Orientation.vertical, 3)
boxButtons = newBox(Orientation.horizontal, 3)
labelAsk = newLabel("Do you want to kill dangerous applications?")
btnYes = newButton("Yes")
btnNo = newButton("No")
btnYes.connect("clicked", onClickYesGtk, d)
btnNo.connect("clicked", onClickNoGtk, d)
boxButtons.packEnd(btnYes, false, true, 3)
boxButtons.packEnd(btnNo, false, true, 3)
retBox.add(labelAsk)
retBox.add(boxButtons)
return retBox
proc initAskDialog*() =
let
retDialog = newDialog()
dialogArea = retDialog.getContentArea()
boxDialog = boxAskKillAppsGtk(retDialog)
retDialog.setTitle("Data cleaner")
dialogArea.add(boxDialog)
retDialog.showAll()
discard retDialog.run()
retDialog.destroy()
import osproc
# import .. / displays / askKill
proc start*() =
const
command = "gksudo /usr/sbin/service anonsurfd start"
# initAskDialog()
# TODO check killall
let runResult = execCmd(command)
if runResult == 0:
discard # sendnotify done
else:
discard # send notify failed
proc stop*() =
const
command = "gksudo /usr/sbin/service anonsurfd stop"
# TODO kill app
# TODO check kill app
let runResult = execCmd(command)
if runResult == 0:
discard # send notify done
else:
discard # send notify failed
proc restart*() =
const
command = "gksudo /usr/sbin/service anonsurfd restart"
let runResult = execCmd(command)
if runResult == 0:
discard # send NOtify done
else:
discard # send notify failed
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment