Правки кода, завершение настройки после финальной секции
This commit is contained in:
parent
d3fd4f5858
commit
cb44386061
7 changed files with 38 additions and 10 deletions
|
|
@ -50,6 +50,10 @@ func (m *FinalModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||
case key.Matches(msg, types.MainKeys.Bottom):
|
||||
//Обработчик клавиши перехода на самый верх
|
||||
m.viewport.GotoBottom()
|
||||
case key.Matches(msg, types.MainKeys.Confirm):
|
||||
return m, func() tea.Msg {
|
||||
return types.NextSectionMsg{}
|
||||
}
|
||||
}
|
||||
case tea.WindowSizeMsg:
|
||||
//Отслеживаем и записываем новые размер окна, вносим изменения в размеры viewport
|
||||
|
|
|
|||
|
|
@ -12,7 +12,6 @@ import (
|
|||
|
||||
func Start() {
|
||||
//Создаем новый объект Main для настройки.
|
||||
//todo работа внутри apt, вывод интерфейса во время выполнения apt
|
||||
m := NewMain()
|
||||
p := tea.NewProgram(m, tea.WithAltScreen()) //Запускаем через bubble tea программу
|
||||
m.Program = p //Указываем объекту настроек, программу в которой запущен, чтобы передавать туда сигналы
|
||||
|
|
@ -108,7 +107,7 @@ func (m *Main) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||
return types.ShowModalMsg{
|
||||
Type: types.ModalWarning,
|
||||
Title: "Закрытие приложения",
|
||||
Message: "Вы нажали ctrl+c, вы желаете закрыть приложение?",
|
||||
Message: "Вы нажали ctrl+c/ctrl+q, вы желаете закрыть приложение?",
|
||||
ModalButtons: []types.ModalButton{
|
||||
{Text: "Закрыть приложение", Value: true},
|
||||
{Text: "Не закрывать", Value: false},
|
||||
|
|
@ -295,7 +294,7 @@ func (m *Main) executeSectionActions() {
|
|||
for _, action := range m.CurrentSection.Actions {
|
||||
//Если условие для действия не выполняется, то пропускаем
|
||||
if !utils.CheckCondition(action.Condition, m.CurrentApplication) {
|
||||
return
|
||||
continue
|
||||
}
|
||||
sectionActionLog := fmt.Sprintf("Выполнение действия: %s", action.Name)
|
||||
logrus.Infof(sectionActionLog)
|
||||
|
|
@ -330,6 +329,7 @@ func (m *Main) executeSectionActions() {
|
|||
// NextSectionProcess проверяет доступность следующей секции для настройки
|
||||
func (m *Main) NextSectionProcess() (bool, types.ShowModalMsg) {
|
||||
//Ищем индекс следующей секции, если он остался 0, то следующие секции недоступны.
|
||||
//Если текущая секция последняя секция, то завершаем настройку.
|
||||
//Возвращаем модальное окно с выходом к списку приложений
|
||||
nextSectionIndex := 0
|
||||
for sectionIDx := m.CurrentSectionIdx + 1; sectionIDx < len(m.CurrentApplication.Sections); sectionIDx++ {
|
||||
|
|
@ -339,7 +339,22 @@ func (m *Main) NextSectionProcess() (bool, types.ShowModalMsg) {
|
|||
break
|
||||
}
|
||||
}
|
||||
if nextSectionIndex == 0 {
|
||||
|
||||
if nextSectionIndex == 0 && m.CurrentSectionIdx+1 == len(m.CurrentApplication.Sections) {
|
||||
return false, types.ShowModalMsg{
|
||||
Type: types.ModalInfo,
|
||||
Title: "Настройка завершена",
|
||||
Message: "Настройка завершена, нажмите enter чтобы закрыть приложение",
|
||||
ModalButtons: []types.ModalButton{
|
||||
{Text: "Закрыть приложение", Value: true},
|
||||
},
|
||||
OnResult: func(result any) tea.Cmd {
|
||||
return func() tea.Msg {
|
||||
return tea.Quit()
|
||||
}
|
||||
},
|
||||
}
|
||||
} else if nextSectionIndex == 0 {
|
||||
return false, types.ShowModalMsg{
|
||||
Type: types.ModalWarning,
|
||||
Title: "Ошибка секций приложения",
|
||||
|
|
|
|||
|
|
@ -100,7 +100,7 @@ func RunCommand(cmdStr, runAs string) (string, error) {
|
|||
}
|
||||
var cmd *exec.Cmd
|
||||
if runAs != "" && runAs != "root" {
|
||||
cmd = exec.Command("su", "-c", cmdStr, runAs)
|
||||
cmd = exec.Command("sudo", "-u", runAs, "bash", "-c", cmdStr)
|
||||
} else {
|
||||
cmd = exec.Command("bash", "-c", cmdStr)
|
||||
}
|
||||
|
|
@ -142,7 +142,7 @@ func RenderFileTemplate(source, target string, vars map[string]interface{}) erro
|
|||
|
||||
//В файл помещаем переменные
|
||||
if err = tmpl.Execute(&rendered, vars); err != nil {
|
||||
return fmt.Errorf("ошибка подстановки значений в шаблон")
|
||||
return fmt.Errorf("ошибка подстановки значений в шаблон: %v", err)
|
||||
}
|
||||
if _, err = os.Stat(target); err == nil {
|
||||
backup := target + ".bak" + time.Now().Format("20060102-150405")
|
||||
|
|
|
|||
|
|
@ -255,7 +255,7 @@ func DefineExprCustomFunctions() []expr.Option {
|
|||
return false, fmt.Errorf("file is dir")
|
||||
}
|
||||
if errors.Is(err, fs.ErrNotExist) {
|
||||
return false, fmt.Errorf("no such directory or file")
|
||||
return false, nil
|
||||
} else {
|
||||
return false, err
|
||||
}
|
||||
|
|
@ -275,7 +275,7 @@ func DefineExprCustomFunctions() []expr.Option {
|
|||
return false, fmt.Errorf("file is not a dir")
|
||||
}
|
||||
if errors.Is(err, fs.ErrNotExist) {
|
||||
return false, fmt.Errorf("no such directory or file")
|
||||
return false, nil
|
||||
} else {
|
||||
return false, err
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue