Simplify path logic
This commit is contained in:
@@ -152,6 +152,8 @@ export class OpenCodeView extends ItemView {
|
||||
cls: "opencode-iframe-container",
|
||||
});
|
||||
|
||||
console.log("[OpenCode] Loading iframe with URL:", this.plugin.getServerUrl());
|
||||
|
||||
this.iframeEl = iframeContainer.createEl("iframe", {
|
||||
cls: "opencode-iframe",
|
||||
attr: {
|
||||
|
||||
@@ -9,18 +9,15 @@ export class ProcessManager {
|
||||
private lastError: string | null = null;
|
||||
private earlyExitCode: number | null = null;
|
||||
private settings: OpenCodeSettings;
|
||||
private workingDirectory: string;
|
||||
private projectDirectory: string;
|
||||
private onStateChange: (state: ProcessState) => void;
|
||||
|
||||
constructor(
|
||||
settings: OpenCodeSettings,
|
||||
workingDirectory: string,
|
||||
projectDirectory: string,
|
||||
onStateChange: (state: ProcessState) => void
|
||||
) {
|
||||
this.settings = settings;
|
||||
this.workingDirectory = workingDirectory;
|
||||
this.projectDirectory = projectDirectory;
|
||||
this.onStateChange = onStateChange;
|
||||
}
|
||||
@@ -71,7 +68,7 @@ export class ProcessManager {
|
||||
opencodePath: this.settings.opencodePath,
|
||||
port: this.settings.port,
|
||||
hostname: this.settings.hostname,
|
||||
cwd: this.workingDirectory,
|
||||
cwd: this.projectDirectory,
|
||||
projectDirectory: this.projectDirectory,
|
||||
});
|
||||
|
||||
@@ -87,7 +84,7 @@ export class ProcessManager {
|
||||
"app://obsidian.md",
|
||||
],
|
||||
{
|
||||
cwd: this.workingDirectory,
|
||||
cwd: this.projectDirectory,
|
||||
env: { ...process.env },
|
||||
stdio: ["ignore", "pipe", "pipe"],
|
||||
detached: false,
|
||||
|
||||
18
src/main.ts
18
src/main.ts
@@ -17,12 +17,10 @@ export default class OpenCodePlugin extends Plugin {
|
||||
|
||||
await this.loadSettings();
|
||||
|
||||
const vaultPath = this.getVaultPath();
|
||||
const projectDirectory = this.getProjectDirectory();
|
||||
|
||||
this.processManager = new ProcessManager(
|
||||
this.settings,
|
||||
vaultPath,
|
||||
projectDirectory,
|
||||
(state) => this.notifyStateChange(state)
|
||||
);
|
||||
@@ -182,7 +180,7 @@ export default class OpenCodePlugin extends Plugin {
|
||||
}
|
||||
|
||||
getServerUrl(): string {
|
||||
return this.processManager.getUrl() ?? `http://127.0.0.1:${this.settings.port}`;
|
||||
return this.processManager.getUrl();
|
||||
}
|
||||
|
||||
onProcessStateChange(callback: (state: ProcessState) => void): () => void {
|
||||
@@ -201,19 +199,17 @@ export default class OpenCodePlugin extends Plugin {
|
||||
}
|
||||
}
|
||||
|
||||
private getVaultPath(): string {
|
||||
getProjectDirectory(): string {
|
||||
if (this.settings.projectDirectory) {
|
||||
console.log("[OpenCode] Using project directory from settings:", this.settings.projectDirectory);
|
||||
return this.settings.projectDirectory;
|
||||
}
|
||||
const adapter = this.app.vault.adapter as any;
|
||||
const vaultPath = adapter.basePath || "";
|
||||
if (!vaultPath) {
|
||||
console.warn("[OpenCode] Warning: Could not determine vault path");
|
||||
}
|
||||
console.log("[OpenCode] Using vault path as project directory:", vaultPath);
|
||||
return vaultPath;
|
||||
}
|
||||
|
||||
getProjectDirectory(): string {
|
||||
if (this.settings.projectDirectory) {
|
||||
return this.settings.projectDirectory;
|
||||
}
|
||||
return this.getVaultPath();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user