Compare commits
13 Commits
feature/ba
...
feat/extra
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
254145f0e5 | ||
|
|
c28f11336e | ||
|
|
2e30683b7b | ||
|
|
0af7b8b145 | ||
|
|
5d39b84886 | ||
|
|
537c4051cc | ||
|
|
d0a22bc517 | ||
|
|
19a75acf3f | ||
|
|
3f0abce874 | ||
|
|
36dd29f919 | ||
|
|
d7838f0b67 | ||
|
|
3353d4f436 | ||
|
|
7740154bdc |
@@ -535,6 +535,7 @@ export type FilteredCommandNames<T extends CommandData> = keyof Pick<CommandMapp
|
|||||||
|
|
||||||
export class AppContext extends Component {
|
export class AppContext extends Component {
|
||||||
isMainWindow: boolean;
|
isMainWindow: boolean;
|
||||||
|
windowId: string;
|
||||||
components: Component[];
|
components: Component[];
|
||||||
beforeUnloadListeners: (WeakRef<BeforeUploadListener> | (() => boolean))[];
|
beforeUnloadListeners: (WeakRef<BeforeUploadListener> | (() => boolean))[];
|
||||||
tabManager!: TabManager;
|
tabManager!: TabManager;
|
||||||
@@ -543,10 +544,11 @@ export class AppContext extends Component {
|
|||||||
|
|
||||||
lastSearchString?: string;
|
lastSearchString?: string;
|
||||||
|
|
||||||
constructor(isMainWindow: boolean) {
|
constructor(isMainWindow: boolean, windowId: string) {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
this.isMainWindow = isMainWindow;
|
this.isMainWindow = isMainWindow;
|
||||||
|
this.windowId = windowId;
|
||||||
// non-widget/layout components needed for the application
|
// non-widget/layout components needed for the application
|
||||||
this.components = [];
|
this.components = [];
|
||||||
this.beforeUnloadListeners = [];
|
this.beforeUnloadListeners = [];
|
||||||
@@ -676,8 +678,7 @@ export class AppContext extends Component {
|
|||||||
this.beforeUnloadListeners = this.beforeUnloadListeners.filter(l => l !== listener);
|
this.beforeUnloadListeners = this.beforeUnloadListeners.filter(l => l !== listener);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
const appContext = new AppContext(window.glob.isMainWindow, window.glob.windowId);
|
||||||
const appContext = new AppContext(window.glob.isMainWindow);
|
|
||||||
|
|
||||||
// we should save all outstanding changes before the page/app is closed
|
// we should save all outstanding changes before the page/app is closed
|
||||||
$(window).on("beforeunload", () => {
|
$(window).on("beforeunload", () => {
|
||||||
|
|||||||
@@ -142,14 +142,15 @@ export default class Entrypoints extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async openInWindowCommand({ notePath, hoistedNoteId, viewScope }: NoteCommandData) {
|
async openInWindowCommand({ notePath, hoistedNoteId, viewScope }: NoteCommandData) {
|
||||||
|
const extraWindowId = utils.randomString(4);
|
||||||
const extraWindowHash = linkService.calculateHash({ notePath, hoistedNoteId, viewScope });
|
const extraWindowHash = linkService.calculateHash({ notePath, hoistedNoteId, viewScope });
|
||||||
|
|
||||||
if (utils.isElectron()) {
|
if (utils.isElectron()) {
|
||||||
const { ipcRenderer } = utils.dynamicRequire("electron");
|
const { ipcRenderer } = utils.dynamicRequire("electron");
|
||||||
|
|
||||||
ipcRenderer.send("create-extra-window", { extraWindowHash });
|
ipcRenderer.send("create-extra-window", { extraWindowId, extraWindowHash });
|
||||||
} else {
|
} else {
|
||||||
const url = `${window.location.protocol}//${window.location.host}${window.location.pathname}?extraWindow=1${extraWindowHash}`;
|
const url = `${window.location.protocol}//${window.location.host}${window.location.pathname}?extraWindow=${extraWindowId}${extraWindowHash}`;
|
||||||
|
|
||||||
window.open(url, "", "width=1000,height=800");
|
window.open(url, "", "width=1000,height=800");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ import linkService from "../services/link.js";
|
|||||||
import type { EventData } from "./app_context.js";
|
import type { EventData } from "./app_context.js";
|
||||||
import type FNote from "../entities/fnote.js";
|
import type FNote from "../entities/fnote.js";
|
||||||
|
|
||||||
|
const MAX_SAVED_WINDOWS = 10;
|
||||||
|
|
||||||
interface TabState {
|
interface TabState {
|
||||||
contexts: NoteContext[];
|
contexts: NoteContext[];
|
||||||
position: number;
|
position: number;
|
||||||
@@ -41,9 +43,6 @@ export default class TabManager extends Component {
|
|||||||
this.recentlyClosedTabs = [];
|
this.recentlyClosedTabs = [];
|
||||||
|
|
||||||
this.tabsUpdate = new SpacedUpdate(async () => {
|
this.tabsUpdate = new SpacedUpdate(async () => {
|
||||||
if (!appContext.isMainWindow) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (options.is("databaseReadonly")) {
|
if (options.is("databaseReadonly")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -52,9 +51,21 @@ export default class TabManager extends Component {
|
|||||||
.map((nc) => nc.getPojoState())
|
.map((nc) => nc.getPojoState())
|
||||||
.filter((t) => !!t);
|
.filter((t) => !!t);
|
||||||
|
|
||||||
await server.put("options", {
|
// Update the current window’s openNoteContexts in options
|
||||||
openNoteContexts: JSON.stringify(openNoteContexts)
|
const savedWindows = options.getJson("openNoteContexts");
|
||||||
});
|
const win = savedWindows.find(w => w.windowId === appContext.windowId);
|
||||||
|
if (win) {
|
||||||
|
win.contexts = openNoteContexts;
|
||||||
|
} else {
|
||||||
|
savedWindows.push({
|
||||||
|
windowId: appContext.windowId,
|
||||||
|
createdAt: Date.now(),
|
||||||
|
closedAt: null,
|
||||||
|
contexts: openNoteContexts
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
await options.save("openNoteContexts", JSON.stringify(savedWindows));
|
||||||
});
|
});
|
||||||
|
|
||||||
appContext.addBeforeUnloadListener(this);
|
appContext.addBeforeUnloadListener(this);
|
||||||
@@ -69,8 +80,13 @@ export default class TabManager extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async loadTabs() {
|
async loadTabs() {
|
||||||
|
// Get the current window’s openNoteContexts
|
||||||
|
const savedWindows = options.getJson("openNoteContexts");
|
||||||
|
const currentWin = savedWindows.find(w => w.windowId === appContext.windowId);
|
||||||
|
const openNoteContexts = currentWin ? currentWin.contexts : undefined;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const noteContextsToOpen = (appContext.isMainWindow && options.getJson("openNoteContexts")) || [];
|
const noteContextsToOpen = openNoteContexts || [];
|
||||||
|
|
||||||
// preload all notes at once
|
// preload all notes at once
|
||||||
await froca.getNotes([...noteContextsToOpen.flatMap((tab: NoteContextState) =>
|
await froca.getNotes([...noteContextsToOpen.flatMap((tab: NoteContextState) =>
|
||||||
@@ -119,6 +135,32 @@ export default class TabManager extends Component {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Save window contents
|
||||||
|
if (currentWin) {
|
||||||
|
currentWin.createdAt = Date.now();
|
||||||
|
currentWin.closedAt = null;
|
||||||
|
currentWin.contexts = filteredNoteContexts;
|
||||||
|
} else {
|
||||||
|
// Filter out the oldest entry (excluding the main window)
|
||||||
|
if (savedWindows?.length >= MAX_SAVED_WINDOWS) {
|
||||||
|
const candidates = savedWindows.filter(w => w.windowId !== "main");
|
||||||
|
if (candidates.length > 0) {
|
||||||
|
const oldest = candidates.reduce((a, b) =>
|
||||||
|
a.createdAt < b.createdAt ? a : b
|
||||||
|
);
|
||||||
|
savedWindows.splice(savedWindows.indexOf(oldest), 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
savedWindows.push({
|
||||||
|
windowId: appContext.windowId,
|
||||||
|
createdAt: Date.now(),
|
||||||
|
closedAt: null,
|
||||||
|
contexts: filteredNoteContexts
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
await options.save("openNoteContexts", JSON.stringify(savedWindows));
|
||||||
|
|
||||||
// if there's a notePath in the URL, make sure it's open and active
|
// if there's a notePath in the URL, make sure it's open and active
|
||||||
// (useful, for e.g., opening clipped notes from clipper or opening link in an extra window)
|
// (useful, for e.g., opening clipped notes from clipper or opening link in an extra window)
|
||||||
if (parsedFromUrl.notePath) {
|
if (parsedFromUrl.notePath) {
|
||||||
|
|||||||
1
apps/client/src/types.d.ts
vendored
@@ -36,6 +36,7 @@ interface CustomGlobals {
|
|||||||
isProtectedSessionAvailable: boolean;
|
isProtectedSessionAvailable: boolean;
|
||||||
isDev: boolean;
|
isDev: boolean;
|
||||||
isMainWindow: boolean;
|
isMainWindow: boolean;
|
||||||
|
windowId: string;
|
||||||
maxEntityChangeIdAtLoad: number;
|
maxEntityChangeIdAtLoad: number;
|
||||||
maxEntityChangeSyncIdAtLoad: number;
|
maxEntityChangeSyncIdAtLoad: number;
|
||||||
assetPath: string;
|
assetPath: string;
|
||||||
|
|||||||
|
After Width: | Height: | Size: 545 B |
|
After Width: | Height: | Size: 727 B |
|
After Width: | Height: | Size: 828 B |
|
After Width: | Height: | Size: 931 B |
BIN
apps/desktop/src/assets/images/tray/closed-windowsTemplate.png
Normal file
|
After Width: | Height: | Size: 292 B |
|
After Width: | Height: | Size: 355 B |
|
After Width: | Height: | Size: 434 B |
|
After Width: | Height: | Size: 492 B |
@@ -6,6 +6,8 @@ import sqlInit from "@triliumnext/server/src/services/sql_init.js";
|
|||||||
import windowService from "@triliumnext/server/src/services/window.js";
|
import windowService from "@triliumnext/server/src/services/window.js";
|
||||||
import tray from "@triliumnext/server/src/services/tray.js";
|
import tray from "@triliumnext/server/src/services/tray.js";
|
||||||
import options from "@triliumnext/server/src/services/options.js";
|
import options from "@triliumnext/server/src/services/options.js";
|
||||||
|
import { randomString } from "@triliumnext/server/src/services/utils.js";
|
||||||
|
|
||||||
import electronDebug from "electron-debug";
|
import electronDebug from "electron-debug";
|
||||||
import electronDl from "electron-dl";
|
import electronDl from "electron-dl";
|
||||||
import { PRODUCT_NAME } from "./app-info";
|
import { PRODUCT_NAME } from "./app-info";
|
||||||
@@ -72,7 +74,8 @@ async function main() {
|
|||||||
app.on("second-instance", (event, commandLine) => {
|
app.on("second-instance", (event, commandLine) => {
|
||||||
const lastFocusedWindow = windowService.getLastFocusedWindow();
|
const lastFocusedWindow = windowService.getLastFocusedWindow();
|
||||||
if (commandLine.includes("--new-window")) {
|
if (commandLine.includes("--new-window")) {
|
||||||
windowService.createExtraWindow("");
|
const extraWindowId = randomString(4);
|
||||||
|
windowService.createExtraWindow(extraWindowId, "");
|
||||||
} else if (lastFocusedWindow) {
|
} else if (lastFocusedWindow) {
|
||||||
if (lastFocusedWindow.isMinimized()) {
|
if (lastFocusedWindow.isMinimized()) {
|
||||||
lastFocusedWindow.restore();
|
lastFocusedWindow.restore();
|
||||||
|
|||||||
@@ -382,6 +382,8 @@
|
|||||||
"tooltip": "Trilium Notes",
|
"tooltip": "Trilium Notes",
|
||||||
"close": "Quit Trilium",
|
"close": "Quit Trilium",
|
||||||
"recents": "Recent notes",
|
"recents": "Recent notes",
|
||||||
|
"recently-closed-windows": "Recently closed windows",
|
||||||
|
"tabs-total": "total {{number}} tabs",
|
||||||
"bookmarks": "Bookmarks",
|
"bookmarks": "Bookmarks",
|
||||||
"today": "Open today's journal note",
|
"today": "Open today's journal note",
|
||||||
"new-note": "New note",
|
"new-note": "New note",
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
</head>
|
</head>
|
||||||
<body
|
<body
|
||||||
id="trilium-app"
|
id="trilium-app"
|
||||||
class="desktop heading-style-<%= headingStyle %> layout-<%= layoutOrientation %> platform-<%= platform %> <%= isElectron ? 'electron' : '' %> <%= hasNativeTitleBar ? 'native-titlebar' : '' %> <%= hasBackgroundEffects ? 'background-effects' : '' %>"
|
class="desktop heading-style-<%= headingStyle %> layout-<%= layoutOrientation %> platform-<%= platform %> <%= isElectron ? 'electron' : '' %> <%= hasNativeTitleBar ? 'native-titlebar' : '' %> <%= hasBackgroundEffects ? 'background-effects' : '' %> <%= isMainWindow ? '' : 'extra-window' %>"
|
||||||
lang="<%= currentLocale.id %>" dir="<%= currentLocale.rtl ? 'rtl' : 'ltr' %>"
|
lang="<%= currentLocale.id %>" dir="<%= currentLocale.rtl ? 'rtl' : 'ltr' %>"
|
||||||
>
|
>
|
||||||
<noscript><%= t("javascript-required") %></noscript>
|
<noscript><%= t("javascript-required") %></noscript>
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
isDev: <%= isDev %>,
|
isDev: <%= isDev %>,
|
||||||
appCssNoteIds: <%- JSON.stringify(appCssNoteIds) %>,
|
appCssNoteIds: <%- JSON.stringify(appCssNoteIds) %>,
|
||||||
isMainWindow: <%= isMainWindow %>,
|
isMainWindow: <%= isMainWindow %>,
|
||||||
|
windowId: "<%= windowId %>",
|
||||||
isProtectedSessionAvailable: <%= isProtectedSessionAvailable %>,
|
isProtectedSessionAvailable: <%= isProtectedSessionAvailable %>,
|
||||||
triliumVersion: "<%= triliumVersion %>",
|
triliumVersion: "<%= triliumVersion %>",
|
||||||
assetPath: "<%= assetPath %>",
|
assetPath: "<%= assetPath %>",
|
||||||
|
|||||||
@@ -0,0 +1,48 @@
|
|||||||
|
import cls from "../services/cls.js";
|
||||||
|
import sql from "../services/sql.js";
|
||||||
|
|
||||||
|
export default () => {
|
||||||
|
cls.init(() => {
|
||||||
|
const row = sql.getRow<{ value: string }>(
|
||||||
|
`SELECT value FROM options WHERE name = 'openNoteContexts'`
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!row || !row.value) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let parsed: any;
|
||||||
|
try {
|
||||||
|
parsed = JSON.parse(row.value);
|
||||||
|
} catch {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Already in new format (array + windowId), skip
|
||||||
|
if (
|
||||||
|
Array.isArray(parsed) &&
|
||||||
|
parsed.length > 0 &&
|
||||||
|
parsed[0] &&
|
||||||
|
typeof parsed[0] === "object" &&
|
||||||
|
parsed[0].windowId
|
||||||
|
) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Old format: just contexts
|
||||||
|
const migrated = [
|
||||||
|
{
|
||||||
|
windowId: "main",
|
||||||
|
createdAt: 0,
|
||||||
|
closedAt: null,
|
||||||
|
contexts: parsed
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
sql.execute(
|
||||||
|
`UPDATE options SET value = ? WHERE name = 'openNoteContexts'`,
|
||||||
|
[JSON.stringify(migrated)]
|
||||||
|
);
|
||||||
|
|
||||||
|
});
|
||||||
|
};
|
||||||
@@ -6,6 +6,11 @@
|
|||||||
|
|
||||||
// Migrations should be kept in descending order, so the latest migration is first.
|
// Migrations should be kept in descending order, so the latest migration is first.
|
||||||
const MIGRATIONS: (SqlMigration | JsMigration)[] = [
|
const MIGRATIONS: (SqlMigration | JsMigration)[] = [
|
||||||
|
// Migrate openNoteContexts option to the new structured format with window metadata
|
||||||
|
{
|
||||||
|
version: 234,
|
||||||
|
module: async () => import("./0234__migrate_open_note_contexts_format")
|
||||||
|
},
|
||||||
// Migrate geo map to collection
|
// Migrate geo map to collection
|
||||||
{
|
{
|
||||||
version: 233,
|
version: 233,
|
||||||
|
|||||||
@@ -56,6 +56,7 @@ function index(req: Request, res: Response) {
|
|||||||
appCssNoteIds: getAppCssNoteIds(),
|
appCssNoteIds: getAppCssNoteIds(),
|
||||||
isDev,
|
isDev,
|
||||||
isMainWindow: view === "mobile" ? true : !req.query.extraWindow,
|
isMainWindow: view === "mobile" ? true : !req.query.extraWindow,
|
||||||
|
windowId: view !== "mobile" && req.query.extraWindow ? req.query.extraWindow : "main",
|
||||||
isProtectedSessionAvailable: protectedSessionService.isProtectedSessionAvailable(),
|
isProtectedSessionAvailable: protectedSessionService.isProtectedSessionAvailable(),
|
||||||
triliumVersion: packageJson.version,
|
triliumVersion: packageJson.version,
|
||||||
assetPath,
|
assetPath,
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import packageJson from "../../package.json" with { type: "json" };
|
|||||||
import dataDir from "./data_dir.js";
|
import dataDir from "./data_dir.js";
|
||||||
import { AppInfo } from "@triliumnext/commons";
|
import { AppInfo } from "@triliumnext/commons";
|
||||||
|
|
||||||
const APP_DB_VERSION = 233;
|
const APP_DB_VERSION = 234;
|
||||||
const SYNC_VERSION = 36;
|
const SYNC_VERSION = 36;
|
||||||
const CLIPPER_PROTOCOL_VERSION = "1.0";
|
const CLIPPER_PROTOCOL_VERSION = "1.0";
|
||||||
|
|
||||||
|
|||||||
@@ -72,6 +72,19 @@ function getOptionBool(name: FilterOptionsByType<boolean>): boolean {
|
|||||||
return val === "true";
|
return val === "true";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getOptionJson(name: OptionNames) {
|
||||||
|
const val = getOptionOrNull(name);
|
||||||
|
|
||||||
|
if (typeof val !== "string") {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return JSON.parse(val);
|
||||||
|
} catch (e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function setOption<T extends OptionNames>(name: T, value: string | OptionDefinitions[T]) {
|
function setOption<T extends OptionNames>(name: T, value: string | OptionDefinitions[T]) {
|
||||||
const option = becca.getOption(name);
|
const option = becca.getOption(name);
|
||||||
|
|
||||||
@@ -137,6 +150,7 @@ export default {
|
|||||||
getOption,
|
getOption,
|
||||||
getOptionInt,
|
getOptionInt,
|
||||||
getOptionBool,
|
getOptionBool,
|
||||||
|
getOptionJson,
|
||||||
setOption,
|
setOption,
|
||||||
createOption,
|
createOption,
|
||||||
getOptions,
|
getOptions,
|
||||||
|
|||||||
@@ -45,8 +45,15 @@ async function initNotSyncedOptions(initialized: boolean, opts: NotSyncedOpts =
|
|||||||
"openNoteContexts",
|
"openNoteContexts",
|
||||||
JSON.stringify([
|
JSON.stringify([
|
||||||
{
|
{
|
||||||
notePath: "root",
|
windowId: "main",
|
||||||
active: true
|
createdAt: 0,
|
||||||
|
closedAt: null,
|
||||||
|
contexts: [
|
||||||
|
{
|
||||||
|
notePath: "root",
|
||||||
|
active: true
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
]),
|
]),
|
||||||
false
|
false
|
||||||
@@ -257,8 +264,15 @@ function initStartupOptions() {
|
|||||||
"openNoteContexts",
|
"openNoteContexts",
|
||||||
JSON.stringify([
|
JSON.stringify([
|
||||||
{
|
{
|
||||||
notePath: process.env.TRILIUM_START_NOTE_ID || "root",
|
windowId: "main",
|
||||||
active: true
|
createdAt: 0,
|
||||||
|
closedAt: null,
|
||||||
|
contexts: [
|
||||||
|
{
|
||||||
|
notePath: process.env.TRILIUM_START_NOTE_ID || "root",
|
||||||
|
active: true
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
])
|
])
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -147,8 +147,15 @@ async function createInitialDatabase(skipDemoDb?: boolean) {
|
|||||||
"openNoteContexts",
|
"openNoteContexts",
|
||||||
JSON.stringify([
|
JSON.stringify([
|
||||||
{
|
{
|
||||||
notePath: startNoteId,
|
windowId: "main",
|
||||||
active: true
|
createdAt: 0,
|
||||||
|
closedAt: null,
|
||||||
|
contexts: [
|
||||||
|
{
|
||||||
|
notePath: startNoteId,
|
||||||
|
active: true
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
])
|
])
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -196,6 +196,44 @@ function updateTrayMenu() {
|
|||||||
return menuItems;
|
return menuItems;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function buildClosedWindowsMenu() {
|
||||||
|
const savedOpenNoteContexts = optionService.getOptionJson("openNoteContexts") || "[]";
|
||||||
|
const openedWindowIds = windowService.getAllWindowIds();
|
||||||
|
const closedWindows = savedOpenNoteContexts
|
||||||
|
.filter(win => !openedWindowIds.includes(win.windowId))
|
||||||
|
.sort((a, b) => {
|
||||||
|
// If closedAt is null, it indicates an abnormal closure and should be placed at the end
|
||||||
|
if (a.closedAt === null && b.closedAt === null) return 0;
|
||||||
|
if (a.closedAt === null) return 1;
|
||||||
|
if (b.closedAt === null) return -1;
|
||||||
|
// Otherwise, sort by time in descending order
|
||||||
|
return b.closedAt - a.closedAt;
|
||||||
|
});
|
||||||
|
const menuItems: Electron.MenuItemConstructorOptions[] = [];
|
||||||
|
for (const win of closedWindows) {
|
||||||
|
const activeCtx = win.contexts.find(c => c.active === true);
|
||||||
|
const activateNotePath = (activeCtx ?? win.contexts[0])?.notePath;
|
||||||
|
const activateNoteId = activateNotePath?.split("/").pop() ?? null;
|
||||||
|
|
||||||
|
// Get the title of the closed window
|
||||||
|
const rawTitle = activateNoteId ? becca_service.getNoteTitle(activateNoteId) : "";
|
||||||
|
let winTitle = rawTitle.length > 20 ? `${rawTitle.slice(0, 17)}...` : rawTitle;
|
||||||
|
const mainTabCount = win.contexts.filter(ctx => ctx.mainNtxId === null).length;
|
||||||
|
if (mainTabCount > 1) {
|
||||||
|
const tabSuffix = t("tray.tabs-total", { number: mainTabCount });
|
||||||
|
winTitle += ` (${tabSuffix})`;
|
||||||
|
}
|
||||||
|
|
||||||
|
menuItems.push({
|
||||||
|
label: winTitle,
|
||||||
|
type: "normal",
|
||||||
|
click: () => win.windowId !== "main" ? windowService.createExtraWindow(win.windowId, "") : windowService.createMainWindow()
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return menuItems;
|
||||||
|
}
|
||||||
|
|
||||||
const windowVisibilityMenuItems: Electron.MenuItemConstructorOptions[] = [];
|
const windowVisibilityMenuItems: Electron.MenuItemConstructorOptions[] = [];
|
||||||
|
|
||||||
// Only call getWindowTitle if windowVisibilityMap has more than one window
|
// Only call getWindowTitle if windowVisibilityMap has more than one window
|
||||||
@@ -258,6 +296,12 @@ function updateTrayMenu() {
|
|||||||
icon: getIconPath("recents"),
|
icon: getIconPath("recents"),
|
||||||
submenu: buildRecentNotesMenu()
|
submenu: buildRecentNotesMenu()
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
label: t("tray.recently-closed-windows"),
|
||||||
|
type: "submenu",
|
||||||
|
icon: getIconPath("closed-windows"),
|
||||||
|
submenu: buildClosedWindowsMenu()
|
||||||
|
},
|
||||||
{ type: "separator" },
|
{ type: "separator" },
|
||||||
{
|
{
|
||||||
label: t("tray.close"),
|
label: t("tray.close"),
|
||||||
|
|||||||
@@ -16,28 +16,45 @@ import { formatDownloadTitle, isMac, isWindows } from "./utils.js";
|
|||||||
// Prevent the window being garbage collected
|
// Prevent the window being garbage collected
|
||||||
let mainWindow: BrowserWindow | null;
|
let mainWindow: BrowserWindow | null;
|
||||||
let setupWindow: BrowserWindow | null;
|
let setupWindow: BrowserWindow | null;
|
||||||
let allWindows: BrowserWindow[] = []; // // Used to store all windows, sorted by the order of focus.
|
|
||||||
|
|
||||||
function trackWindowFocus(win: BrowserWindow) {
|
interface WindowEntry {
|
||||||
|
window: BrowserWindow;
|
||||||
|
windowId: string; // custom window ID
|
||||||
|
}
|
||||||
|
let allWindowEntries: WindowEntry[] = [];
|
||||||
|
|
||||||
|
function trackWindowFocus(win: BrowserWindow, windowId: string) {
|
||||||
// We need to get the last focused window from allWindows. If the last window is closed, we return the previous window.
|
// We need to get the last focused window from allWindows. If the last window is closed, we return the previous window.
|
||||||
// Therefore, we need to push the window into the allWindows array every time it gets focused.
|
// Therefore, we need to push the window into the allWindows array every time it gets focused.
|
||||||
win.on("focus", () => {
|
win.on("focus", () => {
|
||||||
allWindows = allWindows.filter(w => !w.isDestroyed() && w !== win);
|
allWindowEntries = allWindowEntries.filter(w => !w.window.isDestroyed() && w.window !== win);
|
||||||
allWindows.push(win);
|
allWindowEntries.push({ window: win, windowId: windowId });
|
||||||
|
|
||||||
if (!optionService.getOptionBool("disableTray")) {
|
if (!optionService.getOptionBool("disableTray")) {
|
||||||
electron.ipcMain.emit("reload-tray");
|
electron.ipcMain.emit("reload-tray");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
win.on("closed", () => {
|
win.on("closed", () => {
|
||||||
allWindows = allWindows.filter(w => !w.isDestroyed());
|
cls.wrap(() => {
|
||||||
|
const savedWindows = optionService.getOptionJson("openNoteContexts") || "[]";
|
||||||
|
|
||||||
|
const win = savedWindows.find(w => w.windowId === windowId);
|
||||||
|
if (win) {
|
||||||
|
win.closedAt = Date.now();
|
||||||
|
}
|
||||||
|
|
||||||
|
optionService.setOption("openNoteContexts", JSON.stringify(savedWindows));
|
||||||
|
})();
|
||||||
|
|
||||||
|
allWindowEntries = allWindowEntries.filter(w => !w.window.isDestroyed());
|
||||||
if (!optionService.getOptionBool("disableTray")) {
|
if (!optionService.getOptionBool("disableTray")) {
|
||||||
electron.ipcMain.emit("reload-tray");
|
electron.ipcMain.emit("reload-tray");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function createExtraWindow(extraWindowHash: string) {
|
async function createExtraWindow(extraWindowId: string, extraWindowHash: string) {
|
||||||
const spellcheckEnabled = optionService.getOptionBool("spellCheckEnabled");
|
const spellcheckEnabled = optionService.getOptionBool("spellCheckEnabled");
|
||||||
|
|
||||||
const { BrowserWindow } = await import("electron");
|
const { BrowserWindow } = await import("electron");
|
||||||
@@ -56,15 +73,15 @@ async function createExtraWindow(extraWindowHash: string) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
win.setMenuBarVisibility(false);
|
win.setMenuBarVisibility(false);
|
||||||
win.loadURL(`http://127.0.0.1:${port}/?extraWindow=1${extraWindowHash}`);
|
win.loadURL(`http://127.0.0.1:${port}/?extraWindow=${extraWindowId}${extraWindowHash}`);
|
||||||
|
|
||||||
configureWebContents(win.webContents, spellcheckEnabled);
|
configureWebContents(win.webContents, spellcheckEnabled);
|
||||||
|
|
||||||
trackWindowFocus(win);
|
trackWindowFocus(win, extraWindowId);
|
||||||
}
|
}
|
||||||
|
|
||||||
electron.ipcMain.on("create-extra-window", (event, arg) => {
|
electron.ipcMain.on("create-extra-window", (event, arg) => {
|
||||||
createExtraWindow(arg.extraWindowHash);
|
createExtraWindow(arg.extraWindowId, arg.extraWindowHash);
|
||||||
});
|
});
|
||||||
|
|
||||||
interface PrintOpts {
|
interface PrintOpts {
|
||||||
@@ -168,8 +185,8 @@ async function getBrowserWindowForPrinting(e: IpcMainEvent, notePath: string, ac
|
|||||||
return { browserWindow, printReport };
|
return { browserWindow, printReport };
|
||||||
}
|
}
|
||||||
|
|
||||||
async function createMainWindow(app: App) {
|
async function createMainWindow(app?: App) {
|
||||||
if ("setUserTasks" in app) {
|
if (app && "setUserTasks" in app) {
|
||||||
app.setUserTasks([
|
app.setUserTasks([
|
||||||
{
|
{
|
||||||
program: process.execPath,
|
program: process.execPath,
|
||||||
@@ -219,7 +236,7 @@ async function createMainWindow(app: App) {
|
|||||||
mainWindow.on("closed", () => (mainWindow = null));
|
mainWindow.on("closed", () => (mainWindow = null));
|
||||||
|
|
||||||
configureWebContents(mainWindow.webContents, spellcheckEnabled);
|
configureWebContents(mainWindow.webContents, spellcheckEnabled);
|
||||||
trackWindowFocus(mainWindow);
|
trackWindowFocus(mainWindow, "main");
|
||||||
}
|
}
|
||||||
|
|
||||||
function getWindowExtraOpts() {
|
function getWindowExtraOpts() {
|
||||||
@@ -381,11 +398,15 @@ function getMainWindow() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getLastFocusedWindow() {
|
function getLastFocusedWindow() {
|
||||||
return allWindows.length > 0 ? allWindows[allWindows.length - 1] : null;
|
return allWindowEntries.length > 0 ? allWindowEntries[allWindowEntries.length - 1]?.window : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getAllWindows() {
|
function getAllWindows() {
|
||||||
return allWindows;
|
return allWindowEntries.map(e => e.window);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getAllWindowIds(): string[] {
|
||||||
|
return allWindowEntries.map(e => e.windowId);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
@@ -396,5 +417,6 @@ export default {
|
|||||||
registerGlobalShortcuts,
|
registerGlobalShortcuts,
|
||||||
getMainWindow,
|
getMainWindow,
|
||||||
getLastFocusedWindow,
|
getLastFocusedWindow,
|
||||||
getAllWindows
|
getAllWindows,
|
||||||
|
getAllWindowIds
|
||||||
};
|
};
|
||||||
|
|||||||