Skip to content
This repository was archived by the owner on Mar 24, 2025. It is now read-only.

Commit d946c9e

Browse files
committed
update system for windows
1 parent 320c5fa commit d946c9e

File tree

5 files changed

+214
-5
lines changed

5 files changed

+214
-5
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
return function (Name, FileName)
2+
local Http = require("coro-http")
3+
local Json = require("json")
4+
local ProgressBar = require("ProgressBar")
5+
6+
local Response, Body = Http.request(
7+
"HEAD",
8+
string.format(
9+
"https://github.com/%s/releases/latest/download/%s",
10+
Name,
11+
FileName
12+
),
13+
{
14+
{"user-agent", "typewriter-installer"}
15+
}
16+
)
17+
18+
19+
local Response, Body = Http.request(
20+
"HEAD",
21+
Response[6][2],
22+
{
23+
{"user-agent", "typewriter-installer"}
24+
},
25+
nil,
26+
{followRedirects = true}
27+
)
28+
29+
30+
31+
return Response[6][2]
32+
33+
34+
end

TypeWriter/Actions/Update/Init.lua

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
local Logger = require("Logger")
2+
local Http = require("coro-http")
3+
local Json = require("json")
4+
local FS = require("fs")
5+
6+
function GetLatest(RepoName)
7+
local ResponseData, RawData = Http.request("GET", "https://api.github.com/repos/" .. RepoName .. "/releases", {{"user-agent", "TypeWriter updater"}})
8+
local UnpackedData = Json.decode(RawData)
9+
10+
return UnpackedData[1].tag_name
11+
end
12+
13+
return function(Args)
14+
15+
Logger.Info("Loading...")
16+
17+
local CurrentTag = FS.readFileSync(RuntimePath .. "/Config/Version.dont_change")
18+
19+
local Response, RawData = Http.request("GET", "https://api.github.com/repos/Dot-Lua/TypeWriter/releases", {{"user-agent", "typewriter"}})
20+
local Data = Json.decode(RawData)
21+
22+
local RemoteTag = Data[1].tag_name
23+
24+
Logger.Info("Remote tag is " .. RemoteTag)
25+
Logger.Info("Current tag is " .. CurrentTag)
26+
27+
28+
if CurrentTag ~= RemoteTag then
29+
Logger.Info("Updating in 5 seconds")
30+
require("timer").sleep(5000)
31+
local Response, Body = Http.request("GET", require(RuntimePath .. "/Actions/Update/GetLatest.lua")("Dot-Lua/TypeWriterInstaller", "TypeWriter-Installer.exe"))
32+
33+
local TempPath
34+
35+
if RuntimeOS == "Windows" then
36+
TempPath = _G.process.env.TEMP
37+
TempName = TempPath .. "/TW-Installer.exe"
38+
elseif RuntimeOS == "Mac" then
39+
TempPath = _G.process.env.TMPDIR
40+
end
41+
42+
FS.writeFileSync(TempName, Body)
43+
44+
45+
require(RuntimePath .. "/deps/coro-spawn")(
46+
"cmd.exe",
47+
{
48+
args = {
49+
"/k " .. TempName
50+
},
51+
detached = true,
52+
hide = false,
53+
stdio = {true, true, true}
54+
}
55+
)
56+
57+
process:exit()
58+
else
59+
Logger.Info("You are running the latest release!")
60+
end
61+
62+
63+
64+
65+
end

