Skip to content

armgit / WacOS

Public Imported from GitHub
0

A new style desktop shell for Windows 11: menu bar, Dock, Finder, Spotlight, Control Center and Liquid Glass, in native C++.

Rust

Dock pins, desktop icon positions, alarms and the Island shelf are saved atomically

Eternity070628b5b563838ab2
diff --git a/docs/registro-mudancas.txt b/docs/registro-mudancas.txt
index 5447deb..588b311 100644
--- a/docs/registro-mudancas.txt
+++ b/docs/registro-mudancas.txt
@@ -1362,3 +1362,9 @@ Compilado (tudo), instalado, Shell e reserva do Finder reiniciados às 23:07 sem
- Revisado sem achar problema: renomear (não sobrescreve nome existente, devolve o .lnk), apagar e esvaziar a Lixeira (pelos verbos do Windows, com a confirmação dele), desfazer.
Compilado (build completo). NÃO testado na tela (sem cliques simulados).
DESFAZER: reverter o commit.
+
+[2026-11-23 04:10, hora do PC] Caça a bugs, rodada 5 (Dock, mesa e arquivos do Shell). Só código.
+ - src/comum/ajustes_arquivo.h: ajarq::GravarTexto (texto em .tmp trocado de uma vez).
+ - src/shell/apps.cpp (dock.txt), mesa.cpp (mesa.txt), notificacoes.cpp (relogio.txt, ao desligar um alarme de uma vez) e ilha.cpp (prateleira): eram regravados direto com "w". O vigia encerra o Shell travado com TerminateProcess; caindo no meio da gravação o arquivo ficava vazio: o Dock voltava sem nenhum app fixado, os ícones da mesa se embaralhavam e os alarmes do Relógio sumiam. Agora a gravação é atômica. Testado: ida e volta com acentos e tabs, sem sobrar .tmp.
+ Compilado (build completo). NÃO testado na tela.
+ DESFAZER: reverter o commit.
diff --git a/src/comum/ajustes_arquivo.h b/src/comum/ajustes_arquivo.h
index 5575f3c..ff50997 100644
--- a/src/comum/ajustes_arquivo.h
+++ b/src/comum/ajustes_arquivo.h
@@ -64,4 +64,23 @@ inline bool Gravar(const std::wstring& path, const std::map<std::wstring, std::w
return true;
}
+// Texto pronto (UTF-8 com BOM, como o "w, ccs=UTF-8") num .tmp trocado de uma vez: o dock.txt e o mesa.txt eram
+// regravados direto, e o Shell encerrado no meio (o vigia faz TerminateProcess no Shell travado) deixava o arquivo
+// vazio — o Dock voltava sem nenhum app fixado.
+inline bool GravarTexto(const std::wstring& path, const std::wstring& texto) {
+ std::wstring tmp = path + L".tmp";
+ FILE* fp = nullptr;
+ if (_wfopen_s(&fp, tmp.c_str(), L"w, ccs=UTF-8") || !fp) return false;
+ fputws(texto.c_str(), fp);
+ bool ok = fflush(fp) == 0;
+ fclose(fp);
+ if (!ok) { DeleteFileW(tmp.c_str()); return false; }
+ for (int i = 0; i < 5; i++) {
+ if (MoveFileExW(tmp.c_str(), path.c_str(), MOVEFILE_REPLACE_EXISTING)) return true;
+ Sleep(10);
+ }
+ DeleteFileW(tmp.c_str());
+ return false;
+}
+
} // namespace ajarq
diff --git a/src/shell/apps.cpp b/src/shell/apps.cpp
index 9cd9cc5..a83d1d7 100644
--- a/src/shell/apps.cpp
+++ b/src/shell/apps.cpp
@@ -2,6 +2,7 @@
// os abertos (janelas que apareceriam na barra de tarefas) e os recentes. Abrir, ativar, ocultar,
// encerrar, fixar, abrir ao iniciar sessão.
#include "shell.h"
+#include "../comum/ajustes_arquivo.h"
#include <mutex>
#include <unordered_map>
#include <memory>
@@ -270,10 +271,10 @@ App* apps::OfWindow(HWND h) {
}
void apps::Save() {
- FILE* f = nullptr;
- if (_wfopen_s(&f, (DataDir() + L"\\dock.txt").c_str(), L"w, ccs=UTF-8") || !f) return;
- for (auto& a : list) if (a.pinned && !a.finder) fwprintf(f, L"%ls\t%ls\t%ls\t%ls\n", a.id.c_str(), a.launch.c_str(), a.name.c_str(), a.exe.c_str());
- fclose(f);
+ // atômico (.tmp + troca): o Shell encerrado no meio da gravação deixava o dock.txt vazio e o Dock sem apps fixos
+ std::wstring s;
+ for (auto& a : list) if (a.pinned && !a.finder) s += a.id + L"\t" + a.launch + L"\t" + a.name + L"\t" + a.exe + L"\n";
+ ajarq::GravarTexto(DataDir() + L"\\dock.txt", s);
}
void apps::Load(const std::wstring& finderExe) {
diff --git a/src/shell/ilha.cpp b/src/shell/ilha.cpp
index a7b031d..2a01382 100644
--- a/src/shell/ilha.cpp
+++ b/src/shell/ilha.cpp
@@ -24,6 +24,7 @@
// Ocioso tem que ser ocioso: mídia, microfone/câmera, downloads e área de transferência chegam por eventos; o relógio
// de quadros só roda enquanto a mola mexe; barrinhas (30 q/s), timer (4/s) e Sistema (1/s) só enquanto aparecem.
#include "shell.h"
+#include "../comum/ajustes_arquivo.h"
#include "../comum/simbolos.h"
#include <mmdeviceapi.h>
#include <endpointvolume.h>
@@ -573,8 +574,7 @@ std::wstring ShelfFile() {
void ShelfSave() {
std::wstring s;
for (auto& p : g_shelf) s += p + L"\r\n";
- FILE* f = nullptr;
- if (_wfopen_s(&f, ShelfFile().c_str(), L"w, ccs=UTF-8") == 0 && f) { fputws(s.c_str(), f); fclose(f); }
+ ajarq::GravarTexto(ShelfFile(), s); // atômico: o Shell encerrado no meio deixava a prateleira vazia
}
void ShelfLoad() {
diff --git a/src/shell/mesa.cpp b/src/shell/mesa.cpp
index 3dfaaca..cd26e75 100644
--- a/src/shell/mesa.cpp
+++ b/src/shell/mesa.cpp
@@ -17,6 +17,7 @@
// da mesa ou para outra casa da grade), soltar arquivos de fora, F2 renomeia, Delete vai para a Lixeira,
// Ctrl+C/X/V, menu de contexto (o nosso, com as extensões do Windows) e o menu do fundo do Mac.
#include "shell.h"
+#include "../comum/ajustes_arquivo.h"
#include <dwmapi.h>
#include "../menu/context_menu.h"
#include <shlobj.h>
@@ -461,15 +462,17 @@ bool Blocked(int col, int row) {
}
void SavePositions() {
- FILE* fp = nullptr;
- if (_wfopen_s(&fp, g_posFile.c_str(), L"w, ccs=UTF-8") || !fp) return;
+ // atômico (.tmp + troca): o Shell encerrado no meio da gravação deixava o mesa.txt vazio (ícones embaralhados)
+ std::wstring s;
+ wchar_t b[96];
for (auto& [k, v] : g_pos) {
auto o = g_off.find(k);
if (o != g_off.end() && (o->second.first != 0 || o->second.second != 0))
- fwprintf(fp, L"%d,%d,%.1f,%.1f|%ls\n", v.first, v.second, o->second.first, o->second.second, k.c_str());
- else fwprintf(fp, L"%d,%d|%ls\n", v.first, v.second, k.c_str());
+ swprintf_s(b, L"%d,%d,%.1f,%.1f|", v.first, v.second, o->second.first, o->second.second);
+ else swprintf_s(b, L"%d,%d|", v.first, v.second);
+ s += b; s += k; s += L'\n';
}
- fclose(fp);
+ ajarq::GravarTexto(g_posFile, s);
}
void LoadPositions() {
g_pos.clear(); g_off.clear();
diff --git a/src/shell/notificacoes.cpp b/src/shell/notificacoes.cpp
index 918bd70..9caa3e0 100644
--- a/src/shell/notificacoes.cpp
+++ b/src/shell/notificacoes.cpp
@@ -10,6 +10,7 @@
// conteúdo por cima (Direct2D na GPU). O Windows não avisa quando chega notificação para app sem pacote
// (NotificationChanged dá "Elemento não encontrado"), então uma thread relê a lista a cada 2 s com o painel aberto.
#include "shell.h"
+#include "../comum/ajustes_arquivo.h"
#include "vidro_wuc.h"
#include "../menu/context_menu.h"
#include "../comum/simbolos.h"
@@ -1719,7 +1720,7 @@ void ChecarAvisos() {
size_t p = 0; for (int k = 0; k < 4 && p != std::wstring::npos; k++) p = s.find(L'\t', p + 1);
if (p != std::wstring::npos && p + 1 < s.size() && s[p + 1] == L'1') s[p + 1] = L'0';
}
- if (!_wfopen_s(&f, path.c_str(), L"w, ccs=UTF-8") && f) { for (auto& s : lines) fwprintf(f, L"%ls\n", s.c_str()); fclose(f); }
+ { std::wstring all; for (auto& s : lines) { all += s; all += L'\n'; } ajarq::GravarTexto(path, all); } // atômico: são os alarmes do usuário
}
}
if (due.empty()) return;