Skip to content

Commit

Permalink
[patch] improvements/optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
Z3NTL3 committed Jun 30, 2024
1 parent cb865a2 commit 6cb6eaa
Show file tree
Hide file tree
Showing 10 changed files with 79 additions and 29 deletions.
28 changes: 13 additions & 15 deletions core/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package core

import (
"context"
"fmt"
"os"
path "path/filepath"
"sync/atomic"
Expand Down Expand Up @@ -69,12 +68,12 @@ func (a *App) OnExit(ctx context.Context) {

func (a *App) Startup(ctx context.Context) {
var err error
defer func(err_ *error) {
defer func() {
// fatal
if *err_ != nil {
runtime.EventsEmit(a.ctx, Fire_FatalError, (*err_).Error())
if err != nil {
runtime.EventsEmit(a.ctx, Fire_FatalError, err.Error())
}
}(&err)
}()

a.ctx = ctx
runtime.WindowCenter(ctx)
Expand Down Expand Up @@ -134,7 +133,7 @@ func (a *App) DomReady(ctx context.Context) {
runtime.EventsEmit(a.ctx, Fire_ErrEvent, err.(error).Error())
}
}()
MX.StartScan(a.ctx, data[0].(string))
MX.StartScan(a.ctx, data[0].(string)) // may panic
},
},
}
Expand All @@ -154,12 +153,11 @@ func (g *EventGroup) register_eventListeners(ctx context.Context) {

func (a *App) dialog_exec(optionalData ...interface{}) {
var err error
defer func(err_ *error) {
if *err_ != nil {
fmt.Println((*err_).Error())
runtime.EventsEmit(a.ctx, Fire_ErrEvent, (*err_).Error())
defer func() {
if err != nil {
runtime.EventsEmit(a.ctx, Fire_ErrEvent, err.Error())
}
}(&err)
}()

props, ok := optionalData[0].(string)
if !ok {
Expand Down Expand Up @@ -205,11 +203,11 @@ func (a *App) cancel_scan(...interface{}) {
func (a *App) modify_default_timeout(data ...interface{}) {
var err error

defer func(err_ *error){
if *err_ != nil {
runtime.EventsEmit(APP.ctx, Fire_ErrEvent, (*err_).Error())
defer func(){
if err != nil {
runtime.EventsEmit(APP.ctx, Fire_ErrEvent, err.Error())
}
}(&err)
}()

timeout, ok := data[0].(string)
if !ok {
Expand Down
1 change: 1 addition & 0 deletions core/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ func (c *Controller) CanExit() {
}

// Cancels all threads, signals shut down
// may panic
func (c *Controller) Cancel() {
defer func(){
recover()
Expand Down
2 changes: 1 addition & 1 deletion core/globals.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var (
MX *Controller = &Controller{}

DefaultTimeout time.Duration = time.Second * 8
DefaultPoolSize uint32 = 10_000
DefaultPoolSize uint32 = 2_000
DefaultJudge string = "https://pool.proxyspace.pro/judge.php"
DefaultConfigFile string = "config.json"
)
11 changes: 6 additions & 5 deletions core/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ func (c *Controller) StartScan(ctx context.Context, proto string) {
var err error

// if err fire to js runtime
defer func(err_ *error) {
if *err_ != nil {
runtime.EventsEmit(APP.ctx, Fire_ErrEvent, (*err_).Error())
defer func() {
if err != nil {
runtime.EventsEmit(APP.ctx, Fire_ErrEvent, err.Error())
}
}(&err)
}()

// determine if a scan is ongoing
if c.CurrentThread() != 0 {
Expand Down Expand Up @@ -104,7 +104,8 @@ func (c *Controller) StartScan(ctx context.Context, proto string) {
break
}

proc := proc
// https://pkg.go.dev/golang.org/x/tools/go/analysis/passes/loopclosure
// closure capture on iterator valid in go >1.22
go func(){
err = checker.WRAP_COMPLETION(proc, proxy.proxy, done)
}()
Expand Down
2 changes: 1 addition & 1 deletion frontend/dist/js/root_listeners.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ setInterval(async () => {

document.getElementById("TotalChecks").innerText = checks

}, 100)
}, 600)
window.runtime.EventsOn("checker_end", async () => {
Fire({
...STD_PROPS,
Expand Down
2 changes: 1 addition & 1 deletion frontend/public/js/root_listeners.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ setInterval(async () => {

document.getElementById("TotalChecks").innerText = checks

}, 100)
}, 600)
window.runtime.EventsOn("checker_end", async () => {
Fire({
...STD_PROPS,
Expand Down
14 changes: 14 additions & 0 deletions frontend/wailsjs/runtime/runtime.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,3 +233,17 @@ export function ClipboardGetText(): Promise<string>;
// [ClipboardSetText](https://wails.io/docs/reference/runtime/clipboard#clipboardsettext)
// Sets a text on the clipboard
export function ClipboardSetText(text: string): Promise<boolean>;

// [OnFileDrop](https://wails.io/docs/reference/runtime/draganddrop#onfiledrop)
// OnFileDrop listens to drag and drop events and calls the callback with the coordinates of the drop and an array of path strings.
export function OnFileDrop(callback: (x: number, y: number ,paths: string[]) => void, useDropTarget: boolean) :void

// [OnFileDropOff](https://wails.io/docs/reference/runtime/draganddrop#dragandddropoff)
// OnFileDropOff removes the drag and drop listeners and handlers.
export function OnFileDropOff() :void

// Check if the file path resolver is available
export function CanResolveFilePaths(): boolean;

// Resolves file paths for an array of files
export function ResolveFilePaths(files: File[]): void
36 changes: 36 additions & 0 deletions frontend/wailsjs/runtime/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,4 +199,40 @@ export function ClipboardGetText() {

export function ClipboardSetText(text) {
return window.runtime.ClipboardSetText(text);
}

/**
* Callback for OnFileDrop returns a slice of file path strings when a drop is finished.
*
* @export
* @callback OnFileDropCallback
* @param {number} x - x coordinate of the drop
* @param {number} y - y coordinate of the drop
* @param {string[]} paths - A list of file paths.
*/

/**
* OnFileDrop listens to drag and drop events and calls the callback with the coordinates of the drop and an array of path strings.
*
* @export
* @param {OnFileDropCallback} callback - Callback for OnFileDrop returns a slice of file path strings when a drop is finished.
* @param {boolean} [useDropTarget=true] - Only call the callback when the drop finished on an element that has the drop target style. (--wails-drop-target)
*/
export function OnFileDrop(callback, useDropTarget) {
return window.runtime.OnFileDrop(callback, useDropTarget);
}

/**
* OnFileDropOff removes the drag and drop listeners and handlers.
*/
export function OnFileDropOff() {
return window.runtime.OnFileDropOff();
}

export function CanResolveFilePaths() {
return window.runtime.CanResolveFilePaths();
}

export function ResolveFilePaths(files) {
return window.runtime.ResolveFilePaths(files);
}
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ module ProxyBeast
go 1.22.2

require (
github.com/Z3NTL3/proxifier v1.7.6
github.com/wailsapp/wails/v2 v2.8.1
github.com/Z3NTL3/proxifier v1.7.7
github.com/wailsapp/wails/v2 v2.9.1
)

require (
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
github.com/Z3NTL3/proxifier v1.7.6 h1:5s6+J/yhRRzLKEgsbj1YWZaOVlcRYA7EI7Gs0JZiqVM=
github.com/Z3NTL3/proxifier v1.7.6/go.mod h1:z/D+exzmQ5tTFbg4UiFlrDrQxqBtOZq3SJjzHtlMyqk=
github.com/Z3NTL3/proxifier v1.7.7 h1:0U8diEX0NSR2Us5AXlOMRG2mILYYUsBRMBaqZ3oua1w=
github.com/Z3NTL3/proxifier v1.7.7/go.mod h1:z/D+exzmQ5tTFbg4UiFlrDrQxqBtOZq3SJjzHtlMyqk=
github.com/bep/debounce v1.2.1 h1:v67fRdBA9UQu2NhLFXrSg0Brw7CexQekrBwDMM8bzeY=
github.com/bep/debounce v1.2.1/go.mod h1:H8yggRPQKLUhUoqrJC1bO2xNya7vanpDl7xR3ISbCJ0=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
Expand Down Expand Up @@ -57,8 +57,8 @@ github.com/wailsapp/go-webview2 v1.0.10 h1:PP5Hug6pnQEAhfRzLCoOh2jJaPdrqeRgJKZhy
github.com/wailsapp/go-webview2 v1.0.10/go.mod h1:Uk2BePfCRzttBBjFrBmqKGJd41P6QIHeV9kTgIeOZNo=
github.com/wailsapp/mimetype v1.4.1 h1:pQN9ycO7uo4vsUUuPeHEYoUkLVkaRntMnHJxVwYhwHs=
github.com/wailsapp/mimetype v1.4.1/go.mod h1:9aV5k31bBOv5z6u+QP8TltzvNGJPmNJD4XlAL3U+j3o=
github.com/wailsapp/wails/v2 v2.8.1 h1:KAudNjlFaiXnDfFEfSNoLoibJ1ovoutSrJ8poerTPW0=
github.com/wailsapp/wails/v2 v2.8.1/go.mod h1:EFUGWkUX3KofO4fmKR/GmsLy3HhPH7NbyOEaMt8lBF0=
github.com/wailsapp/wails/v2 v2.9.1 h1:irsXnoQrCpeKzKTYZ2SUVlRRyeMR6I0vCO9Q1cvlEdc=
github.com/wailsapp/wails/v2 v2.9.1/go.mod h1:7maJV2h+Egl11Ak8QZN/jlGLj2wg05bsQS+ywJPT0gI=
golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI=
golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8=
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 h1:vr/HnozRka3pE4EsMEg1lgkXJkTFJCVUX+S/ZT6wYzM=
Expand Down

0 comments on commit 6cb6eaa

Please sign in to comment.