Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable refresh delay for stylesheets when using inject and override remote CSS #707

Open
maxwellhibbert opened this issue Sep 19, 2023 · 4 comments

Comments

@maxwellhibbert
Copy link

When working on a remote server with a refresh delay and overriding CSS, it'd be great to not have any delay for stylesheet injection.

@bdkjones
Copy link
Owner

The issue is that while 80% of the use-case for the delay feature is working with an external server that's remote and requires an upload, there ARE other reasons to use the delay. Over the years, I've seen complex setups with certain CMSes that need a moment when files change, users working on network drives with latency, folks hosting their websites on a Synology NAS, etc.

So there ARE still cases where people would want the delay even when overriding remote CSS with a local copy.

As a workaround, I'd recommend this:

  1. Turn off the delay. This will make sure your stylesheets are reloaded immediately after they finish compiling.

  2. Add a Hook (codekitapp.com/help/hooks) that uses CodeKit's scripting API to issue a browser refresh command after X seconds. Assign this hook to run only when page-like files change (*.html, *.php, etc.)

When you save a page-like file, CodeKit will immediately reload the browsers once (but no changes will appear because the file hasn't finished uploading to your remote server yet). But the second refresh call from your Hook will get the job done. This essentially lets you apply the delay only when you need it.

@maxwellhibbert
Copy link
Author

Thanks for the explanation and workaround suggestion, I think that’ll work nicely for now 👍

@maxwellhibbert
Copy link
Author

maxwellhibbert commented Sep 20, 2023

The AppleScript to refresh works with the delay when executing from anywhere other than the CK hook, otherwise it fires right after the first refresh.

tell application "CodeKit"
	refresh browsers by reloading the whole page after delay 5
end tell

@bdkjones
Copy link
Owner

Ha, of course it does. So the issue is that AppleScript must run on the main thread. If you do this:

delay 5

tell application "CodeKit"
  refresh browsers by reloading the whole page
end tell

You'll get the delay you're after, but CodeKit will hang for 5 seconds because the main thread is tied up running the AppleScript command (which includes the delay). Apparently, 2012 Bryan was smart enough to recognize that a Hook calling the refresh command with the delay parameter would hang the UI, so the delay parameter is ignored there.

You may have better luck using the osascript -e command in a Bash script Hook. CodeKit executes bash Hooks on a background thread, so the UI should remain responsive, but you'll still likely see the "processing..." bar across the bottom of the app for five seconds because the Hook won't finish running until the delay completes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants