From 537db89a828dc6fdd3729154dc7300daed0c415e Mon Sep 17 00:00:00 2001 From: kepler155c Date: Sat, 24 Nov 2018 14:16:44 -0500 Subject: [PATCH] milo autorun programs --- milo/MiloRemote.lua | 18 +++++++++++++++++- milo/apps/furni.lua | 8 ++++++++ milo/autorun/milo.lua | 2 -- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/milo/MiloRemote.lua b/milo/MiloRemote.lua index c4637da..3434260 100644 --- a/milo/MiloRemote.lua +++ b/milo/MiloRemote.lua @@ -9,10 +9,12 @@ local Util = require('util') local colors = _G.colors local device = _G.device +local fs = _G.fs local os = _G.os local socket -local SHIELD_SLOT = 2 +local SHIELD_SLOT = 2 +local STARTUP_FILE = 'usr/autorun/miloRemote.lua' local config = Config.load('miloRemote', { displayMode = 0 }) @@ -139,6 +141,10 @@ local page = UI.Page { formLabel = 'Shield Slot', formKey = 'useShield', help = 'Or, use the shield slot for sending' }, + [4] = UI.Checkbox { + formLabel = 'Run on startup', formKey = 'runOnStartup', + help = 'Run this program on startup' + }, info = UI.TextArea { x = 1, ex = -1, y = 6, ey = -4, textColor = colors.yellow, @@ -307,6 +313,16 @@ function page:eventHandler(event) self.grid:draw() self:setFocus(self.statusBar.filter) + if config.runOnStartup then + if not fs.exists(STARTUP_FILE) then + Util.writeFile(STARTUP_FILE, + [[os.sleep(1) +shell.openForegroundTab('packages/milo/MiloRemote')]]) + end + elseif fs.exists(STARTUP_FILE) then + fs.delete(STARTUP_FILE) + end + elseif event.type == 'form_cancel' then self.setup:hide() self:setFocus(self.statusBar.filter) diff --git a/milo/apps/furni.lua b/milo/apps/furni.lua index 21244a4..188519c 100644 --- a/milo/apps/furni.lua +++ b/milo/apps/furni.lua @@ -21,10 +21,13 @@ local Peripheral = require('peripheral') local Util = require('util') local device = _G.device +local fs = _G.fs local os = _G.os local peripheral = _G.peripheral local turtle = _G.turtle +local STARTUP_FILE = 'usr/autorun/miloFurni.lua' + local function equip(side, item, rawName) local equipped = Peripheral.lookup('side/' .. side) @@ -50,6 +53,11 @@ local intro = device['plethora:introspection'] local inv = intro.getInventory() local sides = { 'front', 'back', 'right', 'top' } +if not fs.exists(STARTUP_FILE) then + Util.writeFile(STARTUP_FILE, + [[os.sleep(1) +shell.openForegroundTab('packages/milo/apps/furni')]]) +end -- slot 1: item to cook -- slot 2: fuel -- slot 3: return diff --git a/milo/autorun/milo.lua b/milo/autorun/milo.lua index 3304f36..91e9f22 100644 --- a/milo/autorun/milo.lua +++ b/milo/autorun/milo.lua @@ -3,6 +3,4 @@ local shell = _ENV.shell if device.workbench then shell.openForegroundTab('Milo') -elseif device.neuralInterface then - shell.openForegroundTab('MiloRemote') end