Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
ollama
Commits
6fbd96da
Commit
6fbd96da
authored
Jul 06, 2023
by
Eva Ho
Browse files
prevent more than one instance
parent
7c2bb764
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
45 additions
and
42 deletions
+45
-42
app/src/index.ts
app/src/index.ts
+45
-42
No files found.
app/src/index.ts
View file @
6fbd96da
import
{
spawn
,
exec
}
from
'
child_process
'
import
{
app
,
autoUpdater
,
dialog
,
Tray
,
Menu
,
nativeTheme
}
from
'
electron
'
import
{
app
,
autoUpdater
,
dialog
,
Tray
,
Menu
,
nativeTheme
,
Notification
}
from
'
electron
'
import
*
as
path
from
'
path
'
import
*
as
fs
from
'
fs
'
require
(
'
@electron/remote/main
'
).
initialize
()
let
tray
:
Tray
|
null
=
null
let
secondInstance
:
Boolean
=
false
const
SingleInstanceLock
=
app
.
requestSingleInstanceLock
()
const
createSystemtray
=
()
=>
{
let
brightModeIconPath
=
path
.
join
(
__dirname
,
'
..
'
,
'
..
'
,
'
assets
'
,
'
ollama_icon_dark_16x16.png
'
)
...
...
@@ -108,52 +110,53 @@ function installCLI() {
})
}
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app
.
on
(
'
ready
'
,
()
=>
{
if
(
process
.
platform
===
'
darwin
'
)
{
app
.
dock
.
hide
()
if
(
!
app
.
isInApplicationsFolder
())
{
const
chosen
=
dialog
.
showMessageBoxSync
({
type
:
'
question
'
,
buttons
:
[
'
Move to Applications
'
,
'
Do Not Move
'
],
message
:
'
Move Ollama to the Applications directory?
'
,
defaultId
:
0
,
cancelId
:
1
})
if
(
chosen
===
0
)
{
try
{
app
.
moveToApplicationsFolder
({
conflictHandler
:
(
conflictType
)
=>
{
if
(
conflictType
===
'
existsAndRunning
'
)
{
dialog
.
showMessageBoxSync
({
type
:
'
info
'
,
message
:
'
Cannot move to Applications directory
'
,
detail
:
'
Another version of Ollama is currently running from your Applications directory. Close it first and try again.
'
})
if
(
!
SingleInstanceLock
)
{
app
.
quit
()
}
else
{
app
.
on
(
'
ready
'
,
()
=>
{
if
(
process
.
platform
===
'
darwin
'
)
{
app
.
dock
.
hide
()
if
(
!
app
.
isInApplicationsFolder
())
{
const
chosen
=
dialog
.
showMessageBoxSync
({
type
:
'
question
'
,
buttons
:
[
'
Move to Applications
'
,
'
Do Not Move
'
],
message
:
'
Move Ollama to the Applications directory?
'
,
defaultId
:
0
,
cancelId
:
1
})
if
(
chosen
===
0
)
{
try
{
app
.
moveToApplicationsFolder
({
conflictHandler
:
(
conflictType
)
=>
{
if
(
conflictType
===
'
existsAndRunning
'
)
{
dialog
.
showMessageBoxSync
({
type
:
'
info
'
,
message
:
'
Cannot move to Applications directory
'
,
detail
:
'
Another version of Ollama is currently running from your Applications directory. Close it first and try again.
'
})
}
return
true
}
return
true
}
})
return
}
catch
(
e
)
{
console
.
error
(
'
Failed to move to applications folder
'
)
console
.
error
(
e
)
})
return
}
catch
(
e
)
{
console
.
error
(
'
Failed to move to applications folder
'
)
console
.
error
(
e
)
}
}
}
}
}
createSystemtray
()
createSystemtray
()
if
(
app
.
isPackaged
)
{
installCLI
()
}
})
}
if
(
app
.
isPackaged
)
{
installCLI
()
}
})
// Quit when all windows are closed, except on macOS. There, it's common
// for applications and their menu bar to stay active until the user quits
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment