mirror of
https://github.com/ivabus/gui
synced 2025-04-23 14:07:14 +03:00
deep link improvements (#296)
* #293 package fullname to sveltekit slug * macos default behavior of cmd+w vs cmd+q * #293 open tea gui: when minimized, all windows closed, or when the app is closed * #293 open package page when minimized and restored via tea:// --------- Co-authored-by: neil <neil@neils-MacBook-Pro.local>
This commit is contained in:
parent
eae71795d4
commit
185712e1b7
4 changed files with 52 additions and 17 deletions
|
@ -88,8 +88,8 @@ pnpm dev
|
|||
|
||||
```sh
|
||||
pnpm install
|
||||
pnpm --filter desktop exec pnpm predist
|
||||
pnpm --filter desktop exec pnpm dist
|
||||
pnpm --filter tea exec pnpm predist
|
||||
pnpm --filter tea exec pnpm dist
|
||||
```
|
||||
|
||||
# Dependencies
|
||||
|
|
|
@ -43,6 +43,9 @@ const port = process.env.PORT || 3000;
|
|||
const allowDebug = !app.isPackaged || process.env.DEBUG_BUILD === "1";
|
||||
let mainWindow: BrowserWindow | null;
|
||||
|
||||
// todo: this is awful, there should be a way to check where all windows are closed in mac
|
||||
let macWindowClosed = false;
|
||||
|
||||
setupTitlebar();
|
||||
|
||||
function createWindow() {
|
||||
|
@ -147,29 +150,27 @@ function loadVite(port) {
|
|||
|
||||
function createMainWindow() {
|
||||
autoUpdater.checkForUpdatesAndNotify();
|
||||
mainWindow = createWindow();
|
||||
if (mainWindow) {
|
||||
if (mainWindow.isMinimized()) mainWindow.restore();
|
||||
mainWindow.focus();
|
||||
} else {
|
||||
mainWindow = createWindow();
|
||||
}
|
||||
|
||||
mainWindow.once("close", () => {
|
||||
mainWindow = null;
|
||||
});
|
||||
|
||||
if (mainWindow.isMinimized()) {
|
||||
mainWindow.restore();
|
||||
}
|
||||
|
||||
if (!app.isPackaged) {
|
||||
// dev
|
||||
loadVite(port);
|
||||
} else {
|
||||
serveURL(mainWindow);
|
||||
}
|
||||
|
||||
global.protocol_path = "hello-world";
|
||||
}
|
||||
|
||||
if (process.defaultApp) {
|
||||
if (process.argv.length >= 2) {
|
||||
app.setAsDefaultProtocolClient("tea", process.execPath, [path.resolve(process.argv[1])]);
|
||||
}
|
||||
app.setAsDefaultProtocolClient("tea", process.execPath, [path.resolve(process.argv[1])]);
|
||||
} else {
|
||||
app.setAsDefaultProtocolClient("tea");
|
||||
}
|
||||
|
@ -182,8 +183,11 @@ app.on("activate", () => {
|
|||
}
|
||||
});
|
||||
app.on("window-all-closed", async () => {
|
||||
await autoUpdater.quitAndInstall();
|
||||
app.quit();
|
||||
// mac ux is just minimize them when closed unless forced quite CMD+Q
|
||||
macWindowClosed = true;
|
||||
if (process.platform !== "darwin") {
|
||||
app.quit();
|
||||
}
|
||||
});
|
||||
|
||||
// NOTE: this doesnt work in linux
|
||||
|
@ -191,7 +195,31 @@ app.on("window-all-closed", async () => {
|
|||
app.on("open-url", (event, url) => {
|
||||
// ie url: tea://packages/slug
|
||||
event.preventDefault();
|
||||
teaProtocolPath = url.replace("tea:/", "");
|
||||
|
||||
const packagesPrefix = "/packages/";
|
||||
|
||||
let rawPath = url.replace("tea:/", "");
|
||||
|
||||
const isPackage = url.includes(packagesPrefix);
|
||||
if (isPackage) {
|
||||
// /packages/github.com/pypa/twine -> /packages/github_com_pypa_twine
|
||||
const packageSlug = rawPath
|
||||
.replace(packagesPrefix, "")
|
||||
.replace(/[^\w\s]/gi, "_")
|
||||
.toLocaleLowerCase();
|
||||
rawPath = [packagesPrefix, packageSlug].join("");
|
||||
}
|
||||
|
||||
teaProtocolPath = rawPath;
|
||||
|
||||
if (mainWindow && mainWindow.isMinimized()) {
|
||||
mainWindow.restore();
|
||||
log.info("restored");
|
||||
mainWindow?.webContents.send("sync-path");
|
||||
} else if (macWindowClosed) {
|
||||
log.info("open new window");
|
||||
createMainWindow();
|
||||
}
|
||||
});
|
||||
|
||||
ipcMain.handle("get-installed-packages", async () => {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"name": "@tea/desktop",
|
||||
"name": "tea",
|
||||
"version": "0.0.8",
|
||||
"private": true,
|
||||
"description": "tea gui app",
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
import TopBar from '$components/top-bar/top-bar.svelte';
|
||||
import SideBar from '$components/side-bar/side-bar.svelte';
|
||||
import { navStore, notificationStore } from '$libs/stores';
|
||||
import { listenToChannel } from "@native";
|
||||
|
||||
import Notification from "@tea/ui/notification/notification.svelte";
|
||||
|
||||
|
@ -31,10 +32,16 @@
|
|||
}
|
||||
});
|
||||
|
||||
onMount(async () => {
|
||||
const syncPath = async () => {
|
||||
// used by the tea:// protocol to suggest a path to open
|
||||
const path = await getProtocolPath();
|
||||
if (path) goto(path);
|
||||
}
|
||||
|
||||
onMount(async () => {
|
||||
// used by the tea:// protocol to suggest a path to open
|
||||
syncPath();
|
||||
listenToChannel("sync-path", syncPath);
|
||||
});
|
||||
</script>
|
||||
|
||||
|
|
Loading…
Reference in a new issue