Skip to content

Commit 86c113e

Browse files
authored
Web app: similar support to the URI scheme should work no matter where the Web app is deployed.
2 parents 261c33b + d6dedf1 commit 86c113e

File tree

7 files changed

+40
-44
lines changed

7 files changed

+40
-44
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"url": "git+https://github.com/opencor/webapp.git"
2424
},
2525
"type": "module",
26-
"version": "2025.03.17",
26+
"version": "2025.03.18",
2727
"pnpm": {
2828
"onlyBuiltDependencies": [
2929
"electron",

src/constants.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export const URI_SCHEME = 'opencor'
2+
export const FULL_URI_SCHEME = `${URI_SCHEME}://`
3+
4+
export const SHORT_DELAY = 69
5+
export const LONG_DELAY = 369
6+
7+
export const TOAST_LIFE = 3000

src/main/MainWindow.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import electron from 'electron'
22
import * as electronSettings from 'electron-settings'
33
import path from 'path'
44

5+
import { FULL_URI_SCHEME, LONG_DELAY, SHORT_DELAY } from '../constants'
56
import { isDevMode, isMacOs } from '../electron'
67

78
import icon from './assets/icon.png?asset'
8-
import { URI_SCHEME } from './index'
99
import { ApplicationWindow } from './ApplicationWindow'
1010
import { disableMainMenu, enableMainMenu } from './MainMenu'
1111
import type { SplashScreenWindow } from './SplashScreenWindow'
@@ -85,18 +85,16 @@ export class MainWindow extends ApplicationWindow {
8585
// (also with a short delay if needed).
8686

8787
this.once('show', () => {
88-
let handleCommandLineDelay = 0
88+
let handleCommandLineDelay = SHORT_DELAY
8989

9090
if (!this._splashScreenWindowClosed && !!splashScreenWindow) {
91-
const SHORT_DELAY = 369
92-
9391
this._splashScreenWindowClosed = true
9492

95-
handleCommandLineDelay = SHORT_DELAY
93+
handleCommandLineDelay = LONG_DELAY
9694

9795
setTimeout(() => {
9896
splashScreenWindow.close()
99-
}, SHORT_DELAY)
97+
}, LONG_DELAY)
10098
}
10199

102100
setTimeout(() => {
@@ -168,10 +166,8 @@ export class MainWindow extends ApplicationWindow {
168166

169167
// Handle our command line arguments.
170168

171-
private _FULL_URI_SCHEME = `${URI_SCHEME}://`
172-
173169
isAction(argument: string): boolean {
174-
return argument.startsWith(this._FULL_URI_SCHEME)
170+
return argument.startsWith(FULL_URI_SCHEME)
175171
}
176172

177173
handleArguments(commandLine: string[]): void {
@@ -181,7 +177,7 @@ export class MainWindow extends ApplicationWindow {
181177

182178
commandLine.forEach((argument) => {
183179
if (this.isAction(argument)) {
184-
this.webContents.send('action', argument.slice(this._FULL_URI_SCHEME.length))
180+
this.webContents.send('action', argument.slice(FULL_URI_SCHEME.length))
185181
} else if (argument !== '--allow-file-access-from-files' && argument !== '--enable-avfoundation') {
186182
// The argument is not an action (and not --allow-file-access-from-files or --enable-avfoundation either), so it
187183
// must be a file to open. But, first, check whether the argument is a relative path and, if so, convert it to

src/main/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import fs from 'fs'
66
import * as nodeChildProcess from 'node:child_process'
77
import path from 'path'
88

9+
import { URI_SCHEME } from '../constants'
910
import { isDevMode, isWindows, isLinux } from '../electron'
1011

1112
import { disableMainMenu, enableMainMenu } from './MainMenu'
@@ -27,8 +28,6 @@ if (electronSettings.getSync('resetAll')) {
2728

2829
// Register our URI scheme.
2930

30-
export const URI_SCHEME = 'opencor'
31-
3231
electron.app.setAsDefaultProtocolClient(URI_SCHEME, isWindows() ? process.execPath : undefined)
3332

3433
if (isLinux()) {

src/renderer/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"url": "git+https://github.com/opencor/webapp.git"
1717
},
1818
"type": "module",
19-
"version": "2025.03.17",
19+
"version": "2025.03.18",
2020
"devDependencies": {
2121
"@primeuix/themes": "^1.0.0",
2222
"@primevue/auto-import-resolver": "^4.3.2",

src/renderer/src/App.vue

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import { useToast } from 'primevue/usetoast'
2727
import * as vue from 'vue'
2828
import * as vueusecore from '@vueuse/core'
2929
30+
import { SHORT_DELAY, TOAST_LIFE } from '../../constants'
3031
import { electronAPI } from '../../electronAPI'
3132
import * as locAPI from '../../libopencor/locAPI'
3233
@@ -51,9 +52,6 @@ function handleAction(action: string): void {
5152
const actionName = index !== -1 ? action.substring(0, index) : action
5253
const actionArguments = index !== -1 ? action.substring(index + 1) : ''
5354
54-
console.log(`actionName: >${actionName}<`)
55-
console.log(`actionArguments: >${actionArguments}<`)
56-
5755
if (isAction(actionName, 'openAboutDialog')) {
5856
onAbout()
5957
} else if (isAction(actionName, 'openSettingsDialog')) {
@@ -68,6 +66,13 @@ function handleAction(action: string): void {
6866
for (const filePath of filePaths) {
6967
openFile(filePath)
7068
}
69+
} else {
70+
toast.add({
71+
severity: 'error',
72+
summary: 'Handling an action',
73+
detail: action + '\n\nThe action could not be handled.',
74+
life: TOAST_LIFE
75+
})
7176
}
7277
}
7378
}
@@ -115,7 +120,7 @@ electronAPI?.onCheckForUpdates(() => {
115120
severity: 'info',
116121
summary: 'Check for updates',
117122
detail: 'The Check for updates dialog has yet to be implemented.',
118-
life: common.toastLife
123+
life: TOAST_LIFE
119124
})
120125
})
121126
@@ -142,7 +147,7 @@ function onSettings(): void {
142147
severity: 'info',
143148
summary: 'Settings',
144149
detail: 'The Settings dialog has yet to be implemented.',
145-
life: common.toastLife
150+
life: TOAST_LIFE
146151
})
147152
}
148153
@@ -180,7 +185,7 @@ function openFile(fileOrFilePath: string | File): void {
180185
(fileType === locAPI.FileType.UnknownFile
181186
? 'Only CellML files, SED-ML files, and COMBINE archives are supported.'
182187
: 'The file could not be retrieved.'),
183-
life: common.toastLife
188+
life: TOAST_LIFE
184189
})
185190
} else {
186191
contentsRef.value?.addFile(file)
@@ -199,7 +204,7 @@ function openFile(fileOrFilePath: string | File): void {
199204
severity: 'error',
200205
summary: 'Opening a file',
201206
detail: filePath + '\n\n' + (error instanceof Error ? error.message : String(error)),
202-
life: common.toastLife
207+
life: TOAST_LIFE
203208
})
204209
})
205210
}
@@ -277,37 +282,28 @@ function onResetAll(): void {
277282
278283
// Things that need to be done when the component is mounted.
279284
280-
const url = vueusecore.useStorage('url', '')
285+
const action = vueusecore.useStorage('action', '')
281286
282287
vue.onMounted(() => {
283-
// Check whether the URL contains an OpenCOR action, but with a bit of a delay to ensure that our background (with the
284-
// OpenCOR logo) is properly rendered.
288+
// Handle the action, if any. We handle the action with a bit of a delay to give our background (with the OpenCOR
289+
// logo) time to be renderered.
285290
// Note: to use vue.nextTick() doesn't do the trick, so we have no choice but to use setTimeout().
286291
287292
setTimeout(() => {
288-
console.log(`window.location.pathname: >${window.location.pathname}<`)
289-
290293
if (electronAPI === undefined) {
291-
console.log(`window.location.pathname: >${window.location.pathname}<`)
292-
293-
console.log('window.location.pathname starts with https://')
294-
if (window.location.pathname !== '/') {
295-
console.log(`window.location.pathname: >${window.location.pathname}<`)
296-
console.log('OLD url:', url.value)
297-
url.value = window.location.pathname
298-
console.log('NEW url:', url.value)
299-
300-
window.location.pathname = '/'
301-
} else {
302-
console.log(`window.location.pathname: >${window.location.pathname}<`)
303-
console.log('CRT url:', url.value.substring(1))
294+
if (window.location.search !== '') {
295+
action.value = window.location.search.substring(1)
304296
305-
handleAction(url.value.substring(1))
297+
window.location.search = ''
298+
} else if (action.value !== '') {
299+
setTimeout(() => {
300+
handleAction(action.value)
306301
307-
url.value = ''
302+
action.value = ''
303+
}, SHORT_DELAY)
308304
}
309305
}
310-
}, 0)
306+
}, SHORT_DELAY)
311307
})
312308
</script>
313309

src/renderer/src/common.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ import { UAParser } from 'ua-parser-js'
33
import { electronAPI } from '../../electronAPI'
44
import * as locAPI from '../../libopencor/locAPI'
55

6-
export const toastLife = 3000
7-
86
const uaParser = new UAParser()
97

108
export function isWindows(): boolean {

0 commit comments

Comments
 (0)