Skip to content

Commit

Permalink
fix(main): adding sign-in and sponsor to main menu
Browse files Browse the repository at this point in the history
  • Loading branch information
johnlindquist committed Aug 13, 2023
1 parent 1bb3246 commit f96af50
Show file tree
Hide file tree
Showing 13 changed files with 169 additions and 20 deletions.
7 changes: 7 additions & 0 deletions SIGN_IN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Sign in with GitHub

## Unlock Community Features

- Share Scripts
- Create Gists
- Discord Server Invite
38 changes: 38 additions & 0 deletions SPONSOR.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<div class="flex flex-col items-center justify-start mt-0">
<h2 class="pb-1 text-xl mt-0">⭐️ Unlock Script Kit Pro ⭐️</h2>
<a href="submit:kit-sponsor" class="shadow-xl shadow-primary/25 text-bg-base font-bold px-3 py-2 no-underline rounded bg-primary bg-opacity-100 hover:opacity-80" style="width: fit-content">Sponsor Script Kit ($7/m.)</a>

<div class="py-1"></div>
<div class="flex justify-evenly">

<div class="list-inside">

<h2 class="text-base">Pro Features</h2>

<ul class="text-xs">
<li>Debugger</li>
<li>Script Log Window</li>
<li>Audio Recording</li>
<li>Support through Discord</li>
<ul>
</div>

<div>


<h2 class="text-base">Upcoming Pro Features</h2>

<ul class="text-xs">
<li>Sync Scripts to GitHub Repo</li>
<li>Run Script Remotely as GitHub Actions</li>
<li>Advanced Widgets</li>
<li>Screenshots</li>
<li>Screen Recording</li>
<li>Webcam Capture</li>
<li>Desktop Color Picker</li>
<li>Measure Tool</li>
</ul>

</div>
</div>
</div>
39 changes: 38 additions & 1 deletion src/api/kit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1055,7 +1055,7 @@ export let getGroupedScripts = async () => {
kitPath("main", "giphy.js"),
kitPath("main", "browse.js"),
kitPath("main", "app-launcher.js"),
kitPath("main", "account.js"),
// kitPath("main", "account.js"),
kitPath("main", "dev.js"),
kitPath("main", "hot.js"),
kitPath("main", "snippets.js"),
Expand All @@ -1070,6 +1070,16 @@ export let getGroupedScripts = async () => {
kitPath("pro", "theme-selector.js"),
]

if (env?.KIT_LOGIN) {
kitScripts.push(kitPath("main", "account.js"))
} else {
kitScripts.push(kitPath("main", "sign-in.js"))
}

if (env?.KIT_PRO !== "true") {
kitScripts.push(kitPath("main", "sponsor.js"))
}

if (isMac) {
kitScripts.push(kitPath("main", "system-commands.js"))
kitScripts.push(kitPath("main", "focus-window.js"))
Expand All @@ -1087,6 +1097,8 @@ export let getGroupedScripts = async () => {
script.ignoreFlags = true
script.preview = `<div></div>`

processPreviewPath(script)

return script
})
)
Expand Down Expand Up @@ -1202,6 +1214,24 @@ export let selectScript = async (
return await getScriptResult(script, message)
}

export let processPreviewPath = async (s: Script) => {
if (s.previewpath) {
s.preview = async () => {
let previewPath = getPreviewPath(s)

let preview = `<div></div>`

if (await isFile(previewPath)) {
preview = await md(
await readFile(previewPath, "utf8")
)
}

return preview
}
}
}

export let processScript =
(timestamps: Stamp[] = []) =>
async (s: Script): Promise<Script> => {
Expand Down Expand Up @@ -1255,6 +1285,13 @@ ${stamp.compileMessage}
}

