Nit: this conditional block is nearly identical to the one for packaged apps; might we be able to factor out more of it?