TypeWriter/Libs/GetOS.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ return function()
55
local Map = {
66
['win32'] = 'Windows',
77
['linux'] = 'Linux',
8-
['darwin'] = 'OSX',
8+
['darwin'] = 'Mac',
99
['bsd'] = 'BSD',
1010
['posix'] = 'POSIX',
1111
['other'] = 'Other'
@@ -16,11 +16,11 @@ return function()
1616
local Supported = {
1717
["Windows"] = true,
1818
["Linux"] = true,
19-
["OSX"] = true,
19+
["Mac"] = true,
2020
}
2121

2222
if not Supported[OS] then
23-
Logger.Error("Your operating system (" .. OS .. ") is not supported for TypeWriter")
23+
Logger.Error("Your operating system (" .. OS .. ") is not supported by TypeWriter")
2424
print()
2525
Logger.Error("Supported Types Are:")
2626
for i, v in pairs(Supported) do

TypeWriter/Options.lua

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ local Executors = {
88
run = require("./Actions/Run/Init.lua"),
99
compile = require("./Actions/Compile/Init.lua"),
1010
execute = require("./Actions/Execute/Init.lua"),
11-
setup = require("./Actions/Setup/Init.lua")
11+
setup = require("./Actions/Setup/Init.lua"),
12+
update = require("./Actions/Update/Init.lua")
13+
1214
}
1315

1416
local ArgumentInfo = {
@@ -23,7 +25,7 @@ local ArgumentInfo = {
2325
local CommandName = string.lower(RuntimeArgs[1])
2426
local Command = Executors[CommandName]
2527

26-
local Metrics = Json.decode(FS.readFileSync(RuntimePath .. "/Config/Metrics.json"))
28+
local Metrics = Json.decode(FS.readFileSync(RuntimePath .. "/Config/Metrics.json") or FS.readFileSync(RuntimePath .. "/Config/MetricsTemplate.json"))
2729

2830
Metrics.TotalRuns = Metrics.TotalRuns + 1
2931

TypeWriter/deps/coro-spawn.lua

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
--[[lit-meta
2+
name = "creationix/coro-spawn"
3+
version = "3.0.2"
4+
dependencies = {
5+
"creationix/[email protected]"
6+
}
7+
homepage = "https://github.com/luvit/lit/blob/master/deps/coro-spawn.lua"
8+
description = "An coro style interface to child processes."
9+
tags = {"coro", "spawn", "child", "process"}
10+
license = "MIT"
11+
author = { name = "Tim Caswell" }
12+
]]
13+
14+
local uv = require('uv')
15+
local channel = require('coro-channel')
16+
local wrapRead = channel.wrapRead
17+
local wrapWrite = channel.wrapWrite
18+
19+
local function assertResume(thread, ...)
20+
local success, err = coroutine.resume(thread, ...)
21+
if not success then
22+
error(debug.traceback(thread, err), 0)
23+
end
24+
end
25+
26+
return function (path, options)
27+
local stdin, stdout, stderr
28+
local stdio = options.stdio
29+
30+
-- If no custom stdio is passed in, create pipes for stdin, stdout, stderr.
31+
if not stdio then
32+
stdio = {true, true, true}
33+
options.stdio = stdio
34+
end
35+
36+
if stdio then
37+
if stdio[1] == true then
38+
stdin = uv.new_pipe(false)
39+
stdio[1] = stdin
40+
end
41+
if stdio[2] == true then
42+
stdout = uv.new_pipe(false)
43+
stdio[2] = stdout
44+
end
45+
if stdio[3] == true then
46+
stderr = uv.new_pipe(false)
47+
stdio[3] = stderr
48+
end
49+
end
50+
51+
local exitThread, exitCode, exitSignal
52+
53+
local function onExit(code, signal)
54+
exitCode = code
55+
exitSignal = signal
56+
if not exitThread then return end
57+
local thread = exitThread
58+
exitThread = nil
59+
return assertResume(thread, code, signal)
60+
end
61+
62+
local handle, pid = uv.spawn(path, options, onExit)
63+
64+
if not handle then
65+
return nil, pid
66+
end
67+
68+
-- If the process has exited already, return the cached result.
69+
-- Otherwise, wait for it to exit and return the result.
70+
local function waitExit()
71+
if exitCode then
72+
return exitCode, exitSignal
73+
end
74+
assert(not exitThread, "Already waiting on exit")
75+
exitThread = coroutine.running()
76+
return coroutine.yield()
77+
end
78+
79+
local result = {
80+
handle = handle,
81+
pid = pid,
82+
waitExit = waitExit
83+
}
84+
85+
if stdin then
86+
result.stdin = {
87+
handle = stdin,
88+
write = wrapWrite(stdin)
89+
}
90+
end
91+
92+
if stdout then
93+
result.stdout = {
94+
handle = stdout,
95+
read = wrapRead(stdout)
96+
}
97+
end
98+
99+
if stderr then
100+
result.stderr = {
101+
handle = stderr,
102+
read = wrapRead(stderr)
103+
}
104+
end
105+
106+
return result
107+
108+
end

0 commit comments

Comments
 (0)