Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Notable changes to Syncshell and its shell adapters are documented here.

## Unreleased

- ask Syncthing to rescan a directory only once while that rescan is still
running, so repeated index updates during a pull cannot pile up requests
- keep the syncing file name visible during bulk syncs: the core no longer
stalls for up to minutes on lookups and rescans for files Syncthing already
reported, and the Omarchy folder card no longer rebuilds on each update
Expand Down
Binary file modified bin/aarch64/syncshell-core
Binary file not shown.
Binary file modified bin/x86_64/syncshell-core
Binary file not shown.
36 changes: 32 additions & 4 deletions core/internal/session/activity.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,37 @@ func (s *Session) rememberFinished(folderID, path string, now time.Time) {
s.finishedItems[folderID+"\x00"+path] = now.Add(finishedItemMemory)
}

// rescanSubdirectory runs in the background: Syncthing answers only once the
// scan ends, which waits for any pull. A directory already being rescanned is
// not asked again, so repeated index events cannot pile up requests.
func (s *Session) rescanSubdirectory(ctx context.Context, folderID, subdirectory string) {
key := folderID + "\x00" + subdirectory
s.rescansMu.Lock()
if s.rescansInFlight[key] {
s.rescansMu.Unlock()
return
}
if s.rescansInFlight == nil {
s.rescansInFlight = make(map[string]bool)
}
s.rescansInFlight[key] = true
s.rescansMu.Unlock()
go func() {
defer func() {
s.rescansMu.Lock()
delete(s.rescansInFlight, key)
s.rescansMu.Unlock()
}()
_ = s.client.RescanSubdirectory(ctx, folderID, subdirectory)
}()
}

func (s *Session) rescanInFlight(folderID, subdirectory string) bool {
s.rescansMu.Lock()
defer s.rescansMu.Unlock()
return s.rescansInFlight[folderID+"\x00"+subdirectory]
}

