diff --git a/src/cmd/main.go b/src/cmd/main.go index 755cc130..a51995b6 100644 --- a/src/cmd/main.go +++ b/src/cmd/main.go @@ -76,13 +76,19 @@ func Run(content embed.FS) { InitConfigFile() + err := InitTrash() + hasTrash := true + if err != nil { + hasTrash = false + } + variable.FixHotkeys = c.Bool("fix-hotkeys") variable.FixConfigFile = c.Bool("fix-config-file") variable.PrintLastDir = c.Bool("print-last-dir") firstUse := checkFirstUse() - p := tea.NewProgram(internal.InitialModel(path, firstUse), tea.WithAltScreen(), tea.WithMouseCellMotion()) + p := tea.NewProgram(internal.InitialModel(path, firstUse, hasTrash), tea.WithAltScreen(), tea.WithMouseCellMotion()) if _, err := p.Run(); err != nil { log.Fatalf("Alas, there's been an error: %v", err) } @@ -115,17 +121,6 @@ func InitConfigFile() { log.Fatalln("Error creating directories:", err) } - // Create trash directories - if runtime.GOOS != "darwin" { - if err := createDirectories( - xdg.DataHome+variable.TrashDirectory, - xdg.DataHome+variable.TrashDirectoryFiles, - xdg.DataHome+variable.TrashDirectoryInfo, - ); err != nil { - log.Fatalln("Error creating directories:", err) - } - } - // Create files if err := createFiles( variable.PinnedFile, @@ -147,6 +142,19 @@ func InitConfigFile() { } } +func InitTrash() error { + // Create trash directories + if runtime.GOOS != "darwin" { + err := createDirectories( + xdg.DataHome+variable.TrashDirectory, + xdg.DataHome+variable.TrashDirectoryFiles, + xdg.DataHome+variable.TrashDirectoryInfo, + ) + return err + } + return nil +} + // Helper functions // Create all dirs that does not already exists func createDirectories(dirs ...string) error { diff --git a/src/internal/handle_file_operations.go b/src/internal/handle_file_operations.go index 39408326..72ef29d0 100644 --- a/src/internal/handle_file_operations.go +++ b/src/internal/handle_file_operations.go @@ -109,7 +109,7 @@ func (m *model) deleteItemWarn() { messageType: sendWarnModal, } - if isExternalDiskPath(panel.location) { + if !hasTrash || isExternalDiskPath(panel.location) { message.warnModal = warnModal{ open: true, title: "Are you sure you want to completely delete", diff --git a/src/internal/key_function.go b/src/internal/key_function.go index 9b8a43f7..c5f14aaa 100644 --- a/src/internal/key_function.go +++ b/src/internal/key_function.go @@ -214,7 +214,7 @@ func (m *model) warnModalOpenKey(msg string) { case confirmDeleteItem: panel := m.fileModel.filePanels[m.filePanelFocusIndex] if m.fileModel.filePanels[m.filePanelFocusIndex].panelMode == selectMode { - if isExternalDiskPath(panel.location) { + if !hasTrash || isExternalDiskPath(panel.location) { go func() { m.completelyDeleteMultipleItems() m.fileModel.filePanels[m.filePanelFocusIndex].selected = m.fileModel.filePanels[m.filePanelFocusIndex].selected[:0] @@ -226,7 +226,7 @@ func (m *model) warnModalOpenKey(msg string) { }() } } else { - if isExternalDiskPath(panel.location) { + if !hasTrash || isExternalDiskPath(panel.location) { go func() { m.completelyDeleteSingleItem() }() diff --git a/src/internal/model.go b/src/internal/model.go index 24587d65..8cf9d148 100644 --- a/src/internal/model.go +++ b/src/internal/model.go @@ -19,6 +19,7 @@ var LastTimeCursorMove = [2]int{int(time.Now().UnixMicro()), 0} var ListeningMessage = true var firstUse = false +var hasTrash = true var theme ThemeType var Config ConfigType @@ -31,9 +32,10 @@ var channel = make(chan channelMessage, 1000) var progressBarLastRenderTime time.Time = time.Now() // Initialize and return model with default configs -func InitialModel(dir string, firstUseCheck bool) model { +func InitialModel(dir string, firstUseCheck bool, hasTrashCheck bool) model { toggleDotFileBool, toggleFooter, firstFilePanelDir := initialConfig(dir) firstUse = firstUseCheck + hasTrash = hasTrashCheck return defaultModelConfig(toggleDotFileBool, toggleFooter, firstFilePanelDir) }