rethink vault opening
This commit is contained in:
parent
676cbe4843
commit
76e14fe125
BIN
.yarn/install-state.gz
vendored
BIN
.yarn/install-state.gz
vendored
Binary file not shown.
@ -3,16 +3,17 @@ import { _electron as electron } from "playwright";
|
|||||||
import { Fixtures } from "@playwright/test";
|
import { Fixtures } from "@playwright/test";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import { ObsidianTestFixtures } from "./fixtures.js";
|
import { ObsidianTestFixtures } from "./fixtures.js";
|
||||||
import { existsSync } from "fs";
|
import { existsSync, readFileSync, writeFileSync } from "fs";
|
||||||
import { getApp, waitForIndexingComplete } from "./util.js";
|
import { getApp, waitForIndexingComplete } from "./util.js";
|
||||||
import { execSync } from "child_process";
|
import { execSync } from "child_process";
|
||||||
import { Page } from "playwright";
|
import { randomBytes } from "crypto";
|
||||||
|
|
||||||
export interface ObsidianTestingConfig {
|
export interface ObsidianTestingConfig {
|
||||||
vault?: string;
|
vault?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getExe(): string {
|
export function getExe(): string {
|
||||||
|
checkToy();
|
||||||
if (process.platform == "win32") {
|
if (process.platform == "win32") {
|
||||||
return path.join(
|
return path.join(
|
||||||
process.env.LOCALAPPDATA!,
|
process.env.LOCALAPPDATA!,
|
||||||
@ -21,9 +22,7 @@ export function getExe(): string {
|
|||||||
"app.asar"
|
"app.asar"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (process.platform == "darwin") {
|
|
||||||
throw new Error("use a non-toy operating system, dumbass");
|
|
||||||
}
|
|
||||||
const possibleDirs = [
|
const possibleDirs = [
|
||||||
"/opt/Obsidian",
|
"/opt/Obsidian",
|
||||||
"/usr/lib/Obsidian",
|
"/usr/lib/Obsidian",
|
||||||
@ -41,28 +40,48 @@ export function getExe(): string {
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
async function selectNewVault(page: Page, vaultPath: string) {
|
function checkToy() {
|
||||||
try {
|
if (process.platform == "darwin") {
|
||||||
let btn = await page.locator("button", { hasText: "Open" });
|
throw new Error("use a non-toy operating system, dumbass");
|
||||||
const promise = page.waitForEvent("filechooser");
|
}
|
||||||
await btn.click();
|
}
|
||||||
const chooser = await promise;
|
|
||||||
let el = chooser.element();
|
function generateVaultConfig(vault: string) {
|
||||||
console.log("chooser el", el);
|
const vaultHash = randomBytes(16).toString("hex").toLocaleLowerCase();
|
||||||
el.setInputFiles(vaultPath);
|
let configLocation;
|
||||||
} catch (e) {
|
checkToy();
|
||||||
console.error(e);
|
if (process.platform == "win32") {
|
||||||
console.debug(
|
configLocation = path.join(`${process.env.LOCALAPPDATA}`, "Obsidian");
|
||||||
"congratulations, you don't have to choose a vault manually!"
|
} else {
|
||||||
);
|
configLocation = path.join(`${process.env.XDG_CONFIG_HOME}`, "obsidian");
|
||||||
|
}
|
||||||
|
const obsidianConfigFile = path.join(configLocation, "obsidian.json");
|
||||||
|
const json: {
|
||||||
|
vaults: {
|
||||||
|
[key: string]: {
|
||||||
|
path: string;
|
||||||
|
ts: number;
|
||||||
|
open?: boolean;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
} = JSON.parse(readFileSync(obsidianConfigFile).toString());
|
||||||
|
|
||||||
|
if (!Object.values(json.vaults).some((a) => a.path === vault)) {
|
||||||
|
json.vaults[vaultHash] = {
|
||||||
|
path: vault,
|
||||||
|
ts: Date.now(),
|
||||||
|
};
|
||||||
|
writeFileSync(obsidianConfigFile, JSON.stringify(json));
|
||||||
|
writeFileSync(path.join(configLocation, `${vaultHash}.json`), "{}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const obsidianTestFixtures: Fixtures<ObsidianTestFixtures> = {
|
const obsidianTestFixtures: Fixtures<ObsidianTestFixtures> = {
|
||||||
electronApp: [
|
electronApp: [
|
||||||
async ({}, run) => {
|
async ({ obsidian: { vault } }, run) => {
|
||||||
process.env.ELECTRON_DISABLE_SECURITY_WARNINGS = "true";
|
process.env.ELECTRON_DISABLE_SECURITY_WARNINGS = "true";
|
||||||
console.log("asar located at:", getExe());
|
console.log("asar located at:", getExe());
|
||||||
|
if (vault) generateVaultConfig(vault);
|
||||||
const electronApp = await electron.launch({
|
const electronApp = await electron.launch({
|
||||||
timeout: 60000,
|
timeout: 60000,
|
||||||
args: [getExe()].filter((a) => !!a) as string[],
|
args: [getExe()].filter((a) => !!a) as string[],
|
||||||
@ -79,13 +98,12 @@ const obsidianTestFixtures: Fixtures<ObsidianTestFixtures> = {
|
|||||||
{ timeout: 60000 },
|
{ timeout: 60000 },
|
||||||
],
|
],
|
||||||
page: [
|
page: [
|
||||||
async ({ electronApp, obsidian: { vault } }, run) => {
|
async ({ electronApp }, run) => {
|
||||||
const windows = electronApp.windows();
|
const windows = electronApp.windows();
|
||||||
// console.log("windows", windows);
|
// console.log("windows", windows);
|
||||||
let page = windows[windows.length - 1]!;
|
let page = windows[windows.length - 1]!;
|
||||||
await page.waitForEvent("load");
|
await page.waitForEvent("load");
|
||||||
await page.waitForLoadState("domcontentloaded");
|
await page.waitForLoadState("domcontentloaded");
|
||||||
await selectNewVault(page, vault!);
|
|
||||||
page = electronApp.windows()[electronApp.windows().length - 1]!;
|
page = electronApp.windows()[electronApp.windows().length - 1]!;
|
||||||
await page.waitForEvent("load");
|
await page.waitForEvent("load");
|
||||||
await page.waitForLoadState("domcontentloaded");
|
await page.waitForLoadState("domcontentloaded");
|
||||||
|
Loading…
Reference in New Issue
Block a user