"},
+// or a config.toml itself. The key a provider table reads from an
+// environment variable (env_key) is the computer's own, not the link's, and
+// is never taken.
+func (c ccSwitchCfg) readCodex() (ccSwitchSettings, error) {
+ var s ccSwitchSettings
+ doc := map[string]any(c)
+ if text := c.str("config"); text != "" {
+ doc = nil
+ if err := toml.Unmarshal([]byte(text), &doc); err != nil {
+ return s, errorf("the ccswitch link's codex config is not TOML")
+ }
+ } else if c.obj("auth") != nil {
+ doc = nil
+ }
+ root := ccSwitchCfg(doc)
+ s.key = c.obj("auth").str("OPENAI_API_KEY")
+ s.models[0] = root.str("model")
+ id := root.str("model_provider")
+ var tbl ccSwitchCfg
+ if provs := root.obj("model_providers"); provs != nil {
+ if tbl = provs.obj(id); tbl == nil && len(provs) == 1 {
+ for _, v := range provs {
+ tbl, _ = v.(map[string]any)
+ }
+ }
+ }
+ if tbl != nil {
+ s.endpoint = tbl.str("base_url")
+ if s.key == "" {
+ s.key = tbl.str("experimental_bearer_token")
+ }
+ switch tbl.str("wire_api") {
+ case "chat":
+ s.format = "openai_chat"
+ case "responses":
+ s.format = "openai_responses"
+ }
+ if s.key == "" && tbl.str("env_key") != "" {
+ return s, errorf("the ccswitch link gives its key through the environment variable %s, which a link can't read: add the key yourself", tbl.str("env_key"))
+ }
+ }
+ return s, nil
+}
diff --git a/internal/provider/importccswitch_test.go b/internal/provider/importccswitch_test.go
new file mode 100644
index 000000000..b2e5dd397
--- /dev/null
+++ b/internal/provider/importccswitch_test.go
@@ -0,0 +1,167 @@
+package provider
+
+import (
+ "os"
+ "reflect"
+ "strings"
+ "testing"
+)
+
+// testdata/ccswitch_links.txt holds CC Switch's own example links, copied
+// as written from its repository (deplink.html and the site integration
+// guide at 3c76d3b), one per line.
+func ccSwitchLinks(t *testing.T) []string {
+ t.Helper()
+ b, err := os.ReadFile("testdata/ccswitch_links.txt")
+ if err != nil {
+ t.Fatal(err)
+ }
+ var out []string
+ for _, l := range strings.Split(string(b), "\n") {
+ if strings.TrimSpace(l) != "" {
+ out = append(out, l)
+ }
+ }
+ return out
+}
+
+func TestCCSwitchOwnExamples(t *testing.T) {
+ type want struct {
+ Name, Chat, Responses, Anthropic, Gemini, Key string
+ Models []string
+ }
+ got := map[string]want{}
+ n := 0
+ for _, l := range ccSwitchLinks(t) {
+ p, err := ParseImport(l)
+ if !strings.Contains(l, "resource=provider") {
+ // prompts, MCP servers and skills are not providers
+ if err == nil || !strings.Contains(err.Error(), "providers") {
+ t.Errorf("%.60s: %v", l, err)
+ }
+ continue
+ }
+ if err != nil {
+ t.Errorf("%.90s: %v", l, err)
+ continue
+ }
+ n++
+ if p.ID != "example-ai" && p.ID != "example-gemini" {
+ t.Errorf("%.90s: id %q", l, p.ID)
+ }
+ app := l[strings.Index(l, "app=")+4:]
+ app = app[:strings.IndexByte(app, '&')]
+ got[app+"/"+map[bool]string{true: "config", false: "params"}[strings.Contains(l, "config=")]+"/"+p.Name+p.Key+strings.Join(p.Models, ",")] = want{p.Name, p.Chat, p.Responses, p.Anthropic, p.Gemini, p.Key, p.Models}
+ }
+ if n != 11 {
+ t.Fatalf("%d provider links in the examples", n)
+ }
+ for _, c := range []struct {
+ key string
+ w want
+ }{
+ // endpoint, apiKey: claude's address is Anthropic's
+ {"claude/params/Example AIsk-test-key123", want{Name: "Example AI", Anthropic: "https://api.example.com", Key: "sk-test-key123"}},
+ // the config's env, with its three tiers
+ {"claude/config/Example AIsk-test-key123example-chat,example-fast,example-pro", want{Name: "Example AI", Anthropic: "https://api.example.com", Key: "sk-test-key123", Models: []string{"example-chat", "example-fast", "example-pro"}}},
+ // the key in the URL, the address in the config
+ {"claude/config/Example AIsk-test-key123", want{Name: "Example AI", Anthropic: "https://api.example.com", Key: "sk-test-key123"}},
+ // codex: config.toml's provider table, wire_api responses
+ {"codex/config/Example AIsk-test-key123example-coder", want{Name: "Example AI", Responses: "https://api.example.com/v1", Key: "sk-test-key123", Models: []string{"example-coder"}}},
+ {"codex/params/Example AIsk-test-key123", want{Name: "Example AI", Responses: "https://api.example.com/v1", Key: "sk-test-key123"}},
+ {"gemini/config/Example GeminiAIzaSy-test-key123", want{Name: "Example Gemini", Gemini: "https://api.example.com", Key: "AIzaSy-test-key123"}},
+ // apiFormat names the API an app of any kind speaks
+ {"opencode/params/Example AIsk-test-key123example-chat", want{Name: "Example AI", Anthropic: "https://api.example.com/v1", Key: "sk-test-key123", Models: []string{"example-chat"}}},
+ {"pi/params/Example AIsk-test-key123example-chat", want{Name: "Example AI", Chat: "https://api.example.com/v1", Key: "sk-test-key123", Models: []string{"example-chat"}}},
+ } {
+ if g, ok := got[c.key]; !ok {
+ t.Errorf("no example gave %q; have %v", c.key, got)
+ } else if !reflect.DeepEqual(g, c.w) {
+ t.Errorf("%s:\n got %+v\nwant %+v", c.key, g, c.w)
+ }
+ }
+}
+
+func TestCCSwitchIconAndUsageDropped(t *testing.T) {
+ for _, l := range ccSwitchLinks(t) {
+ if !strings.Contains(l, "iconUrl=") {
+ continue
+ }
+ p, err := ParseImport(l)
+ if err != nil || p.IconURL == "" {
+ t.Fatalf("iconUrl: %q, %v", p.IconURL, err)
+ }
+ }
+ // a usage script (CC Switch's balance query) is code: never taken
+ p, err := ParseImport("ccswitch://v1/import?resource=provider&app=claude&name=x&endpoint=https%3A%2F%2Fa.example&usageScript=KHsKfSk%3D&usageEnabled=true&usageBaseUrl=https%3A%2F%2Fevil.example")
+ if err != nil || p.BalanceURL != "" {
+ t.Fatalf("%+v %v", p, err)
+ }
+}
+
+func TestCCSwitchRefused(t *testing.T) {
+ const base = "ccswitch://v1/import?resource=provider&app=claude&name=x&endpoint=https%3A%2F%2Fa.example"
+ for name, c := range map[string]struct{ link, why string }{
+ "other version": {strings.Replace(base, "//v1/", "//v2/", 1), "v1"},
+ "other path": {strings.Replace(base, "/import?", "/export?", 1), "/import"},
+ "no resource": {strings.Replace(base, "resource=provider&", "", 1), "resource"},
+ "unknown app": {strings.Replace(base, "app=claude", "app=nope", 1), "app"},
+ "no name": {strings.Replace(base, "name=x&", "", 1), "name"},
+ "plain http": {strings.Replace(base, "https", "http", 1), "https"},
+ "javascript": {strings.Replace(base, "https%3A%2F%2Fa.example", "javascript%3Aalert(1)", 1), "base URL"},
+ "file": {strings.Replace(base, "https%3A%2F%2Fa.example", "file%3A%2F%2F%2Fetc%2Fpasswd", 1), "base URL"},
+ "bad format": {base + "&apiFormat=grpc", "apiFormat"},
+ "remote config": {base + "&configUrl=https%3A%2F%2Fa.example%2Fc.json", "configUrl"},
+ "config not base64": {base + "&config=%25%25%25", "base64"},
+ "config not json": {base + "&config=bm90IGpzb24", "json"},
+ "config huge": {base + "&config=" + strings.Repeat("A", 300<<10), "large"},
+ "claude no env": {base + "&config=e30", "env"},
+ "key with newline": {base + "&apiKey=sk%0Aevil", "key"},
+ "no address": {"ccswitch://v1/import?resource=provider&app=claude&name=x", "base URL"},
+ "codex env_key": {"ccswitch://v1/import?resource=provider&app=codex&name=x&config=" +
+ b64(`{"config":"model_provider=\"p\"\n[model_providers.p]\nbase_url=\"https://a.example/v1\"\nenv_key=\"HOME_SECRET\""}`), "HOME_SECRET"},
+ "name only a symbol": {"ccswitch://v1/import?resource=provider&app=claude&name=%2A%2A&endpoint=https%3A%2F%2Fa.example", "id"},
+ } {
+ t.Run(name, func(t *testing.T) {
+ p, err := ParseImport(c.link)
+ if err == nil {
+ t.Fatalf("accepted: %+v", p)
+ }
+ if !strings.Contains(err.Error(), c.why) {
+ t.Fatalf("%q does not say %q", err, c.why)
+ }
+ })
+ }
+ if _, err := ParseImport("ccswitch://v1/import?resource=provider&app=claude&name=x&endpoint=https%3A%2F%2Fa.example&homepage=javascript%3Aalert(1)"); err != nil {
+ t.Fatalf("a bad homepage turned the link away: %v", err)
+ }
+}
+
+// a ccswitch link is as safe as a magpie one: the balance host rule and
+// the id rules are the shared ones
+func TestCCSwitchNamedAsSubscription(t *testing.T) {
+ p, err := ParseImport("CCSWITCH://V1/import?resource=provider&app=claude&name=claude&endpoint=https%3A%2F%2Fa.example")
+ if err != nil || p.ID == "claude" {
+ t.Fatalf("%+v %v", p, err)
+ }
+}
+
+func b64(s string) string {
+ const a = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"
+ var out []byte
+ for i := 0; i < len(s); i += 3 {
+ var v uint
+ n := 0
+ for j := 0; j < 3; j++ {
+ v <<= 8
+ if i+j < len(s) {
+ v |= uint(s[i+j])
+ n++
+ }
+ }
+ for j := 0; j <= n; j++ {
+ out = append(out, a[(v>>(18-6*uint(j)))&63])
+ }
+ }
+ return string(out)
+}
diff --git a/internal/provider/importurl.go b/internal/provider/importurl.go
index c306257ec..a92585c9a 100644
--- a/internal/provider/importurl.go
+++ b/internal/provider/importurl.go
@@ -53,6 +53,13 @@ const Scheme = "magpie"
// ParseImport reads an import link into the provider it describes.
func ParseImport(link string) (Provider, error) {
u, err := url.Parse(strings.TrimSpace(link))
+ if err == nil && strings.EqualFold(u.Scheme, CCSwitchScheme) {
+ q, err := ccSwitchQuery(u)
+ if err != nil {
+ return Provider{}, err
+ }
+ return importFromQuery(q)
+ }
if err != nil || !strings.EqualFold(u.Scheme, Scheme) {
return Provider{}, errors.New("not a magpie:// link")
}
@@ -63,7 +70,14 @@ func ParseImport(link string) (Provider, error) {
if action != "import" {
return Provider{}, errorf("magpie://%s is not something magpie knows; links start magpie://import?", action)
}
- q := u.Query()
+ return importFromQuery(u.Query())
+}
+
+// importFromQuery is ParseImport after the link's shape is known: q holds
+// the parameters in the list above, from a magpie:// link or translated from
+// a ccswitch:// one (ccSwitchQuery).
+func importFromQuery(q url.Values) (Provider, error) {
+ var err error
get := func(k string) string { return strings.TrimSpace(q.Get(k)) }
var p Provider
diff --git a/internal/provider/testdata/ccswitch_links.txt b/internal/provider/testdata/ccswitch_links.txt
new file mode 100644
index 000000000..81a88afbc
--- /dev/null
+++ b/internal/provider/testdata/ccswitch_links.txt
@@ -0,0 +1,14 @@
+ccswitch://v1/import?resource=mcp&apps=claude%2Ccodex&config=eyJtY3BTZXJ2ZXJzIjp7ImNvbnRleHQ3Ijp7ImNvbW1hbmQiOiJucHgiLCJhcmdzIjpbIi15IiwiQHVwc3Rhc2gvY29udGV4dDctbWNwIl0sImVudiI6e319LCJzZXF1ZW50aWFsLXRoaW5raW5nIjp7ImNvbW1hbmQiOiJucHgiLCJhcmdzIjpbIi15IiwiQG1vZGVsY29udGV4dHByb3RvY29sL3NlcnZlci1zZXF1ZW50aWFsLXRoaW5raW5nIl0sImVudiI6e319fX0%3D
+ccswitch://v1/import?resource=prompt&app=claude&name=%E4%BB%A3%E7%A0%81%E5%AE%A1%E6%9F%A5%E4%B8%93%E5%AE%B6&content=IyDku6PnoIHlrqHmn6XkuJPlrrYKCuS9oOaYr%2BS4gOS9jeaciee7j%2BmqjOeahOS7o%2BeggeWuoeafpeWRmOOAguWuoeafpeS7o%2BeggeaXtu%2B8jOWFiOaMh%2BWHuuS8muWvvOiHtOmUmeivr%2BeahOmXrumimO%2B8jOWGjee7meWHuuS%2FruaUueW7uuiuruOAgg%3D%3D&description=%E4%B8%93%E6%B3%A8%E4%BB%A3%E7%A0%81%E8%B4%A8%E9%87%8F
+ccswitch://v1/import?resource=provider&app=claude&name=Example%20AI&apiKey=sk-test-key123&configFormat=json&config=eyJlbnYiOnsiQU5USFJPUElDX0JBU0VfVVJMIjoiaHR0cHM6Ly9hcGkuZXhhbXBsZS5jb20iLCJBUElfVElNRU9VVF9NUyI6IjYwMDAwMCJ9fQ%3D%3D
+ccswitch://v1/import?resource=provider&app=claude&name=Example%20AI&configFormat=json&config=eyJlbnYiOnsiQU5USFJPUElDX0FVVEhfVE9LRU4iOiJzay10ZXN0LWtleTEyMyIsIkFOVEhST1BJQ19CQVNFX1VSTCI6Imh0dHBzOi8vYXBpLmV4YW1wbGUuY29tIiwiQU5USFJPUElDX01PREVMIjoiZXhhbXBsZS1jaGF0IiwiQU5USFJPUElDX0RFRkFVTFRfSEFJS1VfTU9ERUwiOiJleGFtcGxlLWZhc3QiLCJBTlRIUk9QSUNfREVGQVVMVF9TT05ORVRfTU9ERUwiOiJleGFtcGxlLWNoYXQiLCJBTlRIUk9QSUNfREVGQVVMVF9PUFVTX01PREVMIjoiZXhhbXBsZS1wcm8ifX0%3D
+ccswitch://v1/import?resource=provider&app=claude&name=Example%20AI&endpoint=https%3A%2F%2Fapi.example.com&apiKey=sk-test-key123&iconUrl=https%3A%2F%2Fraw.githubusercontent.com%2Ffarion1231%2Fcc-switch%2Fmain%2Fsrc-tauri%2Ficons%2F128x128.png
+ccswitch://v1/import?resource=provider&app=claude&name=Example+AI&endpoint=https%3A%2F%2Fapi.example.com&apiKey=sk-test-key123&usageScript=KHsKICByZXF1ZXN0OiB7CiAgICB1cmw6ICJ7e2Jhc2VVcmx9fS91c2VyL2JhbGFuY2UiLAogICAgbWV0aG9kOiAiR0VUIiwKICAgIGhlYWRlcnM6IHsKICAgICAgIkF1dGhvcml6YXRpb24iOiAiQmVhcmVyIHt7YXBpS2V5fX0iCiAgICB9CiAgfSwKICBleHRyYWN0b3I6IGZ1bmN0aW9uIChyZXNwb25zZSkgewogICAgaWYgKHJlc3BvbnNlLmVycm9yKSB7CiAgICAgIHJldHVybiB7IGlzVmFsaWQ6IGZhbHNlLCBpbnZhbGlkTWVzc2FnZTogU3RyaW5nKHJlc3BvbnNlLmVycm9yLm1lc3NhZ2UgfHwgcmVzcG9uc2UuZXJyb3IpIH07CiAgICB9CiAgICByZXR1cm4gewogICAgICByZW1haW5pbmc6IE51bWJlcihyZXNwb25zZS5iYWxhbmNlKSwKICAgICAgdW5pdDogIlVTRCIKICAgIH07CiAgfQp9KQ
+ccswitch://v1/import?resource=provider&app=claude&name=Example+AI&endpoint=https%3A%2F%2Fapi.example.com&apiKey=sk-test-key123&usageScript=KHsKICByZXF1ZXN0OiB7CiAgICB1cmw6ICJ7e2Jhc2VVcmx9fSIucmVwbGFjZSgvXC8rJC8sICIiKS5yZXBsYWNlKC9cL3YxJC8sICIiKSArICIvdjEvdXNhZ2UiLAogICAgbWV0aG9kOiAiR0VUIiwKICAgIGhlYWRlcnM6IHsKICAgICAgIkF1dGhvcml6YXRpb24iOiAiQmVhcmVyIHt7YXBpS2V5fX0iLAogICAgICAiVXNlci1BZ2VudCI6ICJjYy1zd2l0Y2gvMS4wIgogICAgfQogIH0sCiAgZXh0cmFjdG9yOiBmdW5jdGlvbiAocmVzcG9uc2UpIHsKICAgIHZhciBxdW90YSA9IHJlc3BvbnNlLnF1b3RhIHx8IHt9OwogICAgdmFyIHJlc3VsdCA9IHsKICAgICAgaXNWYWxpZDogcmVzcG9uc2UuaXNWYWxpZCAhPT0gZmFsc2UsCiAgICAgIHVuaXQ6IHJlc3BvbnNlLnVuaXQgfHwgcXVvdGEudW5pdCB8fCAiVVNEIgogICAgfTsKICAgIGlmICh0eXBlb2YgcmVzcG9uc2UucGxhbk5hbWUgPT09ICJzdHJpbmciKSByZXN1bHQucGxhbk5hbWUgPSByZXNwb25zZS5wbGFuTmFtZTsKICAgIGlmICh0eXBlb2YgcmVzcG9uc2UucmVtYWluaW5nID09PSAibnVtYmVyIiAmJiByZXNwb25zZS5yZW1haW5pbmcgPj0gMCkgewogICAgICByZXN1bHQucmVtYWluaW5nID0gcmVzcG9uc2UucmVtYWluaW5nOwogICAgfQogICAgaWYgKHF1b3RhLmxpbWl0ID4gMCkgewogICAgICByZXN1bHQudXNlZCA9IHF1b3RhLnVzZWQ7CiAgICAgIHJlc3VsdC50b3RhbCA9IHF1b3RhLmxpbWl0OwogICAgfQogICAgaWYgKCFyZXN1bHQuaXNWYWxpZCkgewogICAgICByZXN1bHQuaW52YWxpZE1lc3NhZ2UgPSByZXNwb25zZS5zdGF0dXMKICAgICAgICA%2FIFN0cmluZyhyZXNwb25zZS5zdGF0dXMpCiAgICAgICAgOiAi5p%2Bl6K%2Bi5aSx6LSlIjsKICAgIH0KICAgIHJldHVybiByZXN1bHQ7CiAgfSwKfSk%3D&usageAutoInterval=30
+ccswitch://v1/import?resource=provider&app=codex&name=Example%20AI&configFormat=json&config=eyJhdXRoIjp7Ik9QRU5BSV9BUElfS0VZIjoic2stdGVzdC1rZXkxMjMifSwiY29uZmlnIjoibW9kZWxfcHJvdmlkZXIgPSBcImV4YW1wbGVcIlxubW9kZWwgPSBcImV4YW1wbGUtY29kZXJcIlxuXG5bbW9kZWxfcHJvdmlkZXJzLmV4YW1wbGVdXG5uYW1lID0gXCJFeGFtcGxlIEFJXCJcbmJhc2VfdXJsID0gXCJodHRwczovL2FwaS5leGFtcGxlLmNvbS92MVwiXG53aXJlX2FwaSA9IFwicmVzcG9uc2VzXCIifQ%3D%3D
+ccswitch://v1/import?resource=provider&app=codex&name=Example+AI&endpoint=https%3A%2F%2Fapi.example.com%2Fv1&apiKey=sk-test-key123&usageScript=KHsKICByZXF1ZXN0OiB7CiAgICB1cmw6ICJ7e2Jhc2VVcmx9fS9hcGkvdXNlci9zZWxmIiwKICAgIG1ldGhvZDogIkdFVCIsCiAgICBoZWFkZXJzOiB7CiAgICAgICJBdXRob3JpemF0aW9uIjogIkJlYXJlciB7e2FjY2Vzc1Rva2VufX0iLAogICAgICAiTmV3LUFwaS1Vc2VyIjogInt7dXNlcklkfX0iCiAgICB9CiAgfSwKICBleHRyYWN0b3I6IGZ1bmN0aW9uIChyZXNwb25zZSkgewogICAgaWYgKHJlc3BvbnNlLnN1Y2Nlc3MgJiYgcmVzcG9uc2UuZGF0YSkgewogICAgICByZXR1cm4gewogICAgICAgIHBsYW5OYW1lOiByZXNwb25zZS5kYXRhLmdyb3VwLAogICAgICAgIHJlbWFpbmluZzogcmVzcG9uc2UuZGF0YS5xdW90YSAvIDUwMDAwMCwKICAgICAgICB1c2VkOiByZXNwb25zZS5kYXRhLnVzZWRfcXVvdGEgLyA1MDAwMDAsCiAgICAgICAgdW5pdDogIlVTRCIKICAgICAgfTsKICAgIH0KICAgIHJldHVybiB7IGlzVmFsaWQ6IGZhbHNlLCBpbnZhbGlkTWVzc2FnZTogU3RyaW5nKHJlc3BvbnNlLm1lc3NhZ2UgfHwgIuafpeivouWksei0pSIpIH07CiAgfQp9KQ&usageBaseUrl=https%3A%2F%2Fapi.example.com&usageAccessToken=test-access-token&usageUserId=1&usageAutoInterval=30
+ccswitch://v1/import?resource=provider&app=gemini&name=Example%20Gemini&configFormat=json&config=eyJHRU1JTklfQVBJX0tFWSI6IkFJemFTeS10ZXN0LWtleTEyMyIsIkdPT0dMRV9HRU1JTklfQkFTRV9VUkwiOiJodHRwczovL2FwaS5leGFtcGxlLmNvbSJ9
+ccswitch://v1/import?resource=provider&app=opencode&name=Example%20AI&endpoint=https%3A%2F%2Fapi.example.com%2Fv1&apiKey=sk-test-key123&apiFormat=anthropic&model=example-chat
+ccswitch://v1/import?resource=provider&app=pi&name=Example%20AI&endpoint=https%3A%2F%2Fapi.example.com%2Fv1&apiKey=sk-test-key123&apiFormat=openai_chat&model=example-chat
+ccswitch://v1/import?resource=skill&repo=example%2Fclaude-skills&branch=main
+ccswitch://v1/import?resource=provider&app=claude&name=Example%20AI&endpoint=https%3A%2F%2Fapi.example.com&apiKey=sk-xxxx
diff --git a/internal/uninstall/system_linux.go b/internal/uninstall/system_linux.go
index 13c45d933..3b5185afa 100644
--- a/internal/uninstall/system_linux.go
+++ b/internal/uninstall/system_linux.go
@@ -1,6 +1,7 @@
package uninstall
import (
+ "errors"
"os"
"path/filepath"
"strings"
@@ -21,26 +22,33 @@ func dataHome() string {
// unregisterScheme takes out the desktop entry the app made for magpie://
// links while it runs exe, or an exe that is gone, and its icon with it.
func unregisterScheme(exe string) error {
- entry := filepath.Join(dataHome(), "applications", "magpie.desktop")
+ _, err := removeEntry("magpie-ccswitch.desktop", exe)
+ gone, err2 := removeEntry("magpie.desktop", exe)
+ if gone {
+ _ = os.Remove(filepath.Join(dataHome(), "icons", "hicolor", "256x256", "apps", "magpie.png"))
+ }
+ return errors.Join(err, err2)
+}
+
+// removeEntry takes out one of the app's desktop entries while it runs exe,
+// or an exe that is gone.
+func removeEntry(name, exe string) (bool, error) {
+ entry := filepath.Join(dataHome(), "applications", name)
b, err := os.ReadFile(entry)
if err != nil {
- return nil
+ return false, nil
}
for _, l := range strings.Split(string(b), "\n") {
if run, ok := strings.CutPrefix(l, "Exec="); ok {
run = strings.TrimSuffix(run, " %u")
if run != exe {
if _, err := os.Stat(run); err == nil {
- return nil // another magpie's
+ return false, nil // another magpie's
}
}
}
}
- if err := os.Remove(entry); err != nil {
- return err
- }
- _ = os.Remove(filepath.Join(dataHome(), "icons", "hicolor", "256x256", "apps", "magpie.png"))
- return nil
+ return true, os.Remove(entry)
}
// webData is WebKitGTK's folder for the app's pages (named after the
diff --git a/internal/uninstall/system_windows.go b/internal/uninstall/system_windows.go
index b20bea032..795dc3679 100644
--- a/internal/uninstall/system_windows.go
+++ b/internal/uninstall/system_windows.go
@@ -1,6 +1,7 @@
package uninstall
import (
+ "errors"
"os"
"path/filepath"
"strings"
@@ -12,10 +13,14 @@ import (
const schemeKey = `Software\Classes\magpie`
-// unregisterScheme takes out the magpie:// handler the app registered
-// while it opens exe, or an exe that is gone.
+// unregisterScheme takes out the magpie:// and ccswitch:// handlers the app
+// registered while they open exe, or an exe that is gone.
func unregisterScheme(exe string) error {
- k, err := registry.OpenKey(registry.CURRENT_USER, schemeKey+`\shell\open\command`, registry.QUERY_VALUE)
+ return errors.Join(removeSchemeKey(schemeKey, exe), removeSchemeKey(`Software\Classes\ccswitch`, exe))
+}
+
+func removeSchemeKey(key, exe string) error {
+ k, err := registry.OpenKey(registry.CURRENT_USER, key+`\shell\open\command`, registry.QUERY_VALUE)
if err != nil {
return nil
}
@@ -27,7 +32,7 @@ func unregisterScheme(exe string) error {
}
}
for _, sub := range []string{`\shell\open\command`, `\shell\open`, `\shell`, `\DefaultIcon`, ``} {
- if err := registry.DeleteKey(registry.CURRENT_USER, schemeKey+sub); err != nil && err != registry.ErrNotExist {
+ if err := registry.DeleteKey(registry.CURRENT_USER, key+sub); err != nil && err != registry.ErrNotExist {
return err
}
}
diff --git a/site/public/docs/import.html b/site/public/docs/import.html
index b65399754..2f330d0e0 100644
--- a/site/public/docs/import.html
+++ b/site/public/docs/import.html
@@ -318,6 +318,7 @@ href = "https://usemagpie.ai/import#" + urlencode({
| Linux | By a desktop entry (x-scheme-handler/magpie), written by the installer and again on first run. |
| Terminal | magpie import <link> shows the same summary and asks before adding. |
+ CC Switch links. magpie also opens the ccswitch://v1/import?resource=provider&… links relays make for CC Switch (app, name, endpoint, apiKey, apiFormat, model, or a base64 config), with the same confirmation. Only providers are taken, not prompts, MCP servers or skills. magpie claims the scheme only when no other app has it, so CC Switch, if installed, keeps its links (on macOS, where both can claim it, the system picks).
Import links need magpie 0.1.8 or later. When magpie is already running, the link goes to that instance and its window comes forward.
diff --git a/site/public/docs/ja/import.html b/site/public/docs/ja/import.html
index 7fc9482a1..7f94cf4ce 100644
--- a/site/public/docs/ja/import.html
+++ b/site/public/docs/ja/import.html
@@ -318,6 +318,7 @@ href = "https://usemagpie.ai/import#" + urlencode({
| Linux | デスクトップエントリ(x-scheme-handler/magpie)で登録します。インストーラが書き込み、初回起動時にも再度書き込みます。 |
| ターミナル | magpie import <リンク> が同じ概要を表示し、追加前に確認します。 |
+ CC Switch のリンク。magpie は、リレーが CC Switch 向けに作る ccswitch://v1/import?resource=provider&… リンクも開きます(app、name、endpoint、apiKey、apiFormat、model、または base64 の config)。確認は同じです。取り込むのはプロバイダーだけで、プロンプト、MCP、スキルは対象外です。ほかのアプリがスキームを持っていない場合にだけ登録するため、CC Switch があればそちらが開きます(両方が宣言できる macOS ではシステムが選びます)。
インポートリンクには magpie 0.1.8 以降が必要です。magpie がすでに起動している場合、リンクはそのインスタンスに渡され、ウィンドウが前面に表示されます。
diff --git a/site/public/docs/zh/import.html b/site/public/docs/zh/import.html
index 12986c9a4..9c3bb661d 100644
--- a/site/public/docs/zh/import.html
+++ b/site/public/docs/zh/import.html
@@ -318,6 +318,7 @@ href = "https://usemagpie.ai/import#" + urlencode({
| Linux | 通过桌面文件(x-scheme-handler/magpie)注册,安装器写一次,首次运行时再写一次。 |
| 终端 | magpie import <链接> 显示同样的摘要,添加前会询问。 |
+ CC Switch 链接。magpie 也能打开中转站为 CC Switch 做的 ccswitch://v1/import?resource=provider&… 链接(app、name、endpoint、apiKey、apiFormat、model,或 base64 的 config),同样要用户确认。只收供应商,不收提示词、MCP 和技能。只有没有别的应用占用这个协议时,magpie 才会注册它:装了 CC Switch 就仍由它打开(macOS 上两者都能声明,由系统选择)。
导入链接需要 magpie 0.1.8 或更新版本。magpie 已在运行时,链接会交给那个实例,并把它的窗口调到前台。
diff --git a/site/public/install.sh b/site/public/install.sh
index ae5833fb1..6fcf9426a 100644
--- a/site/public/install.sh
+++ b/site/public/install.sh
@@ -286,6 +286,16 @@ if [ -n "$uninstall" ]; then
if [ -f "$apps/magpie.desktop" ] && { [ "$run" = "$exe" ] || [ ! -e "$run" ]; }; then
gone "$apps/magpie.desktop"
fi
+ # the entry for ccswitch:// links, on the same terms, and its default
+ cc=$(runs "$apps/magpie-ccswitch.desktop" Exec)
+ if [ -f "$apps/magpie-ccswitch.desktop" ] && { [ "$cc" = "$exe" ] || [ ! -e "$cc" ]; }; then
+ gone "$apps/magpie-ccswitch.desktop"
+ list="$config/mimeapps.list"
+ if [ -f "$list" ] && grep -qx 'x-scheme-handler/ccswitch=magpie-ccswitch\.desktop;\{0,1\}' "$list"; then
+ grep -vx 'x-scheme-handler/ccswitch=magpie-ccswitch\.desktop;\{0,1\}' "$list" > "$list.magpie-new" || true
+ mv "$list.magpie-new" "$list"
+ fi
+ fi
# with no menu entry (this one, or the one magpie uninstall took),
# what came with it: the icon, the magpie:// default xdg-mime set
# (that line only) and the menu's cache when it lists nothing else