Compare commits

...

9 Commits

Author SHA1 Message Date
Kelvin Wu
5045393379
Merge e227333737 into 8d183c60f6 2024-09-27 09:32:20 +02:00
Oliver Schwendener
8d183c60f6
Upgraded vite to 5.4.8 2024-09-27 06:12:11 +02:00
Ethan Conneely
5b6b36a531
Merge pull request #1224 from oliverschwendener/IrishBruse-patch-1 2024-09-26 20:43:30 +01:00
Ethan Conneely
98337a9530
Typo 2024-09-26 18:54:38 +01:00
Ethan Conneely
2290f4845a
Add settings to vscode extensions docs 2024-09-26 18:33:10 +01:00
Kelvin Wu
e227333737
Fixed linting 2024-09-21 00:07:35 -07:00
Kelvin Wu
9c6729a0d5
Fixed Core Dependency bootstrap order 2024-09-19 03:04:14 -07:00
Kelvin Wu
044534d853
Fixed test 2024-09-19 02:21:20 -07:00
Kelvin Wu
1f53b9121c
Changed main and SingleInstanceLock 2024-09-18 04:00:15 -07:00
6 changed files with 56 additions and 40 deletions

View File

@ -4,6 +4,11 @@ This extension allows you to open recently edited projects and files in vscode.
![Example](example.png)
## Settings
- Prefix: the prefix that triggers the vscode extension.
- Command: The command that the extension will invoke to open vscode and pass it the recent item.
## About this extension
Author: [Ethan Conneely](https://github.com/IrishBruse)

9
package-lock.json generated
View File

@ -48,7 +48,7 @@
"tree-kill": "^1.2.2",
"typescript": "^5.5.2",
"typescript-eslint": "^8.3.0",
"vite": "^5.4.7",
"vite": "^5.4.8",
"vite-plugin-electron": "^0.28.8",
"vite-plugin-electron-renderer": "^0.14.6",
"vitest": "^2.1.1"
@ -10237,11 +10237,10 @@
}
},
"node_modules/vite": {
"version": "5.4.7",
"resolved": "https://registry.npmjs.org/vite/-/vite-5.4.7.tgz",
"integrity": "sha512-5l2zxqMEPVENgvzTuBpHer2awaetimj2BGkhBPdnwKbPNOlHsODU+oiazEZzLK7KhAnOrO+XGYJYn4ZlUhDtDQ==",
"version": "5.4.8",
"resolved": "https://registry.npmjs.org/vite/-/vite-5.4.8.tgz",
"integrity": "sha512-FqrItQ4DT1NC4zCUqMB4c4AZORMKIa0m8/URVCZ77OZ/QSNeJ54bU1vrFADbDsuwfIPcgknRkmqakQcgnL4GiQ==",
"dev": true,
"license": "MIT",
"dependencies": {
"esbuild": "^0.21.3",
"postcss": "^8.4.43",

View File

@ -49,7 +49,7 @@
"tree-kill": "^1.2.2",
"typescript": "^5.5.2",
"typescript-eslint": "^8.3.0",
"vite": "^5.4.7",
"vite": "^5.4.8",
"vite-plugin-electron": "^0.28.8",
"vite-plugin-electron-renderer": "^0.14.6",
"vitest": "^2.1.1"

View File

@ -1,32 +1,34 @@
import type { Dependencies } from "@Core/Dependencies";
import type { DependencyRegistry } from "@Core/DependencyRegistry";
import type { EventEmitter } from "@Core/EventEmitter";
import type { App } from "electron";
import { describe, expect, it, vi } from "vitest";
import { SingleInstanceLockModule } from "./SingleInstanceLockModule";
describe(SingleInstanceLockModule, () => {
it("should request single instance lock", () => {
const requestSingleInstanceLockMock = vi.fn().mockReturnValue(true);
const quickMock = vi.fn();
it("should register the event listener and event emitter", () => {
const on = vi.fn();
const app = <App>{
on: (event: string, callback: () => void) => on(event, callback),
};
SingleInstanceLockModule.bootstrap(<App>{
requestSingleInstanceLock: () => requestSingleInstanceLockMock(),
quit: () => quickMock(),
});
const emitEvent = vi.fn();
const eventEmitter = <EventEmitter>{
emitEvent: (event: string) => emitEvent(event),
};
expect(requestSingleInstanceLockMock).toHaveBeenCalledOnce();
expect(quickMock).not.toHaveBeenCalled();
});
const dependencyRegistry = <DependencyRegistry<Dependencies>>{
get: (key: keyof Dependencies) => {
const result = <Dependencies>{
App: app,
EventEmitter: eventEmitter,
};
it("should quit the application if another instance is already running", () => {
const requestSingleInstanceLockMock = vi.fn().mockReturnValue(false);
return result[key];
},
};
const quickMock = vi.fn();
SingleInstanceLockModule.bootstrap(<App>{
requestSingleInstanceLock: () => requestSingleInstanceLockMock(),
quit: () => quickMock(),
});
expect(requestSingleInstanceLockMock).toHaveBeenCalledOnce();
expect(quickMock).toHaveBeenCalledOnce();
SingleInstanceLockModule.bootstrap(dependencyRegistry);
expect(on).toHaveBeenCalled();
});
});

View File

@ -1,10 +1,13 @@
import type { App } from "electron";
import type { Dependencies } from "@Core/Dependencies";
import type { DependencyRegistry } from "@Core/DependencyRegistry";
export class SingleInstanceLockModule {
public static bootstrap(app: App) {
if (!app.requestSingleInstanceLock()) {
console.log("Quitting application. Reason: another instance is already running");
app.quit();
}
public static bootstrap(dependencyRegistry: DependencyRegistry<Dependencies>) {
const eventEmitter = dependencyRegistry.get("EventEmitter");
const app = dependencyRegistry.get("App");
app.on("second-instance", () => {
eventEmitter.emitEvent("hotkeyPressed");
});
}
}

View File

@ -1,13 +1,13 @@
import * as Electron from "electron";
import mitt from "mitt";
import { platform } from "os";
import * as Core from "./Core";
import * as Extensions from "./Extensions";
(async () => {
const main = async () => {
await Electron.app.whenReady();
Core.SingleInstanceLockModule.bootstrap(Electron.app);
const mitt = (await import("mitt")).default;
const platform = (await import("os")).platform;
const Core = await import("./Core");
const Extensions = await import("./Extensions");
Core.DockModule.bootstrap(Electron.app);
const dependencyRegistry = Core.DependencyRegistryModule.bootstrap();
@ -37,6 +37,7 @@ import * as Extensions from "./Extensions";
Core.XmlParserModule.bootstrap(dependencyRegistry);
Core.EventEmitterModule.bootstrap(dependencyRegistry);
Core.EventSubscriberModule.bootstrap(dependencyRegistry);
Core.SingleInstanceLockModule.bootstrap(dependencyRegistry);
Core.BrowserWindowNotifierModule.bootstrap(dependencyRegistry);
Core.DateProviderModule.bootstrap(dependencyRegistry);
Core.LoggerModule.bootstrap(dependencyRegistry);
@ -77,4 +78,10 @@ import * as Extensions from "./Extensions";
await Core.BrowserWindowModule.bootstrap(dependencyRegistry);
Core.RescanOrchestratorModule.bootstrap(dependencyRegistry);
})();
};
if (Electron.app.requestSingleInstanceLock()) {
main();
} else {
Electron.app.exit();
}