-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.fs
More file actions
144 lines (121 loc) · 5.54 KB
/
Copy pathProgram.fs
File metadata and controls
144 lines (121 loc) · 5.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
namespace PasswordManager
open System
open Avalonia
open Avalonia.Media
open Avalonia.Media.Imaging
open Avalonia.Logging
open Avalonia.Platform
open Avalonia.Controls.ApplicationLifetimes
open Avalonia.FuncUI.Hosts
open Avalonia.Controls
open Avalonia.FuncUI
open Avalonia.FuncUI.DSL
open Avalonia.Markup.Xaml
open PasswordManager.Types
open PasswordManager.Database
open PasswordManager.Components
open PasswordManager.Components.Pages
open PasswordManager.Components.Modals
module Main =
let view () =
Component(fun ctx ->
let state = ctx.useState {
current_page = Component.create("dd",fun x-> Panel.create[])
loaded_data = ""
first_run = true
notification = None;
modal = None
}
let current_database = ctx.useState { password = ""; filepath=""; database = { lsts = []; trash = [] } }
// INFO : notification actions
let fire_notification (nt_type:NotificationTypes) (title:string) (sub:string) =
state.Set {state.Current with notification = Some(Notification.view nt_type title sub)}
let success (title:string) (text:string) = fire_notification SUCCESS title text
let info (title:string) (text:string) = fire_notification INFO title text
let error (title:string) (text:string) = fire_notification ERROR title text
let rec update_db (action:Database_State_Actions) (state_db) =
match action with
| UPDATE -> current_database.Set state_db
| SAVE ->
update_db UPDATE state_db
match save_database state_db.filepath state_db.database state_db.password with
|Some x-> success "Sucesso" "As informações foram salvas!"
|None -> error "Erro" "Não foi possivel salvar as alterações!"
| CLOSE -> current_database.Set { password = ""; filepath = ""; database = { lsts = []; trash = [] } }
let rec actions = {
n_success = success;
n_info = info;
n_error = error;
update_database = update_db
get_db = fun () -> current_database.Current
nav = fun (page: Pages) ->
let new_page =
match page with
| HOME -> home.Page actions
| VAULT_HOME id ->
(Layouts.Main_Layout actions (VAULT_HOME id))
| NEW_KEY key_params->
KeyStore.view actions key_params.lst_id current_database.Current key_params.item_id
|TRASH ->
Layouts.Main_Layout actions TRASH
state.Set { state.Current with current_page = new_page }
modal_fire = (fun modal_type ->
match modal_type with
| CREATE_LIST fn ->
let modal = NewListModal.view actions current_database.Current fn
state.Set {state.Current with modal = Some modal }
actions.nav ( VAULT_HOME "" )
| EDIT_LIST item ->
let modal = Edit_Modal.view actions item current_database.Current
state.Set {state.Current with modal = Some modal}
actions.nav ( VAULT_HOME "" )
| CLOSE_MODAL item->
state.Set {state.Current with modal = None}
if item then actions.nav (VAULT_HOME "")
)
}
if state.Current.first_run then
actions.nav HOME
state.Set {state.Current with first_run = false}
Panel.create [
Panel.children [
state.Current.current_page
if state.Current.notification.IsSome then state.Current.notification.Value
if state.Current.modal.IsSome then state.Current.modal.Value
]
]
)
type MainWindow() =
inherit HostWindow()
do
let cl = Media.Color.FromRgb(byte 0xB8 ,byte 0xE6 ,byte 0xFE )
let uri = Uri("avares://mvu/Assets/bg.png")
let bg = uri |> AssetLoader.Open |> Bitmap |> ImageBrush
bg.Stretch <- Stretch.UniformToFill
base.Title <- "Chaves Chaveadas em chaveamentos chaveaveis"
base.Content <- Main.view ()
base.MinWidth <- 600
base.MinHeight <- 700
//base.Background <- Media.SolidColorBrush cl
base.Background <- bg
type App() =
inherit Application()
override this.Initialize() =
AvaloniaXamlLoader.Load this
this.RequestedThemeVariant <- Styling.ThemeVariant.Light
override this.OnFrameworkInitializationCompleted() =
match this.ApplicationLifetime with
| :? IClassicDesktopStyleApplicationLifetime as desktopLifetime ->
desktopLifetime.MainWindow <- MainWindow()
| _ -> ()
module Program =
[<EntryPoint>]
let main(args: string[]) =
//let font_manager: FontManagerOptions = new FontManagerOptions(DefaultFamilyName = "avares://mvu/Assets/DroidSansMNerdFontMono-Regular.otf")
AppBuilder
.Configure<App>()
.UsePlatformDetect()
.LogToTrace(LogEventLevel.Debug )
.UseSkia()
//.With(font_manager)
.StartWithClassicDesktopLifetime args