Skip to content
Closed
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
6 changes: 5 additions & 1 deletion shell/plugins/panels/dropbox/Service.qml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ Item {
property string lastError: ""

readonly property int refreshIntervalSec: intSetting("refreshIntervalSec", 60, 10, 3600)
// 0 leaves the plan lookup in charge. Accounts carrying bonus space have a
// real quota the plan name cannot describe, so they set this to correct it.
// Megabytes, not bytes: a quota in bytes overflows a QML int.
readonly property int quotaOverrideMB: intSetting("quotaOverrideMB", 0, 0, 2000000000)
readonly property bool busy: statusProcess.running || loginProcess.running || controlProcess.running
readonly property string helperPath: (omarchyPath || "") + "/shell/plugins/panels/dropbox/status.py"

Expand Down Expand Up @@ -61,7 +65,7 @@ Item {
_statusOutput = ""
_statusError = ""
refreshing = true
statusProcess.command = ["python3", helperPath, "25"]
statusProcess.command = ["python3", helperPath, "25", String(quotaOverrideMB)]
statusProcess.running = true
}

Expand Down
12 changes: 11 additions & 1 deletion shell/plugins/panels/dropbox/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"allowMultiple": false,
"defaultSection": "right",
"defaults": {
"refreshIntervalSec": 60
"refreshIntervalSec": 60,
"quotaOverrideMB": 0
},
"schema": [
{
Expand All @@ -30,6 +31,15 @@
"max": 3600,
"step": 5,
"defaultValue": 60
},
{
"key": "quotaOverrideMB",
"type": "integer",
"label": "Storage quota override (MB, 0 for plan default)",
"min": 0,
"max": 2000000000,
"step": 100,
"defaultValue": 0
}
]
}
Expand Down
20 changes: 19 additions & 1 deletion shell/plugins/panels/dropbox/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
from pathlib import Path


# What a plan ships with, which is not always what an account has. Bonus space
# — referral bonuses on Basic, storage add-ons on the paid tiers — raises the
# real quota permanently, and `subscription_type` still reads "Basic". Nothing
# the local daemon exposes reveals the true figure, so these are a starting
# point that `quota_override_bytes` can correct.
PLAN_QUOTAS = {
"basic": 2_000_000_000,
"plus": 2_000_000_000_000,
Expand Down Expand Up @@ -80,6 +85,18 @@ def scan_dropbox(path, limit):
return total, rows


def quota_override_bytes(raw):
"""Megabytes from the widget's quotaOverrideMB setting, as a byte count.

Returns 0 for anything unusable, which leaves PLAN_QUOTAS in charge.
"""
try:
megabytes = int(raw)
except (TypeError, ValueError):
return 0
return megabytes * 1_000_000 if megabytes > 0 else 0


def main():
limit = 25
if len(sys.argv) > 1:
Expand All @@ -93,7 +110,8 @@ def main():
account = dropbox_account(info)
account_path = account.get("path") if isinstance(account.get("path"), str) else ""
plan = account.get("subscription_type") if isinstance(account.get("subscription_type"), str) else ""
quota = PLAN_QUOTAS.get(plan.lower(), 0)
override = quota_override_bytes(sys.argv[2] if len(sys.argv) > 2 else 0)
quota = override or PLAN_QUOTAS.get(plan.lower(), 0)
authenticated = account_path != "" and Path(account_path).exists()

running = False
Expand Down
33 changes: 33 additions & 0 deletions test/shell.d/dropbox-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,36 @@ assertEqual(
'dropbox file metadata includes relative time and folder'
)
JS

require_command python3

# The plan table describes what a plan ships with, so an account carrying bonus
# space needs the override to win. Everything unusable has to defer to the
# table instead, since a broken setting must not blank out the quota.
read_override() {
HELPER="$ROOT/shell/plugins/panels/dropbox/status.py" RAW="$1" python3 - <<'PY'
import importlib.machinery, importlib.util, os

loader = importlib.machinery.SourceFileLoader("status", os.environ["HELPER"])
spec = importlib.util.spec_from_loader(loader.name, loader)
status = importlib.util.module_from_spec(spec)
loader.exec_module(status)

print(status.quota_override_bytes(os.environ["RAW"]))
PY
}

assert_override() {
local raw=$1 expected=$2 description=$3
local actual

actual=$(read_override "$raw")
[[ $actual == "$expected" ]] || fail "$description" "expected $expected, got $actual"
pass "$description"
}

assert_override 21380 21380000000 "dropbox override reads megabytes as bytes"
assert_override 0 0 "dropbox override of zero defers to the plan table"
assert_override -5 0 "dropbox override refuses negative megabytes"
assert_override "" 0 "dropbox override ignores a blank setting"
assert_override "lots" 0 "dropbox override ignores a non-numeric setting"