Skip to content

Commit

Permalink
Merge pull request #2 from CorrectRoadH/main
Browse files Browse the repository at this point in the history
feat: add custom memos url #1
  • Loading branch information
xudaolong authored Jan 6, 2024
2 parents 1a9fdb7 + db1656a commit c43be82
Show file tree
Hide file tree
Showing 5 changed files with 141 additions and 20 deletions.
Binary file added app/bin/memos
Binary file not shown.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@
"dependencies": {
"electron-debug": "^3.2.0",
"electron-log": "^4.4.8",
"electron-prompt": "^1.7.0",
"electron-store": "^8.1.0",
"electron-updater": "^5.3.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
Expand Down
34 changes: 31 additions & 3 deletions src/main/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import {
BrowserWindow,
MenuItemConstructorOptions,
} from 'electron';
import prompt from 'electron-prompt';
import Store from 'electron-store';

const store = new Store();

interface DarwinMenuItemConstructorOptions extends MenuItemConstructorOptions {
selector?: string;
Expand All @@ -27,9 +31,7 @@ export default class MenuBuilder {
}

const template =
process.platform === 'darwin'
? this.buildDarwinTemplate()
: [];
process.platform === 'darwin' ? this.buildDarwinTemplate() : [];

const menu = Menu.buildFromTemplate(template);
Menu.setApplicationMenu(menu);
Expand Down Expand Up @@ -75,6 +77,32 @@ export default class MenuBuilder {
},
{ label: 'Show All', selector: 'unhideAllApplications:' },
{ type: 'separator' },
{
label: 'Connect Another Memos Server',
click: () => {
const serverAddress =
store.get('serverAddress') || 'http://localhost:8081';
prompt({
title: 'Your Memos Server Address',
label: 'URL:',
value: serverAddress,
inputAttrs: {
type: 'url',
},
type: 'input',
})
.then((r: string | null) => {
if (r === null) {
console.log('user cancelled');
} else {
store.set('serverAddress', r);
this.mainWindow.loadURL(r);
}
return r;
})
.catch(console.error);
},
},
{
label: 'Quit',
accelerator: 'Command+Q',
Expand Down
10 changes: 8 additions & 2 deletions src/main/util.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import { URL } from 'url';
import Store from 'electron-store';

export function resolveHtmlPath() {
export default function resolveHtmlPath() {
const port = process.env.PORT || 8081;
const url = new URL(`http://localhost:${port}`);
const store = new Store();

const serverAddress = store.get('serverAddress') as string;
const url = serverAddress
? new URL(serverAddress)
: new URL(`http://localhost:${port}`);
url.pathname = '';
return url.href;
}
115 changes: 100 additions & 15 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2484,17 +2484,7 @@ ajv@^6.10.0, ajv@^6.12.0, ajv@^6.12.4, ajv@^6.12.5, ajv@^6.9.1:
json-schema-traverse "^0.4.1"
uri-js "^4.2.2"

ajv@^8.0.0:
version "8.12.0"
resolved "https://registry.npmmirror.com/ajv/-/ajv-8.12.0.tgz"
integrity sha512-sRu1kpcO9yLtYxBKvqfTeh9KzZEwO3STyX1HT+4CaDzC6HpTGYhIhPIzj9XuKU7KYDwnaeh5hcOwjy1QuJzBPA==
dependencies:
fast-deep-equal "^3.1.1"
json-schema-traverse "^1.0.0"
require-from-string "^2.0.2"
uri-js "^4.2.2"

ajv@^8.8.0, ajv@^8.8.2:
ajv@^8.0.0, ajv@^8.6.3, ajv@^8.8.0:
version "8.12.0"
resolved "https://registry.npmmirror.com/ajv/-/ajv-8.12.0.tgz"
integrity sha512-sRu1kpcO9yLtYxBKvqfTeh9KzZEwO3STyX1HT+4CaDzC6HpTGYhIhPIzj9XuKU7KYDwnaeh5hcOwjy1QuJzBPA==
Expand Down Expand Up @@ -2728,6 +2718,11 @@ at-least-node@^1.0.0:
resolved "https://registry.npmmirror.com/at-least-node/-/at-least-node-1.0.0.tgz"
integrity sha512-+q/t7Ekv1EDY2l6Gda6LLiX14rU9TV20Wa3ofeQmwPFZbOMo9DXrLbOjFaaclkXKWidIaopwAObQDqwWtGUjqg==

atomically@^1.7.0:
version "1.7.0"
resolved "https://registry.npmmirror.com/atomically/-/atomically-1.7.0.tgz#c07a0458432ea6dbc9a3506fffa424b48bccaafe"
integrity sha512-Xcz9l0z7y9yQ9rdDaxlmaI4uJHf/T8g9hOEzJcsEqX2SjCj4J20uK7+ldkDHMbpJDK76wF7xEIgxc/vSlsfw5w==

available-typed-arrays@^1.0.5:
version "1.0.5"
resolved "https://registry.npmmirror.com/available-typed-arrays/-/available-typed-arrays-1.0.5.tgz"
Expand Down Expand Up @@ -3401,6 +3396,22 @@ concurrently@^7.6.0:
tree-kill "^1.2.2"
yargs "^17.3.1"

conf@^10.2.0:
version "10.2.0"
resolved "https://registry.npmmirror.com/conf/-/conf-10.2.0.tgz#838e757be963f1a2386dfe048a98f8f69f7b55d6"
integrity sha512-8fLl9F04EJqjSqH+QjITQfJF8BrOVaYr1jewVgSRAEWePfxT0sku4w2hrGQ60BC/TNLGQ2pgxNlTbWQmMPFvXg==
dependencies:
ajv "^8.6.3"
ajv-formats "^2.1.1"
atomically "^1.7.0"
debounce-fn "^4.0.0"
dot-prop "^6.0.1"
env-paths "^2.2.1"
json-schema-typed "^7.0.3"
onetime "^5.1.2"
pkg-up "^3.1.0"
semver "^7.3.5"

confusing-browser-globals@^1.0.10:
version "1.0.11"
resolved "https://registry.npmmirror.com/confusing-browser-globals/-/confusing-browser-globals-1.0.11.tgz"
Expand Down Expand Up @@ -3664,7 +3675,14 @@ date-fns@^2.29.1:
resolved "https://registry.npmmirror.com/date-fns/-/date-fns-2.29.3.tgz"
integrity sha512-dDCnyH2WnnKusqvZZ6+jA1O51Ibt8ZMRNkDZdyAyK4YfbDwa/cEmuztzG5pk6hqlp9aSBPYcjOlktquahGwGeA==

debug@^2.6.8:
debounce-fn@^4.0.0:
version "4.0.0"
resolved "https://registry.npmmirror.com/debounce-fn/-/debounce-fn-4.0.0.tgz#ed76d206d8a50e60de0dd66d494d82835ffe61c7"
integrity sha512-8pYCQiL9Xdcg0UPSD3d+0KMlOjp+KGU5EPwYddgzQ7DATsg4fuUDjQtsYLmWjnk2obnNHgV3vE2Y4jejSOJVBQ==
dependencies:
mimic-fn "^3.0.0"

debug@2.6.9, debug@^2.6.8:
version "2.6.9"
resolved "https://registry.npmmirror.com/debug/-/debug-2.6.9.tgz"
integrity sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==
Expand Down Expand Up @@ -3946,6 +3964,13 @@ dot-case@^3.0.4:
no-case "^3.0.4"
tslib "^2.0.3"

dot-prop@^6.0.1:
version "6.0.1"
resolved "https://registry.npmmirror.com/dot-prop/-/dot-prop-6.0.1.tgz#fc26b3cf142b9e59b74dbd39ed66ce620c681083"
integrity sha512-tE7ztYzXHIeyvc7N+hR3oi7FIbf/NIjVP9hmAt3yMXzrQ072/fpjGLx2GxNxGxUl5V73MEqYzioOMoVhGMJ5cA==
dependencies:
is-obj "^2.0.0"

dotenv-expand@^5.1.0:
version "5.1.0"
resolved "https://registry.npmmirror.com/dotenv-expand/-/dotenv-expand-5.1.0.tgz"
Expand Down Expand Up @@ -4046,6 +4071,11 @@ electron-osx-sign@^0.6.0:
minimist "^1.2.0"
plist "^3.0.1"

electron-prompt@^1.7.0:
version "1.7.0"
resolved "https://registry.npmmirror.com/electron-prompt/-/electron-prompt-1.7.0.tgz#6f9dedb2dac1dd6bad2e6592ab81cb87c37f2a35"
integrity sha512-IfqJYEgcRO6NuyPROo8AtdkAiZ6N9I1lQEf4dJAkPuhV5YgOHdmLqZJf6OXumZJfzrjpzCM5jHeYOrhGdgbnEA==

electron-publish@23.6.0:
version "23.6.0"
resolved "https://registry.npmmirror.com/electron-publish/-/electron-publish-23.6.0.tgz"
Expand All @@ -4059,6 +4089,14 @@ electron-publish@23.6.0:
lazy-val "^1.0.5"
mime "^2.5.2"

electron-store@^8.1.0:
version "8.1.0"
resolved "https://registry.npmmirror.com/electron-store/-/electron-store-8.1.0.tgz#46a398f2bd9aa83c4a9daaae28380e2b3b9c7597"
integrity sha512-2clHg/juMjOH0GT9cQ6qtmIvK183B39ZXR0bUoPwKwYHJsEF3quqyDzMFUAu+0OP8ijmN2CbPRAelhNbWUbzwA==
dependencies:
conf "^10.2.0"
type-fest "^2.17.0"

electron-to-chromium@^1.4.284:
version "1.4.328"
resolved "https://registry.npmmirror.com/electron-to-chromium/-/electron-to-chromium-1.4.328.tgz"
Expand Down Expand Up @@ -4164,7 +4202,7 @@ entities@^4.4.0:
resolved "https://registry.npmmirror.com/entities/-/entities-4.4.0.tgz"
integrity sha512-oYp7156SP8LkeGD0GF85ad1X9Ai79WtRsZ2gxJqtBuzH+98YUV6jkHEKlZkMbcrjJjIVJNIDP/3WL9wQkoPbWA==

env-paths@^2.2.0:
env-paths@^2.2.0, env-paths@^2.2.1:
version "2.2.1"
resolved "https://registry.npmmirror.com/env-paths/-/env-paths-2.2.1.tgz"
integrity sha512-+h1lkLKhZMTYjog1VEpJNG7NZJWcuc2DDk/qsqSTRRCOXiLjeQ1d1/udrUGhqMxUgAlwKNZ0cf2uqan5GLuS2A==
Expand Down Expand Up @@ -4843,7 +4881,7 @@ find-root@^1.1.0:
resolved "https://registry.npmmirror.com/find-root/-/find-root-1.1.0.tgz"
integrity sha512-NKfW6bec6GfKc0SGx1e07QZY9PE99u0Bft/0rzSD5k3sO/vwkVUpDUKVm5Gpp5Ue3YfShPFTX2070tDs5kB9Ng==

find-up@^4.0.0:
find-up@^4.0.0, find-up@^4.1.0:
version "4.1.0"
resolved "https://registry.npmmirror.com/find-up/-/find-up-4.1.0.tgz"
integrity sha512-PpOwAdQ/YlXQ2vj8a3h8IipDuYRi3wceVQQGYWxNINccq40Anw7BlsEXCMbt1Zt+OLA6Fq9suIpIWD0OsnISlw==
Expand Down Expand Up @@ -5709,6 +5747,11 @@ is-number@^7.0.0:
resolved "https://registry.npmmirror.com/is-number/-/is-number-7.0.0.tgz"
integrity sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==

is-obj@^2.0.0:
version "2.0.0"
resolved "https://registry.npmmirror.com/is-obj/-/is-obj-2.0.0.tgz#473fb05d973705e3fd9620545018ca8e22ef4982"
integrity sha512-drqDG3cbczxxEJRoOXcOjtdp1J/lyp1mNn0xaznRs8+muBhgQcrnbspox5X5fOw0HnMnbfDzvnEMEtqDEJEo8w==

is-path-inside@^3.0.3:
version "3.0.3"
resolved "https://registry.npmmirror.com/is-path-inside/-/is-path-inside-3.0.3.tgz"
Expand Down Expand Up @@ -6368,6 +6411,11 @@ json-schema-traverse@^1.0.0:
resolved "https://registry.npmmirror.com/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz"
integrity sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==

json-schema-typed@^7.0.3:
version "7.0.3"
resolved "https://registry.npmmirror.com/json-schema-typed/-/json-schema-typed-7.0.3.tgz#23ff481b8b4eebcd2ca123b4fa0409e66469a2d9"
integrity sha512-7DE8mpG+/fVw+dTpjbxnx47TaMnDfOI1jwft9g1VybltZCduyRQPJPvc+zzKY9WPHxhPWczyFuYa6I8Mw4iU5A==

json-stable-stringify-without-jsonify@^1.0.1:
version "1.0.1"
resolved "https://registry.npmmirror.com/json-stable-stringify-without-jsonify/-/json-stable-stringify-without-jsonify-1.0.1.tgz"
Expand Down Expand Up @@ -6541,6 +6589,14 @@ loader-utils@^2.0.0, loader-utils@^2.0.4:
emojis-list "^3.0.0"
json5 "^2.1.2"

locate-path@^3.0.0:
version "3.0.0"
resolved "https://registry.npmmirror.com/locate-path/-/locate-path-3.0.0.tgz#dbec3b3ab759758071b58fe59fc41871af21400e"
integrity sha512-7AO748wWnIhNqAuaty2ZWHkQHRSNfPVIsPIfwEOWO22AmaoVrWavlOcMR5nzTLNYvp36X220/maaRsrec1G65A==
dependencies:
p-locate "^3.0.0"
path-exists "^3.0.0"

locate-path@^5.0.0:
version "5.0.0"
resolved "https://registry.npmmirror.com/locate-path/-/locate-path-5.0.0.tgz"
Expand Down Expand Up @@ -6785,6 +6841,11 @@ mimic-fn@^2.1.0:
resolved "https://registry.npmmirror.com/mimic-fn/-/mimic-fn-2.1.0.tgz"
integrity sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg==

mimic-fn@^3.0.0:
version "3.1.0"
resolved "https://registry.npmmirror.com/mimic-fn/-/mimic-fn-3.1.0.tgz#65755145bbf3e36954b949c16450427451d5ca74"
integrity sha512-Ysbi9uYW9hFyfrThdDEQuykN4Ey6BuwPD2kpI5ES/nFTDn/98yxYNLZJcgUAKPT/mcrLLKaGzJR9YVxJrIdASQ==

mimic-response@^1.0.0:
version "1.0.1"
resolved "https://registry.npmmirror.com/mimic-response/-/mimic-response-1.0.1.tgz"
Expand Down Expand Up @@ -7252,7 +7313,7 @@ p-cancelable@^2.0.0:
resolved "https://registry.npmmirror.com/p-cancelable/-/p-cancelable-2.1.1.tgz"
integrity sha512-BZOr3nRQHOntUjTrH8+Lh54smKHoHyur8We1V8DSMVrl5A2malOOwuJRnKRDjSnkoeBh4at6BwEnb5I7Jl31wg==

p-limit@^2.2.0:
p-limit@^2.0.0, p-limit@^2.2.0:
version "2.3.0"
resolved "https://registry.npmmirror.com/p-limit/-/p-limit-2.3.0.tgz"
integrity sha512-//88mFWSJx8lxCzwdAABTJL2MyWB12+eIY7MDL2SqLmAkeKU9qxRvWuSyTjm3FUmpBEMuFfckAIqEaVGUDxb6w==
Expand All @@ -7266,6 +7327,13 @@ p-limit@^3.0.2, p-limit@^3.1.0:
dependencies:
yocto-queue "^0.1.0"

p-locate@^3.0.0:
version "3.0.0"
resolved "https://registry.npmmirror.com/p-locate/-/p-locate-3.0.0.tgz#322d69a05c0264b25997d9f40cd8a891ab0064a4"
integrity sha512-x+12w/To+4GFfgJhBEpiDcLozRJGegY+Ei7/z0tSLkMmxGZNybVMSfWj9aJn8Z5Fc7dBUNJOOVgPv2H7IwulSQ==
dependencies:
p-limit "^2.0.0"

p-locate@^4.1.0:
version "4.1.0"
resolved "https://registry.npmmirror.com/p-locate/-/p-locate-4.1.0.tgz"
Expand Down Expand Up @@ -7350,6 +7418,11 @@ pascal-case@^3.1.2:
no-case "^3.0.4"
tslib "^2.0.3"

path-exists@^3.0.0:
version "3.0.0"
resolved "https://registry.npmmirror.com/path-exists/-/path-exists-3.0.0.tgz#ce0ebeaa5f78cb18925ea7d810d7b59b010fd515"
integrity sha512-bpC7GYwiDYQ4wYLe+FA8lhRjhQCMcQGuSgGGqDkg/QerRWw9CmGRT0iSOVRSZJ29NMLZgIzqaljJ63oaL4NIJQ==

path-exists@^4.0.0:
version "4.0.0"
resolved "https://registry.npmmirror.com/path-exists/-/path-exists-4.0.0.tgz"
Expand Down Expand Up @@ -7420,6 +7493,13 @@ pkg-dir@^4.2.0:
dependencies:
find-up "^4.0.0"

pkg-up@^3.1.0:
version "3.1.0"
resolved "https://registry.npmmirror.com/pkg-up/-/pkg-up-3.1.0.tgz#100ec235cc150e4fd42519412596a28512a0def5"
integrity sha512-nDywThFk1i4BQK4twPQ6TA4RT8bDY96yeuCVBWL3ePARCiEKDRSrNGbFIgUJpLp+XeIR65v8ra7WuJOFUBtkMA==
dependencies:
find-up "^3.0.0"

plist@^3.0.1, plist@^3.0.4:
version "3.0.6"
resolved "https://registry.npmmirror.com/plist/-/plist-3.0.6.tgz"
Expand Down Expand Up @@ -9123,6 +9203,11 @@ type-fest@^0.21.3, "type-fest@>=0.17.0 <4.0.0":
resolved "https://registry.npmmirror.com/type-fest/-/type-fest-0.21.3.tgz"
integrity sha512-t0rzBq87m3fVcduHDUFhKmyyX+9eo6WQjZvf51Ea/M0Q7+T374Jp1aUiyUl0GKxp8M/OETVHSDvmkyPgvX+X2w==

type-fest@^2.17.0:
version "2.19.0"
resolved "https://registry.npmmirror.com/type-fest/-/type-fest-2.19.0.tgz#88068015bb33036a598b952e55e9311a60fd3a9b"
integrity sha512-RAH822pAdBgcNMAfWnCBU3CFZcfZ/i1eZjwFU/dsLKumyuuP3niueg2UAukXYF0E2AAoc82ZSSf9J0WQBinzHA==

type-is@~1.6.18:
version "1.6.18"
resolved "https://registry.npmmirror.com/type-is/-/type-is-1.6.18.tgz"
Expand Down

0 comments on commit c43be82

Please sign in to comment.