export let getPreviewPath = (s: Script): string => {
if (s?.previewpath) {
return path.normalize(
s.previewpath
.replace("~", home())
.replace("$KIT", kitPath())
)
}
return path.resolve(
path.dirname(path.dirname(s.filePath)),
"docs",
Expand Down
24 changes: 19 additions & 5 deletions src/cli/set-env-var.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,37 @@ let envKey = await arg("env key:")
let envValue = await arg("env value:")
let envFile = kenvPath(".env")
let updateEnv = async (envKey, envValue) => {
let regex = new RegExp("^" + envKey + "=.*$")
sed("-i", regex, envKey + "=" + envValue, envFile)
env[envKey] = envValue
process.env[envKey] = envValue
if (env?.[envKey] !== envValue) {
let regex = new RegExp("^" + envKey + "=.*$")
sed("-i", regex, envKey + "=" + envValue, envFile)
env[envKey] = envValue
process.env[envKey] = envValue
}
}
let writeNewEnv = async (envKey, envValue) => {
await appendFile(envFile, `\n${envKey}=${envValue}`)
env[envKey] = envValue
process.env[envKey] = envValue
}
let removeEnv = async envKey => {
let regex = new RegExp("^" + envKey + "=.*$", "gm")
sed("-i", regex, "", envFile)
delete env[envKey]
delete process.env[envKey]
}

let dotEnvPath = kitDotEnvPath()
await ensureFile(dotEnvPath)
let contents = await readFile(dotEnvPath, "utf-8")
let exists = contents.match(
new RegExp("^" + envKey + "=.*$", "gm")
)
let fn = exists ? updateEnv : writeNewEnv
let fn =
envValue === "__KIT_ClEAR_ENV__"
? removeEnv
: exists
? updateEnv
: writeNewEnv
global.log(
chalk`${
exists ? "Updated" : "Set"
Expand Down
3 changes: 3 additions & 0 deletions src/config/set-login.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
await cli("set-env-var", "KIT_LOGIN", await arg())

export {}
3 changes: 3 additions & 0 deletions src/config/toggle-sponsor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
await cli("set-env-var", "KIT_PRO", await arg())

export {}
2 changes: 1 addition & 1 deletion src/core/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ export let setUserJson = async (user: UserDb) => {
}

export let getUserJson = async (): Promise<UserDb> => {
let user = {}
let user: any = {}
let userDbExists = await isFile(userDbPath)
if (userDbExists) {
try {
Expand Down
2 changes: 1 addition & 1 deletion src/main/account.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Name: Account
// Description: Authenticate to Enable Features
// Description: Join Discord, View Account, and Sponsor
// Enter: View Account

import { authenticate } from "../api/kit.js"
Expand Down
26 changes: 15 additions & 11 deletions src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ let script = await mainMenu({
},
},
{
name: "Sign-In",
name: "Sign In",
flag: "sign-in-to-script-kit",
key: `${cmd}+shift+opt+s`,
onPress: async () => {
Expand Down Expand Up @@ -628,17 +628,21 @@ if (isApp) {
) {
console.warn(`🤔 No script selected`, script)
} else if (typeof script === "string") {
let scriptPath = script as string
let [maybeScript, numarg] = scriptPath.split(/\s(?=\d)/)
if (await isFile(maybeScript)) {
await run(maybeScript, numarg)
if (script === "kit-sponsor") {
await run(kitPath("main", "sponsor.js"))
} else {
await run(
`${kitPath("cli", "new")}.js`,
scriptPath.trim().replace(/\s/g, "-").toLowerCase(),
`--scriptName`,
scriptPath.trim()
)
let scriptPath = script as string
let [maybeScript, numarg] = scriptPath.split(/\s(?=\d)/)
if (await isFile(maybeScript)) {
await run(maybeScript, numarg)
} else {
await run(
`${kitPath("cli", "new")}.js`,
scriptPath.trim().replace(/\s/g, "-").toLowerCase(),
`--scriptName`,
scriptPath.trim()
)
}
}
} else {
let shouldEdit = flag?.open
Expand Down
2 changes: 1 addition & 1 deletion src/main/new.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ interface Main {
guide: Promise<typeof import("./guide")>
hot: Promise<typeof import("./hot")>
index: Promise<typeof import("./index")>
account: Promise<typeof import("./account")>
account: Promise<typeof import("./sign-in")>
kenv: Promise<typeof import("./kenv")>
kit: Promise<typeof import("./kit")>
new: Promise<typeof import("./new")>
Expand Down
12 changes: 12 additions & 0 deletions src/main/sign-in.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Name: Sign In to GitHub
// Description: Authenticate with GitHub to Enable Features
// Enter: View Account
// PreviewPath: $KIT/SIGN_IN.md

import { authenticate } from "../api/kit.js"

hide()

await authenticate()

await mainScript()
30 changes: 30 additions & 0 deletions src/main/sponsor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Name: Unlock Script Kit Pro
// Description: Add Debugger, Logger, and Support Development
// Enter: Open Sponsorship Page
// PreviewPath: $KIT/SPONSOR.md

let sponsorUrl = `https://github.com/sponsors/johnlindquist/sponsorships?sponsor=johnlindquist&tier_id=235205`
try {
sponsorUrl = (
await readFile(
kitPath("data", "sponsor-url.txt"),
"utf-8"
)
).trim()
} catch (error) {
warn(`Failed to read sponsor-url.txt`)
}
try {
sponsorUrl = (
await readFile(
kitPath("data", "sponsor-url.txt"),
"utf-8"
)
).trim()
} catch (error) {
warn(`Failed to read sponsor-url.txt`)
}

open(sponsorUrl)

export {}
1 change: 1 addition & 0 deletions src/types/core.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ export interface ScriptMetadata {
["color-background"]?: string
["opacity"]?: string
preview?: Choice["preview"]
previewpath?: string
debug?: boolean
verbose?: boolean
cache?: boolean
Expand Down

0 comments on commit f96af50

Please sign in to comment.