func (s *Session) localIndex(ctx context.Context, event syncthing.Event, now time.Time) bool {
var data struct {
Folder string `json:"folder"`
Expand Down Expand Up @@ -151,10 +182,7 @@ func (s *Session) localIndex(ctx context.Context, event syncthing.Event, now tim
continue
}
if fileType(entry.Type) == "directory" && !entry.Deleted {
// Syncthing answers only once the scan ends, which waits for any pull.
go func(folderID, subdirectory string) {
_ = s.client.RescanSubdirectory(ctx, folderID, subdirectory)
}(data.Folder, name)
s.rescanSubdirectory(ctx, data.Folder, name)
continue
}
action := "syncing"
Expand Down
35 changes: 35 additions & 0 deletions core/internal/session/events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -617,3 +617,38 @@ func cancelEventUpdates(
t.Fatal("event loop did not cancel")
}
}

func TestSubdirectoryRescanIsNotRepeatedWhileInFlight(t *testing.T) {
api := &actionAPI{folders: map[string]syncthing.Folder{},
devices: []syncthing.Device{{DeviceID: "LOCAL"}},
pending: syncthing.PendingFolders{}, theme: "default",
rescanStarted: make(chan struct{}, 1), rescanRelease: make(chan struct{})}
coreSession := newActionSession(t, api)
ctx := context.Background()
coreSession.rescanSubdirectory(ctx, "folder", "directory")
select {
case <-api.rescanStarted:
case <-time.After(2 * time.Second):
t.Fatal("first rescan never reached Syncthing")
}
// Still blocked in Syncthing: the same directory is not asked again.
coreSession.rescanSubdirectory(ctx, "folder", "directory")
close(api.rescanRelease)
for deadline := time.Now().Add(2 * time.Second); coreSession.rescanInFlight("folder", "directory"); {
if time.Now().After(deadline) {
t.Fatal("finished rescan stayed in flight")
}
time.Sleep(5 * time.Millisecond)
}
if count := api.rescanCount(); count != 1 {
t.Fatalf("rescans while one was in flight: %d", count)
}
// Once it has finished, the directory can be rescanned again.
coreSession.rescanSubdirectory(ctx, "folder", "directory")
for deadline := time.Now().Add(2 * time.Second); api.rescanCount() != 2; {
if time.Now().After(deadline) {
t.Fatalf("a later rescan was dropped: %d", api.rescanCount())
}
time.Sleep(5 * time.Millisecond)
}
}
2 changes: 2 additions & 0 deletions core/internal/session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ type Session struct {
activityMu sync.Mutex
activityRecords map[string]activityRecord
finishedItems map[string]time.Time
rescansMu sync.Mutex
rescansInFlight map[string]bool
lastFile *Activity
lastFileUntil time.Time
activityIndex int
Expand Down
75 changes: 56 additions & 19 deletions hosts/omarchy/OmarchyPanel.qml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
pragma ComponentBehavior: Bound

import QtQuick
import QtQuick.Window
import Quickshell
import Quickshell.Io
import qs.Commons
Expand Down Expand Up @@ -826,31 +827,67 @@ Panel {
onTriggered: root.showBarTooltip()
}

BarIconButton {
// WidgetButton, not BarIconButton: the host fits the mark's width, which
// includes the side nodes, so its ring would draw smaller than round glyphs.
// Sizing the ring to the theme's icon size keeps it optically level.
WidgetButton {
id: button
anchors.fill: parent
bar: root.bar
iconComponent: Component {
Item {
opacity: root.syncthing && root.syncthing.online ? 1.0 : 0.55

// Keep the effect warm under the brand icon for reliable live switches.
SharedWidgetMonoIcon {
anchors.fill: parent
source: root.themedIconSource
tint: button.foreground
}
labelVisible: false
hasVisualContent: true
fixedWidth: vertical ? -1 : Style.bar.iconSlot
fixedHeight: vertical ? Style.bar.iconSlot : -1

Item {
id: iconBox
// A raster drawn at fractional device pixels is resampled and blurs,
// so size and place it on whole pixels. Qt's Screen ratio is
// integral; the window carries the fractional one.
readonly property real dpr: Window.window ? Window.window.devicePixelRatio : 1
// The mono view box is 14.5 units; the ring spans 13.31 of them. The
// branded disc shares the box so both styles read the same size.
readonly property real logicalSize: Style.bar.iconSize * 14.5 / 13.31
property real snapX: 0
property real snapY: 0

function align() {
var p = button.mapToItem(null, (button.width - width) / 2, (button.height - height) / 2);
snapX = Math.round(p.x * dpr) / dpr - p.x;
snapY = Math.round(p.y * dpr) / dpr - p.y;
}

Image {
anchors.fill: parent
source: root.syncthingIconSource
sourceSize.width: width
sourceSize.height: height
fillMode: Image.PreserveAspectFit
smooth: true
visible: !root.themedIcon
width: Math.round(logicalSize * dpr) / dpr
height: width
x: (button.width - width) / 2 + snapX
y: (button.height - height) / 2 + snapY
scale: button.pressScale
opacity: root.syncthing && root.syncthing.online ? 1.0 : 0.55

// The bar moves widgets as neighbours resize; re-snap before each frame.
Connections {
target: iconBox.Window.window
function onAfterAnimating() {
iconBox.align();
}
}

// Keep the effect warm under the brand icon for reliable live switches.
SharedWidgetMonoIcon {
anchors.fill: parent
source: root.themedIconSource
tint: button.foreground
}

Image {
anchors.fill: parent
source: root.syncthingIconSource
sourceSize.width: width
sourceSize.height: height
fillMode: Image.PreserveAspectFit
smooth: true
visible: !root.themedIcon
}
}
active: root.hasProblems
tooltipText: ""
Expand Down
4 changes: 3 additions & 1 deletion hosts/omarchy/ui/SharedDialogConfirm.qml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ Item {

property bool opened: false
property string message: ""
// StyledText callers must escape any user data they embed.
property int messageFormat: Text.PlainText
property string cancelText: "Cancel"
property string confirmText: "Confirm"
property int selectedIndex: 1
Expand Down Expand Up @@ -68,7 +70,7 @@ Item {
anchors.right: parent.right
anchors.top: parent.top
text: root.message
textFormat: Text.PlainText
textFormat: root.messageFormat
color: root.foreground
font.family: root.fontFamily
font.pixelSize: Style.font.body
Expand Down
11 changes: 8 additions & 3 deletions hosts/omarchy/ui/SyncshellPanelPopup.qml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ KeyboardPanel {
return rows;
}

function escapeStyled(value) {
return String(value || "").replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
}

function resetKeyboardCursor() {
cursorActive = false;
cursorAction = null;
Expand Down Expand Up @@ -521,11 +525,12 @@ KeyboardPanel {
if (!folder)
return "Change this folder?";
if (root.controller.folderConfirmAction === "link")
return "Link " + folder.label + " (" + folder.id + ")?\n\nSyncthing will resume synchronization for this folder.";
return "Link folder: <b>" + root.escapeStyled(folder.label) + "</b> (folder ID: " + root.escapeStyled(folder.id) + ")?<br><br>Syncthing will resume synchronization for this folder.";
if (root.controller.folderConfirmAction === "unlink")
return "Unlink " + folder.label + " (" + folder.id + ")?\n\nSyncthing will pause synchronization. Its configuration " + "and local files remain.";
return "Forget " + folder.label + " (" + folder.id + ")?\n\n" + "This removes only its Syncthing configuration. The " + "directory and data files will not be deleted. " + (folder.markerName === ".stfolder" ? "Syncthing will also attempt to remove its internal " + ".stfolder marker. " : "") + "Rejoining the same remote folder requires this exact " + "Folder ID.";
return "Unlink folder: <b>" + root.escapeStyled(folder.label) + "</b> (folder ID: " + root.escapeStyled(folder.id) + ")?<br><br>Syncthing will pause synchronization. Its configuration " + "and local files remain.";
return "Forget folder: <b>" + root.escapeStyled(folder.label) + "</b> (folder ID: " + root.escapeStyled(folder.id) + ")?<br><br>" + "This removes only its Syncthing configuration. The " + "directory and data files will not be deleted. " + (folder.markerName === ".stfolder" ? "Syncthing will also attempt to remove its internal " + ".stfolder marker. " : "") + "Rejoining the same remote folder requires this exact " + "Folder ID.";
}
messageFormat: ["link", "unlink", "forget"].indexOf(root.controller.folderConfirmAction) >= 0 ? Text.StyledText : Text.PlainText
confirmText: root.controller.folderConfirmAction === "create" ? "Create and add" : "Yes"
cancelText: root.controller.folderConfirmAction === "create" ? "Cancel" : "No"
background: Commons.Color.popups.background
Expand Down
4 changes: 2 additions & 2 deletions packaging/bundled/SHA256SUMS
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
314a89c32525c5b746f50a52b65967ed301e11f12bbbf5f3d44e387a10d540fc bin/syncshell-core
583506f451c0d0b5d090b43e4e7a6a3a760e256b1342fe08bd88a37831b6c25e bin/x86_64/syncshell-core
1b9b1efa912ed1b96420d5c2c6ab70bb6d4b194d5f0930d6916e6d23cf9edf02 bin/aarch64/syncshell-core
2b441a4caa43466eef0153dfd4b47a5fb19c21909a6a1fed37ba614cd2bf49c0 bin/x86_64/syncshell-core
15b98c1a07cbf67b7e634d117d698425dc89ba6d51f8663b31864eb3550bb4ce bin/aarch64/syncshell-core
Loading