1
1
import { ipcMain } from "electron" ;
2
2
import {
3
- AnyAddonManifest ,
4
3
CheckResultFailure ,
5
4
CheckResultSuccess ,
6
5
InstallResultFailure ,
@@ -13,7 +12,8 @@ import { CONFIG_PATH, CONFIG_PATHS } from "../../util.mjs";
13
12
import { readFile , writeFile } from "fs/promises" ;
14
13
import fetch from "node-fetch" ;
15
14
import { join } from "path" ;
16
- import { RepluggedManifest , anyAddon } from "src/types/addon" ;
15
+ import { AnyAddonManifestOrReplugged , anyAddonOrReplugged } from "src/types/addon" ;
16
+ import { readTransaction } from "./settings" ;
17
17
18
18
const octokit = new Octokit ( ) ;
19
19
@@ -59,33 +59,21 @@ async function github(
59
59
( manifestAsset ) => manifestAsset . name === asset . name . replace ( / \. a s a r $ / , ".json" ) ,
60
60
) ;
61
61
62
- if ( ! manifestAsset && identifier !== "replugged-org/replugged" ) {
62
+ if ( ! manifestAsset ) {
63
63
return {
64
64
success : false ,
65
65
error : "No manifest asset found" ,
66
66
} ;
67
67
}
68
68
69
- let manifest : AnyAddonManifest | RepluggedManifest ;
70
- if ( manifestAsset ) {
71
- try {
72
- const json = await fetch ( manifestAsset . browser_download_url ) . then ( ( res ) => res . json ( ) ) ;
73
- manifest = anyAddon . parse ( json ) ;
74
- } catch {
75
- return {
76
- success : false ,
77
- error : "Failed to parse manifest" ,
78
- } ;
79
- }
80
- } else {
81
- // For Replugged itself
82
- manifest = {
83
- version : res . data . tag_name . replace ( / ^ v / , "" ) ,
84
- updater : {
85
- id : identifier ,
86
- type : "github" ,
87
- } ,
88
- type : "replugged" ,
69
+ let manifest : AnyAddonManifestOrReplugged ;
70
+ try {
71
+ const json = await fetch ( manifestAsset . browser_download_url ) . then ( ( res ) => res . json ( ) ) ;
72
+ manifest = anyAddonOrReplugged . parse ( json ) ;
73
+ } catch {
74
+ return {
75
+ success : false ,
76
+ error : "Failed to parse manifest" ,
89
77
} ;
90
78
}
91
79
@@ -98,11 +86,47 @@ async function github(
98
86
} ;
99
87
}
100
88
89
+ async function store ( id : string ) : Promise < CheckResultSuccess | CheckResultFailure > {
90
+ const apiUrl =
91
+ ( ( await readTransaction ( "dev.replugged.Settings" , ( settings ) => settings . get ( "apiUrl" ) ) ) as
92
+ | string
93
+ | undefined ) ?? "https://replugged.dev" ;
94
+ const STORE_BASE_URL = `${ apiUrl } /api/v1/store` ;
95
+ const manifestUrl = `${ STORE_BASE_URL } /${ id } ` ;
96
+ const asarUrl = `${ manifestUrl } .asar` ;
97
+
98
+ const res = await fetch ( manifestUrl ) ;
99
+ if ( ! res . ok ) {
100
+ return {
101
+ success : false ,
102
+ error : "Failed to fetch manifest" ,
103
+ } ;
104
+ }
105
+
106
+ let manifest ;
107
+ try {
108
+ manifest = anyAddonOrReplugged . parse ( await res . json ( ) ) ;
109
+ } catch {
110
+ return {
111
+ success : false ,
112
+ error : "Failed to parse manifest" ,
113
+ } ;
114
+ }
115
+
116
+ return {
117
+ success : true ,
118
+ manifest,
119
+ name : `${ id } .asar` ,
120
+ url : asarUrl ,
121
+ } ;
122
+ }
123
+
101
124
const handlers : Record <
102
125
string ,
103
126
( identifier : string , id ?: string ) => Promise < CheckResultSuccess | CheckResultFailure >
104
127
> = {
105
128
github,
129
+ store,
106
130
} ;
107
131
108
132
ipcMain . handle (
0 commit comments