Skip to content

Commit

Permalink
Merge pull request #14 from tvler/tvler/safari-2
Browse files Browse the repository at this point in the history
safari part 2
  • Loading branch information
tvler committed Mar 12, 2023
2 parents de3360f + 71d09fc commit 25fe403
Show file tree
Hide file tree
Showing 12 changed files with 179 additions and 57 deletions.
35 changes: 35 additions & 0 deletions api/pages/privacy.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import Link from "next/link";

export default function Page() {
return (
<div className="flex max-w-prose flex-col gap-y-1 p-3">
<h1 className="text-lg font-semibold">StreetPass privacy policy</h1>

<p>
StreetPass does not have any analytics. StreetPass does share your
personal data. All data is stored locally in your web browser and never
stored on a server.
</p>

<p>
If you email the developer for support, your email address and other
information will be kept private and never be shared with anyone.
</p>

<p>
<Link
className="text-purple underline"
href="https://github.com/tvler/streetpass/issues"
>
Support page
</Link>
</p>

<p>
<Link className="text-purple underline" href="/">
Home
</Link>
</p>
</div>
);
}
2 changes: 1 addition & 1 deletion constants.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const VERSION = "2023.6"
export const VERSION = "2023.7"
21 changes: 21 additions & 0 deletions extension/global.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
declare namespace TSReset {
type NonFalsy<T> = T extends false | 0 | "" | null | undefined | 0n
? never
: T;

type WidenLiteral<T> = T extends string
? string
: T extends number
? number
: T extends boolean
? boolean
: T extends bigint
? bigint
: T extends symbol
? symbol
: T;
}

