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

[Issue] How lazy load ags? Or make sure that the options in ags change without restarting #633

Open
sh1zicus opened this issue Nov 19, 2024 · 1 comment

Comments

@sh1zicus
Copy link

my ags takes quite a long time to start, 5-7 seconds,
I have a gjs script that switches options in modules and after that ags should restart.
Is it possible to somehow load some modules lazily or change module options in ags without restarting it?

@Aylur
Copy link
Owner

Aylur commented Nov 22, 2024

5-7 seconds

sounds like you have some expensive blocking operation that should be reworked

load some modules lazily

making use of the bundler you can do something like this

// a.js
console.log("some very heavy operation")
export const value = "value";
// b.js
async function getValue() {
  const { value } = await import("./a.js") // load the module async
}

but if you statically import it in any module, it will still be evaluated at startup though

import { value } from "./a.js"

all this does is just wrap your module in a function, which might not be what you want
since you did not provide much context, my guess is you have some exec("heavy-operation") that takes too long, you should use execAsync instead.

If all you want to do is to change some values at runtime you can use the cli client

// options.js
export const options = {
  opt: Variable("value")
}

// app.tsx
import { options } from "./options"

App.start({
  requestHandler(req, res) {
    const [cmd, opt, value] = req.split(" ")
    if (cmd == "set") {
      options[opt].set(value)
      return res("ok")
    }
    res("unknown command")
  }
  main() {
    return <window>
      <label label={options.opt()} />
    </window>
  }
})
astal set opt "new value"

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