Skip to content

Commit

Permalink
refactor: split adapter by platform
Browse files Browse the repository at this point in the history
  • Loading branch information
pd4d10 committed Feb 15, 2024
1 parent d38c769 commit c130366
Show file tree
Hide file tree
Showing 13 changed files with 329 additions and 339 deletions.
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
Expand Down
16 changes: 0 additions & 16 deletions src/main/adapter.ts

This file was deleted.

72 changes: 0 additions & 72 deletions src/main/linux.ts

This file was deleted.

63 changes: 0 additions & 63 deletions src/main/macos.ts

This file was deleted.

27 changes: 0 additions & 27 deletions src/main/utils.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
import type { AppInfo } from "../reducers/app";
import fs from "fs";
import { machineId } from "node-machine-id";
import os from "os";
// import { setUpdateNotification } from 'electron-update-notification' // TODO:
import plist from "simple-plist";
import ua from "universal-analytics";

interface MacosAppInfo {
CFBundleIdentifier: string;
CFBundleName: string;
CFBundleExecutable: string;
CFBundleIconFile: string;
}

export async function readdirSafe(p: string) {
try {
return await fs.promises.readdir(p);
Expand Down Expand Up @@ -40,20 +31,6 @@ export async function readFileAsBufferSafe(p: string) {
}
}

export async function readPlistFile(path: string): Promise<MacosAppInfo> {
return new Promise((resolve, reject) => {
plist.readFile<MacosAppInfo>(path, (error, data) => {
// console.log(error, data)

if (error || !data) {
reject(error);
} else {
resolve(data);
}
});
});
}

export async function setReporter() {
try {
const id = await machineId();
Expand All @@ -74,7 +51,3 @@ export async function setUpdater() {
// });
}
}
export abstract class Adapter {
abstract readApps(): Promise<(AppInfo | undefined)[]>;
abstract readAppByPath(p: string): Promise<AppInfo | undefined>;
}
154 changes: 0 additions & 154 deletions src/main/win.ts

This file was deleted.

12 changes: 12 additions & 0 deletions src/platforms/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export function importByPlatform() {
switch (process.platform) {
case "win32":
return import("../platforms/win");
case "darwin":
return import("../platforms/macos");
case "linux":
return import("../platforms/linux");
default:
throw new Error("platform not supported");
}
}
Loading

0 comments on commit c130366

Please sign in to comment.