Skip to content

Commit

Permalink
Smooth progress bar animations
Browse files Browse the repository at this point in the history
  • Loading branch information
dtcooper committed Aug 15, 2023
1 parent af6979b commit 7c6f572
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 16 deletions.
10 changes: 6 additions & 4 deletions client/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,15 +295,17 @@ if (squirrelCheck || !singleInstanceLock) {
"org.freedesktop.portal.Settings",
function (err, notifications) {
notifications.Read("org.freedesktop.appearance", "color-scheme", function (err, resp) {
console.log("Current color-scheme", resp[1][0][1][0])
nativeTheme.themeSource = resp[1][0][1][0] ? "dark" : "light"
const colorScheme = resp[1][0][1][0] ? "dark" : "light"
nativeTheme.themeSource = colorScheme
console.log("(linux) Set initial color scheme to", colorScheme)
})

// dbus signals are EventEmitter events
notifications.on("SettingChanged", function () {
if (arguments["0"] == "org.freedesktop.appearance" && arguments["1"] == "color-scheme") {
nativeTheme.themeSource = arguments["2"][1][0] ? "dark" : "light"
console.log("SettingChanged", arguments)
const colorScheme = arguments["2"][1][0] ? "dark" : "light"
nativeTheme.themeSource = colorScheme
console.log("(linux) Updated color scheme to", colorScheme)
}
})
}
Expand Down
7 changes: 4 additions & 3 deletions client/src/main/Player.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
const addStopset = () => {
// Prepend a full wait interval IF:
// There's nothing in the items list, or the previous item is a stopset
// Happens on app start, and when a wait interval is enabled (having previously been 0)
// Happens on app start, and when a wait interval is skipped or enabled (having previously been 0)
if ($config.WAIT_INTERVAL > 0 && (items.length === 0 || items[items.length - 1].type === "stopset")) {
items.push(new Wait($config.WAIT_INTERVAL, doneWaiting, updateUI))
}
Expand All @@ -76,7 +76,9 @@
$config.WAIT_INTERVAL_SUBTRACTS_FROM_STOPSET_PLAYTIME_MIN_LENGTH
)
}
items.push(new Wait(duration, doneWaiting, updateUI))
if (duration > 0) {
items.push(new Wait(duration, doneWaiting, updateUI))
}
}
} else {
console.warn("Couldn't generate a stopset!")
Expand Down Expand Up @@ -146,7 +148,6 @@
if (nextItem.type === "wait") {
nextItem.run()
} else if (nextItem.type === "stopset" && (play || (IS_DEV && $userConfig.autoplay))) {
console.log("processItem(): playing first stopset")
nextItem.play()
}
}
Expand Down
2 changes: 1 addition & 1 deletion client/src/main/SettingsModal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
<div class="flex items-center justify-end text-lg font-bold">Power save blocker:</div>
<div
class="tooltip tooltip-warning tooltip-bottom flex w-max items-center justify-center gap-4 text-xl"
data-tip="When on, attempts to suppress your display from going to sleep and your system from suspending while Tomato is running"
data-tip="When set to ON, Tomato attempts to suppress your display from going to sleep and your system from suspending"
>
<span class="font-bold" class:text-error={!$userConfig.powerSaveBlocker}>OFF</span>
<input type="checkbox" class="toggle toggle-success toggle-lg" bind:checked={$userConfig.powerSaveBlocker} />
Expand Down
2 changes: 1 addition & 1 deletion client/src/main/player/Bar.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
await tick()
if (el.clientWidth - el.firstChild.clientWidth - 10 < 0) {
el.firstChild.remove()
console.log("too big!")
console.log("Duration for element too big! Hiding.")
}
}
</script>
Expand Down
2 changes: 1 addition & 1 deletion client/src/stores/client-logs.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const sendPendingLogs = (forceClear = false) => {
if (authenticated && connected) {
for (const [id, data] of entries) {
messageServer("log", { id, ...data })
console.log("Sending", { id, ...data })
console.log("Sending log:", { id, ...data })
}
}
}
Expand Down
1 change: 0 additions & 1 deletion client/src/stores/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export const setServerConfig = ({ _numeric: numeric, ...newConfig }) => {
console.log("Got new config", newConfig)

if (newConfig.UI_MODES && newConfig.UI_MODES.indexOf(get(userConfig).uiMode) === -1) {
console.log(get(userConfig).uiMode)
userConfig.update(($userConfig) => {
return { ...$userConfig, uiMode: Math.min(newConfig.UI_MODES) }
})
Expand Down
1 change: 0 additions & 1 deletion client/src/stores/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { acknowledgeLog, log, sendPendingLogs } from "./client-logs"
import { resetUserConfig, setServerConfig } from "./config"
import { clearAssetsDB, clearSoftIgnoredAssets, syncAssetsDB } from "./db"

// TODO this is a mess, connecting + connected SHOULD NOT be persisted, they are ephemeral
const connPersisted = persisted("conn", {
username: "",
password: "",
Expand Down
1 change: 0 additions & 1 deletion client/src/stores/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ class Asset extends AssetStopsetHydratableObject {
tmpPath,
tmpBasename: path.basename(tmpPath)
}
// TODO: override weight via END_DATE_PRIORITY_WEIGHT_MULTIPLIER
}

async download() {
Expand Down
16 changes: 14 additions & 2 deletions client/src/stores/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ let compressorEnabled = false
let currentGeneratedId = 0
const audioContext = new AudioContext()

const progressBarAnimationFramerate = 30

const inputNode = audioContext.createGain()
inputNode.gain.value = 1
inputNode.connect(audioContext.destination)
Expand Down Expand Up @@ -81,6 +83,7 @@ class PlayableAsset extends GeneratedStopsetAssetBase {
this.playable = true
this.audio = null
this.error = false
this.interval = null
this._duration = duration
this.didSkip = false
this.didLogError = false
Expand Down Expand Up @@ -134,6 +137,7 @@ class PlayableAsset extends GeneratedStopsetAssetBase {
}

unloadAudio() {
clearInterval(this.interval)
if (this.audio) {
this.audio.ondurationchange = this.audio.ontimeupdate = this.audio.onended = this.audio.onended = null
this.audio.pause()
Expand Down Expand Up @@ -172,11 +176,19 @@ class PlayableAsset extends GeneratedStopsetAssetBase {
} else {
this.playing = true
this.audio.play().catch((e) => this._errorHelper(e))
clearInterval(this.interval)
this.interval = setInterval(() => {
if (this.audio) {
this._elapsed = this.audio.currentTime
this.updateCallback()
}
}, progressBarAnimationFramerate)
}
this.updateCallback()
}

done() {
clearInterval(this.interval)
log(
this.didSkip ? "skipped_asset" : "played_asset",
`[Stopset=${this.generatedStopset.name}] [Rotator=${this.rotator.name}] [Asset=${this.name}]`
Expand All @@ -191,6 +203,7 @@ class PlayableAsset extends GeneratedStopsetAssetBase {
}

pause() {
clearInterval(this.interval)
this.playing = false
this.audio.pause()
this.updateCallback()
Expand Down Expand Up @@ -284,7 +297,6 @@ export class GeneratedStopset {
this.playing = false
this.unloadAudio()
if (!skipCallback) {
console.log("calling done callback")
this.doneCallback()
}
if (!this.didLog) {
Expand Down Expand Up @@ -345,7 +357,7 @@ export class Wait {
this.doneCountdown()
}
this.updateCallback()
}, 50)
}, progressBarAnimationFramerate)
}

doneCountdown() {
Expand Down
1 change: 0 additions & 1 deletion server/ws_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ async def broadcast_data_change(cls, single_websocket=None):
await asyncio.sleep(0.5)

subscribers = cls.subscribers.keys() if single_websocket is None else (single_websocket,)
# TODO: convert numeric types to ints or floats
json_data = json.dumps({"type": "data", "data": app.state.data}, cls=DjangoJSONEncoder)
num_broadcasted_to = 0

Expand Down

0 comments on commit 7c6f572

Please sign in to comment.