interface Array<T> {
filter(predicate: BooleanConstructor, thisArg?: any): TSReset.NonFalsy<T>[];
}
4 changes: 3 additions & 1 deletion extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
"build": "tsc && yarn build:chrome && yarn build:firefox",
"build:chrome": "vite build --config vite.config.chrome.ts",
"build:firefox": "vite build --config vite.config.firefox.ts",
"build:safari": "vite build --config vite.config.safari.ts"
"build:safari": "yarn build:safari:background && yarn build:safari:main",
"build:safari:main": "vite build --config vite.config.safari.ts",
"build:safari:background": "vite build --config vite.config.safari-background.ts"
},
"devDependencies": {
"@types/webextension-polyfill": "^0.10.0",
Expand Down
Binary file added extension/public/icon-128-nopadding.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added extension/public/icon-256-nopadding.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion extension/src/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<body>
<div
id="root"
class="relative flex flex-col min-h-[600px] w-[350px] gap-18"
class="relative flex flex-col h-[600px] w-[350px] gap-18 bg-white overflow-auto"
>
<div class="flex flex-col items-center pt-[9px]">
<img src="/icon-128.png" width="48" height="48" />
Expand Down
14 changes: 14 additions & 0 deletions extension/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,20 @@ export type SendRelMeHrefPayload = {

export type Target = "chrome" | "firefox" | "safari";

export type Build = "chrome" | "firefox" | "safari" | "safari-background";

export function getTargetFromBuild(build: Build): Target {
switch (build) {
case "chrome":
case "firefox":
case "safari":
return build;

case "safari-background":
return "safari";
}
}

type Profile = { type: "profile"; profileUrl: string };

type NotProfile = { type: "notProfile" };
Expand Down
3 changes: 3 additions & 0 deletions extension/todo.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ safari
- https://developer.apple.com/videos/play/wwdc2020/10665/
- https://developer.apple.com/videos/play/wwdc2022/10099/
- https://developer.apple.com/safari/extensions/
- https://developer.apple.com/help/app-store-connect/reference/screenshot-specifications
- privacy policy https://overcast.fm/privacy
- privacy policy https://underpassapp.com/homecoming/privacy.html

good screenshot sites

Expand Down
3 changes: 2 additions & 1 deletion extension/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"jsx": "react-jsx",
"noEmit": true,
"noUncheckedIndexedAccess": true,
"noImplicitAny": true
"noImplicitAny": true,
"exactOptionalPropertyTypes": true
},
"include": ["./**/*"],
"exclude": ["node_modules", "dist-chrome", "dist-firefox"]
Expand Down
6 changes: 6 additions & 0 deletions extension/vite.config.safari-background.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { defineConfig } from "vite";
import { getConfig } from "./vite.config.shared.js";

export default defineConfig((config) => {
return getConfig("safari-background", config);
});
146 changes: 93 additions & 53 deletions extension/vite.config.shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ import { z } from "zod";
import assert from "node:assert";

import { VERSION } from "../constants.js";
import { actionActive, actionInactive, Target } from "./src/util.js";
import {
actionActive,
actionInactive,
Build,
getTargetFromBuild,
} from "./src/util.js";

const dirname = path.dirname(url.fileURLToPath(import.meta.url));
const require = createRequire(import.meta.url);
Expand All @@ -18,28 +23,33 @@ const configSchema = z.object({
mode: z.union([z.literal("dev"), z.literal("production")]),
});

export function getConfig(
target: Target,
unparsedConfig: ConfigEnv
): UserConfig {
export function getConfig(build: Build, unparsedConfig: ConfigEnv): UserConfig {
const config = configSchema.parse(unparsedConfig);

function targets<Value>(
args: Record<Target, Value>
): (typeof args)[keyof typeof args] {
return args[target];
}
function targets<Value>(args: {
chrome: Value;
firefox: Value;
safari: Value;
}): Value;
function targets<Value>(args: {
chrome: Value;
firefox: Value;
safari: Value;
"safari-background": Value;
}): Value;
function targets<Value>(args: {
chrome: Value;
firefox: Value;
safari: Value;
"safari-background"?: Value;
}): Value {
const resolvedSafariBackground: Value =
"safari-background" in args ? args["safari-background"] : args.safari;

const input = [
webextensionPolyfillPathName,
path.resolve(dirname, "src/popup.html"),
path.resolve(dirname, "src/content-script.ts"),
targets({
chrome: path.resolve(dirname, "src/background.ts"),
firefox: path.resolve(dirname, "src/background-page.html"),
safari: path.resolve(dirname, "src/background-page.html"),
}),
];
return build === "safari-background"
? resolvedSafariBackground
: args[build];
}

const extensionName = `StreetPass for Mastodon${
config.mode === "dev"
Expand Down Expand Up @@ -73,10 +83,20 @@ export function getConfig(
js: ["browser-polyfill.js", "content-script.js"],
},
],
icons: {
128: "icon-128.png",
256: "icon-256.png",
},
icons: targets({
chrome: {
128: "icon-128.png",
256: "icon-256.png",
},
firefox: {
128: "icon-128.png",
256: "icon-256.png",
},
safari: {
128: "icon-128-nopadding.png",
256: "icon-256-nopadding.png",
},
}),
...(() => {
const action: Manifest.ActionManifest = {
default_popup: "src/popup.html",
Expand All @@ -100,7 +120,7 @@ export function getConfig(
safari: { action: action },
});
})(),
background: targets<Manifest.WebExtensionManifest["background"]>({
background: targets({
chrome: {
service_worker: "background.js",
type: "module",
Expand All @@ -110,11 +130,11 @@ export function getConfig(
persistent: false,
},
safari: {
page: "src/background-page.html",
service_worker: "background.js",
},
}),
};
if (target === "firefox") {
if (build === "firefox") {
// Chrome doesn't support this yet
manifest.browser_specific_settings = {
gecko: {
Expand All @@ -123,11 +143,13 @@ export function getConfig(
};
}

this.emitFile({
type: "asset",
fileName: "manifest.json",
source: JSON.stringify(manifest),
});
if (build !== "safari-background") {
this.emitFile({
type: "asset",
fileName: "manifest.json",
source: JSON.stringify(manifest),
});
}
},
},
targets<PluginOption>({
Expand All @@ -154,36 +176,38 @@ export function getConfig(
}
);

childProcess.spawnSync(
"xcodebuild",
[
"-project",
`"${path.resolve(
options.dir,
`${extensionName}`,
`${extensionName}.xcodeproj`
)}"`,
"-allowProvisioningUpdates",
"DEVELOPMENT_TEAM=WLTVAXDPZT",
"-quiet",
],
{
shell: true,
stdio: "inherit",
}
);
// childProcess.spawnSync(
// "xcodebuild",
// [
// "-project",
// `"${path.resolve(
// options.dir,
// `${extensionName}`,
// `${extensionName}.xcodeproj`
// )}"`,
// "-allowProvisioningUpdates",
// "DEVELOPMENT_TEAM=WLTVAXDPZT",
// "-quiet",
// ],
// {
// shell: true,
// stdio: "inherit",
// }
// );
},
},
"safari-background": null,
}),
],
publicDir: build === "safari-background" ? false : "public",
build: {
outDir: targets({
firefox: path.resolve(dirname, "dist-firefox"),
chrome: path.resolve(dirname, "dist-chrome"),
safari: path.resolve(dirname, "dist-safari"),
}),
target: "esnext",
emptyOutDir: true,
emptyOutDir: build === "safari" ? false : true,
minify: false,
modulePreload: {
polyfill: false,
Expand All @@ -195,9 +219,25 @@ export function getConfig(
rollupOptions: {
strictDeprecations: true,
preserveEntrySignatures: "strict",
input: input,
input: (() => {
if (build === "safari-background") {
return path.resolve(dirname, "src/background.ts");
}

return [
webextensionPolyfillPathName,
path.resolve(dirname, "src/popup.html"),
path.resolve(dirname, "src/content-script.ts"),
targets({
chrome: path.resolve(dirname, "src/background.ts"),
firefox: path.resolve(dirname, "src/background-page.html"),
safari: null,
}),
].filter(Boolean);
})(),
output: {
minifyInternalExports: false,
inlineDynamicImports: build === "safari-background" ? true : false,
validate: true,
entryFileNames: `[name].js`,
assetFileNames: `[name].[ext]`,
Expand All @@ -207,7 +247,7 @@ export function getConfig(
},
},
define: {
__TARGET__: JSON.stringify(target),
__TARGET__: JSON.stringify(getTargetFromBuild(build)),
},
};
}

1 comment on commit 25fe403

@vercel
Copy link

@vercel vercel bot commented on 25fe403 Mar 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.