Skip to content
Open
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
23 changes: 23 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
description = "clipse dev shell";

inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";

outputs = { self, nixpkgs }: let
system = "x86_64-linux";
pkgs = nixpkgs.legacyPackages.${system};
in {
devShells.${system}.default = pkgs.mkShell {
buildInputs = with pkgs; [
go
gnumake
];

shellHook = ''
echo "clipse dev shell ready"
echo " make wayland → Wayland build"
echo " make x11 → X11 build"
'';
};
};
}
5 changes: 4 additions & 1 deletion handlers/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

func SaveImage(imgData []byte) error {
if !utils.DiskspaceAvailable(len(imgData)) {
if !utils.DiskspaceAvailable(len(imgData), config.ClipseConfig.TempDirPath) {
return fmt.Errorf("no available disk space to store image")
}

Expand All @@ -33,6 +33,9 @@ func SaveImage(imgData []byte) error {
}

func SaveText(textData string) error {
if !utils.DiskspaceAvailable(len(textData), config.ClipseConfig.HistoryFilePath) {
return fmt.Errorf("no available disk space to store text")
}
if err := config.AddClipboardItem(textData, "null"); err != nil {
return err
}
Expand Down
4 changes: 4 additions & 0 deletions handlers/wayland.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ func StoreWLData() {
if inputStr == "" {
return
}
if !utils.DiskspaceAvailable(len(inputStr), config.ClipseConfig.HistoryFilePath) {
utils.LogERROR("no available disk space to store text")
return
}
if err := config.AddClipboardItem(inputStr, "null"); err != nil {
utils.LogERROR(fmt.Sprintf("failed to add new item `( %s )` | %s", input, err))
}
Expand Down
13 changes: 9 additions & 4 deletions utils/disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,19 @@ import (
"golang.org/x/sys/unix"
)

func DiskspaceAvailable(bytes int) bool {
// path ex. config.ClipseConfig.HistoryFilePath, config.ClipseConfig.TempDirPath, defaults to "/"
func DiskspaceAvailable(bytes int, path ...string) bool {
checkPath := "/"
if len(path) > 0 {
checkPath = path[0]
}

var stat unix.Statfs_t
if err := unix.Statfs("/", &stat); err != nil {
if err := unix.Statfs(checkPath, &stat); err != nil {
LogERROR(fmt.Sprintf("failed to check disk space: %s", err))
return true
}

bytefree := (stat.Bavail * uint64(stat.Bsize))
bytefree := stat.Bavail * uint64(stat.Bsize)

return bytefree > (uint64(bytes) * 2) // *2 for safety buffer
}