This repository has been archived by the owner on Apr 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
141 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
--- Copyright 2024 [lihan aooohan@gmail.com] | ||
-- | ||
-- Licensed under the Apache License, Version 2.0 (the "License"); | ||
-- you may not use this file except in compliance with the License. | ||
-- You may obtain a copy of the License at | ||
-- | ||
-- http://www.apache.org/licenses/LICENSE-2.0 | ||
-- | ||
-- Unless required by applicable law or agreed to in writing, software | ||
-- distributed under the License is distributed on an "AS IS" BASIS, | ||
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
-- See the License for the specific language governing permissions and | ||
-- limitations under the License. | ||
|
||
local http = require("http") | ||
local json = require("json") | ||
|
||
OS_TYPE = "" | ||
ARCH_TYPE = "" | ||
|
||
BASE_URL = "https://storage.flutter-io.cn/flutter_infra_release/releases/releases_%s.json" | ||
|
||
PLUGIN = { | ||
--- Plugin name | ||
name = "flutter", | ||
--- Plugin author | ||
author = "Aooohan", | ||
--- Plugin version | ||
version = "0.0.1", | ||
description = "flutter plugin for China, support for getting stable, dev, beta version", | ||
-- Update URL | ||
updateUrl = "https://raw.githubusercontent.com/version-fox/version-fox-plugins/main/flutter/flutter-cn.lua", | ||
} | ||
|
||
function PLUGIN:PreInstall(ctx) | ||
local arg = ctx.version | ||
if arg == "beta" or arg == "dev" or arg == "stable" then | ||
local type = getOsTypeAndArch() | ||
local resp, err = http.get({ | ||
url = BASE_URL:format(type.osType) | ||
}) | ||
if err ~= nil or resp.status_code ~= 200 then | ||
error("get version failed" .. err) | ||
end | ||
local body = json.decode(resp.body) | ||
local cr = body.current_release | ||
local key = cr[arg] | ||
local releases = self:Available({}) | ||
for _, info in ipairs(releases) do | ||
if info.key == key then | ||
return { | ||
version = info.version, | ||
url = info.url, | ||
sha256 = info.sha256 | ||
} | ||
end | ||
end | ||
end | ||
local releases = self:Available({}) | ||
for _, info in ipairs(releases) do | ||
if info.version == arg then | ||
return { | ||
version = info.version, | ||
url = info.url, | ||
sha256 = info.sha256 | ||
} | ||
end | ||
end | ||
return nil | ||
end | ||
|
||
function PLUGIN:PostInstall(ctx) | ||
end | ||
|
||
function PLUGIN:Available(ctx) | ||
local type = getOsTypeAndArch() | ||
local resp, err = http.get({ | ||
url = BASE_URL:format(type.osType) | ||
}) | ||
if err ~= nil or resp.status_code ~= 200 then | ||
error("get version failed" .. err) | ||
end | ||
local body = json.decode(resp.body) | ||
local result = {} | ||
for _, info in ipairs(body.releases) do | ||
local version = info.version | ||
local oldVersion = string.sub(version, 1, 1) == "v" | ||
if oldVersion then | ||
break | ||
end | ||
table.insert(result, { | ||
version = info.version, | ||
url = body.base_url .. "/" .. info.archive, | ||
sha256 = info.sha256, | ||
key = info.hash, | ||
note = info.channel, | ||
addition = { | ||
{ | ||
name = "dart", | ||
version = info.dart_sdk_version | ||
} | ||
} | ||
}) | ||
end | ||
return result | ||
end | ||
|
||
|
||
function getOsTypeAndArch() | ||
local osType = OS_TYPE | ||
local archType = ARCH_TYPE | ||
if OS_TYPE == "darwin" then | ||
osType = "macos" | ||
end | ||
if ARCH_TYPE == "amd64" then | ||
archType = "x64" | ||
elseif ARCH_TYPE == "arm64" then | ||
archType = "arm64" | ||
else | ||
error("flutter does not support" .. ARCH_TYPE .. "architecture") | ||
end | ||
return { | ||
osType = osType, archType = archType | ||
} | ||
end | ||
|
||
function PLUGIN:EnvKeys(ctx) | ||
local mainPath = ctx.path | ||
return { | ||
{ | ||
key = "PATH", | ||
value = mainPath .. "/bin" | ||
} | ||
} | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters