-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.fs
More file actions
216 lines (179 loc) · 8.68 KB
/
Copy pathProgram.fs
File metadata and controls
216 lines (179 loc) · 8.68 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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
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.Layout
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 notifications_state = ctx.useState { is_running= false; queue = []}
let current_database = ctx.useState { password = ""; filepath=""; database = { lsts = []; trash = [] } }
// INFO : notification actions
let fire_notification (nt_type:NotificationTypes) (title:string) (sub:string) =
//notification_state.Set {notification_state.Current with kind = nt_type; title=title; description= sub; is_up = true; progress=0 }
notifications_state.Set {
notifications_state.Current with
queue = (
{
kind = nt_type;
title=title;
description= sub;
is_up = true;
progress=0;
id= Guid.NewGuid().ToString()
} :: notifications_state.Current.queue
) }
let success (title:string) (description:string) =
fire_notification SUCCESS title description
let info (title:string) (description:string) =
fire_notification INFO title description
let error (title:string) (description:string) =
fire_notification ERROR title description
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
| None -> printfn ""
| Some x -> printfn $"{x}" //debug
| 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}
let run_notification =
async {
while not notifications_state.Current.queue.IsEmpty do
let mutable lst_mut = notifications_state.Current.queue
let mutable lst_remove = []
for i in 0 .. ( lst_mut.Length - 1) do
let pgrss = lst_mut[i].progress + 1
if pgrss >= 100 then lst_remove <- lst_mut[i].id :: lst_remove
lst_mut[i].progress <- pgrss
if not lst_remove.IsEmpty then
let new_lst =
lst_mut
|> List.filter( fun item ->
lst_remove
|> Seq.tryFind (fun item_re -> not ( item_re = item.id) )
|> Option.exists (fun op -> op.Length > 1 )
)
notifications_state.Set {notifications_state.Current with queue = new_lst}
else
notifications_state.Set {notifications_state.Current with queue = lst_mut}
do! Async.Sleep 100
if notifications_state.Current.queue.IsEmpty then
notifications_state.Set {notifications_state.Current with is_running= false }
}
if not notifications_state.Current.queue.IsEmpty && not notifications_state.Current.is_running then
notifications_state.Set {notifications_state.Current with is_running=true}
Async.Start run_notification
Panel.create [
Panel.children [
state.Current.current_page
if notifications_state.Current.is_running then
Panel.create [
Panel.children [
StackPanel.create [
StackPanel.orientation Orientation.Vertical
StackPanel.horizontalAlignment HorizontalAlignment.Right
StackPanel.verticalAlignment VerticalAlignment.Bottom
StackPanel.spacing 3
StackPanel.children [
for item in notifications_state.Current.queue do
Notification.view item
]
]
]
]
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