Skip to content

Commit a9959d0

Browse files
committed
menu
1 parent dec9022 commit a9959d0

File tree

7 files changed

+140
-54
lines changed

7 files changed

+140
-54
lines changed

backend/obfuscator/config.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ type Config struct {
1919
path string
2020
}
2121

22-
func NewConfig() Config {
22+
func NewConfig() *Config {
2323
var config Config
2424

2525
err := config.load()
@@ -31,9 +31,7 @@ func NewConfig() Config {
3131
log.Fatal(err)
3232
}
3333

34-
log.Println("Hyperion config:", config.path)
35-
36-
return config
34+
return &config
3735
}
3836

3937
func (config *Config) load() error {
@@ -83,3 +81,7 @@ func (config *Config) Save(c Config) {
8381
func (config *Config) GetConfig() Config {
8482
return *config
8583
}
84+
85+
func (config *Config) GetPath() string {
86+
return config.path
87+
}

backend/obfuscator/obfuscator.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ import (
1010

1111
type Obfuscator struct {
1212
ctx context.Context
13-
config Config
13+
config *Config
1414
}
1515

16-
func NewObfuscator(config Config) *Obfuscator {
16+
func NewObfuscator(config *Config) *Obfuscator {
1717
return &Obfuscator{
1818
config: config,
1919
}
@@ -111,7 +111,3 @@ func (o *Obfuscator) Obfuscate(path string) (string, error) {
111111

112112
return content, nil
113113
}
114-
115-
func (o *Obfuscator) Config() Config {
116-
return o.config
117-
}

frontend/wailsjs/go/models.ts

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -19,34 +19,3 @@ export namespace main {
1919

2020
}
2121

22-
export namespace obfuscator {
23-
24-
export class Config {
25-
single_line_output: boolean;
26-
string_literal: boolean;
27-
loop_statement: boolean;
28-
if_statement: boolean;
29-
constant_name: boolean;
30-
variable_name: boolean;
31-
function_name: boolean;
32-
remove_comments: boolean;
33-
34-
static createFrom(source: any = {}) {
35-
return new Config(source);
36-
}
37-
38-
constructor(source: any = {}) {
39-
if ('string' === typeof source) source = JSON.parse(source);
40-
this.single_line_output = source["single_line_output"];
41-
this.string_literal = source["string_literal"];
42-
this.loop_statement = source["loop_statement"];
43-
this.if_statement = source["if_statement"];
44-
this.constant_name = source["constant_name"];
45-
this.variable_name = source["variable_name"];
46-
this.function_name = source["function_name"];
47-
this.remove_comments = source["remove_comments"];
48-
}
49-
}
50-
51-
}
52-
Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
22
// This file is automatically generated. DO NOT EDIT
3-
import {obfuscator} from '../models';
43
import {context} from '../models';
54

6-
export function Config():Promise<obfuscator.Config>;
7-
85
export function Obfuscate(arg1:string):Promise<string>;
96

107
export function SetContext(arg1:context.Context):Promise<void>;

frontend/wailsjs/go/obfuscator/obfuscator.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@
22
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
33
// This file is automatically generated. DO NOT EDIT
44

5-
export function Config() {
6-
return window['go']['obfuscator']['Obfuscator']['Config']();
7-
}
8-
95
export function Obfuscate(arg1) {
106
return window['go']['obfuscator']['Obfuscator']['Obfuscate'](arg1);
117
}

main.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package main
33
import (
44
"context"
55
"embed"
6-
"github.com/wailsapp/wails/v2"
6+
"github.com/wailsapp/wails/v2/pkg/application"
77
"github.com/wailsapp/wails/v2/pkg/options"
88
"github.com/wailsapp/wails/v2/pkg/options/assetserver"
99
"github.com/wailsapp/wails/v2/pkg/options/linux"
@@ -18,15 +18,17 @@ import (
1818
var assets embed.FS
1919

2020
func main() {
21-
// Create an instance of the app structure
2221
app := NewApp()
2322

23+
config := ob.NewConfig()
24+
2425
file := fs.NewFileManager()
2526
dialog := fs.NewDialog()
26-
obfuscator := ob.NewObfuscator(ob.NewConfig())
27+
obfuscator := ob.NewObfuscator(config)
28+
29+
menu := NewMenu(config)
2730

28-
// Create application with options
29-
err := wails.Run(&options.App{
31+
hyperion := application.NewWithOptions(&options.App{
3032
Title: "hyperion",
3133
Width: 1024,
3234
Height: 768,
@@ -38,6 +40,7 @@ func main() {
3840
BackgroundColour: &options.RGBA{R: 0, G: 0, B: 0, A: 0},
3941
OnStartup: func(ctx context.Context) {
4042
app.startup(ctx)
43+
menu.startup(ctx)
4144
file.SetContext(ctx)
4245
dialog.SetContext(ctx)
4346
obfuscator.SetContext(ctx)
@@ -67,8 +70,9 @@ func main() {
6770
WindowIsTranslucent: true,
6871
},
6972
})
73+
hyperion.SetApplicationMenu(menu.CreateMenu(hyperion))
7074

71-
if err != nil {
75+
if err := hyperion.Run(); err != nil {
7276
log.Fatal(err)
7377
}
7478
}

menu.go

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"github.com/wailsapp/wails/v2/pkg/application"
6+
"github.com/wailsapp/wails/v2/pkg/menu"
7+
"github.com/wailsapp/wails/v2/pkg/menu/keys"
8+
"github.com/wailsapp/wails/v2/pkg/runtime"
9+
"hyperion/backend/obfuscator"
10+
"os/exec"
11+
"reflect"
12+
"regexp"
13+
rt "runtime"
14+
)
15+
16+
type Menu struct {
17+
ctx context.Context
18+
config *obfuscator.Config
19+
}
20+
21+
func NewMenu(config *obfuscator.Config) *Menu {
22+
return &Menu{config: config}
23+
}
24+
25+
func (m *Menu) startup(ctx context.Context) {
26+
m.ctx = ctx
27+
}
28+
29+
func (m *Menu) CreateMenu(app *application.Application) *menu.Menu {
30+
appMenu := menu.NewMenu()
31+
32+
// File Menu
33+
fileMenu := appMenu.AddSubmenu("File")
34+
fileMenu.AddText("Open", keys.CmdOrCtrl("o"), func(_ *menu.CallbackData) {
35+
runtime.EventsEmit(m.ctx, "menu:open")
36+
})
37+
fileMenu.AddText("Open Folder", keys.Combo("o", keys.ShiftKey, keys.CmdOrCtrlKey), func(_ *menu.CallbackData) {
38+
runtime.EventsEmit(m.ctx, "menu:open-folder")
39+
})
40+
fileMenu.AddSeparator()
41+
fileMenu.AddText("Save", keys.CmdOrCtrl("s"), func(_ *menu.CallbackData) {
42+
runtime.EventsEmit(m.ctx, "menu:save")
43+
})
44+
fileMenu.AddText("Save All", keys.Combo("s", keys.ShiftKey, keys.CmdOrCtrlKey), func(_ *menu.CallbackData) {
45+
runtime.EventsEmit(m.ctx, "menu:save-all")
46+
})
47+
fileMenu.AddSeparator()
48+
fileMenu.AddText("Close", keys.CmdOrCtrl("w"), func(_ *menu.CallbackData) {
49+
runtime.EventsEmit(m.ctx, "menu:close")
50+
})
51+
fileMenu.AddText("Close Folder", keys.Combo("w", keys.ShiftKey, keys.CmdOrCtrlKey), func(_ *menu.CallbackData) {
52+
runtime.EventsEmit(m.ctx, "menu:close-folder")
53+
})
54+
fileMenu.AddSeparator()
55+
fileMenu.AddText("Quit", keys.CmdOrCtrl("q"), func(_ *menu.CallbackData) {
56+
app.Quit()
57+
})
58+
59+
// Run Menu
60+
runMenu := appMenu.AddSubmenu("Run")
61+
runMenu.AddText("Obfuscate", keys.CmdOrCtrl("r"), func(_ *menu.CallbackData) {
62+
runtime.EventsEmit(m.ctx, "run:obfuscate")
63+
})
64+
runMenu.AddText("Obfuscate All", keys.Combo("r", keys.ShiftKey, keys.CmdOrCtrlKey), func(_ *menu.CallbackData) {
65+
runtime.EventsEmit(m.ctx, "run:obfuscate-all")
66+
})
67+
runMenu.AddSeparator()
68+
runMenu.AddText("Cancel Obfuscation", keys.CmdOrCtrl("e"), func(_ *menu.CallbackData) {
69+
runtime.EventsEmit(m.ctx, "run:cancel")
70+
})
71+
runMenu.AddText("Cancel All Obfuscation", keys.Combo("e", keys.ShiftKey, keys.CmdOrCtrlKey), func(_ *menu.CallbackData) {
72+
runtime.EventsEmit(m.ctx, "run:cancel-all")
73+
})
74+
runMenu.AddSeparator()
75+
configMenu := runMenu.AddSubmenu("Configuration")
76+
configValue := reflect.ValueOf(m.config).Elem()
77+
configType := configValue.Type()
78+
for i := 0; i < configValue.NumField(); i++ {
79+
field := configType.Field(i)
80+
if field.Name == "path" {
81+
continue
82+
}
83+
84+
configMenu.AddCheckbox(toCamelCaseLabel(field.Name), configValue.FieldByName(field.Name).Bool(), nil, func(_ *menu.CallbackData) {
85+
currentValue := configValue.FieldByName(field.Name).Bool()
86+
configValue.FieldByName(field.Name).SetBool(!currentValue)
87+
88+
m.config.Save(*m.config)
89+
})
90+
}
91+
runMenu.AddText("Open Configuration Folder", nil, func(_ *menu.CallbackData) {
92+
switch rt.GOOS {
93+
case "windows":
94+
_ = exec.Command("explorer", m.config.GetPath()).Start()
95+
break
96+
case "darwin":
97+
_ = exec.Command("open", "-R", m.config.GetPath()).Start()
98+
break
99+
case "linux":
100+
_ = exec.Command("xdg-open", m.config.GetPath()).Start()
101+
break
102+
default:
103+
break
104+
}
105+
})
106+
107+
// Help Menu
108+
helpMenu := appMenu.AddSubmenu("Help")
109+
helpMenu.AddText("How to Contribute", nil, func(_ *menu.CallbackData) {
110+
println("How to Contribute clicked")
111+
})
112+
helpMenu.AddText("Report Issue", nil, func(_ *menu.CallbackData) {
113+
runtime.BrowserOpenURL(m.ctx, "https://github.com/404NotFoundIndonesia/hyperion/issues")
114+
})
115+
116+
return appMenu
117+
}
118+
119+
func toCamelCaseLabel(input string) string {
120+
re := regexp.MustCompile("([a-z])([A-Z])")
121+
return re.ReplaceAllString(input, "$1 $2")
122+
}

0 commit comments

Comments
 (0)