Self Updating App

Can anyone post here a super simple code that “writes itself” by checking a Url ??? Ty :smiley:

The ticket I think is here:

https://bitbucket.org/TwoLivesLeft/core/issues/235/listproject

I found it a while back and upvoted it, so please do the same if you’d like to see this added (this could perhaps impinge slightly on Apple guidelines, but no harm in upvoting I think. Pythonista is allowed to do this, not that that means anything: Apple is nothing if not maddeningly inconsistent)

Have a look at the installer for AutoGist, here:

https://gist.github.com/briarfox/5762703

@yojimbo2000 thanks ! :slight_smile:

You could probably simplify the above code quite a bit. For one thing, Codea now has json.encode and json.decode built in, so you wouldn’t need the first step of grabbing the json library. I think json is being used here for a table that stores the order of tabs (presumably for multifile gists). But I don’t think you would need that if all the tabs were in a single file, you could just save them in the order they’re found in the file. Essentially you write code that replicates Codea’s “paste into project” function.

Ok, here’s my super simple installer. It’s for files in Codea’s copy/paste-into-project format. The gmatch replicates the paste-into-format operation.

--Installer
--Known issue: the code being installed should have its Main tab as the left-most tab

local function success(data)
    data = data.."--# " --add new file tag to end in order to capture last file
    for name, file in data:gmatch("(%w+)\
(.-)\
%-%-%# ") do
        saveProjectTab(name, file)
        print("Saved", name)
    end
    load(data)() --load the file
    setup() --run it
end

local function failure(error)
    print("Error", error)
end

http.request("https://raw.githubusercontent.com/Utsira/Codea-OBJ-Importer/master/Codea%202_3_2%20OBJ%20Importer%20Installer.lua", success, failure)

Hmmm, the URL in the above code should have %20 space encoding, seemed to get lost when I cut and pasted. Hope it works without them.

@yojimbo2000 oh! that “simplification” helped me a lot … ty :smiley:

Installers and file-handling operations such as these would be so much more powerful if we could programmatically create new projects and list current projects. A listProjects and newProject command. It would mean that programs could automatically install any missing dependency libraries. Perhaps this would be skirting the rules of what Apple allows, but Pythonista can do this, and people have created very powerful library browsing/ installing programs.

@yojimbo2000 I’ve ask for something like listProjects and newProjects at least 2-3 years ago. I’m still waiting. PS. I found where I listed it in the issue tracker for May 2013.

Well, let’s start up voting it

Creating a function that lists the projects shouldn’t be a problem because Codea is already doing it by showing all the projects on the Codea startup page. And I don’t see a problem with creating a project because the apps are kept in their own area. The only problem might be creating projects in an endless loop. If that’s a problem, there could be a maxCreate variable that has a default limit of maybe 10, but it could be changed if needed.

A slightly different version of the above code that first checks whether there is a --# Main tab:

--Installer
--Known issue: the code being installed should have its Main tab as the left-most tab

local function success(data)
    if data:find("%-%-%# Main") then --paste-into-project format
        data = data.."--# " --add new file tag to end in order to capture last file
        for name, file in data:gmatch("(%w+)\
(.-)\
%-%-%# ") do --capture each name and file
            saveProjectTab(name, file)
            print("Saved", name)
        end
    else --put it all in one tab
        saveProjectTab("Main", data)
    end
    load(data)() --load the file
    setup() --run it
end

local function failure(error)
    print("Error", error)
end

http.request("https://raw.githubusercontent.com/Utsira/Codea-OBJ-Importer/master/Codea%202_3_2%20OBJ%20Importer%20Installer.lua", success, failure)

Quick question for the community:

When creating installers like this, is it possible to change the position of the Main tab? For every other tab, they appear in the order that you save them in. But, I think because the Main tab already exists in the project, Main always ends up in the far left, even if it is, say, the third tab to be saved. This means that it seems you can’t make proper installers for programs where the Main tab cannot be (for various reasons) on the far left. Can anyone with experience of installer-creation confirm whether it’s possible to have the Main tab appear in the correct position?

thanks

@yojimbo2000 upvoted :slight_smile:
Seem’s crazy that those two functions are missing. I’m going to try and work on a dropbox backup / restore app and a local tool that will run on Lua on a PC to prepare a file for restoring.

You’re right we could have a really nice backup to / from dropbox solution with those functions.