Skip to content

Commit 28f6236

Browse files
committed
Add reset script + fix default config screen showing without error
1 parent 7e730be commit 28f6236

File tree

4 files changed

+68
-0
lines changed

4 files changed

+68
-0
lines changed

docs/app-assets/car-images/kona.png

80.2 KB
Loading

src/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ import { getConfig, loadConfigScreen, configExists } from 'config'
66
import { confirm } from './lib/scriptable-utils'
77
;(async () => {
88
if (!configExists() && (config.runsWithSiri || config.runsInWidget)) return
9+
if (!configExists()) {
10+
await loadConfigScreen()
11+
return
12+
}
13+
914
const blConfig = getConfig()
1015
const bl = await initRegionalBluelink(blConfig)
1116

@@ -33,6 +38,7 @@ import { confirm } from './lib/scriptable-utils'
3338
const resp = await createApp(blConfig, bl)
3439
// @ts-ignore - undocumented api
3540
App.close() // add this back after dev
41+
Script.complete()
3642
return resp
3743
} catch (error) {
3844
logError(JSON.stringify(error))

src/lib/bluelink-regions/base.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ const carImageHttpURL = 'https://bluelink.andyfase.com/app-assets/car-images/'
8181
const carImageMap: Record<string, string> = {
8282
'ioniq 5': 'ioniq5.png',
8383
ev6: 'ev6.png',
84+
kona: 'kona.png',
8485
default: 'ioniq5.png',
8586
}
8687

src/reset.ts

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import { initRegionalBluelink } from 'lib/bluelink'
2+
import { getConfig, deleteConfig } from 'config'
3+
import { deleteWidgetCache } from 'widget'
4+
import { loadTintedIcons } from './lib/util'
5+
import { Spacer, getTable, Div, P, destructiveConfirm } from './lib/scriptable-utils'
6+
import { Bluelink } from 'lib/bluelink-regions/base'
7+
;(async () => {
8+
if (config.runsWithSiri || config.runsInWidget) {
9+
return
10+
}
11+
const blConfig = getConfig()
12+
const bl = await initRegionalBluelink(blConfig)
13+
14+
await loadTintedIcons()
15+
16+
const { present } = getTable<{
17+
foo: string
18+
}>({
19+
name: 'Reset',
20+
})
21+
22+
return present({
23+
defaultState: {
24+
foo: 'foobar',
25+
},
26+
render: () => [Spacer({ rowHeight: 200 }), reset(bl)],
27+
})
28+
})()
29+
30+
function reset(bl: Bluelink | Bluelink | undefined) {
31+
return Div(
32+
[
33+
P('Click me to Reset All Settings?', {
34+
font: (n) => Font.boldSystemFont(n),
35+
fontSize: 25,
36+
align: 'center',
37+
}),
38+
],
39+
{
40+
onTap() {
41+
destructiveConfirm('Confirm Setting Reset - ALL settings/data will be removed', {
42+
confirmButtonTitle: 'Delete all Settings/Data',
43+
onConfirm: () => {
44+
if (bl) bl.deleteCache()
45+
try {
46+
deleteConfig()
47+
} catch {
48+
// do nothing it if fails as it didnt exist
49+
}
50+
try {
51+
deleteWidgetCache()
52+
} catch {
53+
// do nothing it if fails as it didnt exist
54+
}
55+
Script.complete()
56+
},
57+
})
58+
},
59+
},
60+
)
61+
}

0 commit comments

Comments
 (0)