Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 57 additions & 9 deletions electron/lib/core/appMenu.cjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { Menu } = require("electron");
const { Menu, app } = require("electron");

// Sends a menu-action signal to the renderer for the given window.
function sendMenuAction(win, action) {
Expand Down Expand Up @@ -69,9 +69,23 @@ function buildAppMenuTemplate(win, context = {}) {
const fileSubmenu = screen === "document"
? [
{
label: "New Note",
accelerator: "CmdOrCtrl+N",
click: () => sendMenuAction(win, "new-note")
label: "New",
submenu: [
{
label: "Note",
accelerator: "CmdOrCtrl+N",
click: () => sendMenuAction(win, "new-note")
},
{
label: "Folder",
click: () => sendMenuAction(win, "new-folder")
},
{ type: "separator" },
{
label: "Workspace",
click: () => sendMenuAction(win, "new-workspace")
}
]
},
{
label: "Open Workspace",
Expand Down Expand Up @@ -127,13 +141,31 @@ function buildAppMenuTemplate(win, context = {}) {
click: () => sendMenuAction(win, "back-to-notes")
},
{ type: "separator" },
{ role: "quit" }
{
label: "Restart Notely",
click: () => sendMenuAction(win, "restart-app")
},
{ role: "quit", click: () => app.quit() }
]
: [
{
label: "New Note",
accelerator: "CmdOrCtrl+N",
click: () => sendMenuAction(win, "new-note")
label: "New",
submenu: [
{
label: "Note",
accelerator: "CmdOrCtrl+N",
click: () => sendMenuAction(win, "new-note")
},
{
label: "Folder",
click: () => sendMenuAction(win, "new-folder")
},
{ type: "separator" },
{
label: "Workspace",
click: () => sendMenuAction(win, "new-workspace")
}
]
},
{
label: "Open Workspace",
Expand Down Expand Up @@ -162,7 +194,11 @@ function buildAppMenuTemplate(win, context = {}) {
click: () => sendMenuAction(win, "remove-folder")
},
{ type: "separator" },
{ role: "quit" }
{
label: "Restart Notely",
click: () => sendMenuAction(win, "restart-app")
},
{ role: "quit", click: () => app.quit() }
];

const editSubmenu = [
Expand Down Expand Up @@ -504,11 +540,23 @@ function buildAppMenuTemplate(win, context = {}) {
{
label: "Workspace",
submenu: [
{
label: "Workspace Information",
click: () => sendMenuAction(win, "open-workspace-info")
},
{
label: "Workspace Activity",
accelerator: "CmdOrCtrl+Shift+A",
click: () => sendMenuAction(win, "open-workspace-activity")
},
{
label: "Assets Library",
click: () => sendMenuAction(win, "open-assets")
},
{
label: "Trash / Removed Items",
click: () => sendMenuAction(win, "open-trash")
},
{
label: "Reload Workspace",
accelerator: "CmdOrCtrl+Alt+R",
Expand Down
69 changes: 66 additions & 3 deletions electron/lib/core/workspaceMetadata.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,25 @@ class WorkspaceMetadata {
if (this.fs.existsSync(p)) {
this.state = JSON.parse(this.fs.readFileSync(p, "utf8"));
} else {
this.state = { items: {} };
this.state = { items: {}, favorites: [], info: {} };
}
} catch {
this.state = { items: {} };
this.state = { items: {}, favorites: [], info: {} };
}
if (!this.state.items) this.state.items = {};
if (!Array.isArray(this.state.favorites)) this.state.favorites = [];
if (!this.state.info || typeof this.state.info !== "object") {
const root = this.getNotesRoot();
const defaultName = root ? this.path.basename(root) : "Workspace";
this.state.info = {
name: defaultName,
description: "",
domainTags: [],
projectType: "General",
primaryGoal: "",
icon: "",
color: "",
};
}
}

Expand Down Expand Up @@ -67,6 +82,44 @@ class WorkspaceMetadata {
return this.state?.items || {};
}

getFavorites() {
this._load();
return Array.isArray(this.state?.favorites) ? this.state.favorites : [];
}

setFavorites(favoritesList) {
this._load();
this.state.favorites = Array.isArray(favoritesList) ? favoritesList : [];
this._save();
return this.state.favorites;
}

getWorkspaceInfo() {
this._load();
const root = this.getNotesRoot();
const defaultName = root ? this.path.basename(root) : "Workspace";
return {
name: this.state.info?.name || defaultName,
description: this.state.info?.description || "",
domainTags: Array.isArray(this.state.info?.domainTags) ? this.state.info.domainTags : [],
projectType: this.state.info?.projectType || "General",
primaryGoal: this.state.info?.primaryGoal || "",
icon: this.state.info?.icon || "",
color: this.state.info?.color || "",
};
}

updateWorkspaceInfo(infoPayload) {
this._load();
const current = this.getWorkspaceInfo();
this.state.info = {
...current,
...infoPayload,
};
this._save();
return this.state.info;
}

updateMetadata(absolutePath, { icon, color }) {
this._load();
const relPath = this._getRelativePath(absolutePath);
Expand All @@ -89,8 +142,18 @@ class WorkspaceMetadata {
}
}

function validateIsWorkspace(fs, path, dirPath) {
if (!dirPath || typeof dirPath !== "string") return false;
try {
const metaFolder = path.join(dirPath, ".notes-app");
return fs.existsSync(metaFolder) && fs.statSync(metaFolder).isDirectory();
} catch {
return false;
}
}

function createWorkspaceMetadata(deps) {
return new WorkspaceMetadata(deps);
}

module.exports = { createWorkspaceMetadata };
module.exports = { createWorkspaceMetadata, validateIsWorkspace };
20 changes: 3 additions & 17 deletions electron/lib/git/gitService.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -111,17 +111,6 @@ async function initRepo(workspacePath) {

await g.init();

// README
const readmePath = path.join(workspacePath, "README.md");
if (!fs.existsSync(readmePath)) {
const name = path.basename(workspacePath);
fs.writeFileSync(
readmePath,
`# ${name}\n\nNotes workspace managed by [Notely](https://github.com/WGLabz/notely).\n`,
"utf8"
);
}

// .gitignore
const gitignorePath = path.join(workspacePath, ".gitignore");
if (!fs.existsSync(gitignorePath)) {
Expand Down Expand Up @@ -1049,13 +1038,10 @@ async function migrateFromLegacy(workspacePath, metadataStore = null) {
return ok({ alreadyMigrated: false, migrated: 0, skipped: 0 });
}

// Ensure we have a git repo to commit into
// Check if workspace is a git repository
const repoInfo = await getRepoInfo(workspacePath);
if (!repoInfo.ok) return repoInfo;

if (!repoInfo.data.isRepo) {
const initResult = await initRepo(workspacePath);
if (!initResult.ok) return initResult;
if (!repoInfo.ok || !repoInfo.data.isRepo) {
return ok({ alreadyMigrated: false, migrated: 0, skipped: 0 });
}

const repoRoot = repoInfo.data.repoRoot || (await findRepoRoot(workspacePath));
Expand Down
Loading
Loading